From 70a920cdd0e1574b2224a399f6347c888e5ab97d Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Tue, 5 May 2020 17:20:32 +0800 Subject: [PATCH] Update display orientation that was interrupted by recents animation When launching an activity with different orientation, the recents animation can still be started before the transition is completed. During animating recents, the display will keep original orientation. So once the recents animation is finished, it still needs to check again if the top activity may have pending orientation change. Fixes: 155863908 Test: atest RecentsAnimationControllerTest# \ testClearFixedRotationLaunchingAppAfterCleanupAnimation Change-Id: I0f85dae9f55073fefe366d1f82929f5d250fc866 --- .../com/android/server/wm/DisplayContent.java | 23 +++++++--- .../server/wm/RecentsAnimationController.java | 7 +--- .../com/android/server/wm/WindowToken.java | 5 +++ .../wm/RecentsAnimationControllerTest.java | 42 +++++++++++++++---- 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 1f10c467e1e6f..5461af68b01ca 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -5531,7 +5531,7 @@ class DisplayContent extends WindowContainer { pw.print(" waitingToShow=true"); } pw.println(); + if (hasFixedRotationTransform()) { + pw.print(prefix); + pw.print("fixedRotationConfig="); + pw.println(mFixedRotationTransformState.mRotatedOverrideConfiguration); + } } @Override diff --git a/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java index 906646894ee0f..209db62f38deb 100644 --- a/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java @@ -16,7 +16,6 @@ package com.android.server.wm; -import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.view.Display.DEFAULT_DISPLAY; @@ -159,7 +158,7 @@ public class RecentsAnimationControllerTest extends WindowTestsBase { hiddenActivity.setVisible(false); mDefaultDisplay.getConfiguration().windowConfiguration.setRotation( mDefaultDisplay.getRotation()); - mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeActivity); + initializeRecentsAnimationController(mController, homeActivity); // Ensure that we are animating the target activity as well assertTrue(mController.isAnimatingTask(homeActivity.getTask())); @@ -182,7 +181,7 @@ public class RecentsAnimationControllerTest extends WindowTestsBase { mDefaultDisplay.getConfiguration().windowConfiguration.setRotation( mDefaultDisplay.getRotation()); - mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeActivity); + initializeRecentsAnimationController(mController, homeActivity); mController.startAnimation(); // Ensure that we are animating the app and wallpaper target @@ -205,7 +204,7 @@ public class RecentsAnimationControllerTest extends WindowTestsBase { mDefaultDisplay.getConfiguration().windowConfiguration.setRotation( mDefaultDisplay.getRotation()); - mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeActivity); + initializeRecentsAnimationController(mController, homeActivity); mController.startAnimation(); // Cancel the animation and ensure the controller is still running @@ -231,7 +230,7 @@ public class RecentsAnimationControllerTest extends WindowTestsBase { doReturn(true).when(mDefaultDisplay.mWallpaperController).isWallpaperVisible(); // Start and finish the animation - mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeActivity); + initializeRecentsAnimationController(mController, homeActivity); mController.startAnimation(); assertTrue(mController.isAnimatingTask(homeActivity.getTask())); @@ -342,7 +341,7 @@ public class RecentsAnimationControllerTest extends WindowTestsBase { assertEquals(Configuration.ORIENTATION_LANDSCAPE, mDefaultDisplay.getConfiguration().orientation); - mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeActivity); + initializeRecentsAnimationController(mController, homeActivity); assertEquals(homeActivity, mDefaultDisplay.mFixedRotationLaunchingApp); @@ -357,6 +356,30 @@ public class RecentsAnimationControllerTest extends WindowTestsBase { assertNull(mDefaultDisplay.mFixedRotationLaunchingApp); } + @Test + public void testClearFixedRotationLaunchingAppAfterCleanupAnimation() { + final ActivityRecord homeActivity = createHomeActivity(); + homeActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + final ActivityRecord activity = createActivityRecord(mDefaultDisplay, + WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); + // Assume an activity is launching to different rotation. + mDefaultDisplay.setFixedRotationLaunchingApp(activity, + (mDefaultDisplay.getRotation() + 1) % 4); + + assertTrue(activity.hasFixedRotationTransform()); + assertEquals(activity, mDefaultDisplay.mFixedRotationLaunchingApp); + + // Before the transition is done, the recents animation is triggered. + initializeRecentsAnimationController(mController, homeActivity); + assertFalse(homeActivity.hasFixedRotationTransform()); + + // Simulate giving up the swipe up gesture to keep the original activity as top. + mController.cleanupAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION); + // The rotation transform should be cleared after updating orientation with display. + assertFalse(activity.hasFixedRotationTransform()); + assertNull(mDefaultDisplay.mFixedRotationLaunchingApp); + } + @Test public void testWallpaperHasFixedRotationApplied() { mWm.mIsFixedRotationTransformEnabled = true; @@ -394,7 +417,7 @@ public class RecentsAnimationControllerTest extends WindowTestsBase { doReturn(true).when(mDefaultDisplay.mWallpaperController).isWallpaperVisible(); // Start the recents animation - mController.initialize(ACTIVITY_TYPE_HOME, new SparseBooleanArray(), homeActivity); + initializeRecentsAnimationController(mController, homeActivity); mDefaultDisplay.mWallpaperController.adjustWallpaperWindows(); @@ -433,6 +456,11 @@ public class RecentsAnimationControllerTest extends WindowTestsBase { return homeActivity; } + private static void initializeRecentsAnimationController(RecentsAnimationController controller, + ActivityRecord activity) { + controller.initialize(activity.getActivityType(), new SparseBooleanArray(), activity); + } + private static void verifyNoMoreInteractionsExceptAsBinder(IInterface binder) { verify(binder, atLeast(0)).asBinder(); verifyNoMoreInteractions(binder);