From 9239d7c6788234c73fb659e63ec41492746983e6 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Thu, 20 Feb 2020 01:35:56 +0800 Subject: [PATCH] Fix seamless condition of fixed rotation transform The top window from display policy relies on layout to be updated. It is more accurate to check the active transformed record. Fix: 149793692 Test: atest DisplayContentTests#testApplyTopFixedRotationTransform Change-Id: I8694190faab343e6c524a4399fec0a9b16bfa561 --- .../com/android/server/wm/DisplayRotation.java | 10 ++++------ .../com/android/server/wm/DisplayContentTests.java | 14 ++++++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java index 1a0dcb9e12185..0e84b152296e3 100644 --- a/services/core/java/com/android/server/wm/DisplayRotation.java +++ b/services/core/java/com/android/server/wm/DisplayRotation.java @@ -552,16 +552,14 @@ public class DisplayRotation { @VisibleForTesting boolean shouldRotateSeamlessly(int oldRotation, int newRotation, boolean forceUpdate) { - final WindowState w = mDisplayPolicy.getTopFullscreenOpaqueWindow(); - if (w == null) { - return false; - } // Display doesn't need to be frozen because application has been started in correct // rotation already, so the rest of the windows can use seamless rotation. - if (w.mToken.hasFixedRotationTransform()) { + if (mDisplayContent.mFixedRotationLaunchingApp != null) { return true; } - if (w != mDisplayContent.mCurrentFocus) { + + final WindowState w = mDisplayPolicy.getTopFullscreenOpaqueWindow(); + if (w == null || w != mDisplayContent.mCurrentFocus) { return false; } // We only enable seamless rotation if the top window has requested it and is in the 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 1a8f2a6b65f53..b3c6b22bf265c 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java @@ -27,6 +27,7 @@ import static android.view.Display.DEFAULT_DISPLAY; import static android.view.DisplayCutout.BOUNDS_POSITION_LEFT; import static android.view.DisplayCutout.BOUNDS_POSITION_TOP; import static android.view.DisplayCutout.fromBoundingRect; +import static android.view.Surface.ROTATION_0; import static android.view.Surface.ROTATION_90; import static android.view.View.SYSTEM_UI_FLAG_FULLSCREEN; import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; @@ -998,12 +999,10 @@ public class DisplayContentTests extends WindowTestsBase { public void testApplyTopFixedRotationTransform() { mWm.mIsFixedRotationTransformEnabled = true; final Configuration config90 = new Configuration(); - mDisplayContent.getDisplayRotation().setRotation(ROTATION_90); - mDisplayContent.computeScreenConfiguration(config90); - mDisplayContent.onRequestedOverrideConfigurationChanged(config90); + mDisplayContent.computeScreenConfiguration(config90, ROTATION_90); final Configuration config = new Configuration(); - mDisplayContent.getDisplayRotation().setRotation(Surface.ROTATION_0); + mDisplayContent.getDisplayRotation().setRotation(ROTATION_0); mDisplayContent.computeScreenConfiguration(config); mDisplayContent.onRequestedOverrideConfigurationChanged(config); @@ -1014,11 +1013,18 @@ public class DisplayContentTests extends WindowTestsBase { app.setRequestedOrientation(SCREEN_ORIENTATION_LANDSCAPE); assertTrue(app.isFixedRotationTransforming()); + assertTrue(mDisplayContent.getDisplayRotation().shouldRotateSeamlessly( + ROTATION_0 /* oldRotation */, ROTATION_90 /* newRotation */, + false /* forceUpdate */)); + // The display should keep current orientation and the rotated configuration should apply + // to the activity. assertEquals(config.orientation, mDisplayContent.getConfiguration().orientation); assertEquals(config90.orientation, app.getConfiguration().orientation); + assertEquals(config90.windowConfiguration.getBounds(), app.getBounds()); mDisplayContent.mAppTransition.notifyAppTransitionFinishedLocked(app.token); + // The display should be rotated after the launch is finished. assertFalse(app.hasFixedRotationTransform()); assertEquals(config90.orientation, mDisplayContent.getConfiguration().orientation); }