Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 498b87a3 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Clear fixed rotation if rotated recents activity becomes top

If recents animation is active, the transition is controlled by it.
There won't be a transition finish event after recents animation.
For example, if an activity finishes during swiping-up gesture,
the recents activity in rotated state won't be restored. So this
change checks whether recents become the top activity, then continue
the orientation update procedure to clear fixed rotation state and
let display orientation follow the current top.

Bug: 173143462
Test: atest RecentsAnimationControllerTest# \
            testClearFixedRotationLaunchingAppAfterCleanupAnimation
Change-Id: If82744bb846ac823c8fdd76bbf23b584b63776d4
parent 331168f1
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -5664,7 +5664,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            }
            }


            if (animatingRecents != null && animatingRecents == mFixedRotationLaunchingApp
            if (animatingRecents != null && animatingRecents == mFixedRotationLaunchingApp
                    && animatingRecents.isVisible()) {
                    && animatingRecents.isVisible() && animatingRecents != topRunningActivity()) {
                // The recents activity should be going to be invisible (switch to another app or
                // The recents activity should be going to be invisible (switch to another app or
                // return to original top). Only clear the top launching record without finishing
                // return to original top). Only clear the top launching record without finishing
                // the transform immediately because it won't affect display orientation. And before
                // the transform immediately because it won't affect display orientation. And before
+26 −9
Original line number Original line Diff line number Diff line
@@ -378,23 +378,25 @@ public class RecentsAnimationControllerTest extends WindowTestsBase {
        // Simulate giving up the swipe up gesture to keep the original activity as top.
        // Simulate giving up the swipe up gesture to keep the original activity as top.
        mController.cleanupAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION);
        mController.cleanupAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION);
        // The rotation transform should be cleared after updating orientation with display.
        // The rotation transform should be cleared after updating orientation with display.
        assertFalse(activity.hasFixedRotationTransform());
        assertTopFixedRotationLaunchingAppCleared(activity);
        assertFalse(mDefaultDisplay.hasTopFixedRotationLaunchingApp());


        // Simulate swiping up recents (home) in different rotation.
        // Simulate swiping up recents (home) in different rotation.
        final ActivityRecord home = mDefaultDisplay.getDefaultTaskDisplayArea().getHomeActivity();
        final ActivityRecord home = mDefaultDisplay.getDefaultTaskDisplayArea().getHomeActivity();
        mDefaultDisplay.setFixedRotationLaunchingApp(home, (mDefaultDisplay.getRotation() + 1) % 4);
        startRecentsInDifferentRotation(home);
        mController = new RecentsAnimationController(mWm, mMockRunner, mAnimationCallbacks,
                mDefaultDisplay.getDisplayId());
        initializeRecentsAnimationController(mController, home);
        assertTrue(home.hasFixedRotationTransform());


        // If the recents activity becomes the top running activity (e.g. the original top activity
        // is either finishing or moved to back during recents animation), the display orientation
        // will be determined by it so the fixed rotation must be cleared.
        activity.finishing = true;
        mController.cleanupAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION);
        assertTopFixedRotationLaunchingAppCleared(home);

        startRecentsInDifferentRotation(home);
        // Assume recents activity becomes invisible for some reason (e.g. screen off).
        // Assume recents activity becomes invisible for some reason (e.g. screen off).
        home.setVisible(false);
        home.setVisible(false);
        mController.cleanupAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION);
        mController.cleanupAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION);
        // Although there won't be a transition finish callback, the fixed rotation must be cleared.
        // Although there won't be a transition finish callback, the fixed rotation must be cleared.
        assertFalse(home.hasFixedRotationTransform());
        assertTopFixedRotationLaunchingAppCleared(home);
        assertFalse(mDefaultDisplay.hasTopFixedRotationLaunchingApp());
    }
    }


    @Test
    @Test
@@ -508,6 +510,21 @@ public class RecentsAnimationControllerTest extends WindowTestsBase {
        return homeActivity;
        return homeActivity;
    }
    }


    private void startRecentsInDifferentRotation(ActivityRecord recentsActivity) {
        final DisplayContent displayContent = recentsActivity.mDisplayContent;
        displayContent.setFixedRotationLaunchingApp(recentsActivity,
                (displayContent.getRotation() + 1) % 4);
        mController = new RecentsAnimationController(mWm, mMockRunner, mAnimationCallbacks,
                displayContent.getDisplayId());
        initializeRecentsAnimationController(mController, recentsActivity);
        assertTrue(recentsActivity.hasFixedRotationTransform());
    }

    private static void assertTopFixedRotationLaunchingAppCleared(ActivityRecord activity) {
        assertFalse(activity.hasFixedRotationTransform());
        assertFalse(activity.mDisplayContent.hasTopFixedRotationLaunchingApp());
    }

    private static void initializeRecentsAnimationController(RecentsAnimationController controller,
    private static void initializeRecentsAnimationController(RecentsAnimationController controller,
            ActivityRecord activity) {
            ActivityRecord activity) {
        controller.initialize(activity.getActivityType(), new SparseBooleanArray(), activity);
        controller.initialize(activity.getActivityType(), new SparseBooleanArray(), activity);