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

Commit b4bd7974 authored by Mariia Sandrikova's avatar Mariia Sandrikova Committed by Android (Google) Code Review
Browse files

Merge "Add a DeviceConfig flag for ignoreOrientationRequest." into tm-qpr-dev

parents 9435fbff dc8d87fe
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.wm;


import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.LetterboxConfigurationDeviceConfig.KEY_ALLOW_IGNORE_ORIENTATION_REQUEST;
import static com.android.server.wm.LetterboxConfigurationDeviceConfig.KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY;
import static com.android.server.wm.LetterboxConfigurationDeviceConfig.KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY;


import android.annotation.IntDef;
import android.annotation.IntDef;
@@ -311,11 +312,22 @@ final class LetterboxConfiguration {
        mDeviceConfig.updateFlagActiveStatus(
        mDeviceConfig.updateFlagActiveStatus(
                /* isActive */ mIsDisplayRotationImmersiveAppCompatPolicyEnabled,
                /* isActive */ mIsDisplayRotationImmersiveAppCompatPolicyEnabled,
                /* key */ KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY);
                /* key */ KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY);
        mDeviceConfig.updateFlagActiveStatus(
                /* isActive */ true,
                /* key */ KEY_ALLOW_IGNORE_ORIENTATION_REQUEST);


        mLetterboxConfigurationPersister = letterboxConfigurationPersister;
        mLetterboxConfigurationPersister = letterboxConfigurationPersister;
        mLetterboxConfigurationPersister.start();
        mLetterboxConfigurationPersister.start();
    }
    }


    /**
     * Whether enabling ignoreOrientationRequest is allowed on the device. This value is controlled
     * via {@link android.provider.DeviceConfig}.
     */
    boolean isIgnoreOrientationRequestAllowed() {
        return mDeviceConfig.getFlag(KEY_ALLOW_IGNORE_ORIENTATION_REQUEST);
    }

    /**
    /**
     * Overrides the aspect ratio of letterbox for fixed orientation. If given value is <= {@link
     * Overrides the aspect ratio of letterbox for fixed orientation. If given value is <= {@link
     * #MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO}, both it and a value of {@link
     * #MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO}, both it and a value of {@link
+17 −1
Original line number Original line Diff line number Diff line
@@ -38,10 +38,16 @@ final class LetterboxConfigurationDeviceConfig
    private static final boolean DEFAULT_VALUE_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY =
    private static final boolean DEFAULT_VALUE_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY =
            true;
            true;


    static final String KEY_ALLOW_IGNORE_ORIENTATION_REQUEST =
            "allow_ignore_orientation_request";
    private static final boolean DEFAULT_VALUE_ALLOW_IGNORE_ORIENTATION_REQUEST = true;

    @VisibleForTesting
    @VisibleForTesting
    static final Map<String, Boolean> sKeyToDefaultValueMap = Map.of(
    static final Map<String, Boolean> sKeyToDefaultValueMap = Map.of(
            KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY,
            KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY,
            DEFAULT_VALUE_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY
            DEFAULT_VALUE_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY,
            KEY_ALLOW_IGNORE_ORIENTATION_REQUEST,
            DEFAULT_VALUE_ALLOW_IGNORE_ORIENTATION_REQUEST
    );
    );


    // Whether enabling rotation compat policy for immersive apps that prevents auto rotation
    // Whether enabling rotation compat policy for immersive apps that prevents auto rotation
@@ -52,6 +58,10 @@ final class LetterboxConfigurationDeviceConfig
    private boolean mIsDisplayRotationImmersiveAppCompatPolicyEnabled =
    private boolean mIsDisplayRotationImmersiveAppCompatPolicyEnabled =
            DEFAULT_VALUE_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY;
            DEFAULT_VALUE_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY;


    // Whether enabling ignoreOrientationRequest is allowed on the device.
    private boolean mIsAllowIgnoreOrientationRequest =
            DEFAULT_VALUE_ALLOW_IGNORE_ORIENTATION_REQUEST;

    // Set of active device configs that need to be updated in
    // Set of active device configs that need to be updated in
    // DeviceConfig.OnPropertiesChangedListener#onPropertiesChanged.
    // DeviceConfig.OnPropertiesChangedListener#onPropertiesChanged.
    private final ArraySet<String> mActiveDeviceConfigsSet = new ArraySet<>();
    private final ArraySet<String> mActiveDeviceConfigsSet = new ArraySet<>();
@@ -93,6 +103,8 @@ final class LetterboxConfigurationDeviceConfig
        switch (key) {
        switch (key) {
            case KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY:
            case KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY:
                return mIsDisplayRotationImmersiveAppCompatPolicyEnabled;
                return mIsDisplayRotationImmersiveAppCompatPolicyEnabled;
            case KEY_ALLOW_IGNORE_ORIENTATION_REQUEST:
                return mIsAllowIgnoreOrientationRequest;
            default:
            default:
                throw new AssertionError("Unexpected flag name: " + key);
                throw new AssertionError("Unexpected flag name: " + key);
        }
        }
@@ -108,6 +120,10 @@ final class LetterboxConfigurationDeviceConfig
                mIsDisplayRotationImmersiveAppCompatPolicyEnabled =
                mIsDisplayRotationImmersiveAppCompatPolicyEnabled =
                        getDeviceConfig(key, defaultValue);
                        getDeviceConfig(key, defaultValue);
                break;
                break;
            case KEY_ALLOW_IGNORE_ORIENTATION_REQUEST:
                mIsAllowIgnoreOrientationRequest =
                        getDeviceConfig(key, defaultValue);
                break;
            default:
            default:
                throw new AssertionError("Unexpected flag name: " + key);
                throw new AssertionError("Unexpected flag name: " + key);
        }
        }
+2 −1
Original line number Original line Diff line number Diff line
@@ -4170,7 +4170,8 @@ public class WindowManagerService extends IWindowManager.Stub
     * <p>Note: this assumes that {@link #mGlobalLock} is held by the caller.
     * <p>Note: this assumes that {@link #mGlobalLock} is held by the caller.
     */
     */
    boolean isIgnoreOrientationRequestDisabled() {
    boolean isIgnoreOrientationRequestDisabled() {
        return mIsIgnoreOrientationRequestDisabled;
        return mIsIgnoreOrientationRequestDisabled
                || !mLetterboxConfiguration.isIgnoreOrientationRequestAllowed();
    }
    }


    @Override
    @Override
+23 −0
Original line number Original line Diff line number Diff line
@@ -2312,6 +2312,29 @@ public class SizeCompatTests extends WindowTestsBase {
        assertActivityMaxBoundsSandboxed();
        assertActivityMaxBoundsSandboxed();
    }
    }


    @Test
    public void testDisplayIgnoreOrientationRequest_disabledViaDeviceConfig_orientationRespected() {
        // Set up a display in landscape
        setUpDisplaySizeWithApp(2800, 1400);

        final ActivityRecord activity = buildActivityRecord(/* supportsSizeChanges= */ false,
                RESIZE_MODE_UNRESIZEABLE, SCREEN_ORIENTATION_PORTRAIT);
        activity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);

        spyOn(activity.mWmService.mLetterboxConfiguration);
        doReturn(true).when(activity.mWmService.mLetterboxConfiguration)
                .isIgnoreOrientationRequestAllowed();

        // Display should not be rotated.
        assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, activity.mDisplayContent.getOrientation());

        doReturn(false).when(activity.mWmService.mLetterboxConfiguration)
                .isIgnoreOrientationRequestAllowed();

        // Display should be rotated.
        assertEquals(SCREEN_ORIENTATION_PORTRAIT, activity.mDisplayContent.getOrientation());
    }

    @Test
    @Test
    public void testSandboxDisplayApis_unresizableAppNotSandboxed() {
    public void testSandboxDisplayApis_unresizableAppNotSandboxed() {
        // Set up a display in landscape with an unresizable app.
        // Set up a display in landscape with an unresizable app.