Extend CUJ_LAUNCHER_CLOSE_ALL_APPS_BACK to start as early as when user starts predictive back swipe

Bug: 330405993
Test: prefetto trace https://ui.perfetto.dev/#!/?s=58c0513fe0190f84ea1621a96d790a53b83fefc1ee402085b0d75bfc7b51e019
Flag: aconfig com.android.launcher3.enable_predictive_back_gesture TEAMFOOD
Change-Id: I76c32975e5ae6dcb0395d2eee68417f761455262
This commit is contained in:
Fengjiang Li
2024-03-26 16:21:01 -07:00
parent 081d6f4b59
commit 10c03e499d
5 changed files with 54 additions and 13 deletions
@@ -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);
@@ -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);
}
@@ -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);
}
}
+10 -1
View File
@@ -660,6 +660,11 @@ public class Launcher extends StatefulActivity<LauncherState>
// #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<LauncherState>
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) {
+14 -5
View File
@@ -424,20 +424,29 @@ public abstract class LauncherState implements BaseState<LauncherState> {
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<LauncherState> 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.
}