From e525c01439d1fc1c4c4ce48ebe4ab1a41a4bd03a Mon Sep 17 00:00:00 2001 From: Wilson Wu Date: Tue, 18 May 2021 15:15:14 +0800 Subject: Fix IME be dismissed abruptly CL[1] used to fix some IME animation issue. And simplified the check focused view logic. But when window focus changed, the focused view may still be null. So ImeFocusdController use the DecorView to start an new Input and hide keyboard. Use the focused view after focus change callbacks when we call onPostWindowFocus as before. [1]: Ib140801f1ce03b5566e756914f96dacba3ad8892 Bug: 186331446 Test: Manual test with the bug steps Test: atest FocusHandlingTest#testRequestFocusOnWindowFocusChanged Change-Id: I2f8fde0b6575db17955ff8b8804b61378f9d6dad --- core/java/android/view/ViewRootImpl.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (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 89562dc494e9..bb2cea9fb957 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -3370,9 +3370,9 @@ public final class ViewRootImpl implements ViewParent, } // TODO (b/131181940): Make sure this doesn't leak Activity with mActivityConfigCallback // config changes. - final View focusedView = mView != null ? mView.findFocus() : null; if (hasWindowFocus) { - mInsetsController.onWindowFocusGained(focusedView != null /* hasViewFocused */); + mInsetsController.onWindowFocusGained( + getFocusedViewOrNull() != null /* hasViewFocused */); } else { mInsetsController.onWindowFocusLost(); } @@ -3421,7 +3421,8 @@ public final class ViewRootImpl implements ViewParent, // Note: must be done after the focus change callbacks, // so all of the view state is set up correctly. - mImeFocusController.onPostWindowFocus(focusedView, hasWindowFocus, mWindowAttributes); + mImeFocusController.onPostWindowFocus( + getFocusedViewOrNull(), hasWindowFocus, mWindowAttributes); if (hasWindowFocus) { // Clear the forward bit. We can just do this directly, since @@ -6390,6 +6391,11 @@ public final class ViewRootImpl implements ViewParent, mView.dispatchTooltipHoverEvent(event); } + @Nullable + private View getFocusedViewOrNull() { + return mView != null ? mView.findFocus() : null; + } + /** * Performs synthesis of new input events from unhandled input events. */ -- cgit v1.2.3