From b0fa378f9d390d27ab2a2f83eb6fa16f2b5cbb97 Mon Sep 17 00:00:00 2001 From: Dake Gu Date: Mon, 26 Feb 2018 12:25:14 -0800 Subject: autofill: touch on IME should not close autofill ag/3434666 causes a regression: Before ag/3434666, autofill gets touch event after IME, autofill close itself if it gets ACTION_OUTSIDE touch event. But after ag/3434666, autofill intercepts touch events before IME, if user touches within IME, autofill still gets ACTION_OUTSIDE event, and close itself unexpectedly. The fix moves the closing code to ViewRootImpl.EarlyPostImeStage around the same place closing tooltip. If user taps outside autofill window, we will force to close window, even last autofillid that requestShowUi does not match. Bug: 73796497 Test: atest CtsAutoFillServiceTestCases Test: Added LoginActivityTest.testAutofillTapOutside Test: manually tested using IME and sample app TODO: need a fake IME service to dispatch given key upon touch. Change-Id: I10fc0d29dc30d29a48b2118264ec1c4375062deb --- core/java/android/view/ViewRootImpl.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'core/java/android/view/ViewRootImpl.java') diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 01d9265cc92c..62755669affd 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -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(); } -- cgit v1.2.3