diff --git a/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java b/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java index 921e0e3deeb47..b5826f0c1106b 100644 --- a/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java @@ -132,9 +132,10 @@ public class AppWindowTokenTests extends WindowTestsBase { sWm.mDisplayEnabled = true; // Create an app window with token on a display. - final TaskStack stack = createTaskStackOnDisplay(sDisplayContent); + final DisplayContent defaultDisplayContent = sWm.getDefaultDisplayContentLocked(); + final TaskStack stack = createTaskStackOnDisplay(defaultDisplayContent); final Task task = createTaskInStack(stack, 0 /* userId */); - final TestAppWindowToken appWindowToken = new TestAppWindowToken(sDisplayContent); + final TestAppWindowToken appWindowToken = new TestAppWindowToken(defaultDisplayContent); task.addChild(appWindowToken, 0); final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( TYPE_BASE_APPLICATION); diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java b/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java index 65efd9cd23aed..ce632ae619133 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java @@ -73,8 +73,8 @@ class WindowTestsBase { private final static Session sMockSession = mock(Session.class); // The default display is removed in {@link #setUp} and then we iterate over all displays to // make sure we don't collide with any existing display. If we run into no other display, the - // added display should be treated as default. - private static int sNextDisplayId = Display.DEFAULT_DISPLAY; + // added display should be treated as default. This cannot be the default display + private static int sNextDisplayId = Display.DEFAULT_DISPLAY + 1; static int sNextStackId = FIRST_DYNAMIC_STACK_ID; private static int sNextTaskId = 0; @@ -105,17 +105,23 @@ class WindowTestsBase { sWm = TestWindowManagerPolicy.getWindowManagerService(context); sPolicy = (TestWindowManagerPolicy) sWm.mPolicy; sLayersController = new WindowLayersController(sWm); - sDisplayContent = sWm.mRoot.getDisplayContent(context.getDisplay().getDisplayId()); - if (sDisplayContent != null) { - sDisplayContent.removeImmediately(); - } + // Make sure that display ids don't overlap, so there won't be several displays with same // ids among RootWindowContainer children. for (DisplayContent dc : sWm.mRoot.mChildren) { if (dc.getDisplayId() >= sNextDisplayId) { sNextDisplayId = dc.getDisplayId() + 1; } + + // The default display must be preserved as some tests require it to function + // (such as policy rotation). + if (dc.getDisplayId() != Display.DEFAULT_DISPLAY) { + // It is safe to remove these displays as new displays will always be created with + // new ids. + dc.removeImmediately(); + } } + context.getDisplay().getDisplayInfo(sDisplayInfo); sDisplayContent = createNewDisplay(); sWm.mDisplayEnabled = true;