@@ -393,23 +393,25 @@ public void testClearFixedRotationLaunchingAppAfterCleanupAnimation() {
393393 // Simulate giving up the swipe up gesture to keep the original activity as top.
394394 mController .cleanupAnimation (REORDER_MOVE_TO_ORIGINAL_POSITION );
395395 // The rotation transform should be cleared after updating orientation with display.
396- assertFalse (activity .hasFixedRotationTransform ());
397- assertFalse (mDefaultDisplay .hasTopFixedRotationLaunchingApp ());
396+ assertTopFixedRotationLaunchingAppCleared (activity );
398397
399398 // Simulate swiping up recents (home) in different rotation.
400399 final ActivityRecord home = mDefaultDisplay .getDefaultTaskDisplayArea ().getHomeActivity ();
401- mDefaultDisplay .setFixedRotationLaunchingApp (home , (mDefaultDisplay .getRotation () + 1 ) % 4 );
402- mController = new RecentsAnimationController (mWm , mMockRunner , mAnimationCallbacks ,
403- mDefaultDisplay .getDisplayId ());
404- initializeRecentsAnimationController (mController , home );
405- assertTrue (home .hasFixedRotationTransform ());
400+ startRecentsInDifferentRotation (home );
406401
402+ // If the recents activity becomes the top running activity (e.g. the original top activity
403+ // is either finishing or moved to back during recents animation), the display orientation
404+ // will be determined by it so the fixed rotation must be cleared.
405+ activity .finishing = true ;
406+ mController .cleanupAnimation (REORDER_MOVE_TO_ORIGINAL_POSITION );
407+ assertTopFixedRotationLaunchingAppCleared (home );
408+
409+ startRecentsInDifferentRotation (home );
407410 // Assume recents activity becomes invisible for some reason (e.g. screen off).
408411 home .setVisible (false );
409412 mController .cleanupAnimation (REORDER_MOVE_TO_ORIGINAL_POSITION );
410413 // Although there won't be a transition finish callback, the fixed rotation must be cleared.
411- assertFalse (home .hasFixedRotationTransform ());
412- assertFalse (mDefaultDisplay .hasTopFixedRotationLaunchingApp ());
414+ assertTopFixedRotationLaunchingAppCleared (home );
413415 }
414416
415417 @ Test
@@ -503,6 +505,21 @@ private ActivityRecord createHomeActivity() {
503505 return homeActivity ;
504506 }
505507
508+ private void startRecentsInDifferentRotation (ActivityRecord recentsActivity ) {
509+ final DisplayContent displayContent = recentsActivity .mDisplayContent ;
510+ displayContent .setFixedRotationLaunchingApp (recentsActivity ,
511+ (displayContent .getRotation () + 1 ) % 4 );
512+ mController = new RecentsAnimationController (mWm , mMockRunner , mAnimationCallbacks ,
513+ displayContent .getDisplayId ());
514+ initializeRecentsAnimationController (mController , recentsActivity );
515+ assertTrue (recentsActivity .hasFixedRotationTransform ());
516+ }
517+
518+ private static void assertTopFixedRotationLaunchingAppCleared (ActivityRecord activity ) {
519+ assertFalse (activity .hasFixedRotationTransform ());
520+ assertFalse (activity .mDisplayContent .hasTopFixedRotationLaunchingApp ());
521+ }
522+
506523 private static void initializeRecentsAnimationController (RecentsAnimationController controller ,
507524 ActivityRecord activity ) {
508525 controller .initialize (activity .getActivityType (), new SparseBooleanArray (), activity );
0 commit comments