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

Commit eb4511f4 authored by Nick Chameyev's avatar Nick Chameyev
Browse files

Finish unfold Shell transition on fold

UnfoldTransitionHandler might be left in the state
when it waits for the unfold animation if we folded
the device before the unfold animation has finished.

This area is very fragile as UnfoldTransitionHandler
tries to 'predict' if UnfoldTransitionProgressProvider
will play the animation or not, so we are getting
these situations when transition might be waiting
for the animation to happen when it won't happen.
Ideally both components should use the same signal,
we have a refactoring bug for this: b/318803244.

Bug: 332548849
Test: atest UnfoldTransitionHandlerTest
Test: fold/unfold quickly => verify transition is finished
Change-Id: I0474f896bb4e307e32675e6a0060e16cfd32ba33
parent e9a3a78f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -293,7 +293,13 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
    @Override
    public void onFoldStateChanged(boolean isFolded) {
        if (isFolded) {
            // Reset unfold animation finished flag on folding, so it could be used next time
            // when we unfold the device as an indication that animation hasn't finished yet
            mAnimationFinished = false;

            // If we are currently animating unfold animation we should finish it because
            // the animation might not start and finish as the device was folded
            finishTransitionIfNeeded();
        }
    }

+26 −0
Original line number Diff line number Diff line
@@ -297,6 +297,32 @@ public class UnfoldTransitionHandlerTest {
        verify(finishCallback).onTransitionFinished(any());
    }

    @Test
    public void fold_animationInProgress_finishesTransition() {
        TransitionRequestInfo requestInfo = createUnfoldTransitionRequestInfo();
        TransitionFinishCallback finishCallback = mock(TransitionFinishCallback.class);

        // Unfold
        mShellUnfoldProgressProvider.onFoldStateChanged(/* isFolded= */ false);
        mUnfoldTransitionHandler.handleRequest(mTransition, requestInfo);
        mUnfoldTransitionHandler.startAnimation(
                mTransition,
                mock(TransitionInfo.class),
                mock(SurfaceControl.Transaction.class),
                mock(SurfaceControl.Transaction.class),
                finishCallback
        );

        // Start animation but don't finish it
        mShellUnfoldProgressProvider.onStateChangeStarted();
        mShellUnfoldProgressProvider.onStateChangeProgress(0.5f);

        // Fold
        mShellUnfoldProgressProvider.onFoldStateChanged(/* isFolded= */ true);

        verify(finishCallback).onTransitionFinished(any());
    }

    @Test
    public void mergeAnimation_eatsDisplayOnlyTransitions() {
        TransitionRequestInfo requestInfo = createUnfoldTransitionRequestInfo();