From 5a06af21df9edfb14fe0d169d5baa72afc9756e9 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 9 Dec 2022 16:14:10 +0000 Subject: [PATCH] Fix high flakiness of InsetsPolicyTest The spy() will return a different instance. The caller who doesn't use the instance will only update its own fields. The test app window was default non-focusable set up by test. So it was no problem before the change [1], that there will be no candidate window in updateSystemBarAttributes. Now updateSystemBarAttributes will choose the app window and then updateBarControlTarget(). That causes abortTransient() because focus change. And the focus change is because the policy.updateBarControlTarget updated to a different instance of InsetsPolicy#mFocusedWin. [1] I957e1eddcfa3f7b873f7a9b32eeaf69db5927b00 Bug: 254268165 Test: atest InsetsPolicyTest Change-Id: I21eb14313cc848894b6be3aafc4965a42c10ae0d --- .../com/android/server/wm/InsetsPolicyTest.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java b/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java index fd2a1d1c352fa..c7971bc7911f0 100644 --- a/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java @@ -37,6 +37,8 @@ import static android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE; import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; +import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -46,7 +48,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import android.app.StatusBarManager; @@ -265,7 +266,8 @@ public class InsetsPolicyTest extends WindowTestsBase { final WindowState navBar = addNavigationBar(); navBar.setHasSurface(true); navBar.getControllableInsetProvider().setServerVisible(true); - final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy()); + final InsetsPolicy policy = mDisplayContent.getInsetsPolicy(); + spyOn(policy); doNothing().when(policy).startAnimation(anyBoolean(), any()); // Make both system bars invisible. @@ -302,12 +304,15 @@ public class InsetsPolicyTest extends WindowTestsBase { addStatusBar().getControllableInsetProvider().getSource().setVisible(false); addNavigationBar().getControllableInsetProvider().setServerVisible(true); - final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy()); + final InsetsPolicy policy = mDisplayContent.getInsetsPolicy(); + spyOn(policy); doNothing().when(policy).startAnimation(anyBoolean(), any()); policy.updateBarControlTarget(mAppWindow); policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR}, true /* isGestureOnSystemBar */); waitUntilWindowAnimatorIdle(); + assertTrue(policy.isTransient(ITYPE_STATUS_BAR)); + assertFalse(policy.isTransient(ITYPE_NAVIGATION_BAR)); final InsetsSourceControl[] controls = mDisplayContent.getInsetsStateController().getControlsForDispatch(mAppWindow); @@ -335,7 +340,8 @@ public class InsetsPolicyTest extends WindowTestsBase { navBarSource.setVisible(false); mAppWindow.mAboveInsetsState.addSource(navBarSource); mAppWindow.mAboveInsetsState.addSource(statusBarSource); - final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy()); + final InsetsPolicy policy = mDisplayContent.getInsetsPolicy(); + spyOn(policy); doNothing().when(policy).startAnimation(anyBoolean(), any()); policy.updateBarControlTarget(mAppWindow); policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR}, @@ -383,7 +389,8 @@ public class InsetsPolicyTest extends WindowTestsBase { final WindowState app = addWindow(TYPE_APPLICATION, "app"); final WindowState app2 = addWindow(TYPE_APPLICATION, "app"); - final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy()); + final InsetsPolicy policy = mDisplayContent.getInsetsPolicy(); + spyOn(policy); doNothing().when(policy).startAnimation(anyBoolean(), any()); policy.updateBarControlTarget(app); policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR},