Only associate the same windowing mode to a transition info

Different windowing modes of launching activities are usually
independent launch events. In other words, the launch cookie
won't be transferred across windowing mode.

Bug: 190833924
Test: atest ActivityMetricsLaunchObserverTests# \
      testConsecutiveLaunchWithDifferentWindowingMode
Test: Launch from widget whose trampoline redirects to a bubble.
Change-Id: Ic95732e0ed7fbeaf57550d392e4b3f04a67e311f
diff --git a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java
index 2b6a838..14f6fb3 100644
--- a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java
+++ b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java
@@ -312,6 +312,12 @@
             }
         }
 
+        /** Returns {@code true} if the incoming activity can belong to this transition. */
+        boolean canCoalesce(ActivityRecord r) {
+            return mLastLaunchedActivity.mDisplayContent == r.mDisplayContent
+                    && mLastLaunchedActivity.getWindowingMode() == r.getWindowingMode();
+        }
+
         /** @return {@code true} if the activity matches a launched activity in this transition. */
         boolean contains(ActivityRecord r) {
             return r != null && (r == mLastLaunchedActivity || mPendingDrawActivities.contains(r));
@@ -604,8 +610,7 @@
             return;
         }
 
-        final DisplayContent targetDisplay = launchedActivity.mDisplayContent;
-        if (info != null && info.mLastLaunchedActivity.mDisplayContent == targetDisplay) {
+        if (info != null && info.canCoalesce(launchedActivity)) {
             // If we are already in an existing transition on the same display, only update the
             // activity name, but not the other attributes.
 
@@ -633,7 +638,7 @@
             // As abort for no process switch.
             launchObserverNotifyIntentFailed();
         }
-        if (targetDisplay.isSleeping()) {
+        if (launchedActivity.mDisplayContent.isSleeping()) {
             // It is unknown whether the activity can be drawn or not, e.g. ut depends on the
             // keyguard states and the attributes or flags set by the activity. If the activity
             // keeps invisible in the grace period, the tracker will be cancelled so it won't get
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 82c459c..38466eb 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java
@@ -38,6 +38,7 @@
 import android.app.ActivityOptions;
 import android.app.ActivityOptions.SourceInfo;
 import android.app.WaitResult;
+import android.app.WindowConfiguration;
 import android.content.Intent;
 import android.os.IBinder;
 import android.os.SystemClock;
@@ -476,6 +477,18 @@
         transitToDrawnAndVerifyOnLaunchFinished(activityOnNewDisplay);
     }
 
+    @Test
+    public void testConsecutiveLaunchWithDifferentWindowingMode() {
+        mTopActivity.setWindowingMode(WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW);
+        onActivityLaunched(mTrampolineActivity);
+        mActivityMetricsLogger.notifyActivityLaunching(mTopActivity.intent,
+                mTrampolineActivity /* caller */, mTrampolineActivity.getUid());
+        notifyActivityLaunched(START_SUCCESS, mTopActivity);
+        // Different windowing modes should be independent launch events.
+        transitToDrawnAndVerifyOnLaunchFinished(mTrampolineActivity);
+        transitToDrawnAndVerifyOnLaunchFinished(mTopActivity);
+    }
+
     private void transitToDrawnAndVerifyOnLaunchFinished(ActivityRecord activity) {
         notifyTransitionStarting(activity);
         notifyWindowsDrawn(activity);