From f4f68a3eb273ee2cdd9dd6102b01d045c927af8d Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Fri, 30 Jul 2021 14:51:27 +0800 Subject: [PATCH] Fix Stay on 'SELECT INPUT METHOD' page after choosing input method CL[1] aims to fix a potential ANR issue happen when the IME focused app popup IME picker dialog and then switching another task through status bar settings button or notifications, system will filter the IME selection dialog window to not be the focused window when finding the next focus during switching to the next task. However, that filtering rule mistakes to ignore the IME picker dialog as focus window when Gboard 'SELECT INPUT METHOD' page popup IME picker dialog by using IMM#showInputMethodPicker (i.e. Gboard page still keeps focused), so that after choosed input method from picker, Gboard page will not receive onWindowFocusChanged callback to update the IME selection status, because the page has already focused. To fix this window focus issue of IME picker dialog and CL[1] issue scenerio , use WindowState#isAnimating() to check if the app window with IME picker dialog is under app transitioning, if so, then we can say it's safe to ignore IME picker focus. [1]: Iae3dd713b1e980067d28debea4e0a03707aa7938 Bug: 195073688 Bug: 194214768 Test: atest InputMethodManagerTest#testShowInputMethodPicker Test: atest atest DisplayContentTests#\ testImeMenuDialogFocusWhenImeLayeringTargetChanges Test: manual as issue steps: 0. Current input method is not Gboard (Canary). 1. Tap Gboard (Canary) icon on App list. 2. Tap 'SELECT INPUT METHOD' icon and select Gboard (Canary). 3. Verify the IME status should updated after dismissed IME picker dialog. Change-Id: I771d9817cd6dfcb1bf0d576d94bea9d1b9adc80e --- .../com/android/server/wm/DisplayContent.java | 16 ++++++++-------- .../android/server/wm/DisplayContentTests.java | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 4c1142257218b..1b799dfbdaabf 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -733,15 +733,15 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp // dismissing during the task switching to keep the window focus because IME window has // higher window hierarchy, we don't give it focus if the next IME layering target // doesn't request IME visible. - if (w.mIsImWindow && (mImeLayeringTarget == null + if (w.mIsImWindow && w.isChildWindow() && (mImeLayeringTarget == null || !mImeLayeringTarget.getRequestedVisibility(ITYPE_IME))) { - if (w.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { - return false; - } - - if (w.isChildWindow()) { - return false; - } + return false; + } + if (w.mAttrs.type == TYPE_INPUT_METHOD_DIALOG && mImeLayeringTarget != null + && !mImeLayeringTarget.getRequestedVisibility(ITYPE_IME) + && mImeLayeringTarget.isAnimating(PARENTS | TRANSITION, + ANIMATION_TYPE_APP_TRANSITION)) { + return false; } final ActivityRecord activity = w.mActivityRecord; diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java index c60b8dcf67cf7..12fc2f4ea1f46 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java @@ -2223,6 +2223,9 @@ public class DisplayContentTests extends WindowTestsBase { // request IME visible. final WindowState nextImeAppTarget = createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "nextImeAppTarget"); + spyOn(nextImeAppTarget); + doReturn(true).when(nextImeAppTarget).isAnimating(PARENTS | TRANSITION, + ANIMATION_TYPE_APP_TRANSITION); mDisplayContent.setImeLayeringTarget(nextImeAppTarget); assertNotEquals(imeMenuDialog, mDisplayContent.findFocusedWindow()); }