Add app bounds to configuration.

The system previously overrode the display size for a specific scope
(task/activity/etc.) by setting the associated Configuration's
screenWidthDp/screenHeightDp. This leads to two issues. First, the
conversion of screen size from pixels to display independent pixels
and then upconverting later on leads to rounding errors. Secondly,
the screenWidthDp and screenHeightDp values account for insets, such
as the status bar. These however are not reflected in the display
size when returned from Display#getMetrics/getSize.

This changelist addresses the issue by adding a Rect value to
Configuration which stores the app display bounds. This is always set
at the display level and overridden as appropriate. As the proper
app insets are accounted for at the root configuration, all overrides
(outside of specific exceptions) are the result of the intersection
between the requested bound and the parent bound.

Change-Id: I2c4fcd0bee92af12aabbca258de05b4ec061d0e1
Fixes: 34338931
Bug: 36812336
Bug: 36676979
Test: cts/hostsidetests/services/activityandwindowmanager/util/run-test CtsAppTestCases android.app.cts.AspectRatioTests
Test: cts/hostsidetests/services/activityandwindowmanager/util/run-test CtsServicesHostTestCases android.server.cts.ActivityManagerDisplayTests
Test: bit FrameworksServicesTests:com.android.server.wm.AppBoundsTests
diff --git a/services/core/java/com/android/server/wm/StackWindowController.java b/services/core/java/com/android/server/wm/StackWindowController.java
index 8186d30..b2029dd 100644
--- a/services/core/java/com/android/server/wm/StackWindowController.java
+++ b/services/core/java/com/android/server/wm/StackWindowController.java
@@ -270,6 +270,12 @@
 
             int width;
             int height;
+
+            final Rect parentAppBounds = parentConfig.appBounds;
+
+            config.setAppBounds(!bounds.isEmpty() ? bounds : null);
+            boolean intersectParentBounds = false;
+
             if (StackId.tasksAreFloating(mStackId)) {
                 // Floating tasks should not be resized to the screen's bounds.
 
@@ -280,6 +286,7 @@
                     // the fullscreen stack, without intersecting it with the display bounds
                     stableBounds.inset(mTmpStableInsets);
                     nonDecorBounds.inset(mTmpNonDecorInsets);
+                    intersectParentBounds = true;
                 }
                 width = (int) (stableBounds.width() / density);
                 height = (int) (stableBounds.height() / density);
@@ -299,6 +306,11 @@
                         parentConfig.screenWidthDp);
                 height = Math.min((int) (stableBounds.height() / density),
                         parentConfig.screenHeightDp);
+                intersectParentBounds = true;
+            }
+
+            if (intersectParentBounds && config.appBounds != null) {
+                config.appBounds.intersect(parentAppBounds);
             }
 
             config.screenWidthDp = width;