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

Commit 0943bf77 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Add activity opt-out property for universal resizable

It can be used by app with target sdk > 35 but the app still needs
to make its specified activity to apply fixed orientation,
aspect ratio, or non-resizable.

Also optimize aspect ratio getter a bit to reduce query of compat
and package property. Because most cases the value is zero if apps
don't declare aspect ratio.

Bug: 357141415
Flag: com.android.window.flags.universal_resizable_by_default
Test: atest SizeCompatTests#testUniversalResizeable
Change-Id: Ic0b52872cf0d99965d1ec85abb771a6cb256b8fe
parent 38c9e553
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -1425,6 +1425,31 @@ public interface WindowManager extends ViewManager {
    String PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE =
            "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
     * {@link android.R.attr#screenOrientation fixed orientation},
     * {@link android.R.attr#minAspectRatio max aspect ratio},
     * {@link android.R.attr#maxAspectRatio min aspect ratio}
     * {@link android.R.attr#resizeableActivity unresizable} on large screen devices with the
     * ignore orientation request display setting enabled since Android 16 (API level 36) or higher.
     *
     * <p>The default value is {@code false}.
     *
     * <p><b>Syntax:</b>
     * <pre>
     * &lt;activity&gt;
     *   &lt;property
     *     android:name="android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY"
     *     android:value="true"/&gt;
     * &lt;/activity&gt;
     * </pre>
     * @hide
     */
    // TODO(b/357141415): Make this public API.
    String PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY =
            "android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY";

    /**
     * @hide
     */
+3 −0
Original line number Diff line number Diff line
@@ -3189,6 +3189,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (mWmService.mConstants.isPackageOptOutIgnoreActivityOrientationRequest(packageName)) {
            return false;
        }
        if (mAppCompatController.mAllowRestrictedResizability.getAsBoolean()) {
            return false;
        }
        // If the user preference respects aspect ratio, then it becomes non-resizable.
        return !mAppCompatController.getAppCompatOverrides().getAppCompatAspectRatioOverrides()
                .shouldApplyUserMinAspectRatioOverride();
+6 −4
Original line number Diff line number Diff line
@@ -128,10 +128,11 @@ class AppCompatAspectRatioPolicy {
        }
        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)
@@ -173,10 +174,11 @@ class AppCompatAspectRatioPolicy {
        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;
    }

    @Nullable
+16 −0
Original line number Diff line number Diff line
@@ -15,12 +15,15 @@
 */
package com.android.server.wm;

import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY;

import android.annotation.NonNull;
import android.content.pm.PackageManager;

import com.android.server.wm.utils.OptPropFactory;

import java.io.PrintWriter;
import java.util.function.BooleanSupplier;

/**
 * Allows the interaction with all the app compat policies and configurations
@@ -47,6 +50,8 @@ class AppCompatController {
    private final AppCompatLetterboxPolicy mAppCompatLetterboxPolicy;
    @NonNull
    private final AppCompatSizeCompatModePolicy mAppCompatSizeCompatModePolicy;
    @NonNull
    final BooleanSupplier mAllowRestrictedResizability;

    AppCompatController(@NonNull WindowManagerService wmService,
                        @NonNull ActivityRecord activityRecord) {
@@ -70,6 +75,17 @@ class AppCompatController {
                mAppCompatOverrides, mTransparentPolicy, wmService.mAppCompatConfiguration);
        mAppCompatSizeCompatModePolicy = new AppCompatSizeCompatModePolicy(mActivityRecord,
                mAppCompatOverrides);
        mAllowRestrictedResizability = AppCompatUtils.asLazy(() -> {
            try {
                return packageManager.getPropertyAsUser(
                        PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY,
                        mActivityRecord.mActivityComponent.getPackageName(),
                        mActivityRecord.mActivityComponent.getClassName(),
                        mActivityRecord.mUserId).getBoolean();
            } catch (PackageManager.NameNotFoundException e) {
                return false;
            }
        });
    }

    @NonNull
+17 −0
Original line number Diff line number Diff line
@@ -4812,6 +4812,23 @@ public class SizeCompatTests extends WindowTestsBase {
        assertFalse(mActivity.isResizeable());
        assertEquals(maxAspect, aspectRatioPolicy.getMaxAspectRatio(), 0 /* delta */);
        assertNotEquals(SCREEN_ORIENTATION_UNSPECIFIED, mActivity.getOverrideOrientation());

        // Activity can opt-out the resizability by component level property.
        final ComponentName name = getUniqueComponentName(mContext.getPackageName());
        final PackageManager pm = mContext.getPackageManager();
        spyOn(pm);
        final PackageManager.Property property = new PackageManager.Property("propertyName",
                true /* value */, name.getPackageName(), name.getClassName());
        try {
            doReturn(property).when(pm).getPropertyAsUser(
                    WindowManager.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY,
                    name.getPackageName(), name.getClassName(), 0 /* userId */);
        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException(e);
        }
        final ActivityRecord optOutActivity = new ActivityBuilder(mAtm)
                .setComponent(name).setTask(mTask).build();
        assertFalse(optOutActivity.isUniversalResizeable());
    }