Improve hostside test for App window resize

The case of an Activity resizing from fullscreen to docked
is currently tested and verified that some key properties are
being correctly updated (Display, Configuration).

This change adds the reverse case, where the Activity starts in
docked mode and transitions to fullscreen.

Bug:28388969
Change-Id: I9b7d37a5250af36e9255a57d873717251d72cc9e
diff --git a/hostsidetests/services/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java b/hostsidetests/services/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java
index 0e4dded..1975aff 100644
--- a/hostsidetests/services/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java
+++ b/hostsidetests/services/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java
@@ -27,16 +27,41 @@
      * and heights. The values reported in fullscreen should be larger than those reported in
      * docked state.
      */
-    public void testConfigurationUpdatesWhenResized() throws Exception {
+    public void testConfigurationUpdatesWhenResizedFromFullscreen() throws Exception {
         launchActivityInStack(TEST_ACTIVITY_NAME, FULLSCREEN_WORKSPACE_STACK_ID);
         final ReportedSizes fullscreenSizes = getActivityDisplaySize(TEST_ACTIVITY_NAME,
                 FULLSCREEN_WORKSPACE_STACK_ID);
-        final boolean portrait = fullscreenSizes.displayWidth < fullscreenSizes.displayHeight;
 
-        moveActivityToDockStack(TEST_ACTIVITY_NAME);
+        moveActivityToStack(TEST_ACTIVITY_NAME, DOCKED_STACK_ID);
         final ReportedSizes dockedSizes = getActivityDisplaySize(TEST_ACTIVITY_NAME,
                 DOCKED_STACK_ID);
 
+        assertSizesAreSane(fullscreenSizes, dockedSizes);
+    }
+
+    /**
+     * Same as {@link #testConfigurationUpdatesWhenResizedFromFullscreen()} but resizing
+     * from docked state to fullscreen (reverse).
+     */
+    public void testConfigurationUpdatesWhenResizedFromDockedStack() throws Exception {
+        launchActivityInStack(TEST_ACTIVITY_NAME, DOCKED_STACK_ID);
+        final ReportedSizes dockedSizes = getActivityDisplaySize(TEST_ACTIVITY_NAME,
+                DOCKED_STACK_ID);
+
+        moveActivityToStack(TEST_ACTIVITY_NAME, FULLSCREEN_WORKSPACE_STACK_ID);
+        final ReportedSizes fullscreenSizes = getActivityDisplaySize(TEST_ACTIVITY_NAME,
+                FULLSCREEN_WORKSPACE_STACK_ID);
+
+        assertSizesAreSane(fullscreenSizes, dockedSizes);
+    }
+
+    /**
+     * Throws an AssertionError if fullscreenSizes has widths/heights (depending on aspect ratio)
+     * that are smaller than the dockedSizes.
+     */
+    private static void assertSizesAreSane(ReportedSizes fullscreenSizes, ReportedSizes dockedSizes)
+            throws Exception {
+        final boolean portrait = fullscreenSizes.displayWidth < fullscreenSizes.displayHeight;
         if (portrait) {
             assertTrue(dockedSizes.displayHeight < fullscreenSizes.displayHeight);
             assertTrue(dockedSizes.heightDp < fullscreenSizes.heightDp);
diff --git a/hostsidetests/services/activitymanager/src/android/server/cts/ActivityManagerTestBase.java b/hostsidetests/services/activitymanager/src/android/server/cts/ActivityManagerTestBase.java
index 1c7ab4b..0100102 100644
--- a/hostsidetests/services/activitymanager/src/android/server/cts/ActivityManagerTestBase.java
+++ b/hostsidetests/services/activitymanager/src/android/server/cts/ActivityManagerTestBase.java
@@ -154,8 +154,12 @@
     }
 
     protected void moveActivityToDockStack(String activityName) throws Exception {
+        moveActivityToStack(activityName, DOCKED_STACK_ID);
+    }
+
+    protected void moveActivityToStack(String activityName, int stackId) throws Exception {
         final int taskId = getActivityTaskId(activityName);
-        final String cmd = AM_MOVE_TASK + taskId + " " + DOCKED_STACK_ID + " true";
+        final String cmd = AM_MOVE_TASK + taskId + " " + stackId + " true";
         executeShellCommand(cmd);
     }