Don't involve decor inset into app bounds of fixed aspect ratio app

Assume the display size is 1000x2000 with a system decor height 100 at
top (e.g. cutout). For an activity declared max aspect ratio as 1.5:1,
its bounds will be (0,0,1000,1600) because decor region is also included.
And the app bounds should be 1000x1500 (0,100,1000,1600) that fits the
declared aspect ratio.

The original problem is that the app bounds is set to override bounds
directly (without intersecting with parent app bounds), so the aspect
ratio becomes 1.6:1 that doesn't match the declaration.

Since non-resizable activity with fixed aspect ratio will follow the
policy of size compatibility mode: fixed screen relative configuration
across display changes, now the app bounds (intersected with parent app
bounds) also becomes a part of override configuration. That makes sure
the app bounds keeps the declared aspect ratio.

Because the app bounds may contain offset that is occupied by the decor
insets, the offset is applied when parent also has the insets at the
corresponding side. This is just to avoid losing the original insets
information, although currently it may not be used.

Bug: 112288258
Fixes: 127661671
Fixes: 127667028
Test: atest AspectRatioTests
Test: atest AspectRatioSdk25Tests
Test: atest ActivityRecordTests# \
      testSizeCompatMode_FixedAspectRatioBoundsWithDecor
Test: atest ActivityDisplayTests#testHandleActivitySizeCompatMode

Change-Id: I7850a556862e1060876ca094fd919d78ddc4185e
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 955f2e9..1e1c482 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -1627,7 +1627,8 @@
                 // If the changes come from change-listener, the incoming parent configuration is
                 // still the old one. Make sure their orientations are the same to reduce computing
                 // the compatibility bounds for the intermediate state.
-                && getResolvedOverrideConfiguration().orientation == newParentConfig.orientation) {
+                && (task.mTaskRecord == null || task.mTaskRecord
+                        .getConfiguration().orientation == newParentConfig.orientation)) {
             final Rect taskBounds = task.getBounds();
             // Since we only center the activity horizontally, if only the fixed height is smaller
             // than its container, the override bounds don't need to take effect.
@@ -1763,7 +1764,8 @@
         final Rect parentAppBounds = newParentConfig.windowConfiguration.getAppBounds();
         final Rect viewportBounds = parentAppBounds != null
                 ? parentAppBounds : newParentConfig.windowConfiguration.getBounds();
-        final Rect contentBounds = getResolvedOverrideBounds();
+        final Rect appBounds = getWindowConfiguration().getAppBounds();
+        final Rect contentBounds = appBounds != null ? appBounds : getResolvedOverrideBounds();
         final float contentW = contentBounds.width();
         final float contentH = contentBounds.height();
         final float viewportW = viewportBounds.width();
@@ -1780,6 +1782,8 @@
         mSizeCompatBounds.set(contentBounds);
         mSizeCompatBounds.offsetTo(0, 0);
         mSizeCompatBounds.scale(mSizeCompatScale);
+        // The decor inset is included in height.
+        mSizeCompatBounds.bottom += viewportBounds.top;
         mSizeCompatBounds.left += offsetX;
         mSizeCompatBounds.right += offsetX;
     }