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

Commit 467b444d authored by Dake Gu's avatar Dake Gu Committed by Android (Google) Code Review
Browse files

Merge "autofill: touch on IME should not close autofill"

parents 3ae0efcc b0fa378f
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ import android.view.accessibility.IAccessibilityInteractionConnection;
import android.view.accessibility.IAccessibilityInteractionConnectionCallback;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.autofill.AutofillManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Scroller;

@@ -4781,6 +4782,21 @@ public final class ViewRootImpl implements ViewParent,
                ensureTouchMode(event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN));
            }

            if (action == MotionEvent.ACTION_DOWN && mView instanceof ViewGroup) {
                // Upon motion event within app window, close autofill ui.
                ViewGroup decorView = (ViewGroup) mView;
                if (decorView.getChildCount() > 0) {
                    // We cannot use decorView's Context for querying AutofillManager: DecorView's
                    // context is based on Application Context, it would allocate a different
                    // AutofillManager instance.
                    AutofillManager afm = (AutofillManager) decorView.getChildAt(0).getContext()
                            .getSystemService(Context.AUTOFILL_MANAGER_SERVICE);
                    if (afm != null) {
                        afm.requestHideFillUi();
                    }
                }
            }

            if (action == MotionEvent.ACTION_DOWN && mAttachInfo.mTooltipHost != null) {
                mAttachInfo.mTooltipHost.hideTooltip();
            }
+24 −5
Original line number Diff line number Diff line
@@ -358,6 +358,9 @@ public final class AutofillManager {
    @GuardedBy("mLock")
    @Nullable private ArraySet<AutofillId> mFillableIds;

    /** id of last requested autofill ui */
    @Nullable private AutofillId mIdShownFillUi;

    /**
     * Views that were already "entered" - if they're entered again when the session is not active,
     * they're ignored
@@ -1547,6 +1550,7 @@ public final class AutofillManager {
        mTrackedViews = null;
        mFillableIds = null;
        mSaveTriggerId = null;
        mIdShownFillUi = null;
        if (resetEnteredIds) {
            mEnteredIds = null;
        }
@@ -1676,8 +1680,9 @@ public final class AutofillManager {

                if (client != null) {
                    if (client.autofillClientRequestShowFillUi(anchor, width, height,
                            anchorBounds, presenter) && mCallback != null) {
                            anchorBounds, presenter)) {
                        callback = mCallback;
                        mIdShownFillUi = id;
                    }
                }
            }
@@ -1944,10 +1949,23 @@ public final class AutofillManager {
        }
    }

    private void requestHideFillUi(AutofillId id) {
        final View anchor = findView(id);
    /** @hide */
    public void requestHideFillUi() {
        requestHideFillUi(mIdShownFillUi, true);
    }

    private void requestHideFillUi(AutofillId id, boolean force) {
        final View anchor = id == null ? null : findView(id);
        if (sVerbose) Log.v(TAG, "requestHideFillUi(" + id + "): anchor = " + anchor);
        if (anchor == null) {
            if (force) {
                // When user taps outside autofill window, force to close fill ui even id does
                // not match.
                AutofillClient client = getClient();
                if (client != null) {
                    client.autofillClientRequestHideFillUi();
                }
            }
            return;
        }
        requestHideFillUi(id, anchor);
@@ -1963,7 +1981,8 @@ public final class AutofillManager {
            //    service being uninstalled and the UI being dismissed.
            AutofillClient client = getClient();
            if (client != null) {
                if (client.autofillClientRequestHideFillUi() && mCallback != null) {
                if (client.autofillClientRequestHideFillUi()) {
                    mIdShownFillUi = null;
                    callback = mCallback;
                }
            }
@@ -2655,7 +2674,7 @@ public final class AutofillManager {
        public void requestHideFillUi(int sessionId, AutofillId id) {
            final AutofillManager afm = mAfm.get();
            if (afm != null) {
                afm.post(() -> afm.requestHideFillUi(id));
                afm.post(() -> afm.requestHideFillUi(id, false));
            }
        }

+1 −13
Original line number Diff line number Diff line
@@ -590,7 +590,7 @@ final class FillUi {
        }
    }

    final class AnchoredWindow implements View.OnTouchListener {
    final class AnchoredWindow {
        private final @NonNull OverlayControl mOverlayControl;
        private final WindowManager mWm;
        private final View mContentView;
@@ -623,7 +623,6 @@ final class FillUi {
                    params.accessibilityTitle = mContentView.getContext()
                            .getString(R.string.autofill_picker_accessibility_title);
                    mWm.addView(mContentView, params);
                    mContentView.setOnTouchListener(this);
                    mOverlayControl.hideOverlays();
                    mShowing = true;
                } else {
@@ -647,7 +646,6 @@ final class FillUi {
        void hide() {
            try {
                if (mShowing) {
                    mContentView.setOnTouchListener(null);
                    mWm.removeView(mContentView);
                    mShowing = false;
                }
@@ -661,16 +659,6 @@ final class FillUi {
                mOverlayControl.showOverlays();
            }
        }

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // When the window is touched outside, hide the window.
            if (view == mContentView && event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                mCallback.onCanceled();
                return true;
            }
            return false;
        }
    }

    public void dump(PrintWriter pw, String prefix) {