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

Commit a06403d5 authored by Winson Chung's avatar Winson Chung
Browse files

Skip animation start logic if canceled



Bug: 110255768
Test: atest CtsActivityManagerDeviceTestCases:ActivityManagerActivityVisibilityTests#testHomeVisibleOnActivityTaskPinned
Change-Id: Ifb3e4d1f44b8df28795d9b2c98a714a6c2b08860
Signed-off-by: default avatarWinson Chung <winsonc@google.com>
parent 0c16e74b
Loading
Loading
Loading
Loading
+20 −10
Original line number Diff line number Diff line
@@ -196,12 +196,6 @@ public class BoundsAnimationController {

        @Override
        public void onAnimationStart(Animator animation) {
            if (!mTarget.isAttached()) {
                // No point of trying to animate something that isn't attached to the hierarchy
                // anymore.
                cancel();
            }

            if (DEBUG) Slog.d(TAG, "onAnimationStart: mTarget=" + mTarget
                    + " mPrevSchedulePipModeChangedState=" + mPrevSchedulePipModeChangedState
                    + " mSchedulePipModeChangedState=" + mSchedulePipModeChangedState);
@@ -216,13 +210,15 @@ public class BoundsAnimationController {
            // Ensure that we have prepared the target for animation before we trigger any size
            // changes, so it can swap surfaces in to appropriate modes, or do as it wishes
            // otherwise.
            boolean continueAnimation;
            if (mPrevSchedulePipModeChangedState == NO_PIP_MODE_CHANGED_CALLBACKS) {
                mTarget.onAnimationStart(mSchedulePipModeChangedState ==
                continueAnimation = mTarget.onAnimationStart(mSchedulePipModeChangedState ==
                        SCHEDULE_PIP_MODE_CHANGED_ON_START, false /* forceUpdate */);

                // When starting an animation from fullscreen, pause here and wait for the
                // windows-drawn signal before we start the rest of the transition down into PiP.
                if (mMoveFromFullscreen && mTarget.shouldDeferStartOnMoveToFullscreen()) {
                if (continueAnimation && mMoveFromFullscreen
                        && mTarget.shouldDeferStartOnMoveToFullscreen()) {
                    pause();
                }
            } else if (mPrevSchedulePipModeChangedState == SCHEDULE_PIP_MODE_CHANGED_ON_END &&
@@ -231,8 +227,19 @@ public class BoundsAnimationController {
                // client will not currently receive any picture-in-picture mode change callbacks.
                // However, we still need to report to them that they are leaving PiP, so this will
                // force an update via a mode changed callback.
                mTarget.onAnimationStart(true /* schedulePipModeChangedCallback */,
                        true /* forceUpdate */);
                continueAnimation = mTarget.onAnimationStart(
                        true /* schedulePipModeChangedCallback */, true /* forceUpdate */);
            } else {
                // The animation is already running, but we should check that the TaskStack is still
                // valid before continuing with the animation
                continueAnimation = mTarget.isAttached();
            }

            if (!continueAnimation) {
                // No point of trying to animate something that isn't attached to the hierarchy
                // anymore.
                cancel();
                return;
            }

            // Immediately update the task bounds if they have to become larger, but preserve
@@ -354,6 +361,9 @@ public class BoundsAnimationController {
            if (DEBUG) Slog.d(TAG, "cancel: mTarget=" + mTarget);
            mSkipAnimationEnd = true;
            super.cancel();

            // Reset the thread priority of the animation thread if the bounds animation is canceled
            updateBooster();
        }

        /**
+2 −1
Original line number Diff line number Diff line
@@ -30,8 +30,9 @@ interface BoundsAnimationTarget {
     *
     * @param schedulePipModeChangedCallback whether or not to schedule the PiP mode changed
     * callbacks
     * @return whether to continue the animation
     */
    void onAnimationStart(boolean schedulePipModeChangedCallback, boolean forceUpdate);
    boolean onAnimationStart(boolean schedulePipModeChangedCallback, boolean forceUpdate);

    /**
     * @return Whether the animation should be paused waiting for the windows to draw before
+36 −24
Original line number Diff line number Diff line
@@ -1645,9 +1645,14 @@ public class TaskStack extends WindowContainer<Task> implements
    }

    @Override  // AnimatesBounds
    public void onAnimationStart(boolean schedulePipModeChangedCallback, boolean forceUpdate) {
    public boolean onAnimationStart(boolean schedulePipModeChangedCallback, boolean forceUpdate) {
        // Hold the lock since this is called from the BoundsAnimator running on the UiThread
        synchronized (mService.mWindowMap) {
            if (!isAttached()) {
                // Don't run the animation if the stack is already detached
                return false;
            }

            mBoundsAnimatingRequested = false;
            mBoundsAnimating = true;
            mCancelCurrentBoundsAnimation = false;
@@ -1677,6 +1682,7 @@ public class TaskStack extends WindowContainer<Task> implements
                controller.updatePictureInPictureModeForPinnedStackAnimation(null, forceUpdate);
            }
        }
        return true;
    }

    @Override  // AnimatesBounds
@@ -1720,13 +1726,16 @@ public class TaskStack extends WindowContainer<Task> implements

    @Override
    public boolean isAttached() {
        synchronized (mService.mWindowMap) {
            return mDisplayContent != null;
        }
    }

    /**
     * Called immediately prior to resizing the tasks at the end of the pinned stack animation.
     */
    public void onPipAnimationEndResize() {
        synchronized (mService.mWindowMap) {
            mBoundsAnimating = false;
            for (int i = 0; i < mChildren.size(); i++) {
                final Task t = mChildren.get(i);
@@ -1734,14 +1743,16 @@ public class TaskStack extends WindowContainer<Task> implements
            }
            mService.requestTraversal();
        }
    }

    @Override
    public boolean shouldDeferStartOnMoveToFullscreen() {
        // Workaround for the recents animation -- normally we need to wait for the new activity to
        // show before starting the PiP animation, but because we start and show the home activity
        // early for the recents animation prior to the PiP animation starting, there is no
        // subsequent all-drawn signal. In this case, we can skip the pause when the home stack is
        // already visible and drawn.
        synchronized (mService.mWindowMap) {
            // Workaround for the recents animation -- normally we need to wait for the new activity
            // to show before starting the PiP animation, but because we start and show the home
            // activity early for the recents animation prior to the PiP animation starting, there
            // is no subsequent all-drawn signal. In this case, we can skip the pause when the home
            // stack is already visible and drawn.
            final TaskStack homeStack = mDisplayContent.getHomeStack();
            if (homeStack == null) {
                return true;
@@ -1756,6 +1767,7 @@ public class TaskStack extends WindowContainer<Task> implements
            }
            return !homeApp.allDrawn;
        }
    }

    /**
     * @return True if we are currently animating the pinned stack from fullscreen to non-fullscreen
+3 −1
Original line number Diff line number Diff line
@@ -151,11 +151,13 @@ public class BoundsAnimationControllerTests extends WindowTestsBase {
        }

        @Override
        public void onAnimationStart(boolean schedulePipModeChangedCallback, boolean forceUpdate) {
        public boolean onAnimationStart(boolean schedulePipModeChangedCallback,
                boolean forceUpdate) {
            mAwaitingAnimationStart = false;
            mAnimationStarted = true;
            mSchedulePipModeChangedOnStart = schedulePipModeChangedCallback;
            mForcePipModeChangedCallback = forceUpdate;
            return true;
        }

        @Override