From c7424a2848e613189b3ef71ba7b12eef9416a34c Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Wed, 1 Apr 2020 01:57:06 +0800 Subject: [PATCH] Only track focused next served view in onViewFocusChanged When introduced ImeFocusController, we originally would like to resolve CL[1] enabling IMM#focusOut issue to archieve auto-hide IME when no more view with focus. However, some problems that we end up to disable because: 1) Bug 152230171 shows the current view focus may be cleared temporary when in touch mode, closing input at this moment isn't the right way. 2) Bug 148974380 hits a case when tapping SearchView which is inside of ListView, several focus in/out events comes up and may break input connection unexptectly because wheather the next served view is no longer coming or not is unpredictable from this callback. Even we fixed the issue with CL[2] to tweak the next served view as null only when the current served view lost focus, we still can't guarantee that input connection won't break when current served view lost focus by moved to other focusable view (e.g. popup window) 3) Setting the next served view as null when no more served view should be handled more conservative in other special events (e.g. view detached from window or the window dismissed). [1]: I2228ae0c48ad3d9e0b55875f0dcb5ef8c55b0c5f [2]: I9e90428387fcf43fbf86a8407de7535913202872 Bug: 152698568 Test: atest FocusHandlingTest Change-Id: I6e38c4425233cea4b0a90285a2dc476b76c20979 --- core/java/android/view/ImeFocusController.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/ImeFocusController.java b/core/java/android/view/ImeFocusController.java index 6784cf7407fad..dbbe4b61c81c9 100644 --- a/core/java/android/view/ImeFocusController.java +++ b/core/java/android/view/ImeFocusController.java @@ -170,10 +170,15 @@ public final class ImeFocusController { } if (DEBUG) Log.d(TAG, "onViewFocusChanged, view=" + view + ", mServedView=" + mServedView); + // We don't need to track the next served view when the view lost focus here because: + // 1) The current view focus may be cleared temporary when in touch mode, closing input + // at this moment isn't the right way. + // 2) We only care about the served view change when it focused, since changing input + // connection when the focus target changed is reasonable. + // 3) Setting the next served view as null when no more served view should be handled in + // other special events (e.g. view detached from window or the window dismissed). if (hasFocus) { mNextServedView = view; - } else if (view == mServedView) { - mNextServedView = null; } mViewRootImpl.dispatchCheckFocus(); }