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

Commit 5a676f6f authored by tomnatan's avatar tomnatan
Browse files

Introduce an OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY change ID

This change ID will determine whether the OVERRIDE_MIN_ASPECT_RATIO override will be applied for portrait only activities (if enabled), and for all orientations (if disable).

Note that this change is enabled by default because it will need to be
enabled for most use cases.

Fix: 203647190
Test: atest WmTests:SizeCompatTests
Change-Id: I0fccbdc22ff387d33695fbf432cf96cd517de095
parent b1626ac3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -785,6 +785,7 @@ package android.content.pm {
    field public static final float OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE = 1.7777778f;
    field public static final long OVERRIDE_MIN_ASPECT_RATIO_MEDIUM = 180326845L; // 0xabf91bdL
    field public static final float OVERRIDE_MIN_ASPECT_RATIO_MEDIUM_VALUE = 1.5f;
    field public static final long OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY = 203647190L; // 0xc2368d6L
    field public static final int RESIZE_MODE_RESIZEABLE = 2; // 0x2
  }

+31 −32
Original line number Diff line number Diff line
@@ -995,10 +995,9 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
     * OVERRIDE_MIN_ASPECT_RATIO_MEDIUM
     * OVERRIDE_MIN_ASPECT_RATIO_LARGE
     *
     * If OVERRIDE_MIN_ASPECT_RATIO is applied, and the activity's orientation is fixed to
     * portrait, the min aspect ratio given in the app's manifest will be overridden to the
     * largest enabled aspect ratio treatment unless the app's manifest value is higher.
     * TODO(b/203647190): add OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY instead of portrait by default
     * If OVERRIDE_MIN_ASPECT_RATIO is applied, the min aspect ratio given in the app's manifest
     * will be overridden to the largest enabled aspect ratio treatment unless the app's manifest
     * value is higher.
     * @hide
     */
    @ChangeId
@@ -1007,6 +1006,19 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
    @TestApi
    public static final long OVERRIDE_MIN_ASPECT_RATIO = 174042980L; // buganizer id

    /**
     * This change id restricts treatments that force a given min aspect ratio to activities
     * whose orientation is fixed to portrait.
     *
     * This treatment only takes effect if OVERRIDE_MIN_ASPECT_RATIO is also enabled.
     * @hide
     */
    @ChangeId
    @Overridable
    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.S)
    @TestApi
    public static final long OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY = 203647190L; // buganizer id

    /**
     * This change id sets the activity's min aspect ratio to a medium value as defined by
     * OVERRIDE_MIN_ASPECT_RATIO_MEDIUM_VALUE.
@@ -1336,9 +1348,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
     */
    @SizeChangesSupportMode
    public int supportsSizeChanges() {
        if (CompatChanges.isChangeEnabled(FORCE_NON_RESIZE_APP,
                applicationInfo.packageName,
                UserHandle.getUserHandleForUid(applicationInfo.uid))) {
        if (isChangeEnabled(FORCE_NON_RESIZE_APP)) {
            return SIZE_CHANGES_UNSUPPORTED_OVERRIDE;
        }

@@ -1346,9 +1356,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
            return SIZE_CHANGES_SUPPORTED_METADATA;
        }

        if (CompatChanges.isChangeEnabled(FORCE_RESIZE_APP,
                applicationInfo.packageName,
                UserHandle.getUserHandleForUid(applicationInfo.uid))) {
        if (isChangeEnabled(FORCE_RESIZE_APP)) {
            return SIZE_CHANGES_SUPPORTED_OVERRIDE;
        }

@@ -1360,9 +1368,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
     * @hide
     */
    public boolean neverSandboxDisplayApis() {
        return CompatChanges.isChangeEnabled(NEVER_SANDBOX_DISPLAY_APIS,
                applicationInfo.packageName,
                UserHandle.getUserHandleForUid(applicationInfo.uid))
        return isChangeEnabled(NEVER_SANDBOX_DISPLAY_APIS)
                || ConstrainDisplayApisConfig.neverConstrainDisplayApis(applicationInfo);
    }

@@ -1371,9 +1377,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
     * @hide
     */
    public boolean alwaysSandboxDisplayApis() {
        return CompatChanges.isChangeEnabled(ALWAYS_SANDBOX_DISPLAY_APIS,
                applicationInfo.packageName,
                UserHandle.getUserHandleForUid(applicationInfo.uid))
        return isChangeEnabled(ALWAYS_SANDBOX_DISPLAY_APIS)
                || ConstrainDisplayApisConfig.alwaysConstrainDisplayApis(applicationInfo);
    }

@@ -1403,31 +1407,28 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
     * @hide
     */
    public float getMinAspectRatio(@ScreenOrientation int orientation) {
        // TODO(b/203647190): check orientation only if OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY
        // In case the activity's orientation isn't fixed to portrait, OVERRIDE_MIN_ASPECT_RATIO
        // shouldn't be applied.
        if (applicationInfo == null || !CompatChanges.isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO,
                applicationInfo.packageName,
                UserHandle.getUserHandleForUid(applicationInfo.uid))
                || !isFixedOrientationPortrait(orientation)) {
        if (applicationInfo == null || !isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO) || (
                isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY)
                        && !isFixedOrientationPortrait(orientation))) {
            return mMinAspectRatio;
        }

        if (CompatChanges.isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO_LARGE,
                applicationInfo.packageName,
                UserHandle.getUserHandleForUid(applicationInfo.uid))) {
        if (isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO_LARGE)) {
            return Math.max(OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE, mMinAspectRatio);
        }

        if (CompatChanges.isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO_MEDIUM,
                applicationInfo.packageName,
                UserHandle.getUserHandleForUid(applicationInfo.uid))) {
        if (isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO_MEDIUM)) {
            return Math.max(OVERRIDE_MIN_ASPECT_RATIO_MEDIUM_VALUE, mMinAspectRatio);
        }

        return mMinAspectRatio;
    }

    private boolean isChangeEnabled(long changeId) {
        return CompatChanges.isChangeEnabled(changeId, applicationInfo.packageName,
                UserHandle.getUserHandleForUid(applicationInfo.uid));
    }

    /** @hide */
    public float getManifestMinAspectRatio() {
        return mMinAspectRatio;
@@ -1495,9 +1496,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
     * @hide
     */
    public boolean shouldCheckMinWidthHeightForMultiWindow() {
        return CompatChanges.isChangeEnabled(CHECK_MIN_WIDTH_HEIGHT_FOR_MULTI_WINDOW,
                applicationInfo.packageName,
                UserHandle.getUserHandleForUid(applicationInfo.uid));
        return isChangeEnabled(CHECK_MIN_WIDTH_HEIGHT_FOR_MULTI_WINDOW);
    }

    public void dump(Printer pw, String prefix) {
+49 −0
Original line number Diff line number Diff line
@@ -1124,6 +1124,7 @@ public class SizeCompatTests extends WindowTestsBase {

    @Test
    @EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
            ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY,
            ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM})
    public void testOverrideMinAspectRatioScreenOrientationNotSetThenChangedToPortrait() {
        // In this test, the activity's orientation isn't fixed to portrait, therefore the override
@@ -1155,6 +1156,7 @@ public class SizeCompatTests extends WindowTestsBase {

    @Test
    @EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
            ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY,
            ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM})
    public void testOverrideMinAspectRatioScreenOrientationLandscapeThenChangedToPortrait() {
        // In this test, the activity's orientation isn't fixed to portrait, therefore the override
@@ -1187,6 +1189,7 @@ public class SizeCompatTests extends WindowTestsBase {

    @Test
    @EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
            ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY,
            ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM})
    public void testOverrideMinAspectRatioScreenOrientationPortraitThenChangedToUnspecified() {
        setUpDisplaySizeWithApp(1000, 1200);
@@ -1214,6 +1217,52 @@ public class SizeCompatTests extends WindowTestsBase {
        assertEquals(1000, activity.getBounds().width());
    }

    @Test
    @EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
            ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM})
    @DisableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY})
    public void testOverrideMinAspectRatioPortraitOnlyDisabledScreenOrientationNotSet() {
        setUpDisplaySizeWithApp(1000, 1200);

        // Create a size compat activity on the same task.
        final ActivityRecord activity = new ActivityBuilder(mAtm)
                .setTask(mTask)
                .setComponent(ComponentName.createRelative(mContext,
                        SizeCompatTests.class.getName()))
                .setUid(android.os.Process.myUid())
                .build();

        // The per-package override forces the activity into a 3:2 aspect ratio
        assertEquals(1200, activity.getBounds().height());
        assertEquals(1200 / ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM_VALUE,
                activity.getBounds().width(), 0.5);
    }

    @Test
    @EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
            ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM})
    @DisableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY})
    public void testOverrideMinAspectRatioPortraitOnlyDisabledScreenOrientationLandscape() {
        // In this test, the activity's orientation isn't fixed to portrait, therefore the override
        // isn't applied.

        setUpDisplaySizeWithApp(1000, 1200);

        // Create a size compat activity on the same task.
        final ActivityRecord activity = new ActivityBuilder(mAtm)
                .setTask(mTask)
                .setScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
                .setComponent(ComponentName.createRelative(mContext,
                        SizeCompatTests.class.getName()))
                .setUid(android.os.Process.myUid())
                .build();

        // The per-package override forces the activity into a 3:2 aspect ratio
        assertEquals(1000 / ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM_VALUE,
                activity.getBounds().height(), 0.5);
        assertEquals(1000, activity.getBounds().width());
    }

    @Test
    @EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM})
    public void testOverrideMinAspectRatioWithoutGlobalOverride() {