Correct errant entry in to DRAG_RESIZE_FREEFORM state.

Observing the logic in computeDragResizing(), we see that whenever an
AppWindowToken has frozen bounds we will enter the drag resizing
state. Furthermore, in setDragResizing() we see that if the docked
divider is not resizing, then we set ourselves as freeform
resizing. Also observe that AppWindowToken#startRelaunching
unconditionally freezes the bounds for tasks not in the freeform
stack. This means we are almost always entering the freeform resize
state while relaunching. Within computeDragResizing, the StackId check
and the MATCH_PARENT check have prevented this from being an issue in
too many places, espescially in pinned.

Once we are in this state, calculateSurfaceBounds() will force us to
0,0 as it thinks we are using the big surface approach.

There's no need to freeze the bounds if we weren't drag resizing at
the time that the app is relaunched, and this CL enforces that.

Bug: 62430780
Test: Manual repro from bug. To verify no regressions, create app with long delay in onResume (>1s) verify no flickers when releasing the docked divider and triggering a resize.
      go/wm-smoke

Change-Id: I1d9bdfbe815ff48c884f933acd65612429d633ef
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 71ecaf6..350a333 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -891,8 +891,24 @@
         return mPendingRelaunchCount > 0;
     }
 
+    boolean shouldFreezeBounds() {
+        final Task task = getTask();
+
+        // For freeform windows, we can't freeze the bounds at the moment because this would make
+        // the resizing unresponsive.
+        if (task == null || task.inFreeformWorkspace()) {
+            return false;
+        }
+
+        // We freeze the bounds while drag resizing to deal with the time between
+        // the divider/drag handle being released, and the handling it's new
+        // configuration. If we are relaunched outside of the drag resizing state,
+        // we need to be careful not to do this.
+        return getTask().isDragResizing();
+    }
+
     void startRelaunching() {
-        if (canFreezeBounds()) {
+        if (shouldFreezeBounds()) {
             freezeBounds();
         }
 
@@ -909,9 +925,8 @@
     }
 
     void finishRelaunching() {
-        if (canFreezeBounds()) {
-            unfreezeBounds();
-        }
+        unfreezeBounds();
+
         if (mPendingRelaunchCount > 0) {
             mPendingRelaunchCount--;
         } else {
@@ -926,9 +941,7 @@
         if (mPendingRelaunchCount == 0) {
             return;
         }
-        if (canFreezeBounds()) {
-            unfreezeBounds();
-        }
+        unfreezeBounds();
         mPendingRelaunchCount = 0;
     }
 
@@ -1032,14 +1045,6 @@
         }
     }
 
-    private boolean canFreezeBounds() {
-        final Task task = getTask();
-
-        // For freeform windows, we can't freeze the bounds at the moment because this would make
-        // the resizing unresponsive.
-        return task != null && !task.inFreeformWorkspace();
-    }
-
     /**
      * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
      * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
@@ -1064,9 +1069,10 @@
      * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
      */
     private void unfreezeBounds() {
-        if (!mFrozenBounds.isEmpty()) {
-            mFrozenBounds.remove();
+        if (mFrozenBounds.isEmpty()) {
+            return;
         }
+        mFrozenBounds.remove();
         if (!mFrozenMergedConfig.isEmpty()) {
             mFrozenMergedConfig.remove();
         }