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

Commit 006239ba authored by Winson Chung's avatar Winson Chung
Browse files

Fix blocking issues re. window transitions and quick scrub

- Clean up the consumer when starting quickscrub/switch in addition to
  motion up
- Defer invalidating the handler until after quickscrub ends
- Ensure that we always finish the remote animation

Bug: 67957962
Bug: 70180755

Change-Id: Id5af5dc9917638f1dfb8e4a04c358aadb19fd67a
parent 3e803c7a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -38,8 +38,10 @@ public abstract class BaseSwipeInteractionHandler extends InternalStateHandler {

    public abstract void updateInteractionType(@InteractionType int interactionType);

    @WorkerThread
    public abstract void onQuickScrubEnd();

    @WorkerThread
    public abstract void onQuickScrubProgress(float progress);

    @WorkerThread
+15 −9
Original line number Diff line number Diff line
@@ -157,13 +157,7 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
                            startTouchTrackingForScreenshotAnimation();
                        }

                        // Notify the handler that the gesture has actually started
                        mInteractionHandler.onGestureStarted();

                        // Notify the system that we have started tracking the event
                        if (mISystemUiProxy != null) {
                            executeSafely(mISystemUiProxy::onRecentsAnimationStarted);
                        }
                        notifyGestureStarted();
                    }
                } else {
                    // Move
@@ -182,6 +176,16 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
        }
    }

    private void notifyGestureStarted() {
        // Notify the handler that the gesture has actually started
        mInteractionHandler.onGestureStarted();

        // Notify the system that we have started tracking the event
        if (mISystemUiProxy != null) {
            executeSafely(mISystemUiProxy::onRecentsAnimationStarted);
        }
    }

    private boolean isNavBarOnRight() {
        return mDisplayRotation == Surface.ROTATION_90 && mStableInsets.right > 0;
    }
@@ -263,7 +267,7 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
        handler.setLauncherOnDrawCallback(() -> {
            drawWaitLock.countDown();
            if (handler == mInteractionHandler) {
                switchToMainConsumer();
                switchToMainChoreographer();
            }
        });
        handler.initWhenReady(mMainThreadExecutor);
@@ -346,6 +350,8 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC

    @Override
    public void updateTouchTracking(int interactionType) {
        notifyGestureStarted();

        mMainThreadExecutor.execute(() -> {
            if (mInteractionHandler != null) {
                mInteractionHandler.updateInteractionType(interactionType);
@@ -378,7 +384,7 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC

    public void onTouchTrackingComplete() { }

    public void switchToMainConsumer() { }
    public void switchToMainChoreographer() { }

    @Override
    public void preProcessMotionEvent(MotionEvent ev) {
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ public class QuickScrubController implements OnAlarmListener {
            int snapDuration = Math.abs(page - mRecentsView.getPageNearestToCenterOfScreen())
                    * QUICKSCRUB_END_SNAP_DURATION_PER_PAGE;
            mRecentsView.snapToPage(page, snapDuration);
            // TODO: Fix this to actually wait until page-settle
            mRecentsView.postDelayed(() -> {
                if (page < mRecentsView.getFirstTaskIndex()) {
                    mRecentsView.getPageAt(page).performClick();
+1 −1
Original line number Diff line number Diff line
@@ -190,7 +190,7 @@ public class TouchInteractionService extends Service {
                mHomeIntent, mISystemUiProxy, mMainThreadExecutor) {

            @Override
            public void switchToMainConsumer() {
            public void switchToMainChoreographer() {
                if (mCurrentConsumer == this) {
                    mEventQueue.setInterimChoreographer(null);
                }
+40 −18
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {

    private @InteractionType int mInteractionType = INTERACTION_NORMAL;
    private boolean mStartedQuickScrubFromHome;
    private boolean mDeferredQuickScrubEnd;

    private final RecentsAnimationWrapper mRecentsAnimationWrapper = new RecentsAnimationWrapper();
    private Matrix mTmpMatrix = new Matrix();
@@ -352,6 +353,7 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {

    private void updateUiForQuickScrub() {
        mStartedQuickScrubFromHome = mWasLauncherAlreadyVisible;
        mDeferredQuickScrubEnd = false;
        mQuickScrubController = mRecentsView.getQuickScrubController();
        mQuickScrubController.onQuickScrubStart(mStartedQuickScrubFromHome);
        animateToProgress(1f, MAX_SWIPE_DURATION);
@@ -547,8 +549,12 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {
    }

    public void reset() {
        if (mInteractionType != INTERACTION_QUICK_SCRUB) {
            // Only invalidate the handler if we are not quick scrubbing, otherwise, it will be
            // invalidated after the quick scrub ends
            setStateOnUiThread(STATE_HANDLER_INVALIDATED);
        }
    }

    private void invalidateHandler() {
        mCurrentShift.cancelAnimation();
@@ -573,21 +579,6 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {
    }

    private void switchToScreenshot() {
        if (mInteractionType == INTERACTION_QUICK_SWITCH) {
            for (int i = mRecentsView.getFirstTaskIndex(); i < mRecentsView.getPageCount(); i++) {
                TaskView taskView = (TaskView) mRecentsView.getPageAt(i);
                if (taskView.getTask().key.id != mRunningTaskId) {
                    mRecentsView.snapToPage(i, QUICK_SWITCH_SNAP_DURATION);
                    taskView.postDelayed(() -> {taskView.launchTask(true);},
                            QUICK_SWITCH_SNAP_DURATION);
                    break;
                }
            }
        } else if (mInteractionType == INTERACTION_QUICK_SCRUB) {
            if (mQuickScrubController != null) {
                mQuickScrubController.snapToPageForCurrentQuickScrubSection();
            }
        } else {
        synchronized (mRecentsAnimationWrapper) {
            if (mRecentsAnimationWrapper.controller != null) {
                TransactionCompat transaction = new TransactionCompat();
@@ -603,6 +594,25 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {
            }
        }
        mRecentsAnimationWrapper.finish(true /* toHome */);

        if (mInteractionType == INTERACTION_QUICK_SWITCH) {
            for (int i = mRecentsView.getFirstTaskIndex(); i < mRecentsView.getPageCount(); i++) {
                TaskView taskView = (TaskView) mRecentsView.getPageAt(i);
                if (taskView.getTask().key.id != mRunningTaskId) {
                    mRecentsView.snapToPage(i, QUICK_SWITCH_SNAP_DURATION);
                    taskView.postDelayed(() -> {taskView.launchTask(true);},
                            QUICK_SWITCH_SNAP_DURATION);
                    break;
                }
            }
        } else if (mInteractionType == INTERACTION_QUICK_SCRUB) {
            if (mQuickScrubController != null) {
                if (mDeferredQuickScrubEnd) {
                    onQuickScrubEnd();
                } else {
                    mQuickScrubController.snapToPageForCurrentQuickScrubSection();
                }
            }
        }
    }

@@ -610,7 +620,6 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {
        // Re apply state in case we did something funky during the transition.
        mLauncher.getStateManager().reapplyState();


        // Animate ui the first icon.
        View currentRecentsPage = mRecentsView.getPageAt(mRecentsView.getCurrentPage());
        if (currentRecentsPage instanceof TaskView) {
@@ -619,11 +628,24 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {
    }

    public void onQuickScrubEnd() {
        if ((mStateCallback.getState() & STATE_SCALED_CONTROLLER_RECENTS) == 0) {
            // If we are still animating into recents, then defer until that has run to end
            // quick scrub since we need to finish the window animation before launching the next
            // task
            mDeferredQuickScrubEnd = true;
            return;
        }

        if (mQuickScrubController != null) {
            mQuickScrubController.onQuickScrubEnd();
        } else {
            // TODO:
        }

        // Normally this is handled in reset(), but since we are still scrubbing after the
        // transition into recents, we need to defer the handler invalidation for quick scrub until
        // after the gesture ends
        setStateOnUiThread(STATE_HANDLER_INVALIDATED);
    }

    public void onQuickScrubProgress(float progress) {