Don't relaunch activity in TaskRecord.size if caller deferResume

If the caller of TaskRecord.resize() requested resume to be deferred,
then we also don't want to ensure configuration on the top activity in
the task as that can lead to a re-launch. In this case the caller will
handle things.

Test: manual
Change-Id: I247c4409d4bd19c8ae801e1720aa415d55395201
Fixes: 37767027
diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java
index 158175f..7bd8b0b 100644
--- a/services/core/java/com/android/server/am/ActivityRecord.java
+++ b/services/core/java/com/android/server/am/ActivityRecord.java
@@ -2328,6 +2328,9 @@
             return true;
         }
 
+        // TODO: We should add ActivityRecord.shouldBeVisible() that checks if the activity should
+        // be visible based on the stack, task, and lockscreen state and use that here instead. The
+        // method should be based on the logic in ActivityStack.ensureActivitiesVisibleLocked().
         // Skip updating configuration for activity is a stack that shouldn't be visible.
         if (stack.shouldBeVisible(null /* starting */) == STACK_INVISIBLE) {
             if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 056fec5..2b4cb8d 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -550,15 +550,11 @@
         boolean kept = true;
         if (updatedConfig) {
             final ActivityRecord r = topRunningActivityLocked();
-            if (r != null) {
+            if (r != null && !deferResume) {
                 kept = r.ensureActivityConfigurationLocked(0 /* globalChanges */, preserveWindow);
-
-                if (!deferResume) {
-                    // All other activities must be made visible with their correct configuration.
-                    mService.mStackSupervisor.ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
-                    if (!kept) {
-                        mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
-                    }
+                mService.mStackSupervisor.ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
+                if (!kept) {
+                    mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
                 }
             }
         }