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

Commit a0e65ae3 authored by Robin Lee's avatar Robin Lee Committed by Riddle Hsu
Browse files

Activity orientation experiment on only large screens

This adds a third value to the DeviceConfig we had added before, that
applies the same rotation treatment on large screens only. This is
more similar to the targetSdk-gated change that will roll out.

This can be set by specifying "large" instead of "true" or "false"
when overriding: adb shell device_config put "window_manager"
"ignore_activity_orientation_request" "large"

See the flag universal_resizable_by_default for more information about
that.

ALTERNATIVES_CONSIDERED: True,False,FileNotFound
Bug: 357141415
Flag: com.android.window.flags.universal_resizable_by_default
Test: atest WmTests:ActivityRecordTests

Change-Id: Ib6b2293c3c4460dd8524823be908f183522dddb2
parent fe30fc14
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -3238,10 +3238,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
        final boolean compatEnabled = isLargeScreen && Flags.universalResizableByDefault()
                && appInfo.isChangeEnabled(ActivityInfo.UNIVERSAL_RESIZABLE_BY_DEFAULT);
        if (!compatEnabled && !wms.mConstants.mIgnoreActivityOrientationRequest) {
            return false;
        }
        if (wms.mConstants.isPackageOptOutIgnoreActivityOrientationRequest(appInfo.packageName)) {
        final boolean configEnabled = (isLargeScreen
                ? wms.mConstants.mIgnoreActivityOrientationRequestLargeScreen
                : wms.mConstants.mIgnoreActivityOrientationRequestSmallScreen)
                && !wms.mConstants.isPackageOptOutIgnoreActivityOrientationRequest(
                        appInfo.packageName);
        if (!compatEnabled && !configEnabled) {
            return false;
        }
        if (forActivity) {
+19 −7
Original line number Diff line number Diff line
@@ -36,7 +36,15 @@ import java.util.concurrent.Executor;
 */
final class WindowManagerConstants {

    /** The orientation of activity will be always "unspecified" except for game apps. */
    /**
     * The orientation of activity will be always "unspecified" except for game apps.
     * <p>Possible values:
     * <ul>
     * <li>false: applies to no apps (default)</li>
     * <li>true: applies to all apps</li>
     * <li>large: applies to all apps but only on large screens</li>
     * </ul>
     */
    private static final String KEY_IGNORE_ACTIVITY_ORIENTATION_REQUEST =
            "ignore_activity_orientation_request";

@@ -69,7 +77,8 @@ final class WindowManagerConstants {
    boolean mSystemGestureExcludedByPreQStickyImmersive;

    /** @see #KEY_IGNORE_ACTIVITY_ORIENTATION_REQUEST */
    boolean mIgnoreActivityOrientationRequest;
    boolean mIgnoreActivityOrientationRequestLargeScreen;
    boolean mIgnoreActivityOrientationRequestSmallScreen;

    /** @see #KEY_OPT_OUT_IGNORE_ACTIVITY_ORIENTATION_REQUEST_LIST */
    private ArraySet<String> mOptOutIgnoreActivityOrientationRequestPackages;
@@ -177,9 +186,12 @@ final class WindowManagerConstants {
    }

    private void updateIgnoreActivityOrientationRequest() {
        mIgnoreActivityOrientationRequest = mDeviceConfig.getBoolean(
        final String value = mDeviceConfig.getProperty(
                DeviceConfig.NAMESPACE_WINDOW_MANAGER,
                KEY_IGNORE_ACTIVITY_ORIENTATION_REQUEST, false);
                KEY_IGNORE_ACTIVITY_ORIENTATION_REQUEST);
        mIgnoreActivityOrientationRequestSmallScreen = Boolean.parseBoolean(value);
        mIgnoreActivityOrientationRequestLargeScreen = mIgnoreActivityOrientationRequestSmallScreen
                || ("large".equals(value));
    }

    private void updateOptOutIgnoreActivityOrientationRequestList() {
@@ -196,8 +208,7 @@ final class WindowManagerConstants {
    }

    boolean isPackageOptOutIgnoreActivityOrientationRequest(String packageName) {
        return mIgnoreActivityOrientationRequest
                && mOptOutIgnoreActivityOrientationRequestPackages != null
        return mOptOutIgnoreActivityOrientationRequestPackages != null
                && mOptOutIgnoreActivityOrientationRequestPackages.contains(packageName);
    }

@@ -211,7 +222,8 @@ final class WindowManagerConstants {
        pw.print("  "); pw.print(KEY_SYSTEM_GESTURES_EXCLUDED_BY_PRE_Q_STICKY_IMMERSIVE);
        pw.print("="); pw.println(mSystemGestureExcludedByPreQStickyImmersive);
        pw.print("  "); pw.print(KEY_IGNORE_ACTIVITY_ORIENTATION_REQUEST);
        pw.print("="); pw.println(mIgnoreActivityOrientationRequest);
        pw.print("="); pw.println(mIgnoreActivityOrientationRequestSmallScreen ? "true"
                : mIgnoreActivityOrientationRequestLargeScreen ? "large" : "false");
        if (mOptOutIgnoreActivityOrientationRequestPackages != null) {
            pw.print("  "); pw.print(KEY_OPT_OUT_IGNORE_ACTIVITY_ORIENTATION_REQUEST_LIST);
            pw.print("="); pw.println(mOptOutIgnoreActivityOrientationRequestPackages);
+1 −1
Original line number Diff line number Diff line
@@ -2670,7 +2670,7 @@ public class ActivityRecordTests extends WindowTestsBase {
        assertSetOrientation(Build.VERSION_CODES.CUR_DEVELOPMENT, CATEGORY_GAME, true);

        // Blanket application, also ignoring Target SDK
        mWm.mConstants.mIgnoreActivityOrientationRequest = true;
        mWm.mConstants.mIgnoreActivityOrientationRequestLargeScreen = true;
        assertSetOrientation(Build.VERSION_CODES.VANILLA_ICE_CREAM, CATEGORY_SOCIAL, false);
    }

+2 −1
Original line number Diff line number Diff line
@@ -4892,7 +4892,8 @@ public class SizeCompatTests extends WindowTestsBase {

    @Test
    public void testUniversalResizeable() {
        mWm.mConstants.mIgnoreActivityOrientationRequest = true;
        mWm.mConstants.mIgnoreActivityOrientationRequestSmallScreen = true;
        mWm.mConstants.mIgnoreActivityOrientationRequestLargeScreen = true;
        setUpApp(mDisplayContent);
        final float maxAspect = 1.8f;
        final float minAspect = 1.5f;