From a57000c33d817c3602b9f840b4be691bda5e8653 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Fri, 8 May 2020 18:08:29 -0500 Subject: [PATCH] Restart running task if another task was started but not appeared If we just finish the controller to resume the running task like we normally would, the delayed task will appear on top when it's ready. Instead, we need to start the original task in this case. - Move mLastStartedTaskId to GestureState, shared between swipe handlers when continuing the gesture. - Update logic to change LAST_TASK to NEW_TASK if a task was started (but not appeared) during the same gesture; likewise, only change NEW_TASK to LAST_TASK if no task was started. - Finish the controller when successfully starting the task that already appeared, since we won't get onTaskAppeared(). Bug: 156132424 Change-Id: I1e9af297840745ab3d5e90214425f10a2616d90a --- .../android/quickstep/BaseSwipeUpHandler.java | 32 +++++++++++++++++-- .../quickstep/LauncherSwipeHandler.java | 21 ++++++++---- .../quickstep/TouchInteractionService.java | 1 + .../com/android/quickstep/GestureState.java | 19 ++++++++++- 4 files changed, 63 insertions(+), 10 deletions(-) diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java index eb976c7f3a..dd41d25e71 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java @@ -40,6 +40,7 @@ import android.util.Pair; import android.view.MotionEvent; import android.view.animation.Interpolator; +import androidx.annotation.CallSuper; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.UiThread; @@ -128,7 +129,6 @@ public abstract class BaseSwipeUpHandler { resultCallback.accept(success); - if (!success) { + if (success) { + if (mRecentsView.indexOfChild(nextTask) + == getLastAppearedTaskIndex()) { + onRestartLastAppearedTask(); + } + } else { mActivityInterface.onLaunchTaskFailed(); nextTask.notifyTaskLaunchFailed(TAG); mRecentsAnimationController.finish(true /* toRecents */, null); @@ -235,6 +240,19 @@ public abstract class BaseSwipeUpHandler mAM.getRunningTask(false /* filterOnlyVisibleRecents */))); diff --git a/quickstep/src/com/android/quickstep/GestureState.java b/quickstep/src/com/android/quickstep/GestureState.java index f06e1a6afc..9b515ae788 100644 --- a/quickstep/src/com/android/quickstep/GestureState.java +++ b/quickstep/src/com/android/quickstep/GestureState.java @@ -15,7 +15,6 @@ */ package com.android.quickstep; -import static com.android.quickstep.GestureState.GestureEndTarget.NEW_TASK; import static com.android.quickstep.MultiStateCallback.DEBUG_STATES; import android.app.ActivityManager; @@ -121,6 +120,7 @@ public class GestureState implements RecentsAnimationCallbacks.RecentsAnimationL private ActivityManager.RunningTaskInfo mRunningTask; private GestureEndTarget mEndTarget; private RemoteAnimationTargetCompat mLastAppearedTaskTarget; + private int mLastStartedTaskId = -1; public GestureState(OverviewComponentObserver componentObserver, int gestureId) { mHomeIntent = componentObserver.getHomeIntent(); @@ -139,6 +139,7 @@ public class GestureState implements RecentsAnimationCallbacks.RecentsAnimationL mRunningTask = other.mRunningTask; mEndTarget = other.mEndTarget; mLastAppearedTaskTarget = other.mLastAppearedTaskTarget; + mLastStartedTaskId = other.mLastStartedTaskId; } public GestureState() { @@ -234,6 +235,21 @@ public class GestureState implements RecentsAnimationCallbacks.RecentsAnimationL return mLastAppearedTaskTarget != null ? mLastAppearedTaskTarget.taskId : -1; } + /** + * Updates the last task that we started via startActivityFromRecents() during this gesture. + */ + public void updateLastStartedTaskId(int lastStartedTaskId) { + mLastStartedTaskId = lastStartedTaskId; + } + + /** + * @return The id of the task that was most recently started during this gesture, or -1 if + * no task has been started yet (i.e. we haven't settled on a new task). + */ + public int getLastStartedTaskId() { + return mLastStartedTaskId; + } + /** * @return the end target for this gesture (if known). */ @@ -300,6 +316,7 @@ public class GestureState implements RecentsAnimationCallbacks.RecentsAnimationL pw.println(" runningTask=" + mRunningTask); pw.println(" endTarget=" + mEndTarget); pw.println(" lastAppearedTaskTarget=" + mLastAppearedTaskTarget); + pw.println(" lastStartedTaskId=" + mLastStartedTaskId); pw.println(" isRecentsAnimationRunning=" + isRecentsAnimationRunning()); } }