Java Code Examples for com.android.internal.annotations.GuardedBy

The following examples show how to use com.android.internal.annotations.GuardedBy. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: AndroidComponentPlugin   Source File: ComponentResolver.java    License: Apache License 2.0 6 votes vote down vote up
@GuardedBy("mLock")
private void addServicesLocked(PackageParser.Package pkg, boolean chatty) {
    final int servicesSize = pkg.services.size();
    StringBuilder r = null;
    for (int i = 0; i < servicesSize; i++) {
        PackageParser.Service s = pkg.services.get(i);
        s.info.processName = fixProcessName(pkg.applicationInfo.processName,
                s.info.processName);
        mServices.addService(s);
        if (DEBUG_PACKAGE_SCANNING && chatty) {
            if (r == null) {
                r = new StringBuilder(256);
            } else {
                r.append(' ');
            }
            r.append(s.info.name);
        }
    }
    if (DEBUG_PACKAGE_SCANNING && chatty) {
        Log.d(TAG, "  Services: " + (r == null ? "<NONE>" : r));
    }
}
 
Example 2
Source Project: AndroidComponentPlugin   Source File: ContentService.java    License: Apache License 2.0 6 votes vote down vote up
@GuardedBy("mCache")
private void invalidateCacheLocked(int userId, String providerPackageName, Uri uri) {
    ArrayMap<String, ArrayMap<Pair<String, Uri>, Bundle>> userCache = mCache.get(userId);
    if (userCache == null) return;

    ArrayMap<Pair<String, Uri>, Bundle> packageCache = userCache.get(providerPackageName);
    if (packageCache == null) return;

    if (uri != null) {
        for (int i = 0; i < packageCache.size();) {
            final Pair<String, Uri> key = packageCache.keyAt(i);
            if (key.second != null && key.second.toString().startsWith(uri.toString())) {
                if (DEBUG) Slog.d(TAG, "Invalidating cache for key " + key);
                packageCache.removeAt(i);
            } else {
                i++;
            }
        }
    } else {
        if (DEBUG) Slog.d(TAG, "Invalidating cache for package " + providerPackageName);
        packageCache.clear();
    }
}
 
Example 3
Source Project: android_9.0.0_r45   Source File: NetworkStatsService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Clean up {@link #mUidRecorder} after UID is removed.
 */
@GuardedBy("mStatsLock")
private void removeUidsLocked(int... uids) {
    if (LOGV) Slog.v(TAG, "removeUidsLocked() for UIDs " + Arrays.toString(uids));

    // Perform one last poll before removing
    performPollLocked(FLAG_PERSIST_ALL);

    mUidRecorder.removeUidsLocked(uids);
    mUidTagRecorder.removeUidsLocked(uids);

    // Clear kernel stats associated with UID
    for (int uid : uids) {
        resetKernelUidStats(uid);
    }
}
 
Example 4
Source Project: android_9.0.0_r45   Source File: IpSecService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Removes a reference to this resource. If the resultant reference count is zero, the
 * underlying resources are freed, and references to all child resources are also dropped
 * recursively (resulting in them freeing their resources and children, etcetera)
 *
 * <p>This method also sets the reference count to an invalid value (-1) to signify that it
 * has been fully released. Any subsequent calls to this method will result in an
 * IllegalStateException being thrown due to resource already having been previously
 * released
 */
@VisibleForTesting
@GuardedBy("IpSecService.this")
public void releaseReference() throws RemoteException {
    mRefCount--;

    if (mRefCount > 0) {
        return;
    } else if (mRefCount < 0) {
        throw new IllegalStateException(
                "Invalid operation - resource has already been released.");
    }

    // Cleanup own resources
    mResource.freeUnderlyingResources();

    // Cleanup child resources as needed
    for (RefcountedResource<? extends IResource> child : mChildren) {
        child.releaseReference();
    }

    // Enforce that resource cleanup can only be called once
    // By decrementing the refcount (from 0 to -1), the next call will throw an
    // IllegalStateException - it has already been released fully.
    mRefCount--;
}
 
Example 5
Source Project: android_9.0.0_r45   Source File: AppStateTracker.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Add to / remove from {@link #mRunAnyRestrictedPackages}.
 */
@GuardedBy("mLock")
boolean updateForcedAppStandbyUidPackageLocked(int uid, @NonNull String packageName,
        boolean restricted) {
    final int index = findForcedAppStandbyUidPackageIndexLocked(uid, packageName);
    final boolean wasRestricted = index >= 0;
    if (wasRestricted == restricted) {
        return false;
    }
    if (restricted) {
        mRunAnyRestrictedPackages.add(Pair.create(uid, packageName));
    } else {
        mRunAnyRestrictedPackages.removeAt(index);
    }
    return true;
}
 
Example 6
Source Project: android_9.0.0_r45   Source File: FingerprintsUserState.java    License: Apache License 2.0 6 votes vote down vote up
@GuardedBy("this")
private void parseStateLocked(XmlPullParser parser)
        throws IOException, XmlPullParserException {
    final int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        String tagName = parser.getName();
        if (tagName.equals(TAG_FINGERPRINTS)) {
            parseFingerprintsLocked(parser);
        }
    }
}
 
Example 7
Source Project: android_9.0.0_r45   Source File: FingerprintsUserState.java    License: Apache License 2.0 6 votes vote down vote up
@GuardedBy("this")
private void parseFingerprintsLocked(XmlPullParser parser)
        throws IOException, XmlPullParserException {

    final int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        String tagName = parser.getName();
        if (tagName.equals(TAG_FINGERPRINT)) {
            String name = parser.getAttributeValue(null, ATTR_NAME);
            String groupId = parser.getAttributeValue(null, ATTR_GROUP_ID);
            String fingerId = parser.getAttributeValue(null, ATTR_FINGER_ID);
            String deviceId = parser.getAttributeValue(null, ATTR_DEVICE_ID);
            mFingerprints.add(new Fingerprint(name, Integer.parseInt(groupId),
                    Integer.parseInt(fingerId), Integer.parseInt(deviceId)));
        }
    }
}
 
Example 8
Source Project: android_9.0.0_r45   Source File: JobServiceContext.java    License: Apache License 2.0 6 votes vote down vote up
@GuardedBy("mLock")
void doCallbackLocked(boolean reschedule, String reason) {
    if (DEBUG) {
        Slog.d(TAG, "doCallback of : " + mRunningJob
                + " v:" + VERB_STRINGS[mVerb]);
    }
    removeOpTimeOutLocked();

    if (mVerb == VERB_STARTING) {
        handleStartedLocked(reschedule);
    } else if (mVerb == VERB_EXECUTING ||
            mVerb == VERB_STOPPING) {
        handleFinishedLocked(reschedule, reason);
    } else {
        if (DEBUG) {
            Slog.d(TAG, "Unrecognised callback: " + mRunningJob);
        }
    }
}
 
Example 9
Source Project: android_9.0.0_r45   Source File: JobServiceContext.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * A job can be in various states when a cancel request comes in:
 * VERB_BINDING    -> Cancelled before bind completed. Mark as cancelled and wait for
 *                    {@link #onServiceConnected(android.content.ComponentName, android.os.IBinder)}
 *     _STARTING   -> Mark as cancelled and wait for
 *                    {@link JobServiceContext#doAcknowledgeStartMessage}
 *     _EXECUTING  -> call {@link #sendStopMessageLocked}}, but only if there are no callbacks
 *                      in the message queue.
 *     _ENDING     -> No point in doing anything here, so we ignore.
 */
@GuardedBy("mLock")
private void handleCancelLocked(String reason) {
    if (JobSchedulerService.DEBUG) {
        Slog.d(TAG, "Handling cancel for: " + mRunningJob.getJobId() + " "
                + VERB_STRINGS[mVerb]);
    }
    switch (mVerb) {
        case VERB_BINDING:
        case VERB_STARTING:
            mCancelled = true;
            applyStoppedReasonLocked(reason);
            break;
        case VERB_EXECUTING:
            sendStopMessageLocked(reason);
            break;
        case VERB_STOPPING:
            // Nada.
            break;
        default:
            Slog.e(TAG, "Cancelling a job without a valid verb: " + mVerb);
            break;
    }
}
 
Example 10
Source Project: android_9.0.0_r45   Source File: UserManagerService.java    License: Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
@GuardedBy("mAppRestrictionsLock")
static void writeApplicationRestrictionsLAr(Bundle restrictions, AtomicFile restrictionsFile) {
    FileOutputStream fos = null;
    try {
        fos = restrictionsFile.startWrite();
        final BufferedOutputStream bos = new BufferedOutputStream(fos);

        final XmlSerializer serializer = new FastXmlSerializer();
        serializer.setOutput(bos, StandardCharsets.UTF_8.name());
        serializer.startDocument(null, true);
        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);

        serializer.startTag(null, TAG_RESTRICTIONS);
        writeBundle(restrictions, serializer);
        serializer.endTag(null, TAG_RESTRICTIONS);

        serializer.endDocument();
        restrictionsFile.finishWrite(fos);
    } catch (Exception e) {
        restrictionsFile.failWrite(fos);
        Slog.e(LOG_TAG, "Error writing application restrictions list", e);
    }
}
 
Example 11
Source Project: android_9.0.0_r45   Source File: MediaFocusControl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper function
 * Pre-conditions: focus stack is not empty, there is one or more locked focus owner
 *                 at the top of the focus stack
 * Push the focus requester onto the audio focus stack at the first position immediately
 * following the locked focus owners.
 * @return {@link AudioManager#AUDIOFOCUS_REQUEST_GRANTED} or
 *     {@link AudioManager#AUDIOFOCUS_REQUEST_DELAYED}
 */
@GuardedBy("mAudioFocusLock")
private int pushBelowLockedFocusOwners(FocusRequester nfr) {
    int lastLockedFocusOwnerIndex = mFocusStack.size();
    for (int index = mFocusStack.size()-1; index >= 0; index--) {
        if (isLockedFocusOwner(mFocusStack.elementAt(index))) {
            lastLockedFocusOwnerIndex = index;
        }
    }
    if (lastLockedFocusOwnerIndex == mFocusStack.size()) {
        // this should not happen, but handle it and log an error
        Log.e(TAG, "No exclusive focus owner found in propagateFocusLossFromGain_syncAf()",
                new Exception());
        // no exclusive owner, push at top of stack, focus is granted, propagate change
        propagateFocusLossFromGain_syncAf(nfr.getGainRequest(), nfr, false /*forceDuck*/);
        mFocusStack.push(nfr);
        return AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
    } else {
        mFocusStack.insertElementAt(nfr, lastLockedFocusOwnerIndex);
        return AudioManager.AUDIOFOCUS_REQUEST_DELAYED;
    }
}
 
Example 12
Source Project: android_9.0.0_r45   Source File: PackageStatusStorage.java    License: Apache License 2.0 6 votes vote down vote up
@GuardedBy("this")
private PackageStatus getPackageStatusLocked() throws ParseException {
    try (FileInputStream fis = mPackageStatusFile.openRead()) {
        XmlPullParser parser = parseToPackageStatusTag(fis);
        Integer checkStatus = getNullableIntAttribute(parser, ATTRIBUTE_CHECK_STATUS);
        if (checkStatus == null) {
            return null;
        }
        int updateAppVersion = getIntAttribute(parser, ATTRIBUTE_UPDATE_APP_VERSION);
        int dataAppVersion = getIntAttribute(parser, ATTRIBUTE_DATA_APP_VERSION);
        return new PackageStatus(checkStatus,
                new PackageVersions(updateAppVersion, dataAppVersion));
    } catch (IOException e) {
        ParseException e2 = new ParseException("Error reading package status", 0);
        e2.initCause(e);
        throw e2;
    }
}
 
Example 13
Source Project: android_9.0.0_r45   Source File: ShortcutService.java    License: Apache License 2.0 6 votes vote down vote up
@GuardedBy("mLock")
private void saveUserInternalLocked(@UserIdInt int userId, OutputStream os,
        boolean forBackup) throws IOException, XmlPullParserException {

    final BufferedOutputStream bos = new BufferedOutputStream(os);

    // Write to XML
    XmlSerializer out = new FastXmlSerializer();
    out.setOutput(bos, StandardCharsets.UTF_8.name());
    out.startDocument(null, true);

    getUserShortcutsLocked(userId).saveToXml(out, forBackup);

    out.endDocument();

    bos.flush();
    os.flush();
}
 
Example 14
Source Project: android_9.0.0_r45   Source File: AutofillManager.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mLock")
private void addEnteredIdLocked(@NonNull AutofillId id) {
    if (mEnteredIds == null) {
        mEnteredIds = new ArraySet<>(1);
    }
    mEnteredIds.add(id);
}
 
Example 15
Source Project: android_9.0.0_r45   Source File: AssetManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that the native implementation has not been destroyed.
 * The AssetManager may have been closed, but references to it still exist
 * and therefore the native implementation is not destroyed.
 */
@GuardedBy("this")
private void ensureValidLocked() {
    if (mObject == 0) {
        throw new RuntimeException("AssetManager has been destroyed");
    }
}
 
Example 16
Source Project: android_9.0.0_r45   Source File: AutofillManager.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mLock")
private boolean shouldIgnoreViewEnteredLocked(@NonNull AutofillId id, int flags) {
    if (isDisabledByServiceLocked()) {
        if (sVerbose) {
            Log.v(TAG, "ignoring notifyViewEntered(flags=" + flags + ", view=" + id
                    + ") on state " + getStateAsStringLocked() + " because disabled by svc");
        }
        return true;
    }
    if (isFinishedLocked()) {
        // Session already finished: ignore if automatic request and view already entered
        if ((flags & FLAG_MANUAL_REQUEST) == 0 && mEnteredIds != null
                && mEnteredIds.contains(id)) {
            if (sVerbose) {
                Log.v(TAG, "ignoring notifyViewEntered(flags=" + flags + ", view=" + id
                        + ") on state " + getStateAsStringLocked()
                        + " because view was already entered: " + mEnteredIds);
            }
            return true;
        }
    }
    if (sVerbose) {
        Log.v(TAG, "not ignoring notifyViewEntered(flags=" + flags + ", view=" + id
                + ", state " + getStateAsStringLocked() + ", enteredIds=" + mEnteredIds);
    }
    return false;
}
 
Example 17
Source Project: android_9.0.0_r45   Source File: AppFuseBridge.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("AppFuseBridge.this")
void setMountResultLocked(boolean result) {
    if (mMounted.getCount() == 0) {
        return;
    }
    mMountResult = result;
    mMounted.countDown();
}
 
Example 18
Source Project: android_9.0.0_r45   Source File: ShortcutService.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mLock")
@VisibleForTesting
void saveBaseStateLocked() {
    final AtomicFile file = getBaseStateFile();
    if (DEBUG) {
        Slog.d(TAG, "Saving to " + file.getBaseFile());
    }

    FileOutputStream outs = null;
    try {
        outs = file.startWrite();

        // Write to XML
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(outs, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, TAG_ROOT);

        // Body.
        writeTagValue(out, TAG_LAST_RESET_TIME, mRawLastResetTime);

        // Epilogue.
        out.endTag(null, TAG_ROOT);
        out.endDocument();

        // Close.
        file.finishWrite(outs);
    } catch (IOException e) {
        Slog.e(TAG, "Failed to write to file " + file.getBaseFile(), e);
        file.failWrite(outs);
    }
}
 
Example 19
Source Project: android_9.0.0_r45   Source File: ProcessStatsService.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mAm")
public boolean setMemFactorLocked(int memFactor, boolean screenOn, long now) {
    mMemFactorLowered = memFactor < mLastMemOnlyState;
    mLastMemOnlyState = memFactor;
    if (mInjectedScreenState != null) {
        screenOn = mInjectedScreenState;
    }
    if (screenOn) {
        memFactor += ProcessStats.ADJ_SCREEN_ON;
    }
    if (memFactor != mProcessStats.mMemFactor) {
        if (mProcessStats.mMemFactor != ProcessStats.STATE_NOTHING) {
            mProcessStats.mMemFactorDurations[mProcessStats.mMemFactor]
                    += now - mProcessStats.mStartTime;
        }
        mProcessStats.mMemFactor = memFactor;
        mProcessStats.mStartTime = now;
        final ArrayMap<String, SparseArray<LongSparseArray<ProcessStats.PackageState>>> pmap
                = mProcessStats.mPackages.getMap();
        for (int ipkg=pmap.size()-1; ipkg>=0; ipkg--) {
            final SparseArray<LongSparseArray<ProcessStats.PackageState>> uids =
                    pmap.valueAt(ipkg);
            for (int iuid=uids.size()-1; iuid>=0; iuid--) {
                final LongSparseArray<ProcessStats.PackageState> vers = uids.valueAt(iuid);
                for (int iver=vers.size()-1; iver>=0; iver--) {
                    final ProcessStats.PackageState pkg = vers.valueAt(iver);
                    final ArrayMap<String, ServiceState> services = pkg.mServices;
                    for (int isvc=services.size()-1; isvc>=0; isvc--) {
                        final ServiceState service = services.valueAt(isvc);
                        service.setMemFactor(memFactor, now);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
 
Example 20
Source Project: android_9.0.0_r45   Source File: PackageInstallerService.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mSessions")
private void addHistoricalSessionLocked(PackageInstallerSession session) {
    CharArrayWriter writer = new CharArrayWriter();
    IndentingPrintWriter pw = new IndentingPrintWriter(writer, "    ");
    session.dump(pw);
    mHistoricalSessions.add(writer.toString());

    int installerUid = session.getInstallerUid();
    // Increment the number of sessions by this installerUid.
    mHistoricalSessionsByInstaller.put(installerUid,
            mHistoricalSessionsByInstaller.get(installerUid) + 1);
}
 
Example 21
Source Project: android_9.0.0_r45   Source File: AutofillManager.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns AutofillCallback if need fire EVENT_INPUT_UNAVAILABLE */
@GuardedBy("mLock")
private AutofillCallback notifyViewEnteredLocked(@NonNull View view, int flags) {
    final AutofillId id = view.getAutofillId();
    if (shouldIgnoreViewEnteredLocked(id, flags)) return null;

    AutofillCallback callback = null;

    ensureServiceClientAddedIfNeededLocked();

    if (!mEnabled) {
        if (mCallback != null) {
            callback = mCallback;
        }
    } else {
        // don't notify entered when Activity is already in background
        if (!isClientDisablingEnterExitEvent()) {
            final AutofillValue value = view.getAutofillValue();

            if (!isActiveLocked()) {
                // Starts new session.
                startSessionLocked(id, null, value, flags);
            } else {
                // Update focus on existing session.
                updateSessionLocked(id, null, value, ACTION_VIEW_ENTERED, flags);
            }
            addEnteredIdLocked(id);
        }
    }
    return callback;
}
 
Example 22
Source Project: android_9.0.0_r45   Source File: StorageManagerService.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mLock")
private void writeSettingsLocked() {
    FileOutputStream fos = null;
    try {
        fos = mSettingsFile.startWrite();

        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, TAG_VOLUMES);
        writeIntAttribute(out, ATTR_VERSION, VERSION_FIX_PRIMARY);
        writeStringAttribute(out, ATTR_PRIMARY_STORAGE_UUID, mPrimaryStorageUuid);
        final int size = mRecords.size();
        for (int i = 0; i < size; i++) {
            final VolumeRecord rec = mRecords.valueAt(i);
            writeVolumeRecord(out, rec);
        }
        out.endTag(null, TAG_VOLUMES);
        out.endDocument();

        mSettingsFile.finishWrite(fos);
    } catch (IOException e) {
        if (fos != null) {
            mSettingsFile.failWrite(fos);
        }
    }
}
 
Example 23
@GuardedBy("mLock")
private void updatePriorityLocked() {
    int priority = (mAppTransitionRunning || mBoundsAnimationRunning)
            ? TOP_APP_PRIORITY_BOOST : THREAD_PRIORITY_DISPLAY;
    setBoostToPriority(priority);
    setThreadPriority(mAnimationThreadId, priority);
    setThreadPriority(mSurfaceAnimationThreadId, priority);
}
 
Example 24
Source Project: android_9.0.0_r45   Source File: SurfaceAnimationRunner.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mLock")
private void startPendingAnimationsLocked() {
    for (int i = mPendingAnimations.size() - 1; i >= 0; i--) {
        startAnimationLocked(mPendingAnimations.valueAt(i));
    }
    mPendingAnimations.clear();
}
 
Example 25
Source Project: android_9.0.0_r45   Source File: UserManagerService.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mUsersLock")
@VisibleForTesting
void addRemovingUserIdLocked(int userId) {
    // We remember deleted user IDs to prevent them from being
    // reused during the current boot; they can still be reused
    // after a reboot or recycling of userIds.
    mRemovingUserIds.put(userId, true);
    mRecentlyRemovedIds.add(userId);
    // Keep LRU queue of recently removed IDs for recycling
    if (mRecentlyRemovedIds.size() > MAX_RECENTLY_REMOVED_IDS_SIZE) {
        mRecentlyRemovedIds.removeFirst();
    }
}
 
Example 26
Source Project: android_9.0.0_r45   Source File: TaskSnapshotPersister.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mLock")
private void ensureStoreQueueDepthLocked() {
    while (mStoreQueueItems.size() > MAX_STORE_QUEUE_DEPTH) {
        final StoreWriteQueueItem item = mStoreQueueItems.poll();
        mWriteQueue.remove(item);
        Slog.i(TAG, "Queue is too deep! Purged item with taskid=" + item.mTaskId);
    }
}
 
Example 27
Source Project: android_9.0.0_r45   Source File: ShortcutService.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mLock")
private void unloadUserLocked(int userId) {
    if (DEBUG) {
        Slog.d(TAG, "unloadUserLocked: user=" + userId);
    }
    // Save all dirty information.
    saveDirtyInfo();

    // Unload
    mUsers.delete(userId);
}
 
Example 28
Source Project: android_9.0.0_r45   Source File: ShortcutService.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mLock")
private ParceledListSlice<ShortcutInfo> getShortcutsWithQueryLocked(@NonNull String packageName,
        @UserIdInt int userId, int cloneFlags, @NonNull Predicate<ShortcutInfo> query) {

    final ArrayList<ShortcutInfo> ret = new ArrayList<>();

    final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId);
    ps.findAll(ret, query, cloneFlags);

    return new ParceledListSlice<>(setReturnedByServer(ret));
}
 
Example 29
Source Project: android_9.0.0_r45   Source File: AppStateTracker.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mLock")
private int findForcedAppStandbyUidPackageIndexLocked(int uid, @NonNull String packageName) {
    final int size = mRunAnyRestrictedPackages.size();
    if (size > 8) {
        return mRunAnyRestrictedPackages.indexOf(Pair.create(uid, packageName));
    }
    for (int i = 0; i < size; i++) {
        final Pair<Integer, String> pair = mRunAnyRestrictedPackages.valueAt(i);

        if ((pair.first == uid) && packageName.equals(pair.second)) {
            return i;
        }
    }
    return -1;
}
 
Example 30
Source Project: android_9.0.0_r45   Source File: UserManagerService.java    License: Apache License 2.0 5 votes vote down vote up
@GuardedBy("mRestrictionsLock")
// Package private for the inner class.
void applyUserRestrictionsForAllUsersLR() {
    if (DBG) {
        debug("applyUserRestrictionsForAllUsersLR");
    }
    // First, invalidate all cached values.
    mCachedEffectiveUserRestrictions.clear();

    // We don't want to call into ActivityManagerService while taking a lock, so we'll call
    // it on a handler.
    final Runnable r = new Runnable() {
        @Override
        public void run() {
            // Then get the list of running users.
            final int[] runningUsers;
            try {
                runningUsers = ActivityManager.getService().getRunningUserIds();
            } catch (RemoteException e) {
                Log.w(LOG_TAG, "Unable to access ActivityManagerService");
                return;
            }
            // Then re-calculate the effective restrictions and apply, only for running users.
            // It's okay if a new user has started after the getRunningUserIds() call,
            // because we'll do the same thing (re-calculate the restrictions and apply)
            // when we start a user.
            synchronized (mRestrictionsLock) {
                for (int i = 0; i < runningUsers.length; i++) {
                    applyUserRestrictionsLR(runningUsers[i]);
                }
            }
        }
    };
    mHandler.post(r);
}