Compute configuration orientation by available screen size

It aligns the same calculation as
TaskFragment#computeConfigResourceOverrides.

Otherwise when the display size is close to square and there are
decor windows, the configuration of activity and non-activity
component will be inconsistent.

Bug: 233855302
Test: atest DisplayContentTests#testOrientationForAspectRatio
Change-Id: If6a1d5e28b51b14a2d154872b3e65f6b3c82c101
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index f314900..336bcf9 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -2422,13 +2422,14 @@
         // AppBounds at the root level should mirror the app screen size.
         outConfig.windowConfiguration.setAppBounds(info.mNonDecorFrame);
         outConfig.windowConfiguration.setRotation(rotation);
-        outConfig.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
 
         final float density = mDisplayMetrics.density;
         outConfig.screenWidthDp = (int) (info.mConfigFrame.width() / density + 0.5f);
         outConfig.screenHeightDp = (int) (info.mConfigFrame.height() / density + 0.5f);
         outConfig.compatScreenWidthDp = (int) (outConfig.screenWidthDp / mCompatibleScreenScale);
         outConfig.compatScreenHeightDp = (int) (outConfig.screenHeightDp / mCompatibleScreenScale);
+        outConfig.orientation = (outConfig.screenWidthDp <= outConfig.screenHeightDp)
+                ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
         outConfig.screenLayout = computeScreenLayout(
                 Configuration.resetScreenLayout(outConfig.screenLayout),
                 outConfig.screenWidthDp, outConfig.screenHeightDp);
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
index c2b7fec..c698b05 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
@@ -969,6 +969,13 @@
         assertEquals(
                 "Screen orientation must be defined by the window even on close-to-square display.",
                 window.mAttrs.screenOrientation, dc.getOrientation());
+
+        // Assume that a decor window occupies the display height, so the configuration orientation
+        // should be landscape.
+        dc.getDisplayPolicy().getDecorInsetsInfo(ROTATION_0, dc.mBaseDisplayHeight,
+                dc.mBaseDisplayWidth).mConfigFrame.set(0, 0, 1000, 990);
+        dc.computeScreenConfiguration(config, ROTATION_0);
+        assertEquals(Configuration.ORIENTATION_LANDSCAPE, config.orientation);
     }
 
     @Test