From fa3efe94943e4f8a48c35114b5d5beaf2330b04e Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Thu, 15 Feb 2018 16:50:37 -0800 Subject: [PATCH] Fix a couple quickscrub issues - Always launch workspace card if it's focused when quick scrub ends - Previously it would get stuck if quick scrub end was called on a background thread (since it was trying to touch RecentsView) - Prevent user from being able to get to the workspace card if starting quick scrub from an app by introducing bounds checking - Prevent getting stuck in overview when ending quick scrub - There was a race condition where the task wouldn't launch if the animation to recents hadn't yet finished. Now there is a callback to ensure that launchTask() is always called after. Bug: 70180755 Change-Id: I3c131011634880a97de8c2935c3ebdab26494b48 --- .../quickstep/OtherActivityTouchConsumer.java | 3 -- .../quickstep/QuickScrubController.java | 5 +++- .../quickstep/RecentsAnimationWrapper.java | 11 +++++++- .../quickstep/TouchInteractionService.java | 2 -- .../WindowTransformSwipeHandler.java | 28 +++++++++---------- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java b/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java index b3354a4645..ef7f894df4 100644 --- a/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java +++ b/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java @@ -21,10 +21,7 @@ import static android.view.MotionEvent.ACTION_MOVE; import static android.view.MotionEvent.ACTION_POINTER_UP; import static android.view.MotionEvent.ACTION_UP; import static android.view.MotionEvent.INVALID_POINTER_ID; - import static com.android.quickstep.RemoteRunnable.executeSafely; -import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_BACK; -import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_HOME; import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_NONE; import android.app.ActivityManager.RunningTaskInfo; diff --git a/quickstep/src/com/android/quickstep/QuickScrubController.java b/quickstep/src/com/android/quickstep/QuickScrubController.java index 01c99d5249..8d5422f046 100644 --- a/quickstep/src/com/android/quickstep/QuickScrubController.java +++ b/quickstep/src/com/android/quickstep/QuickScrubController.java @@ -20,6 +20,7 @@ import android.view.HapticFeedbackConstants; import com.android.launcher3.Alarm; import com.android.launcher3.OnAlarmListener; +import com.android.launcher3.Utilities; /** * Responds to quick scrub callbacks to page through and launch recent tasks. @@ -61,7 +62,8 @@ public class QuickScrubController implements OnAlarmListener { int page = mRecentsView.getNextPage(); Runnable launchTaskRunnable = () -> { if (page < mRecentsView.getFirstTaskIndex()) { - mRecentsView.getPageAt(page).performClick(); + // Call post() since we can't performClick() on a background thread. + mRecentsView.post(() -> mRecentsView.getPageAt(page).performClick()); } else { ((TaskView) mRecentsView.getPageAt(page)).launchTask(true); } @@ -114,6 +116,7 @@ public class QuickScrubController implements OnAlarmListener { } private void goToPageWithHaptic(int pageToGoTo) { + pageToGoTo = Utilities.boundToRange(pageToGoTo, mStartPage, mRecentsView.getPageCount() - 1); if (pageToGoTo != mRecentsView.getNextPage()) { int duration = Math.abs(pageToGoTo - mRecentsView.getNextPage()) * QUICKSCRUB_SNAP_DURATION_PER_PAGE; diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationWrapper.java b/quickstep/src/com/android/quickstep/RecentsAnimationWrapper.java index 7c983173fe..2fae01a66a 100644 --- a/quickstep/src/com/android/quickstep/RecentsAnimationWrapper.java +++ b/quickstep/src/com/android/quickstep/RecentsAnimationWrapper.java @@ -15,6 +15,9 @@ */ package com.android.quickstep; +import android.os.Handler; +import android.os.Looper; + import com.android.systemui.shared.system.BackgroundExecutor; import com.android.systemui.shared.system.RecentsAnimationControllerCompat; import com.android.systemui.shared.system.RemoteAnimationTargetCompat; @@ -39,12 +42,18 @@ public class RecentsAnimationWrapper { } } - public void finish(boolean toHome) { + /** + * @param onFinishComplete A callback that runs on the UI thread. + */ + public void finish(boolean toHome, Runnable onFinishComplete) { BackgroundExecutor.get().submit(() -> { synchronized (this) { if (controller != null) { controller.setInputConsumerEnabled(false); controller.finish(toHome); + if (onFinishComplete != null) { + new Handler(Looper.getMainLooper()).post(onFinishComplete); + } } } }); diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 0e7bc4257f..52cd60e4f5 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -21,7 +21,6 @@ import static android.view.MotionEvent.ACTION_MOVE; import static android.view.MotionEvent.ACTION_POINTER_DOWN; import static android.view.MotionEvent.ACTION_POINTER_UP; import static android.view.MotionEvent.ACTION_UP; - import static com.android.launcher3.LauncherState.OVERVIEW; import static com.android.quickstep.QuickScrubController.QUICK_SWITCH_START_DURATION; import static com.android.quickstep.TouchConsumer.INTERACTION_QUICK_SCRUB; @@ -49,7 +48,6 @@ import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.MainThreadExecutor; import com.android.launcher3.R; -import com.android.launcher3.model.ModelPreload; import com.android.systemui.shared.recents.IOverviewProxy; import com.android.systemui.shared.recents.ISystemUiProxy; import com.android.systemui.shared.system.ActivityManagerWrapper; diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java index 5fd483ff1f..f50204f0f4 100644 --- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java @@ -595,7 +595,7 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler { @UiThread private void resumeLastTask() { - mRecentsAnimationWrapper.finish(false /* toHome */); + mRecentsAnimationWrapper.finish(false /* toHome */, null); } public void reset() { @@ -647,21 +647,21 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler { transaction.apply(); } } - mRecentsAnimationWrapper.finish(true /* toHome */); - - if (mInteractionType == INTERACTION_QUICK_SWITCH) { - if (mQuickScrubController != null) { - mQuickScrubController.onQuickSwitch(); - } - } else if (mInteractionType == INTERACTION_QUICK_SCRUB) { - if (mQuickScrubController != null) { - if (mDeferredQuickScrubEnd) { - onQuickScrubEnd(); - } else { - mQuickScrubController.snapToPageForCurrentQuickScrubSection(); + mRecentsAnimationWrapper.finish(true /* toHome */, () -> { + if (mInteractionType == INTERACTION_QUICK_SWITCH) { + if (mQuickScrubController != null) { + mQuickScrubController.onQuickSwitch(); + } + } else if (mInteractionType == INTERACTION_QUICK_SCRUB) { + if (mQuickScrubController != null) { + if (mDeferredQuickScrubEnd) { + onQuickScrubEnd(); + } else { + mQuickScrubController.snapToPageForCurrentQuickScrubSection(); + } } } - } + }); } private void setupLauncherUiAfterSwipeUpAnimation() {