diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java b/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java index b6002e8b76..7875daee4a 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java @@ -32,6 +32,8 @@ import com.android.launcher3.views.ActivityContext; import com.android.quickstep.util.BaseDepthController; import com.android.systemui.shared.system.InteractionJankMonitorWrapper; +import java.util.concurrent.TimeUnit; + /** * Definition for AllApps state */ @@ -39,6 +41,8 @@ public class AllAppsState extends LauncherState { private static final int STATE_FLAGS = FLAG_WORKSPACE_INACCESSIBLE | FLAG_CLOSE_POPUPS | FLAG_HOTSEAT_INACCESSIBLE; + private static final long BACK_CUJ_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(5); + public AllAppsState(int id) { super(id, LAUNCHER_STATE_ALLAPPS, STATE_FLAGS); @@ -53,14 +57,33 @@ public class AllAppsState extends LauncherState { } @Override - public void onBackPressed(Launcher launcher) { + public void onBackStarted(Launcher launcher) { + // Because the back gesture can take longer time depending on when user release the finger, + // we pass BACK_CUJ_TIMEOUT_MS as timeout to the jank monitor. InteractionJankMonitorWrapper.begin(launcher.getAppsView(), - Cuj.CUJ_LAUNCHER_CLOSE_ALL_APPS_BACK); - super.onBackPressed(launcher); + Cuj.CUJ_LAUNCHER_CLOSE_ALL_APPS_BACK, BACK_CUJ_TIMEOUT_MS); + super.onBackStarted(launcher); } @Override - protected void onBackPressCompleted(boolean success) { + public void onBackInvoked(Launcher launcher) { + // In predictive back swipe, onBackInvoked() will be called after onBackStarted(). + // Because the 2nd InteractionJankMonitor.begin() will be ignore within timeout, it's safe + // to call InteractionJankMonitorWrapper.begin here. + InteractionJankMonitorWrapper.begin(launcher.getAppsView(), + Cuj.CUJ_LAUNCHER_CLOSE_ALL_APPS_BACK); + super.onBackInvoked(launcher); + } + + /** Called when predictive back swipe is cancelled. */ + @Override + public void onBackCancelled(Launcher launcher) { + super.onBackCancelled(launcher); + InteractionJankMonitorWrapper.cancel(Cuj.CUJ_LAUNCHER_CLOSE_ALL_APPS_BACK); + } + + @Override + protected void onBackAnimationCompleted(boolean success) { if (success) { // Animation was successful. InteractionJankMonitorWrapper.end(Cuj.CUJ_LAUNCHER_CLOSE_ALL_APPS_BACK); diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewModalTaskState.java b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewModalTaskState.java index 856b519d88..c63eaebc89 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewModalTaskState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewModalTaskState.java @@ -60,7 +60,7 @@ public class OverviewModalTaskState extends OverviewState { } @Override - public void onBackPressed(Launcher launcher) { + public void onBackInvoked(Launcher launcher) { launcher.getStateManager().goToState(LauncherState.OVERVIEW); } diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java index 8c2efc2910..d0eef8e3bb 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java @@ -199,7 +199,7 @@ public class OverviewState extends LauncherState { } @Override - public void onBackPressed(Launcher launcher) { + public void onBackInvoked(Launcher launcher) { RecentsView recentsView = launcher.getOverviewPanel(); TaskView taskView = recentsView.getRunningTaskView(); if (taskView != null) { @@ -209,7 +209,7 @@ public class OverviewState extends LauncherState { recentsView.snapToPage(recentsView.indexOfChild(taskView)); } } else { - super.onBackPressed(launcher); + super.onBackInvoked(launcher); } } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index e7d2843b64..cd3e146b9a 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -660,6 +660,11 @@ public class Launcher extends StatefulActivity // #5 state handler return new OnBackAnimationCallback() { + @Override + public void onBackStarted(BackEvent backEvent) { + Launcher.this.onBackStarted(); + } + @Override public void onBackInvoked() { onStateBack(); @@ -2063,8 +2068,12 @@ public class Launcher extends StatefulActivity getOnBackAnimationCallback().onBackInvoked(); } + protected void onBackStarted() { + mStateManager.getState().onBackStarted(this); + } + protected void onStateBack() { - mStateManager.getState().onBackPressed(this); + mStateManager.getState().onBackInvoked(this); } protected void onScreenOnChanged(boolean isOn) { diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java index 6e66c1448d..3bdd8635cf 100644 --- a/src/com/android/launcher3/LauncherState.java +++ b/src/com/android/launcher3/LauncherState.java @@ -424,20 +424,29 @@ public abstract class LauncherState implements BaseState { return TestProtocol.stateOrdinalToString(ordinal); } - public void onBackPressed(Launcher launcher) { + /** Called when predictive back gesture is started. */ + public void onBackStarted(Launcher launcher) {} + + /** + * Called when back action is invoked. This can happen when: + * 1. back button is pressed in 3-button navigation. + * 2. when back is committed during back swiped (predictive or non-predictive). + * 3. when we programmatically perform back action. + */ + public void onBackInvoked(Launcher launcher) { if (this != NORMAL) { StateManager lsm = launcher.getStateManager(); LauncherState lastState = lsm.getLastState(); - lsm.goToState(lastState, forEndCallback(this::onBackPressCompleted)); + lsm.goToState(lastState, forEndCallback(this::onBackAnimationCompleted)); } } /** - * To be called if back press is completed in a launcher state. + * To be called if back animation is completed in a launcher state. * - * @param success whether back press animation was successful or canceled. + * @param success whether back animation was successful or canceled. */ - protected void onBackPressCompleted(boolean success) { + protected void onBackAnimationCompleted(boolean success) { // Do nothing. To be overridden by child class. }