Track focus changes on external displays (2/4)
Let each DisplayContent has its own focused window and focused app.
This change also moves the last tapped display to the top.
Test: atest ActivityManagerMultiDisplayTests
ActivityStackSupervisorTests
ActivityStackTests
CtsWindowManagerDeviceTestCases
DisplayContentTests
PointerCaptureTest
Bug: 111361570
Change-Id: I776cabaeaf41ff4240f504fb1430d3e40892023d
diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java b/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java
index 0345a81..3d0bdc9 100644
--- a/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java
+++ b/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java
@@ -232,6 +232,7 @@
doReturn(displaySleeping).when(display).isSleeping();
doReturn(keyguardShowing).when(keyguard).isKeyguardOrAodShowing(anyInt());
+ doReturn(isFocusedStack).when(stack).isFocusedStackOnDisplay();
doReturn(isFocusedStack ? stack : null).when(display).getFocusedStack();
mSupervisor.applySleepTokensLocked(true);
verify(stack, times(expectWakeFromSleep ? 1 : 0)).awakeFromSleepingLocked();
diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java b/services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java
index ab814ee..5fcd2aa 100644
--- a/services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java
+++ b/services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java
@@ -38,6 +38,7 @@
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
import android.content.pm.ActivityInfo;
import android.os.UserHandle;
@@ -71,8 +72,8 @@
setupActivityTaskManagerService();
mDefaultDisplay = mSupervisor.getDefaultDisplay();
- mStack = mDefaultDisplay.createStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD,
- true /* onTop */);
+ mStack = spy(mDefaultDisplay.createStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD,
+ true /* onTop */));
mTask = new TaskBuilder(mSupervisor).setStack(mStack).build();
}
@@ -720,7 +721,7 @@
doReturn(display).when(mSupervisor).getActivityDisplay(anyInt());
doReturn(keyguardGoingAway).when(keyguardController).isKeyguardGoingAway();
doReturn(displaySleeping).when(display).isSleeping();
- doReturn(focusedStack ? mStack : null).when(mSupervisor).getTopDisplayFocusedStack();
+ doReturn(focusedStack).when(mStack).isFocusedStackOnDisplay();
assertEquals(expected, mStack.shouldSleepActivities());
}
diff --git a/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java
index b330304..96c5fde 100644
--- a/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java
+++ b/services/tests/servicestests/src/com/android/server/wm/DisplayContentTests.java
@@ -32,6 +32,7 @@
import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
import static com.android.server.wm.WindowContainer.POSITION_TOP;
+import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
@@ -303,7 +304,8 @@
createTapEvent(dm0.widthPixels / 2, dm0.heightPixels / 2, false));
// Check focus is on primary display.
- assertEquals(sWm.mCurrentFocus, dc0.findFocusedWindow());
+ assertEquals(sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus,
+ dc0.findFocusedWindow());
// Tap on secondary display
DisplayMetrics dm1 = dc1.getDisplayMetrics();
@@ -313,7 +315,8 @@
createTapEvent(dm1.widthPixels / 2, dm1.heightPixels / 2, false));
// Check focus is on secondary.
- assertEquals(sWm.mCurrentFocus, dc1.findFocusedWindow());
+ assertEquals(sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus,
+ dc1.findFocusedWindow());
}
@Test
@@ -321,34 +324,29 @@
// Create a focusable window and check that focus is calculated correctly
final WindowState window1 =
createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "window1");
- assertEquals(window1, sWm.mRoot.computeFocusedWindow());
+ updateFocusedWindow();
+ assertTrue(window1.isFocused());
+ assertEquals(window1, sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus);
// Check that a new display doesn't affect focus
final DisplayContent dc = createNewDisplay();
- assertEquals(window1, sWm.mRoot.computeFocusedWindow());
+ updateFocusedWindow();
+ assertTrue(window1.isFocused());
+ assertEquals(window1, sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus);
// Add a window to the second display, and it should be focused
final WindowState window2 = createWindow(null, TYPE_BASE_APPLICATION, dc, "window2");
- assertEquals(window2, sWm.mRoot.computeFocusedWindow());
+ updateFocusedWindow();
+ assertTrue(window1.isFocused());
+ assertTrue(window2.isFocused());
+ assertEquals(window2, sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus);
// Move the first window to the to including parents, and make sure focus is updated
window1.getParent().positionChildAt(POSITION_TOP, window1, true);
- assertEquals(window1, sWm.mRoot.computeFocusedWindow());
- }
-
- @Test
- public void testKeyguard_preventsSecondaryDisplayFocus() throws Exception {
- final WindowState keyguard = createWindow(null, TYPE_STATUS_BAR,
- sWm.getDefaultDisplayContentLocked(), "keyguard");
- assertEquals(keyguard, sWm.mRoot.computeFocusedWindow());
-
- // Add a window to a second display, and it should be focused
- final DisplayContent dc = createNewDisplay();
- final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, dc, "win");
- assertEquals(win, sWm.mRoot.computeFocusedWindow());
-
- mWmRule.getWindowManagerPolicy().keyguardShowingAndNotOccluded = true;
- assertEquals(keyguard, sWm.mRoot.computeFocusedWindow());
+ updateFocusedWindow();
+ assertTrue(window1.isFocused());
+ assertTrue(window2.isFocused());
+ assertEquals(window1, sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus);
}
/**
@@ -590,6 +588,12 @@
assertEquals(displayContent.mBaseDisplayDensity, expectedBaseDensity);
}
+ private void updateFocusedWindow() {
+ synchronized (sWm.mWindowMap) {
+ sWm.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false);
+ }
+ }
+
/**
* Create DisplayContent that does not update display base/initial values from device to keep
* the values set by test.