Exit split-screen when primary stack moved behind a fullscreen stack.

Activities can request their task be moved to the back of the stack,
which subsequently causes the stack to move as well. When the stack
is a split screen primary stack, this causes an ordering issue where
the secondary will not move back while a fullscreen stack has moved
in front of the primary. This leads to further ordering issues once
the front secondary is dismissed as other stacks are also in the
secondary windowing mode.

To address this issue, we exit split-screen mode when the primary
split-screen stack is moved back.

Test: atest ActivityStackTests#testPrimarySplitScreenToFullscreenWhenMovedToBack
Change-Id: Ic0597831e046a254b3cba216e1cb2fb11191f2c6
Fixes: 69662547
diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java b/services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java
index 6b09363..bcbf40e 100644
--- a/services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java
+++ b/services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java
@@ -47,7 +47,7 @@
  * Tests for the {@link ActivityStack} class.
  *
  * Build/Install/Run:
- *  bit FrameworksServicesTests:com.android.server.am.ActivityStackTests
+ *  atest ActivityStackTests
  */
 @SmallTest
 @Presubmit
@@ -104,6 +104,29 @@
     }
 
     @Test
+    public void testPrimarySplitScreenToFullscreenWhenMovedToBack() throws Exception {
+        // Create primary splitscreen stack. This will create secondary stacks and places the
+        // existing fullscreen stack on the bottom.
+        final ActivityStack primarySplitScreen = mService.mStackSupervisor.getDefaultDisplay()
+                .createStack(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD,
+                        true /* onTop */);
+
+        // Assert windowing mode.
+        assertEquals(primarySplitScreen.getWindowingMode(), WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
+
+        // Move primary to back.
+        primarySplitScreen.moveToBack("testPrimarySplitScreenToFullscreenWhenMovedToBack",
+                null /* task */);
+
+        // Assert that stack is at the bottom.
+        assertEquals(mService.mStackSupervisor.getDefaultDisplay().getIndexOf(primarySplitScreen),
+                0);
+
+        // Ensure no longer in splitscreen.
+        assertEquals(primarySplitScreen.getWindowingMode(), WINDOWING_MODE_FULLSCREEN);
+    }
+
+    @Test
     public void testStopActivityWhenActivityDestroyed() throws Exception {
         final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build();
         r.info.flags |= ActivityInfo.FLAG_NO_HISTORY;