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

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

Merge "Handle autofill auth scenarios where the FillContext cannot be retrieved:" into oc-mr1-dev

parents 9282193c f73795f9
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -633,7 +633,7 @@ final class AutofillManagerServiceImpl {


    void destroySessionsLocked() {
    void destroySessionsLocked() {
        if (mSessions.size() == 0) {
        if (mSessions.size() == 0) {
            mUi.destroyAll(null, null);
            mUi.destroyAll(null, null, false);
            return;
            return;
        }
        }
        while (mSessions.size() > 0) {
        while (mSessions.size() > 0) {
+2 −3
Original line number Original line Diff line number Diff line
@@ -578,9 +578,8 @@ final class RemoteFillService implements DeathRecipient {
        public void run() {
        public void run() {
            synchronized (mLock) {
            synchronized (mLock) {
                if (isCancelledLocked()) {
                if (isCancelledLocked()) {
                    // TODO(b/653742740): we should probably return here, but for now we're justing
                    if (sDebug) Slog.d(LOG_TAG, "run() called after canceled: " + mRequest);
                    // logging to confirm this is the problem if it happens again.
                    return;
                    Slog.e(LOG_TAG, "run() called after canceled: " + mRequest);
                }
                }
            }
            }
            final RemoteFillService remoteService = getService();
            final RemoteFillService remoteService = getService();
+33 −6
Original line number Original line Diff line number Diff line
@@ -566,6 +566,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    // FillServiceCallbacks
    // FillServiceCallbacks
    @Override
    @Override
    public void authenticate(int requestId, int datasetIndex, IntentSender intent, Bundle extras) {
    public void authenticate(int requestId, int datasetIndex, IntentSender intent, Bundle extras) {
        if (sDebug) {
            Slog.d(TAG, "authenticate(): requestId=" + requestId + "; datasetIdx=" + datasetIndex
                    + "; intentSender=" + intent);
        }
        final Intent fillInIntent;
        final Intent fillInIntent;
        synchronized (mLock) {
        synchronized (mLock) {
            if (mDestroyed) {
            if (mDestroyed) {
@@ -574,6 +578,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                return;
                return;
            }
            }
            fillInIntent = createAuthFillInIntentLocked(requestId, extras);
            fillInIntent = createAuthFillInIntentLocked(requestId, extras);
            if (fillInIntent == null) {
                forceRemoveSelfLocked();
                return;
            }
        }
        }
        mService.setAuthenticationSelected(id);
        mService.setAuthenticationSelected(id);


@@ -1568,6 +1576,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    }
    }


    void autoFill(int requestId, int datasetIndex, Dataset dataset, boolean generateEvent) {
    void autoFill(int requestId, int datasetIndex, Dataset dataset, boolean generateEvent) {
        if (sDebug) {
            Slog.d(TAG, "autoFill(): requestId=" + requestId  + "; datasetIdx=" + datasetIndex
                    + "; dataset=" + dataset);
        }
        synchronized (mLock) {
        synchronized (mLock) {
            if (mDestroyed) {
            if (mDestroyed) {
                Slog.w(TAG, "Call to Session#autoFill() rejected - session: "
                Slog.w(TAG, "Call to Session#autoFill() rejected - session: "
@@ -1588,10 +1600,14 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            mService.logDatasetAuthenticationSelected(dataset.getId(), id);
            mService.logDatasetAuthenticationSelected(dataset.getId(), id);
            setViewStatesLocked(null, dataset, ViewState.STATE_WAITING_DATASET_AUTH, false);
            setViewStatesLocked(null, dataset, ViewState.STATE_WAITING_DATASET_AUTH, false);
            final Intent fillInIntent = createAuthFillInIntentLocked(requestId, mClientState);
            final Intent fillInIntent = createAuthFillInIntentLocked(requestId, mClientState);

            if (fillInIntent == null) {
                forceRemoveSelfLocked();
                return;
            }
            final int authenticationId = AutofillManager.makeAuthenticationId(requestId,
            final int authenticationId = AutofillManager.makeAuthenticationId(requestId,
                    datasetIndex);
                    datasetIndex);
            startAuthentication(authenticationId, dataset.getAuthentication(), fillInIntent);
            startAuthentication(authenticationId, dataset.getAuthentication(), fillInIntent);

        }
        }
    }
    }


@@ -1601,14 +1617,16 @@ 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.
    @Nullable
    private Intent createAuthFillInIntentLocked(int requestId, Bundle extras) {
    private Intent createAuthFillInIntentLocked(int requestId, Bundle extras) {
        final Intent fillInIntent = new Intent();
        final Intent fillInIntent = new Intent();


        final FillContext context = getFillContextByRequestIdLocked(requestId);
        final FillContext context = getFillContextByRequestIdLocked(requestId);
        if (context == null) {
        if (context == null) {
            // TODO(b/653742740): this will crash system_server. We need to handle it, but we're
            Slog.wtf(TAG, "createAuthFillInIntentLocked(): no FillContext. requestId=" + requestId
            // keeping it crashing for now so we can diagnose when it happens again
                    + "; mContexts= " + mContexts);
            Slog.wtf(TAG, "no FillContext for requestId" + requestId + "; mContexts= " + mContexts);
            return null;
        }
        }
        fillInIntent.putExtra(AutofillManager.EXTRA_ASSIST_STRUCTURE, context.getStructure());
        fillInIntent.putExtra(AutofillManager.EXTRA_ASSIST_STRUCTURE, context.getStructure());
        fillInIntent.putExtra(AutofillManager.EXTRA_CLIENT_STATE, extras);
        fillInIntent.putExtra(AutofillManager.EXTRA_CLIENT_STATE, extras);
@@ -1748,7 +1766,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        if (mDestroyed) {
        if (mDestroyed) {
            return null;
            return null;
        }
        }
        mUi.destroyAll(mPendingSaveUi, this);
        mUi.destroyAll(mPendingSaveUi, this, true);
        mUi.clearCallback(this);
        mUi.clearCallback(this);
        mDestroyed = true;
        mDestroyed = true;
        writeLog(MetricsEvent.AUTOFILL_SESSION_FINISHED);
        writeLog(MetricsEvent.AUTOFILL_SESSION_FINISHED);
@@ -1764,7 +1782,16 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState


        mPendingSaveUi = null;
        mPendingSaveUi = null;
        removeSelfLocked();
        removeSelfLocked();
        mUi.destroyAll(mPendingSaveUi, this);

        mHandlerCaller.getHandler().post(() -> {
            try {
                mClient.setState(mService.isEnabled(), true, false);
            } catch (RemoteException e) {
                Slog.w(TAG, "error updating client state: " + e);
            }
        });

        mUi.destroyAll(mPendingSaveUi, this, false);
    }
    }


    /**
    /**
+9 −9
Original line number Original line Diff line number Diff line
@@ -275,7 +275,7 @@ public final class AutoFillUI {
                    if (mCallback != null) {
                    if (mCallback != null) {
                        mCallback.save();
                        mCallback.save();
                    }
                    }
                    destroySaveUiUiThread(pendingSaveUi);
                    destroySaveUiUiThread(pendingSaveUi, true);
                }
                }


                @Override
                @Override
@@ -293,7 +293,7 @@ public final class AutoFillUI {
                    if (mCallback != null) {
                    if (mCallback != null) {
                        mCallback.cancelSave();
                        mCallback.cancelSave();
                    }
                    }
                    destroySaveUiUiThread(pendingSaveUi);
                    destroySaveUiUiThread(pendingSaveUi, true);
                }
                }


                @Override
                @Override
@@ -335,8 +335,8 @@ public final class AutoFillUI {
     * Destroy all UI affordances.
     * Destroy all UI affordances.
     */
     */
    public void destroyAll(@Nullable PendingUi pendingSaveUi,
    public void destroyAll(@Nullable PendingUi pendingSaveUi,
            @Nullable AutoFillUiCallback callback) {
            @Nullable AutoFillUiCallback callback, boolean notifyClient) {
        mHandler.post(() -> destroyAllUiThread(pendingSaveUi, callback));
        mHandler.post(() -> destroyAllUiThread(pendingSaveUi, callback, notifyClient));
    }
    }


    public void dump(PrintWriter pw) {
    public void dump(PrintWriter pw) {
@@ -379,7 +379,7 @@ public final class AutoFillUI {
    }
    }


    @android.annotation.UiThread
    @android.annotation.UiThread
    private void destroySaveUiUiThread(@Nullable PendingUi pendingSaveUi) {
    private void destroySaveUiUiThread(@Nullable PendingUi pendingSaveUi, boolean notifyClient) {
        if (mSaveUi == null) {
        if (mSaveUi == null) {
            // Calling destroySaveUiUiThread() twice is normal - it usually happens when the
            // Calling destroySaveUiUiThread() twice is normal - it usually happens when the
            // first call is made after the SaveUI is hidden and the second when the session is
            // first call is made after the SaveUI is hidden and the second when the session is
@@ -391,7 +391,7 @@ public final class AutoFillUI {
        if (sDebug) Slog.d(TAG, "destroySaveUiUiThread(): " + pendingSaveUi);
        if (sDebug) Slog.d(TAG, "destroySaveUiUiThread(): " + pendingSaveUi);
        mSaveUi.destroy();
        mSaveUi.destroy();
        mSaveUi = null;
        mSaveUi = null;
        if (pendingSaveUi != null) {
        if (pendingSaveUi != null && notifyClient) {
            try {
            try {
                if (sDebug) Slog.d(TAG, "destroySaveUiUiThread(): notifying client");
                if (sDebug) Slog.d(TAG, "destroySaveUiUiThread(): notifying client");
                pendingSaveUi.client.setSaveUiState(pendingSaveUi.id, false);
                pendingSaveUi.client.setSaveUiState(pendingSaveUi.id, false);
@@ -403,9 +403,9 @@ public final class AutoFillUI {


    @android.annotation.UiThread
    @android.annotation.UiThread
    private void destroyAllUiThread(@Nullable PendingUi pendingSaveUi,
    private void destroyAllUiThread(@Nullable PendingUi pendingSaveUi,
            @Nullable AutoFillUiCallback callback) {
            @Nullable AutoFillUiCallback callback, boolean notifyClient) {
        hideFillUiUiThread(callback);
        hideFillUiUiThread(callback);
        destroySaveUiUiThread(pendingSaveUi);
        destroySaveUiUiThread(pendingSaveUi, notifyClient);
    }
    }


    @android.annotation.UiThread
    @android.annotation.UiThread
@@ -417,7 +417,7 @@ public final class AutoFillUI {
                Slog.d(TAG, "hideAllUiThread(): "
                Slog.d(TAG, "hideAllUiThread(): "
                        + "destroying Save UI because pending restoration is finished");
                        + "destroying Save UI because pending restoration is finished");
            }
            }
            destroySaveUiUiThread(pendingSaveUi);
            destroySaveUiUiThread(pendingSaveUi, true);
        }
        }
    }
    }
}
}