Fixing “Transition Delay - App to Recents” test: the Launcher part

The fix is quite hacky and should be re-done soon. I’m not leaving TODOs
in the code, but I’m tracking the cleanup elsewhere.

We also need a fix in the server to make the test work, but that will be
another CL.

Bug: 72967764
Test: atest google/perf/app-transition/app-transition-to-recents
Change-Id: Ia21c308caa81bd5502f4a4587ae445928f6eca17
diff --git a/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java b/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java
index a2c54f1..b3354a4 100644
--- a/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java
+++ b/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java
@@ -38,8 +38,10 @@
 import android.graphics.Point;
 import android.graphics.PointF;
 import android.graphics.Rect;
+import android.metrics.LogMaker;
 import android.os.Bundle;
 import android.os.Looper;
+import android.os.SystemClock;
 import android.util.Log;
 import android.view.Display;
 import android.view.MotionEvent;
@@ -64,6 +66,40 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
+class EventLogTags {
+    private EventLogTags() {
+    }  // don't instantiate
+
+    /** 524292 sysui_multi_action (content|4) */
+    public static final int SYSUI_MULTI_ACTION = 524292;
+
+    public static void writeSysuiMultiAction(Object[] content) {
+        android.util.EventLog.writeEvent(SYSUI_MULTI_ACTION, content);
+    }
+}
+
+class MetricsLogger {
+    private static MetricsLogger sMetricsLogger;
+
+    private static MetricsLogger getLogger() {
+        if (sMetricsLogger == null) {
+            sMetricsLogger = new MetricsLogger();
+        }
+        return sMetricsLogger;
+    }
+
+    protected void saveLog(Object[] rep) {
+        EventLogTags.writeSysuiMultiAction(rep);
+    }
+
+    public void write(LogMaker content) {
+        if (content.getType() == 0/*MetricsEvent.TYPE_UNKNOWN*/) {
+            content.setType(4/*MetricsEvent.TYPE_ACTION*/);
+        }
+        saveLog(content.serialize());
+    }
+}
+
 /**
  * Touch consumer for handling events originating from an activity other than Launcher
  */
@@ -91,6 +127,8 @@
 
     private VelocityTracker mVelocityTracker;
 
+    private final MetricsLogger mMetricsLogger = new MetricsLogger();
+
     public OtherActivityTouchConsumer(Context base, RunningTaskInfo runningTaskInfo,
             RecentsModel recentsModel, Intent homeIntent, ISystemUiProxy systemUiProxy,
             MainThreadExecutor mainThreadExecutor) {
@@ -125,7 +163,7 @@
                 // Start the window animation on down to give more time for launcher to draw if the
                 // user didn't start the gesture over the back button
                 if (!isUsingScreenShot()) {
-                    startTouchTrackingForWindowAnimation();
+                    startTouchTrackingForWindowAnimation(ev.getEventTime());
                 }
 
                 Display display = getSystemService(WindowManager.class).getDefaultDisplay();
@@ -264,7 +302,7 @@
         }
     }
 
-    private void startTouchTrackingForWindowAnimation() {
+    private void startTouchTrackingForWindowAnimation(long touchTimeMs) {
         // Create the shared handler
         final WindowTransformSwipeHandler handler =
                 new WindowTransformSwipeHandler(mRunningTask, this);
@@ -302,6 +340,16 @@
                         } else {
                             controller.finish(false /* toHome */);
                         }
+
+                        // Mimic ActivityMetricsLogger.logAppTransitionMultiEvents() logging for
+                        // "Recents" activity for app transition tests.
+                        final LogMaker builder = new LogMaker(761/*APP_TRANSITION*/);
+                        builder.setPackageName("com.android.systemui");
+                        builder.addTaggedData(871/*FIELD_CLASS_NAME*/,
+                                "com.android.systemui.recents.RecentsActivity");
+                        builder.addTaggedData(319/*APP_TRANSITION_DELAY_MS*/,
+                                SystemClock.uptimeMillis() - touchTimeMs);
+                        mMetricsLogger.write(builder);
                     }
 
                     public void onAnimationCanceled() {