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

Commit a35c6afd authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Support application opt-out property for universal resizable" into main

parents 23c916df c5350f74
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -1426,8 +1426,9 @@ public interface WindowManager extends ViewManager {
            "android.window.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE";

    /**
     * Activity-level {@link android.content.pm.PackageManager.Property PackageManager.Property}
     * that specifies whether this activity can declare or request
     * Application or Activity level
     * {@link android.content.pm.PackageManager.Property PackageManager.Property}
     * that specifies whether this package or activity can declare or request
     * {@link android.R.attr#screenOrientation fixed orientation},
     * {@link android.R.attr#minAspectRatio max aspect ratio},
     * {@link android.R.attr#maxAspectRatio min aspect ratio}
@@ -1438,6 +1439,13 @@ public interface WindowManager extends ViewManager {
     *
     * <p><b>Syntax:</b>
     * <pre>
     * &lt;application&gt;
     *   &lt;property
     *     android:name="android.window.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE"
     *     android:value="false"/&gt;
     * &lt;/application&gt;
     * </pre>or
     * <pre>
     * &lt;activity&gt;
     *   &lt;property
     *     android:name="android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY"
@@ -1446,7 +1454,7 @@ public interface WindowManager extends ViewManager {
     * </pre>
     * @hide
     */
    // TODO(b/357141415): Make this public API.
    // TODO(b/357141415): Remove this from sdk 37
    String PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY =
            "android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY";

+10 −0
Original line number Diff line number Diff line
@@ -76,6 +76,16 @@ class AppCompatController {
        mAppCompatSizeCompatModePolicy = new AppCompatSizeCompatModePolicy(mActivityRecord,
                mAppCompatOverrides);
        mAllowRestrictedResizability = AppCompatUtils.asLazy(() -> {
            // Application level.
            try {
                if (packageManager.getProperty(PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY,
                        mActivityRecord.packageName).getBoolean()) {
                    return true;
                }
            } catch (PackageManager.NameNotFoundException e) {
                // Fall through.
            }
            // Activity level.
            try {
                return packageManager.getPropertyAsUser(
                        PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY,
+6 −4
Original line number Diff line number Diff line
@@ -196,10 +196,11 @@ public class DesktopAppCompatAspectRatioPolicy {

        if (!aspectRatioOverrides.shouldOverrideMinAspectRatio()
                && !AppCompatCameraPolicy.shouldOverrideMinAspectRatioForCamera(mActivityRecord)) {
            if (mActivityRecord.isUniversalResizeable()) {
            final float minAspectRatio = info.getMinAspectRatio();
            if (minAspectRatio == 0 || mActivityRecord.isUniversalResizeable()) {
                return 0;
            }
            return info.getMinAspectRatio();
            return minAspectRatio;
        }

        if (info.isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY)
@@ -242,10 +243,11 @@ public class DesktopAppCompatAspectRatioPolicy {
        if (mTransparentPolicy.isRunning()) {
            return mTransparentPolicy.getInheritedMaxAspectRatio();
        }
        if (mActivityRecord.isUniversalResizeable()) {
        final float maxAspectRatio = mActivityRecord.info.getMaxAspectRatio();
        if (maxAspectRatio == 0 || mActivityRecord.isUniversalResizeable()) {
            return 0;
        }
        return mActivityRecord.info.getMaxAspectRatio();
        return maxAspectRatio;
    }

    /**
+14 −0
Original line number Diff line number Diff line
@@ -4928,6 +4928,7 @@ public class SizeCompatTests extends WindowTestsBase {
        spyOn(pm);
        final PackageManager.Property property = new PackageManager.Property("propertyName",
                true /* value */, name.getPackageName(), name.getClassName());
        // Activity level.
        try {
            doReturn(property).when(pm).getPropertyAsUser(
                    WindowManager.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY,
@@ -4938,6 +4939,19 @@ public class SizeCompatTests extends WindowTestsBase {
        final ActivityRecord optOutActivity = new ActivityBuilder(mAtm)
                .setComponent(name).setTask(mTask).build();
        assertFalse(optOutActivity.isUniversalResizeable());

        // Application level.
        try {
            doReturn(property).when(pm).getProperty(
                    WindowManager.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY,
                    name.getPackageName());
        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException(e);
        }
        final ActivityRecord optOutAppActivity = new ActivityBuilder(mAtm)
                .setComponent(getUniqueComponentName(mContext.getPackageName()))
                .setTask(mTask).build();
        assertFalse(optOutAppActivity.isUniversalResizeable());
    }