Merge "Fixing generation of fake app-to-recents events" into ub-launcher3-master
diff --git a/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java b/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java
index 488cd72..73cd503 100644
--- a/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java
+++ b/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java
@@ -37,10 +37,8 @@
 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.Choreographer;
 import android.view.Display;
@@ -66,40 +64,6 @@
 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
  */
@@ -129,8 +93,6 @@
     private VelocityTracker mVelocityTracker;
     private MotionEventQueue mEventQueue;
 
-    private final MetricsLogger mMetricsLogger = new MetricsLogger();
-
     public OtherActivityTouchConsumer(Context base, RunningTaskInfo runningTaskInfo,
             RecentsModel recentsModel, Intent homeIntent, ISystemUiProxy systemUiProxy,
             MainThreadExecutor mainThreadExecutor, Choreographer backgroundThreadChoreographer,
@@ -312,7 +274,7 @@
     private void startTouchTrackingForWindowAnimation(long touchTimeMs) {
         // Create the shared handler
         final WindowTransformSwipeHandler handler =
-                new WindowTransformSwipeHandler(mRunningTask, this);
+                new WindowTransformSwipeHandler(mRunningTask, this, touchTimeMs);
 
         // Preload the plan
         mRecentsModel.loadTasks(mRunningTask.id, null);
@@ -350,16 +312,6 @@
                             TraceHelper.endSection("RecentsController", "Finishing no handler");
                             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() {
diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
index 19942c3..3198790 100644
--- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
+++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
@@ -39,9 +39,11 @@
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.graphics.RectF;
+import android.metrics.LogMaker;
 import android.os.Build;
 import android.os.Handler;
 import android.os.Looper;
+import android.os.SystemClock;
 import android.support.annotation.UiThread;
 import android.support.annotation.WorkerThread;
 import android.util.Log;
@@ -77,6 +79,40 @@
 
 import java.util.StringJoiner;
 
+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());
+    }
+}
+
 @TargetApi(Build.VERSION_CODES.O)
 public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {
     private static final String TAG = WindowTransformSwipeHandler.class.getSimpleName();
@@ -189,10 +225,14 @@
 
     private final RecentsAnimationWrapper mRecentsAnimationWrapper = new RecentsAnimationWrapper();
     private Matrix mTmpMatrix = new Matrix();
+    private final long mTouchTimeMs;
+    private long mLauncherFrameDrawnTime;
+    private final MetricsLogger mMetricsLogger = new MetricsLogger();
 
-    WindowTransformSwipeHandler(RunningTaskInfo runningTaskInfo, Context context) {
+    WindowTransformSwipeHandler(RunningTaskInfo runningTaskInfo, Context context, long touchTimeMs) {
         mContext = context;
         mRunningTaskId = runningTaskInfo.id;
+        mTouchTimeMs = touchTimeMs;
         mInputConsumer.registerInputConsumer();
         initStateCallbacks();
     }
@@ -416,11 +456,22 @@
         if (mLauncherDrawnCallback != null) {
             mLauncherDrawnCallback.run();
         }
+        mLauncherFrameDrawnTime = SystemClock.uptimeMillis();
     }
 
     private void initializeLauncherAnimationController() {
         mLauncherLayoutListener.setHandler(this);
         onLauncherLayoutChanged();
+
+        // Mimic ActivityMetricsLogger.logAppTransitionMultiEvents() logging for
+        // "Recents" activity for app transition tests for the app-to-recents case.
+        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*/,
+                mLauncherFrameDrawnTime - mTouchTimeMs);
+        mMetricsLogger.write(builder);
     }
 
     public void updateInteractionType(@InteractionType int interactionType) {