Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3b010c3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Frameworks: Annotate trivial @GuardedBy in services/autofill"

parents d407ca0d 5f521167
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -306,6 +306,7 @@ public final class AutofillManagerService extends SystemService {
     *
     * @return service instance.
     */
    @GuardedBy("mLock")
    @NonNull
    AutofillManagerServiceImpl getServiceForUserLocked(int userId) {
        final int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
@@ -325,6 +326,7 @@ public final class AutofillManagerService extends SystemService {
     *
     * @return service instance or {@code null} if not already present
     */
    @GuardedBy("mLock")
    @Nullable
    AutofillManagerServiceImpl peekServiceForUserLocked(int userId) {
        final int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
@@ -474,6 +476,7 @@ public final class AutofillManagerService extends SystemService {
    /**
     * Removes a cached service for a given user.
     */
    @GuardedBy("mLock")
    private void removeCachedServiceLocked(int userId) {
        final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId);
        if (service != null) {
@@ -485,6 +488,7 @@ public final class AutofillManagerService extends SystemService {
    /**
     * Updates a cached service for a given user.
     */
    @GuardedBy("mLock")
    private void updateCachedServiceLocked(int userId) {
        updateCachedServiceLocked(userId, mDisabledUsers.get(userId));
    }
@@ -492,6 +496,7 @@ public final class AutofillManagerService extends SystemService {
    /**
     * Updates a cached service for a given user.
     */
    @GuardedBy("mLock")
    private void updateCachedServiceLocked(int userId, boolean disabled) {
        AutofillManagerServiceImpl service = getServiceForUserLocked(userId);
        if (service != null) {
+26 −0
Original line number Diff line number Diff line
@@ -211,6 +211,7 @@ final class AutofillManagerServiceImpl {
        }
    }

    @GuardedBy("mLock")
    private int getServiceUidLocked() {
        if (mInfo == null) {
            Slog.w(TAG,  "getServiceUidLocked(): no mInfo");
@@ -248,6 +249,7 @@ final class AutofillManagerServiceImpl {
                mContext.getContentResolver(), Settings.Secure.AUTOFILL_SERVICE, mUserId);
    }

    @GuardedBy("mLock")
    void updateLocked(boolean disabled) {
        final boolean wasEnabled = isEnabledLocked();
        if (sVerbose) {
@@ -300,6 +302,7 @@ final class AutofillManagerServiceImpl {
        }
    }

    @GuardedBy("mLock")
    boolean addClientLocked(IAutoFillManagerClient client) {
        if (mClients == null) {
            mClients = new RemoteCallbackList<>();
@@ -308,12 +311,14 @@ final class AutofillManagerServiceImpl {
        return isEnabledLocked();
    }

    @GuardedBy("mLock")
    void removeClientLocked(IAutoFillManagerClient client) {
        if (mClients != null) {
            mClients.unregister(client);
        }
    }

    @GuardedBy("mLock")
    void setAuthenticationResultLocked(Bundle data, int sessionId, int authenticationId, int uid) {
        if (!isEnabledLocked()) {
            return;
@@ -336,6 +341,7 @@ final class AutofillManagerServiceImpl {
        }
    }

    @GuardedBy("mLock")
    int startSessionLocked(@NonNull IBinder activityToken, int uid,
            @NonNull IBinder appCallbackToken, @NonNull AutofillId autofillId,
            @NonNull Rect virtualBounds, @Nullable AutofillValue value, boolean hasCallback,
@@ -389,6 +395,7 @@ final class AutofillManagerServiceImpl {
    /**
     * Remove abandoned sessions if needed.
     */
    @GuardedBy("mLock")
    private void pruneAbandonedSessionsLocked() {
        long now = System.currentTimeMillis();
        if (mLastPrune < now - MAX_ABANDONED_SESSION_MILLIS) {
@@ -400,6 +407,7 @@ final class AutofillManagerServiceImpl {
        }
    }

    @GuardedBy("mLock")
    void finishSessionLocked(int sessionId, int uid) {
        if (!isEnabledLocked()) {
            return;
@@ -423,6 +431,7 @@ final class AutofillManagerServiceImpl {
        }
    }

    @GuardedBy("mLock")
    void cancelSessionLocked(int sessionId, int uid) {
        if (!isEnabledLocked()) {
            return;
@@ -436,6 +445,7 @@ final class AutofillManagerServiceImpl {
        session.removeSelfLocked();
    }

    @GuardedBy("mLock")
    void disableOwnedAutofillServicesLocked(int uid) {
        Slog.i(TAG, "disableOwnedServices(" + uid + "): " + mInfo);
        if (mInfo == null) return;
@@ -468,6 +478,7 @@ final class AutofillManagerServiceImpl {
        }
    }

    @GuardedBy("mLock")
    private Session createSessionByTokenLocked(@NonNull IBinder activityToken, int uid,
            @NonNull IBinder appCallbackToken, boolean hasCallback,
            @NonNull ComponentName componentName, int flags) {
@@ -546,6 +557,7 @@ final class AutofillManagerServiceImpl {
    /**
     * Updates a session and returns whether it should be restarted.
     */
    @GuardedBy("mLock")
    boolean updateSessionLocked(int sessionId, int uid, AutofillId autofillId, Rect virtualBounds,
            AutofillValue value, int action, int flags) {
        final Session session = mSessions.get(sessionId);
@@ -568,6 +580,7 @@ final class AutofillManagerServiceImpl {
        return false;
    }

    @GuardedBy("mLock")
    void removeSessionLocked(int sessionId) {
        mSessions.remove(sessionId);
    }
@@ -603,6 +616,7 @@ final class AutofillManagerServiceImpl {
        }
    }

    @GuardedBy("mLock")
    void destroyLocked() {
        if (sVerbose) Slog.v(TAG, "destroyLocked()");

@@ -655,6 +669,7 @@ final class AutofillManagerServiceImpl {
        }
    }

    @GuardedBy("mLock")
    private boolean isValidEventLocked(String method, int sessionId) {
        if (mEventHistory == null) {
            Slog.w(TAG, method + ": not logging event because history is null");
@@ -726,6 +741,7 @@ final class AutofillManagerServiceImpl {
    /**
     * Updates the last fill response when an autofill context is committed.
     */
    @GuardedBy("mLock")
    void logContextCommittedLocked(int sessionId, @Nullable Bundle clientState,
            @Nullable ArrayList<String> selectedDatasets,
            @Nullable ArraySet<String> ignoredDatasets,
@@ -739,6 +755,7 @@ final class AutofillManagerServiceImpl {
                manuallyFilledDatasetIds, null, null, appPackageName);
    }

    @GuardedBy("mLock")
    void logContextCommittedLocked(int sessionId, @Nullable Bundle clientState,
            @Nullable ArrayList<String> selectedDatasets,
            @Nullable ArraySet<String> ignoredDatasets,
@@ -847,6 +864,7 @@ final class AutofillManagerServiceImpl {
        }
    }

    @GuardedBy("mLock")
    private boolean isCalledByServiceLocked(String methodName, int callingUid) {
        if (getServiceUidLocked() != callingUid) {
            Slog.w(TAG, methodName + "() called by UID " + callingUid
@@ -856,6 +874,7 @@ final class AutofillManagerServiceImpl {
        return true;
    }

    @GuardedBy("mLock")
    void dumpLocked(String prefix, PrintWriter pw) {
        final String prefix2 = prefix + "  ";

@@ -965,6 +984,7 @@ final class AutofillManagerServiceImpl {
        mFieldClassificationStrategy.dump(prefix2, pw);
    }

    @GuardedBy("mLock")
    void destroySessionsLocked() {
        if (mSessions.size() == 0) {
            mUi.destroyAll(null, null, false);
@@ -976,6 +996,7 @@ final class AutofillManagerServiceImpl {
    }

    // TODO(b/64940307): remove this method if SaveUI is refactored to be attached on activities
    @GuardedBy("mLock")
    void destroyFinishedSessionsLocked() {
        final int sessionCount = mSessions.size();
        for (int i = sessionCount - 1; i >= 0; i--) {
@@ -987,6 +1008,7 @@ final class AutofillManagerServiceImpl {
        }
    }

    @GuardedBy("mLock")
    void listSessionsLocked(ArrayList<String> output) {
        final int numSessions = mSessions.size();
        for (int i = 0; i < numSessions; i++) {
@@ -995,6 +1017,7 @@ final class AutofillManagerServiceImpl {
        }
    }

    @GuardedBy("mLock")
    boolean isCompatibilityModeRequestedLocked(@NonNull String packageName,
            long versionCode) {
        if (mInfo == null || !mInfo.isCompatibilityModeRequested(packageName, versionCode)) {
@@ -1060,6 +1083,7 @@ final class AutofillManagerServiceImpl {
        }
    }

    @GuardedBy("mLock")
    private boolean isClientSessionDestroyedLocked(IAutoFillManagerClient client) {
        final int sessionCount = mSessions.size();
        for (int i = 0; i < sessionCount; i++) {
@@ -1071,6 +1095,7 @@ final class AutofillManagerServiceImpl {
        return true;
    }

    @GuardedBy("mLock")
    boolean isEnabledLocked() {
        return mSetupComplete && mInfo != null && !mDisabled;
    }
@@ -1123,6 +1148,7 @@ final class AutofillManagerServiceImpl {
    /**
     * Checks if autofill is disabled by service to the given activity.
     */
    @GuardedBy("mLock")
    private boolean isAutofillDisabledLocked(@NonNull ComponentName componentName) {
        // Check activities first.
        long elapsedTime = 0;
+1 −0
Original line number Diff line number Diff line
@@ -475,6 +475,7 @@ final class RemoteFillService implements DeathRecipient {
            return true;
        }

        @GuardedBy("mLock")
        protected boolean isCancelledLocked() {
            return mCancelled;
        }
+35 −0
Original line number Diff line number Diff line
@@ -300,6 +300,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    /**
     * Returns the ids of all entries in {@link #mViewStates} in the same order.
     */
    @GuardedBy("mLock")
    private AutofillId[] getIdsOfAllViewStatesLocked() {
        final int numViewState = mViewStates.size();
        final AutofillId[] ids = new AutofillId[numViewState];
@@ -346,6 +347,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     * <p>Gets the value of a field, using either the {@code viewStates} or the {@code mContexts},
     * or {@code null} when not found on either of them.
     */
    @GuardedBy("mLock")
    private AutofillValue findValueLocked(@NonNull AutofillId id) {
        final ViewState state = mViewStates.get(id);
        if (state == null) {
@@ -369,6 +371,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     * @param fillContext The context to be filled
     * @param flags The flags that started the session
     */
    @GuardedBy("mLock")
    private void fillContextWithAllowedValuesLocked(@NonNull FillContext fillContext, int flags) {
        final ViewNode[] nodes = fillContext
                .findViewNodesByAutofillIds(getIdsOfAllViewStatesLocked());
@@ -409,6 +412,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    /**
     * Cancels the last request sent to the {@link #mRemoteFillService}.
     */
    @GuardedBy("mLock")
    private void cancelCurrentRequestLocked() {
        final int canceledRequest = mRemoteFillService.cancelCurrentRequest();

@@ -430,6 +434,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    /**
     * Reads a new structure and then request a new fill response from the fill service.
     */
    @GuardedBy("mLock")
    private void requestNewFillResponseLocked(int flags) {
        int requestId;

@@ -497,6 +502,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     *
     * @return The activity token
     */
    @GuardedBy("mLock")
    @NonNull IBinder getActivityTokenLocked() {
        return mActivityToken;
    }
@@ -663,6 +669,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     *
     * @return The context or {@code null} if there is no context
     */
    @GuardedBy("mLock")
    @Nullable private FillContext getFillContextByRequestIdLocked(int requestId) {
        if (mContexts == null) {
            return null;
@@ -820,6 +827,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        });
    }

    @GuardedBy("mLock")
    void setAuthenticationResultLocked(Bundle data, int authenticationId) {
        if (mDestroyed) {
            Slog.w(TAG, "Call to Session#setAuthenticationResultLocked() rejected - session: "
@@ -882,6 +890,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        }
    }

    @GuardedBy("mLock")
    void setHasCallbackLocked(boolean hasIt) {
        if (mDestroyed) {
            Slog.w(TAG, "Call to Session#setHasCallbackLocked() rejected - session: "
@@ -891,6 +900,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        mHasCallback = hasIt;
    }

    @GuardedBy("mLock")
    @Nullable
    private FillResponse getLastResponseLocked(@Nullable String logPrefix) {
        if (mContexts == null) {
@@ -923,6 +933,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        return response;
    }

    @GuardedBy("mLock")
    @Nullable
    private SaveInfo getSaveInfoLocked() {
        final FillResponse response = getLastResponseLocked(null);
@@ -941,6 +952,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        });
    }

    @GuardedBy("mLock")
    private void logContextCommittedLocked() {
        final FillResponse lastResponse = getLastResponseLocked("logContextCommited()");
        if (lastResponse == null) return;
@@ -1241,6 +1253,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     *
     * @return {@code true} if session is done, or {@code false} if it's pending user action.
     */
    @GuardedBy("mLock")
    public boolean showSaveLocked() {
        if (mDestroyed) {
            Slog.w(TAG, "Call to Session#showSaveLocked() rejected - session: "
@@ -1510,6 +1523,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    /**
     * Returns whether the session is currently showing the save UI
     */
    @GuardedBy("mLock")
    boolean isSavingLocked() {
        return mIsSaving;
    }
@@ -1517,6 +1531,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    /**
     * Gets the latest non-empty value for the given id in the autofill contexts.
     */
    @GuardedBy("mLock")
    @Nullable
    private AutofillValue getValueFromContextsLocked(AutofillId id) {
        final int numContexts = mContexts.size();
@@ -1539,6 +1554,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    /**
     * Gets the latest autofill options for the given id in the autofill contexts.
     */
    @GuardedBy("mLock")
    @Nullable
    private CharSequence[] getAutofillOptionsFromContextsLocked(AutofillId id) {
        final int numContexts = mContexts.size();
@@ -1556,6 +1572,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    /**
     * Calls service when user requested save.
     */
    @GuardedBy("mLock")
    void callSaveLocked() {
        if (mDestroyed) {
            Slog.w(TAG, "Call to Session#callSaveLocked() rejected - session: "
@@ -1646,6 +1663,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     * @param viewState The view that is entered.
     * @param flags The flag that was passed by the AutofillManager.
     */
    @GuardedBy("mLock")
    private void requestNewFillResponseOnViewEnteredIfNecessaryLocked(@NonNull AutofillId id,
            @NonNull ViewState viewState, int flags) {
        if ((flags & FLAG_MANUAL_REQUEST) != 0) {
@@ -1673,6 +1691,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     *
     * @return {@code true} iff a new partition should be started
     */
    @GuardedBy("mLock")
    private boolean shouldStartNewPartitionLocked(@NonNull AutofillId id) {
        if (mResponses == null) {
            return true;
@@ -1721,6 +1740,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        return true;
    }

    @GuardedBy("mLock")
    void updateLocked(AutofillId id, Rect virtualBounds, AutofillValue value, int action,
            int flags) {
        if (mDestroyed) {
@@ -1830,6 +1850,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    /**
     * Checks whether a view should be ignored.
     */
    @GuardedBy("mLock")
    private boolean isIgnoredLocked(AutofillId id) {
        // Always check the latest response only
        final FillResponse response = getLastResponseLocked(null);
@@ -1910,6 +1931,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        }
    }

    @GuardedBy("mLock")
    private void updateTrackedIdsLocked() {
        // Only track the views of the last response as only those are reported back to the
        // service, see #showSaveLocked
@@ -1982,6 +2004,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        }
    }

    @GuardedBy("mLock")
    private void replaceResponseLocked(@NonNull FillResponse oldResponse,
            @NonNull FillResponse newResponse, @Nullable Bundle newClientState) {
        // Disassociate view states with the old response
@@ -2005,6 +2028,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        removeSelf();
    }

    @GuardedBy("mLock")
    private void processResponseLocked(@NonNull FillResponse newResponse,
            @Nullable Bundle newClientState, int flags) {
        // Make sure we are hiding the UI which will be shown
@@ -2042,6 +2066,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    /**
     * Sets the state of all views in the given response.
     */
    @GuardedBy("mLock")
    private void setViewStatesLocked(FillResponse response, int state, boolean clearResponse) {
        final List<Dataset> datasets = response.getDatasets();
        if (datasets != null) {
@@ -2090,6 +2115,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    /**
     * Sets the state of all views in the given dataset and response.
     */
    @GuardedBy("mLock")
    private void setViewStatesLocked(@Nullable FillResponse response, @NonNull Dataset dataset,
            int state, boolean clearResponse) {
        final ArrayList<AutofillId> ids = dataset.getFieldIds();
@@ -2110,6 +2136,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        }
    }

    @GuardedBy("mLock")
    private ViewState createOrUpdateViewStateLocked(@NonNull AutofillId id, int state,
            @Nullable AutofillValue value) {
        ViewState viewState = mViewStates.get(id);
@@ -2171,6 +2198,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    }

    // TODO: this should never be null, but we got at least one occurrence, probably due to a race.
    @GuardedBy("mLock")
    @Nullable
    private Intent createAuthFillInIntentLocked(int requestId, Bundle extras) {
        final Intent fillInIntent = new Intent();
@@ -2203,6 +2231,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        return "Session: [id=" + id + ", component=" + mComponentName + "]";
    }

    @GuardedBy("mLock")
    void dumpLocked(String prefix, PrintWriter pw) {
        final String prefix2 = prefix + "  ";
        pw.print(prefix); pw.print("id: "); pw.println(id);
@@ -2332,6 +2361,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     *       disabled it).
     * </ul>
     */
    @GuardedBy("mLock")
    RemoteFillService destroyLocked() {
        if (mDestroyed) {
            return null;
@@ -2347,6 +2377,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     * Cleans up this session and remove it from the service always, even if it does have a pending
     * Save UI.
     */
    @GuardedBy("mLock")
    void forceRemoveSelfLocked() {
        if (sVerbose) Slog.v(TAG, "forceRemoveSelfLocked(): " + mPendingSaveUi);

@@ -2376,6 +2407,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     * Cleans up this session and remove it from the service, but but only if it does not have a
     * pending Save UI.
     */
    @GuardedBy("mLock")
    void removeSelfLocked() {
        if (sVerbose) Slog.v(TAG, "removeSelfLocked(): " + mPendingSaveUi);
        if (mDestroyed) {
@@ -2404,6 +2436,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     * a specific {@code token} created by
     * {@link PendingUi#PendingUi(IBinder, int, IAutoFillManagerClient)}.
     */
    @GuardedBy("mLock")
    boolean isSaveUiPendingForTokenLocked(@NonNull IBinder token) {
        return isSaveUiPendingLocked() && token.equals(mPendingSaveUi.getToken());
    }
@@ -2411,10 +2444,12 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    /**
     * Checks whether this session is hiding the Save UI to handle a custom description link.
     */
    @GuardedBy("mLock")
    private boolean isSaveUiPendingLocked() {
        return mPendingSaveUi != null && mPendingSaveUi.getState() == PendingUi.STATE_PENDING;
    }

    @GuardedBy("mLock")
    private int getLastResponseIndexLocked() {
        // The response ids are monotonically increasing so
        // we just find the largest id which is the last. We