Adding gesture error detection to RecentsAnimationCallback

Bug: 289600801
Bug: 285636175
Bug: 290266108
Test: Presubmit
Flag: not needed
Change-Id: I16ec3347b273ba80eadd766dccdcf012bc0872ae
diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationCallbacks.java b/quickstep/src/com/android/quickstep/RecentsAnimationCallbacks.java
index bbcea6c..3d332c2 100644
--- a/quickstep/src/com/android/quickstep/RecentsAnimationCallbacks.java
+++ b/quickstep/src/com/android/quickstep/RecentsAnimationCallbacks.java
@@ -19,8 +19,9 @@
 import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
 
 import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
-import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.CANCEL_RECENTS_ANIMATION;
-import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.START_RECENTS_ANIMATION;
+import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.ON_CANCEL_RECENTS_ANIMATION;
+import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.ON_FINISH_RECENTS_ANIMATION;
+import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.ON_START_RECENTS_ANIMATION;
 
 import android.graphics.Rect;
 import android.os.Bundle;
@@ -112,7 +113,7 @@
             ActiveGestureLog.INSTANCE.addLog(
                     /* event= */ "RecentsAnimationCallbacks.onAnimationStart (canceled)",
                     /* extras= */ 0,
-                    /* gestureEvent= */ START_RECENTS_ANIMATION);
+                    /* gestureEvent= */ ON_START_RECENTS_ANIMATION);
             notifyAnimationCanceled();
             animationController.finish(false /* toHome */, false /* sendUserLeaveHint */);
             return;
@@ -145,7 +146,7 @@
                 ActiveGestureLog.INSTANCE.addLog(
                         /* event= */ "RecentsAnimationCallbacks.onAnimationStart",
                         /* extras= */ targets.apps.length,
-                        /* gestureEvent= */ START_RECENTS_ANIMATION);
+                        /* gestureEvent= */ ON_START_RECENTS_ANIMATION);
                 for (RecentsAnimationListener listener : getListeners()) {
                     listener.onRecentsAnimationStart(mController, targets);
                 }
@@ -159,7 +160,7 @@
         Utilities.postAsyncCallback(MAIN_EXECUTOR.getHandler(), () -> {
             ActiveGestureLog.INSTANCE.addLog(
                     /* event= */ "RecentsAnimationCallbacks.onAnimationCanceled",
-                    /* gestureEvent= */ CANCEL_RECENTS_ANIMATION);
+                    /* gestureEvent= */ ON_CANCEL_RECENTS_ANIMATION);
             for (RecentsAnimationListener listener : getListeners()) {
                 listener.onRecentsAnimationCanceled(thumbnailDatas);
             }
@@ -193,7 +194,8 @@
     private final void onAnimationFinished(RecentsAnimationController controller) {
         Utilities.postAsyncCallback(MAIN_EXECUTOR.getHandler(), () -> {
             ActiveGestureLog.INSTANCE.addLog(
-                    /* event= */ "RecentsAnimationCallbacks.onAnimationFinished");
+                    /* event= */ "RecentsAnimationCallbacks.onAnimationFinished",
+                    ON_FINISH_RECENTS_ANIMATION);
             for (RecentsAnimationListener listener : getListeners()) {
                 listener.onRecentsAnimationFinished(controller);
             }
diff --git a/quickstep/src/com/android/quickstep/util/ActiveGestureErrorDetector.java b/quickstep/src/com/android/quickstep/util/ActiveGestureErrorDetector.java
index 3c08f21..4d7a5bb 100644
--- a/quickstep/src/com/android/quickstep/util/ActiveGestureErrorDetector.java
+++ b/quickstep/src/com/android/quickstep/util/ActiveGestureErrorDetector.java
@@ -34,6 +34,7 @@
     public enum GestureEvent {
         MOTION_DOWN, MOTION_UP, MOTION_MOVE, SET_END_TARGET, SET_END_TARGET_HOME,
         SET_END_TARGET_NEW_TASK, SET_END_TARGET_ALL_APPS, ON_SETTLED_ON_END_TARGET,
+        ON_START_RECENTS_ANIMATION, ON_FINISH_RECENTS_ANIMATION, ON_CANCEL_RECENTS_ANIMATION,
         START_RECENTS_ANIMATION, FINISH_RECENTS_ANIMATION, CANCEL_RECENTS_ANIMATION,
         SET_ON_PAGE_TRANSITION_END_CALLBACK, CANCEL_CURRENT_ANIMATION, CLEANUP_SCREENSHOT,
         SCROLLER_ANIMATION_ABORTED, TASK_APPEARED, EXPECTING_TASK_APPEARED,
@@ -226,6 +227,32 @@
                                     + " couldn't start the recents activity",
                             writer);
                     break;
+                case ON_START_RECENTS_ANIMATION:
+                    errorDetected |= printErrorIfTrue(
+                            !encounteredEvents.contains(GestureEvent.START_RECENTS_ANIMATION),
+                            prefix,
+                            /* errorMessage= */ "ON_START_RECENTS_ANIMATION "
+                                    + "onAnimationStart callback ran before startRecentsAnimation",
+                            writer);
+                    break;
+                case ON_CANCEL_RECENTS_ANIMATION:
+                    errorDetected |= printErrorIfTrue(
+                            !encounteredEvents.contains(GestureEvent.ON_START_RECENTS_ANIMATION),
+                            prefix,
+                            /* errorMessage= */ "ON_CANCEL_RECENTS_ANIMATION "
+                                    + "onAnimationCanceled callback ran before onAnimationStart "
+                                    + "callback",
+                            writer);
+                    break;
+                case ON_FINISH_RECENTS_ANIMATION:
+                    errorDetected |= printErrorIfTrue(
+                            !encounteredEvents.contains(GestureEvent.ON_START_RECENTS_ANIMATION),
+                            prefix,
+                            /* errorMessage= */ "ON_FINISH_RECENTS_ANIMATION "
+                                    + "onAnimationFinished callback ran before onAnimationStart "
+                                    + "callback",
+                            writer);
+                    break;
                 case MOTION_DOWN:
                 case SET_END_TARGET:
                 case SET_END_TARGET_HOME:
@@ -357,6 +384,30 @@
                 /* errorMessage= */ "onTaskAppeared was expected to be called but wasn't.",
                 writer);
 
+        errorDetected |= printErrorIfTrue(
+                /* condition= */ encounteredEvents.contains(GestureEvent.START_RECENTS_ANIMATION)
+                        && !encounteredEvents.contains(GestureEvent.ON_START_RECENTS_ANIMATION),
+                prefix,
+                /* errorMessage= */
+                "startRecentAnimation was called but onAnimationStart callback was not",
+                writer);
+        errorDetected |= printErrorIfTrue(
+                /* condition= */
+                encounteredEvents.contains(GestureEvent.FINISH_RECENTS_ANIMATION)
+                        && !encounteredEvents.contains(GestureEvent.ON_FINISH_RECENTS_ANIMATION),
+                prefix,
+                /* errorMessage= */
+                "finishController was called but onAnimationFinished callback was not",
+                writer);
+        errorDetected |= printErrorIfTrue(
+                /* condition= */
+                encounteredEvents.contains(GestureEvent.CANCEL_RECENTS_ANIMATION)
+                        && !encounteredEvents.contains(GestureEvent.ON_CANCEL_RECENTS_ANIMATION),
+                prefix,
+                /* errorMessage= */
+                "onRecentsAnimationCanceled was called but onAnimationCanceled was not",
+                writer);
+
         if (!errorDetected) {
             writer.println(prefix + "\tNo errors detected.");
         }