Revert "Distinguish warm/hot launch by whether the activity has attached process"

This reverts commit 20efc15caa32eb758d954a2310a873f7283cbd2e.

Reason for revert: Droidcop: Potential culprit for Bug b/171719665 - verifying through Forrest before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.

Merged-In: I18e2f1a5eaf1e07b96d6135be56f8077d37b7504
Change-Id: I46d622d34a984bf40fe9cbb4a6454e41861d8027
diff --git a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java
index 5570c01..189b21f 100644
--- a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java
+++ b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java
@@ -129,6 +129,7 @@
      */
     private static final int IGNORE_CALLER = -1;
     private static final int INVALID_DELAY = -1;
+    private static final int INVALID_TRANSITION_TYPE = -1;
 
     // Preallocated strings we are sending to tron, so we don't have to allocate a new one every
     // time we log.
@@ -223,19 +224,22 @@
         static TransitionInfo create(@NonNull ActivityRecord r,
                 @NonNull LaunchingState launchingState, boolean processRunning,
                 boolean processSwitch, int startResult) {
-            if (startResult != START_SUCCESS && startResult != START_TASK_TO_FRONT) {
-                return null;
-            }
-            final int transitionType;
+            int transitionType = INVALID_TRANSITION_TYPE;
             if (processRunning) {
-                transitionType = r.attachedToProcess()
-                        ? TYPE_TRANSITION_HOT_LAUNCH
-                        : TYPE_TRANSITION_WARM_LAUNCH;
-            } else {
+                if (startResult == START_SUCCESS) {
+                    transitionType = TYPE_TRANSITION_WARM_LAUNCH;
+                } else if (startResult == START_TASK_TO_FRONT) {
+                    transitionType = TYPE_TRANSITION_HOT_LAUNCH;
+                }
+            } else if (startResult == START_SUCCESS || startResult == START_TASK_TO_FRONT) {
                 // Task may still exist when cold launching an activity and the start result will be
                 // set to START_TASK_TO_FRONT. Treat this as a COLD launch.
                 transitionType = TYPE_TRANSITION_COLD_LAUNCH;
             }
+            if (transitionType == INVALID_TRANSITION_TYPE) {
+                // That means the startResult is neither START_SUCCESS nor START_TASK_TO_FRONT.
+                return null;
+            }
             return new TransitionInfo(r, launchingState, transitionType, processRunning,
                     processSwitch);
         }
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java
index 565351a..e1ce431f 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java
@@ -32,7 +32,6 @@
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.timeout;
 
-import android.app.WaitResult;
 import android.content.Intent;
 import android.os.SystemClock;
 import android.platform.test.annotations.Presubmit;
@@ -164,15 +163,10 @@
 
     @Test
     public void testOnActivityLaunchFinished() {
-        // Assume that the process is started (ActivityBuilder has mocked the returned value of
-        // ATMS#getProcessController) but the activity has not attached process.
-        mTopActivity.app = null;
         onActivityLaunched(mTopActivity);
 
         notifyTransitionStarting(mTopActivity);
-        final ActivityMetricsLogger.TransitionInfoSnapshot info = notifyWindowsDrawn(mTopActivity);
-        assertWithMessage("Warm launch").that(info.getLaunchState())
-                .isEqualTo(WaitResult.LAUNCH_STATE_WARM);
+        notifyWindowsDrawn(mTopActivity);
 
         verifyOnActivityLaunchFinished(mTopActivity);
         verifyNoMoreInteractions(mLaunchObserver);
@@ -207,7 +201,7 @@
         notifyActivityLaunching(noDrawnActivity.intent);
         notifyActivityLaunched(START_SUCCESS, noDrawnActivity);
 
-        noDrawnActivity.mVisibleRequested = false;
+        noDrawnActivity.destroyIfPossible("test");
         mActivityMetricsLogger.notifyVisibilityChanged(noDrawnActivity);
 
         verifyAsync(mLaunchObserver).onActivityLaunchCancelled(eqProto(noDrawnActivity));
@@ -223,9 +217,6 @@
         notifyTransitionStarting(mTopActivity);
         // The pending fully drawn event should send when the actual windows drawn event occurs.
         notifyWindowsDrawn(mTopActivity);
-        final ActivityMetricsLogger.TransitionInfoSnapshot info = notifyWindowsDrawn(mTopActivity);
-        assertWithMessage("Hot launch").that(info.getLaunchState())
-                .isEqualTo(WaitResult.LAUNCH_STATE_HOT);
 
         verifyAsync(mLaunchObserver).onReportFullyDrawn(eqProto(mTopActivity), anyLong());
         verifyOnActivityLaunchFinished(mTopActivity);
@@ -269,8 +260,8 @@
         mActivityMetricsLogger.notifyTransitionStarting(reasons);
     }
 
-    private ActivityMetricsLogger.TransitionInfoSnapshot notifyWindowsDrawn(ActivityRecord r) {
-        return mActivityMetricsLogger.notifyWindowsDrawn(r, SystemClock.elapsedRealtimeNanos());
+    private void notifyWindowsDrawn(ActivityRecord r) {
+        mActivityMetricsLogger.notifyWindowsDrawn(r, SystemClock.elapsedRealtimeNanos());
     }
 
     @Test