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

Commit 47a37486 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Use screen rotation animation only if the display has content

It is unnecessary to run animation which is invisible to user.
Especially when adding a new display which is empty initially.

Also make sure that the leash for fade rotation animation is valid.
(For the case if the animation was canceled by other places.)

Bug: 213562756
Test: Either use legacy transition or shell transition.
      Start ScreenRecord and check logcat that there is no
      "Screen frozen" or "Creating Transition".
Change-Id: I8e905e4161a8eb768eadda4b160af57b7148f81d
parent 9771f44d
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -1425,7 +1425,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            mWaitingForConfig = true;
            mWaitingForConfig = true;
            if (mTransitionController.isShellTransitionsEnabled()) {
            if (mTransitionController.isShellTransitionsEnabled()) {
                requestChangeTransitionIfNeeded(changes, null /* displayChange */);
                requestChangeTransitionIfNeeded(changes, null /* displayChange */);
            } else {
            } else if (mLastHasContent) {
                mWmService.startFreezingDisplay(0 /* exitAnim */, 0 /* enterAnim */, this);
                mWmService.startFreezingDisplay(0 /* exitAnim */, 0 /* enterAnim */, this);
            }
            }
            sendNewConfiguration();
            sendNewConfiguration();
@@ -3222,6 +3222,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     */
     */
    void requestChangeTransitionIfNeeded(@ActivityInfo.Config int changes,
    void requestChangeTransitionIfNeeded(@ActivityInfo.Config int changes,
            @Nullable TransitionRequestInfo.DisplayChange displayChange) {
            @Nullable TransitionRequestInfo.DisplayChange displayChange) {
        if (!mLastHasContent) return;
        final TransitionController controller = mTransitionController;
        final TransitionController controller = mTransitionController;
        if (controller.isCollecting()) {
        if (controller.isCollecting()) {
            if (displayChange != null) {
            if (displayChange != null) {
@@ -5090,6 +5091,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        return mLastHasContent;
        return mLastHasContent;
    }
    }


    @VisibleForTesting
    void setLastHasContent() {
        mLastHasContent = true;
    }

    void registerPointerEventListener(@NonNull PointerEventListener listener) {
    void registerPointerEventListener(@NonNull PointerEventListener listener) {
        mPointerEventDispatcher.registerInputEventListener(listener);
        mPointerEventDispatcher.registerInputEventListener(listener);
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -256,7 +256,7 @@ public class FadeRotationAnimationController extends FadeAnimationController {
                    false /* applyFixedTransformationHint */);
                    false /* applyFixedTransformationHint */);
            for (int i = mTargetWindowTokens.size() - 1; i >= 0; i--) {
            for (int i = mTargetWindowTokens.size() - 1; i >= 0; i--) {
                final SurfaceControl leash = mTargetWindowTokens.valueAt(i);
                final SurfaceControl leash = mTargetWindowTokens.valueAt(i);
                if (leash != null) {
                if (leash != null && leash.isValid()) {
                    rotator.applyTransform(t, leash);
                    rotator.applyTransform(t, leash);
                }
                }
            }
            }
@@ -265,7 +265,7 @@ public class FadeRotationAnimationController extends FadeAnimationController {
        // Hide the windows immediately because a screenshot layer should cover the screen.
        // Hide the windows immediately because a screenshot layer should cover the screen.
        for (int i = mTargetWindowTokens.size() - 1; i >= 0; i--) {
        for (int i = mTargetWindowTokens.size() - 1; i >= 0; i--) {
            final SurfaceControl leash = mTargetWindowTokens.valueAt(i);
            final SurfaceControl leash = mTargetWindowTokens.valueAt(i);
            if (leash != null) {
            if (leash != null && leash.isValid()) {
                t.setAlpha(leash, 0f);
                t.setAlpha(leash, 0f);
            }
            }
        }
        }
+1 −0
Original line number Original line Diff line number Diff line
@@ -1718,6 +1718,7 @@ public class DisplayContentTests extends WindowTestsBase {
    @Test
    @Test
    public void testShellTransitRotation() {
    public void testShellTransitRotation() {
        DisplayContent dc = createNewDisplay();
        DisplayContent dc = createNewDisplay();
        dc.setLastHasContent();


        final TestTransitionPlayer testPlayer = registerTestTransitionPlayer();
        final TestTransitionPlayer testPlayer = registerTestTransitionPlayer();
        final DisplayRotation dr = dc.getDisplayRotation();
        final DisplayRotation dr = dc.getDisplayRotation();
+5 −1
Original line number Original line Diff line number Diff line
@@ -488,6 +488,7 @@ public class TransitionTests extends WindowTestsBase {
        final TestTransitionPlayer player = registerTestTransitionPlayer();
        final TestTransitionPlayer player = registerTestTransitionPlayer();


        mDisplayContent.getDisplayRotation().setRotation(mDisplayContent.getRotation() + 1);
        mDisplayContent.getDisplayRotation().setRotation(mDisplayContent.getRotation() + 1);
        mDisplayContent.setLastHasContent();
        mDisplayContent.requestChangeTransitionIfNeeded(1 /* any changes */,
        mDisplayContent.requestChangeTransitionIfNeeded(1 /* any changes */,
                null /* displayChange */);
                null /* displayChange */);
        final FadeRotationAnimationController fadeController =
        final FadeRotationAnimationController fadeController =
@@ -536,6 +537,7 @@ public class TransitionTests extends WindowTestsBase {
                null /* remoteTransition */, null /* displayChange */);
                null /* remoteTransition */, null /* displayChange */);
        mDisplayContent.getDisplayRotation().setRotation(mDisplayContent.getRotation() + 1);
        mDisplayContent.getDisplayRotation().setRotation(mDisplayContent.getRotation() + 1);
        final int anyChanges = 1;
        final int anyChanges = 1;
        mDisplayContent.setLastHasContent();
        mDisplayContent.requestChangeTransitionIfNeeded(anyChanges, null /* displayChange */);
        mDisplayContent.requestChangeTransitionIfNeeded(anyChanges, null /* displayChange */);
        transition.setKnownConfigChanges(mDisplayContent, anyChanges);
        transition.setKnownConfigChanges(mDisplayContent, anyChanges);
        final FadeRotationAnimationController fadeController =
        final FadeRotationAnimationController fadeController =
@@ -550,9 +552,11 @@ public class TransitionTests extends WindowTestsBase {
        assertTrue(app.getTask().inTransition());
        assertTrue(app.getTask().inTransition());


        final SurfaceControl.Transaction startTransaction = mock(SurfaceControl.Transaction.class);
        final SurfaceControl.Transaction startTransaction = mock(SurfaceControl.Transaction.class);
        final SurfaceControl leash = statusBar.mToken.getAnimationLeash();
        doReturn(true).when(leash).isValid();
        player.onTransactionReady(startTransaction);
        player.onTransactionReady(startTransaction);
        // The leash should be unrotated.
        // The leash should be unrotated.
        verify(startTransaction).setMatrix(eq(statusBar.mToken.getAnimationLeash()), any(), any());
        verify(startTransaction).setMatrix(eq(leash), any(), any());


        // The redrawn window will be faded in when the transition finishes. And because this test
        // The redrawn window will be faded in when the transition finishes. And because this test
        // only use one non-activity window, the fade rotation controller should also be cleared.
        // only use one non-activity window, the fade rotation controller should also be cleared.