From e31d74b1162fd8921fad32e20de87daba419bb07 Mon Sep 17 00:00:00 2001 From: Taran Singh Date: Fri, 21 May 2021 19:19:12 +0000 Subject: [PATCH] Fix IME flicker to home screen w/ orientation change In [1] we attempted to updateImeParent() onConfigurationChange(), computeImeParent() can pick a parent that didnt even request IME. This can cause flicker when going from app to launcher. Adding a check for prevents this from happening. Fix: 188864578 Test: atest DisplayContentTests Change-Id: I01b67b9a7fdf04f23ab05c244281f42518352ca5 --- .../com/android/server/wm/DisplayContent.java | 4 ++++ .../android/server/wm/DisplayContentTests.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 1ec07d047e13f..bbf474c3eaa97 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -3963,6 +3963,10 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp // screen. If it's not covering the entire screen the IME might extend beyond the apps // bounds. if (allowAttachToApp && shouldImeAttachedToApp()) { + if (mImeLayeringTarget.mActivityRecord != mImeInputTarget.mActivityRecord) { + // Do not change parent if the window hasn't requested IME. + return null; + } return mImeLayeringTarget.mActivityRecord.getSurfaceControl(); } 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 6d4454bd964a9..e569376b7cce7 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java @@ -357,6 +357,22 @@ public class DisplayContentTests extends WindowTestsBase { verify(imeContainer).assignRelativeLayer(any(), eq(imeSurfaceParent), anyInt(), eq(true)); } + @Test + public void testComputeImeTargetReturnsNull_windowDidntRequestIme() { + final WindowState win1 = createWindow(null, TYPE_BASE_APPLICATION, + new ActivityBuilder(mAtm).setCreateTask(true).build(), "app"); + final WindowState win2 = createWindow(null, TYPE_BASE_APPLICATION, + new ActivityBuilder(mAtm).setCreateTask(true).build(), "app2"); + + mDisplayContent.setImeInputTarget(win1); + mDisplayContent.setImeLayeringTarget(win2); + + doReturn(true).when(mDisplayContent).shouldImeAttachedToApp(); + // Compute IME parent returns nothing if current target and window receiving input + // are different i.e. if current window didn't request IME. + assertNull("computeImeParent() should be null", mDisplayContent.computeImeParent()); + } + /** * This tests root task movement between displays and proper root task's, task's and app token's * display container references updates.