Revert "Restore old stack Z ordering promotion."

This reverts commit d92e7eb2e9a72ac73e992cf502a080ad47a962f3.

Reason for revert: Causes 71736995

Change-Id: I8294bdb65a496bfd0170ec606d20d604d5ef6271
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index a6cfd94..2cc2a0e 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -3464,47 +3464,37 @@
 
         @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;
-            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++);
+
+            // 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 i = 0; i < mChildren.size(); i++) {
                 final TaskStack s = mChildren.get(i);
-                s.assignChildLayers(t);
+                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++);
+                }
             }
 
+            // 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