From 4df3b232250781dc8d1d206d74bc0e854da5fafe Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Mon, 26 Apr 2021 15:26:38 -0700 Subject: [PATCH] Invalidate when switching to new consumer - When switching to a new consumer, also invalidate the handler to clean up references held by that handler - Also make sure that we calculate the task index used for logging prior to starting the task view since the handler can be invalidated between starting the activity and the callback happening Bug: 185909226 Test: Presubmit Change-Id: I20e06b5a6b31a5e242c6fc840bf4f215797eb12c --- .../android/quickstep/AbsSwipeUpHandler.java | 60 ++++++++++++------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index 53f1fd0809..35cb73536f 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -150,6 +150,9 @@ public abstract class AbsSwipeUpHandler, protected Runnable mGestureEndCallback; protected MultiStateCallback mStateCallback; protected boolean mCanceled; + // One time flag set when onConsumerAboutToBeSwitched() is called, indicating that certain + // shared animations should not be canceled when this handler is invalidated + private boolean mConsumerIsSwitching; private boolean mRecentsViewScrollLinked = false; private static int getFlagForIndex(int index, String name) { @@ -1003,7 +1006,14 @@ public abstract class AbsSwipeUpHandler, animateToProgress(startShift, endShift, duration, interpolator, endTarget, velocity); } - private void doLogGesture(GestureEndTarget endTarget, @Nullable TaskView targetTask) { + private int getLogGestureTaskIndex(@Nullable TaskView targetTask) { + return mRecentsView == null || targetTask == null + ? LOG_NO_OP_PAGE_INDEX + : mRecentsView.indexOfChild(targetTask); + } + + private void doLogGesture(GestureEndTarget endTarget, @Nullable TaskView targetTask, + int pageIndex) { StatsLogManager.EventEnum event; switch (endTarget) { case HOME: @@ -1032,9 +1042,6 @@ public abstract class AbsSwipeUpHandler, // We probably never received an animation controller, skip logging. return; } - int pageIndex = endTarget == LAST_TASK - ? LOG_NO_OP_PAGE_INDEX - : mRecentsView.getNextPage(); // TODO: set correct container using the pageIndex logger.log(event); } @@ -1279,18 +1286,18 @@ public abstract class AbsSwipeUpHandler, } public void onConsumerAboutToBeSwitched() { + mConsumerIsSwitching = true; if (mActivity != null) { // In the off chance that the gesture ends before Launcher is started, we should clear // the callback here so that it doesn't update with the wrong state mActivity.clearRunOnceOnStartCallback(); - resetLauncherListeners(); } if (mGestureState.getEndTarget() != null && !mGestureState.isRunningAnimationToLauncher()) { cancelCurrentAnimation(); } else { mStateCallback.setStateOnUiThread(STATE_FINISH_WITH_NO_END); - reset(); } + reset(); } public boolean isCanceled() { @@ -1301,13 +1308,14 @@ public abstract class AbsSwipeUpHandler, private void resumeLastTask() { mRecentsAnimationController.finish(false /* toRecents */, null); ActiveGestureLog.INSTANCE.addLog("finishRecentsAnimation", false); - doLogGesture(LAST_TASK, null); + doLogGesture(LAST_TASK, null, getLogGestureTaskIndex(null)); reset(); } @UiThread private void startNewTask() { TaskView taskToLaunch = mRecentsView == null ? null : mRecentsView.getNextPageTaskView(); + int taskPageIndex = getLogGestureTaskIndex(taskToLaunch); startNewTask(success -> { if (!success) { reset(); @@ -1316,7 +1324,7 @@ public abstract class AbsSwipeUpHandler, endLauncherTransitionController(); updateSysUiFlags(1 /* windowProgress == overview */); } - doLogGesture(NEW_TASK, taskToLaunch); + doLogGesture(NEW_TASK, taskToLaunch, taskPageIndex); }); } @@ -1350,32 +1358,38 @@ public abstract class AbsSwipeUpHandler, } private void invalidateHandler() { - if (!LIVE_TILE.get() || !mActivityInterface.isInLiveTileMode() - || mGestureState.getEndTarget() != RECENTS) { - mInputConsumerProxy.destroy(); - mTaskAnimationManager.setLiveTileCleanUpHandler(null); + if (!mConsumerIsSwitching) { + if (!LIVE_TILE.get() || !mActivityInterface.isInLiveTileMode() + || mGestureState.getEndTarget() != RECENTS) { + mInputConsumerProxy.destroy(); + mTaskAnimationManager.setLiveTileCleanUpHandler(null); + } + endRunningWindowAnim(false /* cancel */); + + if (mGestureEndCallback != null) { + mGestureEndCallback.run(); + } } + mInputConsumerProxy.unregisterCallback(); - endRunningWindowAnim(false /* cancel */); - - if (mGestureEndCallback != null) { - mGestureEndCallback.run(); - } - mActivityInitListener.unregister(); ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mActivityRestartListener); mTaskSnapshot = null; mHandler.post(() -> { // Defer clearing the activity since invalidation can happen over multiple callbacks + // ie. invalidateHandlerWithLauncher() mActivity = null; + mRecentsView = null; }); } private void invalidateHandlerWithLauncher() { - endLauncherTransitionController(); + if (!mConsumerIsSwitching) { + endLauncherTransitionController(); + mRecentsView.onGestureAnimationEnd(); + } mRecentsView.removeOnScrollChangedListener(mOnRecentsScrollListener); - mRecentsView.onGestureAnimationEnd(); resetLauncherListeners(); } @@ -1500,7 +1514,8 @@ public abstract class AbsSwipeUpHandler, () -> mStateCallback.setStateOnUiThread(STATE_CURRENT_TASK_FINISHED)); } ActiveGestureLog.INSTANCE.addLog("finishRecentsAnimation", true); - doLogGesture(HOME, mRecentsView == null ? null : mRecentsView.getCurrentPageTaskView()); + TaskView taskToLaunch = mRecentsView == null ? null : mRecentsView.getCurrentPageTaskView(); + doLogGesture(HOME, taskToLaunch, getLogGestureTaskIndex(taskToLaunch)); } /** @@ -1531,7 +1546,8 @@ public abstract class AbsSwipeUpHandler, } SystemUiProxy.INSTANCE.get(mContext).onOverviewShown(false, TAG); - doLogGesture(RECENTS, mRecentsView.getCurrentPageTaskView()); + TaskView taskToLaunch = mRecentsView.getCurrentPageTaskView(); + doLogGesture(RECENTS, taskToLaunch, getLogGestureTaskIndex(taskToLaunch)); reset(); }