Launch SizeCompat Activities in a Window on Freeform Desktop Mode

Currently, when a display is in freeform mode, an activity that
is not resizable launches in fullscreen. However, for large
screen devices, it is preferable to launch activities in windows
to create the true desktop experience. This CL changes launch
configurations and resize actions to make non-resizable activities
launch in a window and to prevent resizing of these windows. When
the display enters fullscreen mode, the activity keeps its original
bounds and launches in a letterbox.

To make this all work, ActivityRecord was updated to use the
hierarchy instead of trying to recalculate everything independently
with a fullscreen assumption. The result is that the ActivityRecord
configuration now (mostly) has the actual bounds of the app so
that positioning works properly.

Please note, the following tests were removed because the
functionality they were trying to test has changed. Previously,
when a task was nonresizeable, even if the display windowing mode
was freeform, it was launched in fullscreen mode. However this CL
allows nonresizeable tasks in freeform mode to be launched in
windows. These tests were removed since they are redundant
with non-resizable (which is handled by packagemanager):
- TaskLaunchParamsModifierTests#testForceMaximizesPreDApp
- TaskLaunchParamsModifierTests#testForceMaximizesAppWithoutMultipleDensitySupport

The following tests were added:
- TaskPositioningControllerTests#testHandleTapOutsideNonResizableTask
- TaskLaunchParamsModifierTests#testLaunchesAppInWindowOnFreeformDisplay
- ActivityRecordTests#testSizeCompatMode_KeepBoundsWhenChangingFromFreeformToFullscreen

This also adds a developer option to enable size-compat
apps to start in freeform mode.

Test: go/wm-smoke
Change-Id: I3aa3fcdcd2b1e0b875d61dfaed3d5e85313edc29
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index 14df505..014b682 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -54,6 +54,7 @@
 import static android.os.Process.SYSTEM_UID;
 import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
 import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT;
+import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM;
 import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES;
 import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RTL;
 import static android.provider.Settings.Global.HIDE_ERROR_DIALOGS;
@@ -569,6 +570,7 @@
     boolean mSupportsPictureInPicture;
     boolean mSupportsMultiDisplay;
     boolean mForceResizableActivities;
+    boolean mSizeCompatFreeform;
 
     final List<ActivityTaskManagerInternal.ScreenObserver> mScreenObservers = new ArrayList<>();
 
@@ -744,6 +746,8 @@
         final boolean forceRtl = Settings.Global.getInt(resolver, DEVELOPMENT_FORCE_RTL, 0) != 0;
         final boolean forceResizable = Settings.Global.getInt(
                 resolver, DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0;
+        final boolean sizeCompatFreeform = Settings.Global.getInt(
+                resolver, DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM, 0) != 0;
 
         // Transfer any global setting for forcing RTL layout, into a System Property
         DisplayProperties.debug_force_rtl(forceRtl);
@@ -757,6 +761,7 @@
 
         synchronized (mGlobalLock) {
             mForceResizableActivities = forceResizable;
+            mSizeCompatFreeform = sizeCompatFreeform;
             final boolean multiWindowFormEnabled = freeformWindowManagement
                     || supportsSplitScreenMultiWindow
                     || supportsPictureInPicture
@@ -3393,6 +3398,9 @@
 
                 if (stack.inFreeformWindowingMode()) {
                     stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
+                } else if (!mSizeCompatFreeform) {
+                    throw new IllegalStateException("Size-compat windows are currently not"
+                            + "freeform-enabled");
                 } else if (stack.getParent().inFreeformWindowingMode()) {
                     // If the window is on a freeform display, set it to undefined. It will be
                     // resolved to freeform and it can adjust windowing mode when the display mode