From 310de9e5ee7b57b928e7a6613d61bcfb1c0bf166 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Wed, 15 Mar 2017 10:18:21 -0700 Subject: [PATCH] Fix AppWindowTokenTests#testLandscapeSeascapeRotationByPolicy Previously this test was marked as blocked by b/35034729. This bug has been fixed, however the test still fails due to other issues addressed here. Addressed issues are as follows: 1. Updating rotation by display manager requires a display with the default display id present. This display is removed during setup. The first id to be used by a display after this point is the default id + 1. We already have logic in place to avoid collisions so it is safe and correct to start out at the default id. 2. Without allowing the animator to complete its steps after a rotation, future rotations will be deferred. We must simulate the steps taken by the and resulting from the animtor. These include marking the orientation change as complete and performing a surface placement afterwards. Bug: 35034729 Test: bit FrameworksServicesTests:com.android.server.wm.AppWindowTokenTests Change-Id: Ib01c047ac49982a4a3c1debaa3cee1b7b9b53632 --- .../android/server/wm/AppWindowTokenTests.java | 17 ++++++++++------- .../com/android/server/wm/WindowTestsBase.java | 5 ++++- 2 files changed, 14 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 e15d40eecbc0c..125052f0a01f7 100644 --- a/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java @@ -126,8 +126,6 @@ public class AppWindowTokenTests extends WindowTestsBase { } @Test - @Ignore - // TODO(b/35034729): Need to fix before re-enabling public void testLandscapeSeascapeRotationByPolicy() throws Exception { // Some plumbing to get the service ready for rotation updates. sWm.mDisplayReady = true; @@ -145,15 +143,20 @@ public class AppWindowTokenTests extends WindowTestsBase { appWindowToken.addWindow(appWindow); // Set initial orientation and update. - ((TestWindowManagerPolicy) sWm.mPolicy).rotationToReport = Surface.ROTATION_90; - sWm.updateRotation(false, false); + performRotation(Surface.ROTATION_90); appWindow.resizeReported = false; // Update the rotation to perform 180 degree rotation and check that resize was reported. - ((TestWindowManagerPolicy) sWm.mPolicy).rotationToReport = Surface.ROTATION_270; - sWm.updateRotation(false, false); - sWm.mRoot.performSurfacePlacement(false /* recoveringMemory */); + performRotation(Surface.ROTATION_270); assertTrue(appWindow.resizeReported); appWindow.removeImmediately(); } + + private void performRotation(int rotationToReport) { + ((TestWindowManagerPolicy) sWm.mPolicy).rotationToReport = rotationToReport; + sWm.updateRotation(false, false); + // Simulate animator finishing orientation change + sWm.mRoot.mOrientationChangeComplete = true; + sWm.mRoot.performSurfacePlacement(false /* recoveringMemory */); + } } 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 18c48b71270df..620be39067933 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowTestsBase.java @@ -70,7 +70,10 @@ class WindowTestsBase { static WindowManagerService sWm = null; static TestWindowManagerPolicy sPolicy = null; private final static Session sMockSession = mock(Session.class); - private static int sNextDisplayId = Display.DEFAULT_DISPLAY + 1; + // 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; static int sNextStackId = FIRST_DYNAMIC_STACK_ID; private static int sNextTaskId = 0;