Freeze task bounds when relaunching

To make sure that task is only laid out with the size
that matches the current configuration, we have to "freeze"
the task bounds when we send a configuration change. Without this
change, it could happen that the app already laid out with the new
task bounds, but still had the old configuration, leading to
wrong layouts.

Bug: 26311778
Bug: 25015474

Change-Id: I8d3a3fdf3735f446a4affbbdb4986dafc97623a5
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 6e65ac1..223e03a 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -61,6 +61,7 @@
 
     // Content limits relative to the DisplayContent this sits in.
     private Rect mBounds = new Rect();
+    final Rect mPreparedFrozenBounds = new Rect();
 
     // Bounds used to calculate the insets.
     private final Rect mTempInsetBounds = new Rect();
@@ -200,8 +201,7 @@
     boolean removeAppToken(AppWindowToken wtoken) {
         boolean removed = mAppTokens.remove(wtoken);
         if (mAppTokens.size() == 0) {
-            EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId,
-                    "removeAppToken: last token");
+            EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeAppToken: last token");
             if (mDeferRemoval) {
                 removeLocked();
             }
@@ -314,6 +314,14 @@
         return true;
     }
 
+    /**
+     * Prepares the task bounds to be frozen with the current size. See
+     * {@link AppWindowToken#freezeBounds}.
+     */
+    void prepareFreezingBounds() {
+        mPreparedFrozenBounds.set(mBounds);
+    }
+
     boolean scrollLocked(Rect bounds) {
         // shift the task bound if it doesn't fully cover the stack area
         mStack.getDimBounds(mTmpRect);
@@ -601,5 +609,6 @@
             pw.print(prefix + prefix); pw.print("mBounds="); pw.println(mBounds.toShortString());
             pw.print(prefix + prefix); pw.print("mdr="); pw.println(mDeferRemoval);
             pw.print(prefix + prefix); pw.print("appTokens="); pw.println(mAppTokens);
+            pw.print(prefix + prefix); pw.print("mTempInsetBounds="); pw.println(mTempInsetBounds);
     }
 }