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

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

Fix finishing unfold shell transition immediately after folding

This CL addresses an issue with UnfoldTransitionHandler that sometimes
it finishes the animation immediately when the following events happen:
    - [folded the device]
    - onFoldedStateChanged(true) -> mAnimationFinished is set to 'false'
    - onStateChangeFinished() -> mAnimationFinished is set to 'true'
      (the order is not guaranteed between the last two events)
    - [unfolded the device]
    - handleRequest(unfold transition)
    - startAnimation() -> immediately finishes the animation because
      mAnimationFinished is set to true, but it should have animated it

This is fixed by setting mAnimationFinished to false in
onStateChangeFinished based on the last animation progress.
It is guaranteed that we will receive onTransitionProgress with 0f value
when folding and then onStateChangeFinished(), so we can use this signal
instead of onFoldedStateChanged to reset the flag.

Bug: 372319646
Test: atest UnfoldTransitionHandlerTest
Test: fold multiple times
  => verify unfold transition is not finished immediately
Flag: EXEMPT bugfix
Change-Id: I2dc2f578b6132361c09cd8fe7e8ebc8fe586f5e4
parent a7bb06b8
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -66,7 +66,10 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
    @Nullable
    private IBinder mTransition;

    // TODO: b/318803244 - remove when we could guarantee finishing the animation
    //  after startAnimation callback
    private boolean mAnimationFinished = false;
    private float mLastAnimationProgress = 0.0f;
    private final List<UnfoldTaskAnimator> mAnimators = new ArrayList<>();

    public UnfoldTransitionHandler(ShellInit shellInit,
@@ -158,6 +161,8 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene

    @Override
    public void onStateChangeProgress(float progress) {
        mLastAnimationProgress = progress;

        if (mTransition == null) return;

        SurfaceControl.Transaction transaction = null;
@@ -182,8 +187,14 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene

    @Override
    public void onStateChangeFinished() {
        mAnimationFinished = true;
        finishTransitionIfNeeded();

        // mLastAnimationProgress is guaranteed to be 0f when folding finishes, see
        // {@link PhysicsBasedUnfoldTransitionProgressProvider#cancelTransition}.
        // We can use it as an indication that the next animation progress events will be related
        // to unfolding, so let's reset mAnimationFinished to 'false' in this case.
        final boolean isFoldingFinished = mLastAnimationProgress == 0f;
        mAnimationFinished = !isFoldingFinished;
    }

    @Override
@@ -293,10 +304,6 @@ 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();
+3 −0
Original line number Diff line number Diff line
@@ -247,6 +247,7 @@ public class UnfoldTransitionHandlerTest {
        TransitionFinishCallback finishCallback = mock(TransitionFinishCallback.class);

        mShellUnfoldProgressProvider.onStateChangeStarted();
        mShellUnfoldProgressProvider.onStateChangeProgress(0.5f);
        mShellUnfoldProgressProvider.onStateChangeFinished();
        mUnfoldTransitionHandler.startAnimation(
                mTransition,
@@ -279,6 +280,8 @@ public class UnfoldTransitionHandlerTest {
        clearInvocations(finishCallback);

        // Fold
        mShellUnfoldProgressProvider.onStateChangeProgress(/* progress= */ 0.0f);
        mShellUnfoldProgressProvider.onStateChangeFinished();
        mShellUnfoldProgressProvider.onFoldStateChanged(/* isFolded= */ true);

        // Second unfold