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

Commit e4751417 authored by TYM Tsai's avatar TYM Tsai
Browse files

Postpones the fill UI if the save UI is showing

A new fill request will cause the save UI to be hidden immediately. So
postpone the fill UI when the save UI is showing. And reshow the fill UI
after the save UI disappear.

Fixes: 139876545
Test: manual
Test: atest CtsAutoFillServiceTestCases
Change-Id: Ibb1ab903ae1fb70ee5e5f386c522f65f6c2cfa8e
parent f9527fd0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3267,6 +3267,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        if (mDestroyed) {
            return null;
        }

        unlinkClientVultureLocked();
        mUi.destroyAll(mPendingSaveUi, this, true);
        mUi.clearCallback(this);
+39 −19
Original line number Diff line number Diff line
@@ -74,6 +74,9 @@ public final class AutoFillUI {
    private final @NonNull OverlayControl mOverlayControl;
    private final @NonNull UiModeManagerInternal mUiModeMgr;

    private @Nullable Runnable mCreateFillUiRunnable;
    private @Nullable AutoFillUiCallback mSaveUiCallback;

    public interface AutoFillUiCallback {
        void authenticate(int requestId, int datasetIndex, @NonNull IntentSender intent,
                @Nullable Bundle extras);
@@ -98,9 +101,13 @@ public final class AutoFillUI {
        mHandler.post(() -> {
            if (mCallback != callback) {
                if (mCallback != null) {
                    if (isSaveUiShowing()) {
                        // keeps showing the save UI
                        hideFillUiUiThread(callback, true);
                    } else {
                        hideAllUiThread(mCallback);
                    }

                }
                mCallback = callback;
            }
        });
@@ -193,7 +200,7 @@ public final class AutoFillUI {
                .addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_DATASETS,
                        response.getDatasets() == null ? 0 : response.getDatasets().size());

        mHandler.post(() -> {
        final Runnable createFillUiRunnable = () -> {
            if (callback != mCallback) {
                return;
            }
@@ -266,7 +273,15 @@ public final class AutoFillUI {
                    }
                }
            });
        });
        };

        if (isSaveUiShowing()) {
            // postpone creating the fill UI for showing the save UI
            if (sDebug) Slog.d(TAG, "postpone fill UI request..");
            mCreateFillUiRunnable = createFillUiRunnable;
        } else {
            mHandler.post(createFillUiRunnable);
        }
    }

    /**
@@ -298,23 +313,22 @@ public final class AutoFillUI {
                return;
            }
            hideAllUiThread(callback);
            mSaveUiCallback = callback;
            mSaveUi = new SaveUi(mContext, pendingSaveUi, serviceLabel, serviceIcon,
                    servicePackageName, componentName, info, valueFinder, mOverlayControl,
                    new SaveUi.OnSaveListener() {
                @Override
                public void onSave() {
                    log.setType(MetricsEvent.TYPE_ACTION);
                    hideSaveUiUiThread(mCallback);
                    if (mCallback != null) {
                        mCallback.save();
                    }
                    hideSaveUiUiThread(callback);
                    callback.save();
                    destroySaveUiUiThread(pendingSaveUi, true);
                }

                @Override
                public void onCancel(IntentSender listener) {
                    log.setType(MetricsEvent.TYPE_DISMISS);
                    hideSaveUiUiThread(mCallback);
                    hideSaveUiUiThread(callback);
                    if (listener != null) {
                        try {
                            listener.sendIntent(mContext, 0, null, null, null);
@@ -323,9 +337,7 @@ public final class AutoFillUI {
                                    + listener, e);
                        }
                    }
                    if (mCallback != null) {
                        mCallback.cancelSave();
                    }
                    callback.cancelSave();
                    destroySaveUiUiThread(pendingSaveUi, true);
                }

@@ -334,18 +346,14 @@ public final class AutoFillUI {
                    if (log.getType() == MetricsEvent.TYPE_UNKNOWN) {
                        log.setType(MetricsEvent.TYPE_CLOSE);

                        if (mCallback != null) {
                            mCallback.cancelSave();
                        }
                        callback.cancelSave();
                    }
                    mMetricsLogger.write(log);
                }

                @Override
                public void startIntentSender(IntentSender intentSender, Intent intent) {
                    if (mCallback != null) {
                        mCallback.startIntentSender(intentSender, intent);
                    }
                    callback.startIntentSender(intentSender, intent);
                }
            }, mUiModeMgr.isNightMode(), isUpdate, compatMode);
        });
@@ -379,6 +387,10 @@ public final class AutoFillUI {
        mHandler.post(() -> destroyAllUiThread(pendingSaveUi, callback, notifyClient));
    }

    public boolean isSaveUiShowing() {
        return mSaveUi == null ? false : mSaveUi.isShowing();
    }

    public void dump(PrintWriter pw) {
        pw.println("Autofill UI");
        final String prefix = "  ";
@@ -413,7 +425,8 @@ public final class AutoFillUI {
            Slog.v(TAG, "hideSaveUiUiThread(): mSaveUi=" + mSaveUi + ", callback=" + callback
                    + ", mCallback=" + mCallback);
        }
        if (mSaveUi != null && (callback == null || callback == mCallback)) {

        if (mSaveUi != null && mSaveUiCallback == callback) {
            return mSaveUi.hide();
        }
        return null;
@@ -432,6 +445,7 @@ public final class AutoFillUI {
        if (sDebug) Slog.d(TAG, "destroySaveUiUiThread(): " + pendingSaveUi);
        mSaveUi.destroy();
        mSaveUi = null;
        mSaveUiCallback = null;
        if (pendingSaveUi != null && notifyClient) {
            try {
                if (sDebug) Slog.d(TAG, "destroySaveUiUiThread(): notifying client");
@@ -440,6 +454,12 @@ public final class AutoFillUI {
                Slog.e(TAG, "Error notifying client to set save UI state to hidden: " + e);
            }
        }

        if (mCreateFillUiRunnable != null) {
            if (sDebug) Slog.d(TAG, "start the pending fill UI request..");
            mCreateFillUiRunnable.run();
            mCreateFillUiRunnable = null;
        }
    }

    @android.annotation.UiThread
+5 −1
Original line number Diff line number Diff line
@@ -562,6 +562,10 @@ final class SaveUi {
        return mPendingUi;
    }

    boolean isShowing() {
        return mDialog.isShowing();
    }

    void destroy() {
        try {
            if (sDebug) Slog.d(TAG, "destroy()");