From 6272c7f83fd1e78ec610d84621abfd0b87680465 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Fri, 17 Mar 2017 17:22:35 -0700 Subject: [PATCH] Do not remove the default display during tests. The default display is used by some tests that exercise features only functional only on the default display (like policy rotation). This CL makes this display not get removed with the created test displays and ensures no collision in id space from a previous test run (done in the test setup). Change-Id: Ia14b9c023c779d263283fe8c7b512dca17ff312f Fix: 36385757 Test: bit FrameworksServicesTests:com.android.server.wm.StackWindowControllerTests#testRemoveContainer_deferRemoval --- .../android/server/wm/AppWindowTokenTests.java | 5 +++-- .../com/android/server/wm/WindowTestsBase.java | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) 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;