Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3d2b8984 authored by Tiger Huang's avatar Tiger Huang
Browse files

Fix rotation if the shape of display is close to square

For a close-to-square device, the user won't get reasonable benefits
when the content on display is rotated. Worse, the rotation forces the
user to turn their device into an unnatural orientation.

In this CL, if the non-decor aspect ratio of a display is less than
config_closeToSquareDisplayMaxAspectRatio, and the device is configured
to force default orientation, we will ignore all the orientation
requests on the display, and keep the orientation as the user rotation.

For the activity which has a minAspectRatio, the logic will take account
into its preferred orientation while computing its bounds. So the shape
of bounds given to the app can meet its expectation.

Bug: 123507947
Test: atest AspectRatioTests DisplayRotationTests
Test: Manual test with wm size command and simulated display cutout

Change-Id: If99a89d59c805cfc0d305a66067643ce35b3f2bd
parent 9c6db23f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4848,7 +4848,7 @@ public class PackageParser {
    }

    /**
     * Sets every the max aspect ratio of every child activity that doesn't already have an aspect
     * Sets every the min aspect ratio of every child activity that doesn't already have an aspect
     * ratio set.
     */
    private void setMinAspectRatio(Package owner) {
+6 −1
Original line number Diff line number Diff line
@@ -3252,7 +3252,7 @@
         skinny aspect ratio that is not expected to be widely used. -->
    <item name="config_pictureInPictureMinAspectRatio" format="float" type="dimen">0.41841004184</item>

    <!-- The minimum aspect ratio (width/height) that is supported for picture-in-picture. Any
    <!-- The maximum aspect ratio (width/height) that is supported for picture-in-picture. Any
         ratio larger than this is considered to wide and short to be usable. Currently 2.39:1. -->
    <item name="config_pictureInPictureMaxAspectRatio" format="float" type="dimen">2.39</item>

@@ -3273,6 +3273,11 @@
    -->
    <integer name="config_dockedStackDividerSnapMode">0</integer>

    <!-- The maximum aspect ratio (longerSide/shorterSide) that is treated as close-to-square. If
         config_forceDefaultOrientation is set to true, the rotation on a close-to-square display
         will be fixed. -->
    <item name="config_closeToSquareDisplayMaxAspectRatio" format="float" type="dimen">1.333</item>

    <!-- List of comma separated package names for which we the system will not show crash, ANR,
         etc. dialogs. -->
    <string translatable="false" name="config_appsNotReportingCrashes"></string>
+1 −0
Original line number Diff line number Diff line
@@ -403,6 +403,7 @@
  <java-symbol type="integer" name="config_defaultPictureInPictureGravity" />
  <java-symbol type="dimen" name="config_pictureInPictureMinAspectRatio" />
  <java-symbol type="dimen" name="config_pictureInPictureMaxAspectRatio" />
  <java-symbol type="dimen" name="config_closeToSquareDisplayMaxAspectRatio" />
  <java-symbol type="integer" name="config_wifi_framework_5GHz_preference_boost_threshold" />
  <java-symbol type="integer" name="config_wifi_framework_5GHz_preference_boost_factor" />
  <java-symbol type="integer" name="config_wifi_framework_5GHz_preference_penalty_threshold" />
+31 −8
Original line number Diff line number Diff line
@@ -2677,8 +2677,9 @@ final class ActivityRecord extends ConfigurationContainer {
     * Get the configuration orientation by the requested screen orientation
     * ({@link ActivityInfo.ScreenOrientation}) of this activity.
     *
     * @return orientation in ({@link #ORIENTATION_LANDSCAPE}, {@link #ORIENTATION_PORTRAIT},
     *         {@link #ORIENTATION_UNDEFINED}).
     * @return orientation in ({@link Configuration#ORIENTATION_LANDSCAPE},
     *         {@link Configuration#ORIENTATION_PORTRAIT},
     *         {@link Configuration#ORIENTATION_UNDEFINED}).
     */
    int getRequestedConfigurationOrientation() {
        final int screenOrientation = getOrientation();
@@ -2936,14 +2937,36 @@ final class ActivityRecord extends ConfigurationContainer {
                // should be given the aspect ratio.
                activityWidth = (int) ((activityHeight * maxAspectRatio) + 0.5f);
            }
        } else if (containingRatio < minAspectRatio && minAspectRatio != 0) {
        } else if (containingRatio < minAspectRatio) {
            boolean adjustWidth;
            switch (getRequestedConfigurationOrientation()) {
                case ORIENTATION_LANDSCAPE:
                    // Width should be the longer side for this landscape app, so we use the width
                    // to figure-out what the max. height should be given the aspect ratio.
                    adjustWidth = false;
                    break;
                case ORIENTATION_PORTRAIT:
                    // Height should be the longer side for this portrait app, so we use the height
                    // to figure-out what the max. width should be given the aspect ratio.
                    adjustWidth = true;
                    break;
                default:
                    // This app doesn't have a preferred orientation, so we keep the length of the
                    // longer side, and use it to figure-out the length of the shorter side.
                    if (containingAppWidth < containingAppHeight) {
                // Width is the shorter side, so we use the height to figure-out what the max. width
                // should be given the aspect ratio.
                        // Width is the shorter side, so we use the height to figure-out what the
                        // max. width should be given the aspect ratio.
                        adjustWidth = true;
                    } else {
                        // Height is the shorter side, so we use the width to figure-out what the
                        // max. height should be given the aspect ratio.
                        adjustWidth = false;
                    }
                    break;
            }
            if (adjustWidth) {
                activityWidth = (int) ((activityHeight / minAspectRatio) + 0.5f);
            } else {
                // Height is the shorter side, so we use the width to figure-out what the max.
                // height should be given the aspect ratio.
                activityHeight = (int) ((activityWidth / minAspectRatio) + 0.5f);
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -1500,8 +1500,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        final int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
        final int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;

        mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
        mDisplayPolicy.configure(width, height, shortSizeDp);
        mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);

        mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
                calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Loading