Include assistant in RemoteTargetGluer

* The UI isn't terribly great, but this fixes the crashes

Bug: 285781761
Change-Id: Ie3376a98b16c19bbdb4e39e7a0a436ddae200c4a
diff --git a/quickstep/src/com/android/quickstep/RemoteTargetGluer.java b/quickstep/src/com/android/quickstep/RemoteTargetGluer.java
index 84b90b9..27fb476 100644
--- a/quickstep/src/com/android/quickstep/RemoteTargetGluer.java
+++ b/quickstep/src/com/android/quickstep/RemoteTargetGluer.java
@@ -16,6 +16,7 @@
 
 package com.android.quickstep;
 
+import android.app.WindowConfiguration;
 import android.content.Context;
 import android.graphics.Rect;
 import android.view.RemoteAnimationTarget;
@@ -123,7 +124,14 @@
             mRemoteTargetHandles = newHandles;
         }
 
+        boolean containsSplitTargets = Arrays.stream(targets.apps)
+                .anyMatch(remoteAnimationTarget ->
+                        remoteAnimationTarget.windowConfiguration.getWindowingMode()
+                                == WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW);
+
         if (mRemoteTargetHandles.length == 1) {
+            // Single fullscreen app
+
             // If we're not in split screen, the splitIds count doesn't really matter since we
             // should always hit this case.
             mRemoteTargetHandles[0].mTransformParams.setTargetSet(targets);
@@ -131,13 +139,29 @@
                 // Unclear why/when target.apps length == 0, but it sure does happen :(
                 mRemoteTargetHandles[0].mTaskViewSimulator.setPreview(targets.apps[0], null);
             }
+        } else if (!containsSplitTargets) {
+            // Single App + Assistant
+            for (int i = 0; i < mRemoteTargetHandles.length; i++) {
+                mRemoteTargetHandles[i].mTransformParams.setTargetSet(targets);
+                mRemoteTargetHandles[i].mTaskViewSimulator.setPreview(targets.apps[i], null);
+            }
         } else {
-            RemoteAnimationTarget topLeftTarget = targets.apps[0];
+            // Split apps (+ maybe assistant)
+            RemoteAnimationTarget topLeftTarget = Arrays.stream(targets.apps)
+                    .filter(remoteAnimationTarget ->
+                            remoteAnimationTarget.windowConfiguration.getWindowingMode()
+                                    == WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW)
+                    .findFirst().get();
 
             // Fetch the adjacent target for split screen.
             RemoteAnimationTarget bottomRightTarget = null;
-            for (int i = 1; i < targets.apps.length; i++) {
+            for (int i = 0; i < targets.apps.length; i++) {
                 final RemoteAnimationTarget target = targets.apps[i];
+                if (target.windowConfiguration.getWindowingMode() !=
+                        WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW ||
+                        target == topLeftTarget) {
+                    continue;
+                }
                 Rect topLeftBounds = getStartBounds(topLeftTarget);
                 Rect bounds = getStartBounds(target);
                 if (topLeftBounds.left > bounds.right || topLeftBounds.top > bounds.bottom) {
diff --git a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
index f8893bd..303a528 100644
--- a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
+++ b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
@@ -411,7 +411,7 @@
             // transitions, the animation leashes are reparented to an animation container so we
             // can bump layers as needed.
             builder.setLayer(mDrawsBelowRecents
-                    ? Integer.MIN_VALUE + 1
+                    ? Integer.MIN_VALUE + app.prefixOrderIndex
                     : ENABLE_SHELL_TRANSITIONS ? Integer.MAX_VALUE : 0);
         }
     }