Restore old stack Z ordering promotion.

This is a more direct translation of what was in WindowLayersController.
We hoped that it wasn't necessary and that they were always in the correct
position in the WindowContainer hierarchy. However it seems there is no mechanism
to position them as such. It's not obvious for me how to resolve things from that angle
so I'm proposing reintroducing this logic.

Bug: 69553456
Bug: 70178829
Test: Manual. go/wm-smoke
Change-Id: I32ab03b1bcd6c498bf643c0f207d3f72286f258b
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index d053015..2decbcb 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -3493,37 +3493,47 @@
 
         @Override
         void assignChildLayers(SurfaceControl.Transaction t) {
+
+            final int NORMAL_STACK_STATE = 0;
+            final int SPLIT_SCREEN_STACK_STATE = 1;
+            final int ASSISTANT_STACK_STATE = 2;
+            final int BOOSTED_STATE = 3;
+            final int ALWAYS_ON_TOP_STATE = 4;
+
             int layer = 0;
-
-            // We allow stacks to change visual order from the AM specified order due to
-            // Z-boosting during animations. However we must take care to ensure TaskStacks
-            // which are marked as alwaysOnTop remain that way.
-            for (int i = 0; i < mChildren.size(); i++) {
-                final TaskStack s = mChildren.get(i);
-                s.assignChildLayers();
-                if (!s.needsZBoost() && !s.isAlwaysOnTop()) {
-                    s.assignLayer(t, layer++);
+            for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
+                for (int i = 0; i < mChildren.size(); i++) {
+                    final TaskStack s = mChildren.get(i);
+                    layer++;
+                    if (state == NORMAL_STACK_STATE && !s.inSplitScreenPrimaryWindowingMode() &&
+                            !s.isActivityTypeAssistant() &&
+                            !s.needsZBoost() && !s.isAlwaysOnTop()) {
+                        s.assignLayer(t, layer);
+                    } else if (state == SPLIT_SCREEN_STACK_STATE &&
+                            s.inSplitScreenPrimaryWindowingMode()) {
+                        s.assignLayer(t, layer);
+                    } else if (state == ASSISTANT_STACK_STATE &&
+                            s.isActivityTypeAssistant()) {
+                        s.assignLayer(t, layer);
+                    } else if (state == BOOSTED_STATE && s.needsZBoost()) {
+                        s.assignLayer(t, layer);
+                    } else if (state == ALWAYS_ON_TOP_STATE &&
+                            s.isAlwaysOnTop()) {
+                        s.assignLayer(t, layer);
+                    }
+                }
+                // The appropriate place for App-Transitions to occur is right
+                // above all other animations but still below things in the Picture-and-Picture
+                // windowing mode.
+                if (state == BOOSTED_STATE && mAppAnimationLayer != null) {
+                    t.setLayer(mAppAnimationLayer, layer++);
                 }
             }
             for (int i = 0; i < mChildren.size(); i++) {
                 final TaskStack s = mChildren.get(i);
-                if (s.needsZBoost() && !s.isAlwaysOnTop()) {
-                    s.assignLayer(t, layer++);
-                }
-            }
-            for (int i = 0; i < mChildren.size(); i++) {
-                final TaskStack s = mChildren.get(i);
-                if (s.isAlwaysOnTop()) {
-                    s.assignLayer(t, layer++);
-                }
+                s.assignChildLayers(t);
             }
 
-            // The appropriate place for App-Transitions to occur is right
-            // above all other animations but still below things in the Picture-and-Picture
-            // windowing mode.
-            if (mAppAnimationLayer != null) {
-                t.setLayer(mAppAnimationLayer, layer++);
-            }
         }
 
         @Override