From a56779d1ab1f73385881cab4a945f376df27a84c Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Mon, 13 Apr 2020 23:23:34 +0800 Subject: [PATCH] Fix the logics in ImeFocusController#onPostWindowFocus In ImeFocusController#onPostWindowFocus -> onViewFocusChanged, it implies that the view has focus after onPostWindowFocus, this logics we keep leveraged from IMM#onPostWindowFocus -> focusInLocked() long ago, which may not always be true as SearchView layout may call View#clearFocus when size changed after IME switcher shown. When IME switched and back to app activity, in the above call path, even activity window focused, and set the fallback focus view as activity's root view, but the root view is not actually focused, if we set this view as the next served view, then calling View#onCreateInputConnection will return null, because it's not an editor. Use correct view focus state when calling onViewFocusChanged. Fix: 153612876 Test: manual as below: 1) Launch Files app, taps SearchView EditText 2) switch IMEs with IME switcher dialog 3) see if Password keyboard shown. 4) keeps 2) and 3) several time. Expected: There is no password keyboard and the keyboard input is still workable. Change-Id: I68bb95fc3cbfe1f5992ccf87694b34c3e52bb31f --- core/java/android/view/ImeFocusController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/view/ImeFocusController.java b/core/java/android/view/ImeFocusController.java index dbbe4b61c81c9..d6d9fc628ac9f 100644 --- a/core/java/android/view/ImeFocusController.java +++ b/core/java/android/view/ImeFocusController.java @@ -123,7 +123,7 @@ public final class ImeFocusController { } // Update mNextServedView when focusedView changed. final View viewForWindowFocus = focusedView != null ? focusedView : mViewRootImpl.mView; - onViewFocusChanged(viewForWindowFocus, true); + onViewFocusChanged(viewForWindowFocus, viewForWindowFocus.hasFocus()); immDelegate.startInputAsyncOnWindowFocusGain(viewForWindowFocus, windowAttribute.softInputMode, windowAttribute.flags, forceFocus);