From 216740142fa7939149404cb6725950509a492cb5 Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Wed, 1 Jun 2022 17:54:22 +0000 Subject: [PATCH] Fix unexpected IME visible temporary while dismissing the editor dialog In DC#computeImeParent we defer reparenting IME surface to the target until the target has started the input to be the input target since the IME requested visibility will updated after then. However the logic didn't aware of the IME input target may null when it be removed, so IME surface will be appear on the display area if the next layering target has not yet to start the input. The lucky thing is CloseImeEditorPopupDialogTest caught this errorprone when verifying IME layer will expected gone after IME-snapshot/dialog dismissed, but actually may failed by IME layer may still visible after dismissed the dialog. Fix this defer IME reparent logic and also consolidate CloseImeEditorPopupDialogTest in FlickerTest to verify IME snpshot and IME visiblity until IME window has gone to ensure the layer tracing could record the full animation frames to verify the IME-snapshot / IME layer visiblity correctly during the animation. Fix: 231108751 Test: atest FlickerTests:CloseImeEditorPopupDialogTest --rerun-until-failure 20 Change-Id: I863231507c210739fd363746ccbc8ac9072e8094 --- services/core/java/com/android/server/wm/DisplayContent.java | 4 ++-- .../src/com/android/server/wm/DisplayContentTests.java | 3 +++ .../server/wm/flicker/ime/CloseImeEditorPopupDialogTest.kt | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index a870ed3faa284..974340ee2510e 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -4407,8 +4407,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp boolean imeLayeringTargetMayUseIme = LayoutParams.mayUseInputMethod(mImeLayeringTarget.mAttrs.flags) || mImeLayeringTarget.mAttrs.type == TYPE_APPLICATION_STARTING; - if (imeLayeringTargetMayUseIme && mImeInputTarget != null - && mImeLayeringTarget.mActivityRecord != mImeInputTarget.getActivityRecord()) { + if (imeLayeringTargetMayUseIme && (mImeInputTarget == null + || mImeLayeringTarget.mActivityRecord != mImeInputTarget.getActivityRecord())) { // Do not change parent if the window hasn't requested IME. return null; } 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 b27060872baa5..8f5da44212800 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java @@ -643,6 +643,7 @@ public class DisplayContentTests extends WindowTestsBase { final DisplayContent dc = mDisplayContent; final WindowState ws = createWindow(null, TYPE_APPLICATION, dc, "app window"); dc.setImeLayeringTarget(ws); + dc.setImeInputTarget(ws); // Adjust bounds so that matchesRootDisplayAreaBounds() returns false. final Rect bounds = new Rect(dc.getBounds()); @@ -1154,6 +1155,7 @@ public class DisplayContentTests extends WindowTestsBase { dc.setImeLayeringTarget(createWindow(null, TYPE_STATUS_BAR, "app")); dc.getImeTarget(IME_TARGET_LAYERING).getWindow().setWindowingMode( WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW); + dc.setImeInputTarget(dc.getImeTarget(IME_TARGET_LAYERING).getWindow()); assertEquals(dc.getImeContainer().getParentSurfaceControl(), dc.computeImeParent()); } @@ -1172,6 +1174,7 @@ public class DisplayContentTests extends WindowTestsBase { public void testComputeImeParent_noApp() throws Exception { final DisplayContent dc = createNewDisplay(); dc.setImeLayeringTarget(createWindow(null, TYPE_STATUS_BAR, "statusBar")); + dc.setImeInputTarget(dc.getImeTarget(IME_TARGET_LAYERING).getWindow()); assertEquals(dc.getImeContainer().getParentSurfaceControl(), dc.computeImeParent()); } diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/CloseImeEditorPopupDialogTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/CloseImeEditorPopupDialogTest.kt index 6257484be9bde..2e29b3e314ca7 100644 --- a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/CloseImeEditorPopupDialogTest.kt +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/CloseImeEditorPopupDialogTest.kt @@ -59,7 +59,7 @@ class CloseImeEditorPopupDialogTest(private val testSpec: FlickerTestParameter) } transitions { imeTestApp.dismissDialog(wmHelper) - instrumentation.uiAutomation.syncInputTransactions() + wmHelper.waitImeGone() } teardown { eachRun { @@ -91,7 +91,7 @@ class CloseImeEditorPopupDialogTest(private val testSpec: FlickerTestParameter) .then() .isVisible(FlickerComponentName.IME_SNAPSHOT) .then() - .isInvisible(FlickerComponentName.IME_SNAPSHOT) + .isInvisible(FlickerComponentName.IME_SNAPSHOT, isOptional = true) .isInvisible(FlickerComponentName.IME) } }