Add FULLSCREEN policies to task level

When a task is in FULLSCREEN windowing mode, it will
fill its parent subject to some policy constraints.
This is handled at the configuration resolution step
which means that FULLSCREEN now implies matchParentBounds
even if the requestedOverrideBounds is not empty.

If it has an overridden orientation (app requested), and
this orientation doesn't match it's parent, the task will
fill as much of it's parent as it can while maintaining
it's requested orientation and will be centered.

This also sets the *requested* override bounds back to
mLastNonFullscreenBounds when entering freeform mode so
that restore works properly. This happens in tandem with
the mode change. Because this is changing *requested*
bounds, callers are free to manipulate it afterwards.

Bug: 113252962
Test: go/wm-smoke, wmtests, "maximizing" and restoring a
      freeform app now properly resizes the task, added
      some TaskRecordTests. Also, tested on freeform display.
Change-Id: If0e32d4240a9331dcf18209eaf4718d7ba800c5c
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 2cd0168..58083a0 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -725,9 +725,10 @@
             mLastReportedMultiWindowMode = inPictureInPictureMode;
             final Configuration newConfig = new Configuration();
             if (targetStackBounds != null && !targetStackBounds.isEmpty()) {
-                task.computeResolvedOverrideConfiguration(newConfig,
-                        task.getParent().getConfiguration(),
-                        task.getRequestedOverrideConfiguration());
+                newConfig.setTo(task.getRequestedOverrideConfiguration());
+                Rect outBounds = newConfig.windowConfiguration.getBounds();
+                task.adjustForMinimalTaskDimensions(outBounds, outBounds);
+                task.computeConfigResourceOverrides(newConfig, task.getParent().getConfiguration());
             }
             schedulePictureInPictureModeChanged(newConfig);
             scheduleMultiWindowModeChanged(newConfig);
@@ -2498,7 +2499,8 @@
             return;
         }
 
-        final IBinder binder = freezeScreenIfNeeded ? appToken.asBinder() : null;
+        final IBinder binder =
+                (freezeScreenIfNeeded && appToken != null) ? appToken.asBinder() : null;
         mAppWindowToken.setOrientation(requestedOrientation, binder, this);
     }
 
@@ -2542,7 +2544,6 @@
 
     // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
     private void updateOverrideConfiguration() {
-        mTmpConfig.unset();
         computeBounds(mTmpBounds);
 
         if (mTmpBounds.equals(getRequestedOverrideBounds())) {
@@ -2553,8 +2554,10 @@
 
         // Bounds changed...update configuration to match.
         if (!matchParentBounds()) {
-            task.computeResolvedOverrideConfiguration(mTmpConfig,
-                    task.getParent().getConfiguration(), getRequestedOverrideConfiguration());
+            mTmpConfig.setTo(getRequestedOverrideConfiguration());
+            task.computeConfigResourceOverrides(mTmpConfig, task.getParent().getConfiguration());
+        } else {
+            mTmpConfig.unset();
         }
 
         onRequestedOverrideConfigurationChanged(mTmpConfig);