Displays that have focused apps can also be top focused
There was no focus window during activity switches.
- While starting an activity, the previous top activity was paused and set
the AppWindowToken.hiddenRequested to true (while #setVisibility)
- While finishing current top activity, the focused window was updated a
bit early, which was before the next top activity resumed.
In both two cases, the focused window was set to null for a small amount of
time. So, we tried to look up the focus in other displays and resulted
the extra onWindowFocusChanged() calls for activities on other displays.
Bug: 131374329
Test: DisplayContentTests
Change-Id: Ia77bf697c237696cad7b42ca6b38157eff497b23
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 e60e54c..04f897e 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
@@ -380,6 +380,14 @@
assertTrue(window1.isFocused());
assertEquals(perDisplayFocusEnabled && targetSdk >= Q, window2.isFocused());
assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus);
+
+ // Make sure top focused display not changed if there is a focused app.
+ window1.mAppToken.hiddenRequested = true;
+ window1.getDisplayContent().setFocusedApp(window1.mAppToken);
+ updateFocusedWindow();
+ assertTrue(!window1.isFocused());
+ assertEquals(window1.getDisplayId(),
+ mWm.mRoot.getTopFocusedDisplayContent().getDisplayId());
}
/**