diff --git a/services/core/java/com/android/server/wm/LetterboxConfiguration.java b/services/core/java/com/android/server/wm/LetterboxConfiguration.java index 800fe090b457c..b64420af7c982 100644 --- a/services/core/java/com/android/server/wm/LetterboxConfiguration.java +++ b/services/core/java/com/android/server/wm/LetterboxConfiguration.java @@ -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_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 android.annotation.IntDef; @@ -311,11 +312,22 @@ final class LetterboxConfiguration { mDeviceConfig.updateFlagActiveStatus( /* isActive */ mIsDisplayRotationImmersiveAppCompatPolicyEnabled, /* key */ KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY); + mDeviceConfig.updateFlagActiveStatus( + /* isActive */ true, + /* key */ KEY_ALLOW_IGNORE_ORIENTATION_REQUEST); mLetterboxConfigurationPersister = letterboxConfigurationPersister; 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 * #MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO}, both it and a value of {@link diff --git a/services/core/java/com/android/server/wm/LetterboxConfigurationDeviceConfig.java b/services/core/java/com/android/server/wm/LetterboxConfigurationDeviceConfig.java index cf123a1f9ace0..3f067e3a15567 100644 --- a/services/core/java/com/android/server/wm/LetterboxConfigurationDeviceConfig.java +++ b/services/core/java/com/android/server/wm/LetterboxConfigurationDeviceConfig.java @@ -38,10 +38,16 @@ final class LetterboxConfigurationDeviceConfig private static final boolean DEFAULT_VALUE_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY = 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 static final Map sKeyToDefaultValueMap = Map.of( 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 @@ -52,6 +58,10 @@ final class LetterboxConfigurationDeviceConfig private boolean mIsDisplayRotationImmersiveAppCompatPolicyEnabled = 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 // DeviceConfig.OnPropertiesChangedListener#onPropertiesChanged. private final ArraySet mActiveDeviceConfigsSet = new ArraySet<>(); @@ -93,6 +103,8 @@ final class LetterboxConfigurationDeviceConfig switch (key) { case KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY: return mIsDisplayRotationImmersiveAppCompatPolicyEnabled; + case KEY_ALLOW_IGNORE_ORIENTATION_REQUEST: + return mIsAllowIgnoreOrientationRequest; default: throw new AssertionError("Unexpected flag name: " + key); } @@ -108,6 +120,10 @@ final class LetterboxConfigurationDeviceConfig mIsDisplayRotationImmersiveAppCompatPolicyEnabled = getDeviceConfig(key, defaultValue); break; + case KEY_ALLOW_IGNORE_ORIENTATION_REQUEST: + mIsAllowIgnoreOrientationRequest = + getDeviceConfig(key, defaultValue); + break; default: throw new AssertionError("Unexpected flag name: " + key); } diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 5065014b9bee0..2911890bf80e2 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -4170,7 +4170,8 @@ public class WindowManagerService extends IWindowManager.Stub *

Note: this assumes that {@link #mGlobalLock} is held by the caller. */ boolean isIgnoreOrientationRequestDisabled() { - return mIsIgnoreOrientationRequestDisabled; + return mIsIgnoreOrientationRequestDisabled + || !mLetterboxConfiguration.isIgnoreOrientationRequestAllowed(); } @Override diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index a09bb337d56f1..5b6c43fe6e9eb 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -2312,6 +2312,29 @@ public class SizeCompatTests extends WindowTestsBase { 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 public void testSandboxDisplayApis_unresizableAppNotSandboxed() { // Set up a display in landscape with an unresizable app.