Add overview button rate-limiter to fix recurring bug

Processing the TYPE_TOGGLE command immediately makes it relatively easy to start overlapping animations that clobber each other and prevent clean up callbacks from running. This would cause a janky overview animation, a full command queue that can't be emptied and a recents tile than gets stuck on the screen. Added a rate limiter to (hopefully) prevent this type of bug from recurring.

Flag: not needed
Fixes: 298792963
Test: quickly and repeatedly pressed the overview button, checked logs to check that the error case never occurs anymore and rate-limiter procs instead.
Change-Id: I1575c932bb24d2405792539e8a14ed8d4171f5ae
This commit is contained in:
Schneider Victor-tulias
2023-09-14 12:24:29 -04:00
parent 3554656c13
commit 89d64bb346
2 changed files with 21 additions and 2 deletions

View File

@@ -437,11 +437,13 @@ public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_T
}
protected void runOnInitBackgroundStateUI(Runnable callback) {
mOnInitBackgroundStateUICallback = callback;
ACTIVITY_TYPE activity = getCreatedActivity();
if (activity != null && activity.getStateManager().getState() == mBackgroundState) {
callback.run();
onInitBackgroundStateUI();
return;
}
mOnInitBackgroundStateUICallback = callback;
}
private void onInitBackgroundStateUI() {

View File

@@ -78,6 +78,14 @@ public class OverviewCommandHelper {
*/
private int mTaskFocusIndexOverride = -1;
/**
* Whether we should incoming toggle commands while a previous toggle command is still ongoing.
* This serves as a rate-limiter to prevent overlapping animations that can clobber each other
* and prevent clean-up callbacks from running. This thus prevents a recurring set of bugs with
* janky recents animations and unresponsive home and overview buttons.
*/
private boolean mWaitForToggleCommandComplete = false;
public OverviewCommandHelper(TouchInteractionService service,
OverviewComponentObserver observer,
TaskAnimationManager taskAnimationManager) {
@@ -160,15 +168,20 @@ public class OverviewCommandHelper {
private boolean launchTask(RecentsView recents, @Nullable TaskView taskView, CommandInfo cmd) {
RunnableList callbackList = null;
if (taskView != null) {
mWaitForToggleCommandComplete = true;
taskView.setEndQuickswitchCuj(true);
callbackList = taskView.launchTasks();
}
if (callbackList != null) {
callbackList.add(() -> scheduleNextTask(cmd));
callbackList.add(() -> {
scheduleNextTask(cmd);
mWaitForToggleCommandComplete = false;
});
return false;
} else {
recents.startHome();
mWaitForToggleCommandComplete = false;
return true;
}
}
@@ -178,6 +191,9 @@ public class OverviewCommandHelper {
* task is deferred until {@link #scheduleNextTask} is called
*/
private <T extends StatefulActivity<?>> boolean executeCommand(CommandInfo cmd) {
if (mWaitForToggleCommandComplete && cmd.type == TYPE_TOGGLE) {
return true;
}
BaseActivityInterface<?, T> activityInterface =
mOverviewComponentObserver.getActivityInterface();
RecentsView recents = activityInterface.getVisibleRecentsView();
@@ -359,6 +375,7 @@ public class OverviewCommandHelper {
pw.println(" pendingCommandType=" + mPendingCommands.get(0).type);
}
pw.println(" mTaskFocusIndexOverride=" + mTaskFocusIndexOverride);
pw.println(" mWaitForToggleCommandComplete=" + mWaitForToggleCommandComplete);
}
private static class CommandInfo {