diff options
3 files changed, 76 insertions, 6 deletions
diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java index d13d962015de..12da66515c07 100644 --- a/core/java/android/content/pm/ActivityInfo.java +++ b/core/java/android/content/pm/ActivityInfo.java @@ -1393,6 +1393,18 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { public static final long OVERRIDE_USE_DISPLAY_LANDSCAPE_NATURAL_ORIENTATION = 255940284L; /** + * Enables {@link #SCREEN_ORIENTATION_USER} which overrides any orientation requested + * by the activity. Fixed orientation apps can be overridden to fullscreen on large + * screen devices with ignoreOrientationRequest enabled with this override. + * + * @hide + */ + @ChangeId + @Overridable + @Disabled + public static final long OVERRIDE_ANY_ORIENTATION_TO_USER = 310816437L; + + /** * Compares activity window layout min width/height with require space for multi window to * determine if it can be put into multi window mode. */ diff --git a/services/core/java/com/android/server/wm/LetterboxUiController.java b/services/core/java/com/android/server/wm/LetterboxUiController.java index 5518de7b64fd..9305396caa19 100644 --- a/services/core/java/com/android/server/wm/LetterboxUiController.java +++ b/services/core/java/com/android/server/wm/LetterboxUiController.java @@ -20,6 +20,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.content.pm.ActivityInfo.FORCE_NON_RESIZE_APP; import static android.content.pm.ActivityInfo.FORCE_RESIZE_APP; import static android.content.pm.ActivityInfo.OVERRIDE_ANY_ORIENTATION; +import static android.content.pm.ActivityInfo.OVERRIDE_ANY_ORIENTATION_TO_USER; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_FORCE_ROTATION; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_REFRESH; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE; @@ -170,6 +171,8 @@ final class LetterboxUiController { // Corresponds to OVERRIDE_ANY_ORIENTATION private final boolean mIsOverrideAnyOrientationEnabled; + // Corresponds to OVERRIDE_ANY_ORIENTATION_TO_USER + private final boolean mIsOverrideToUserOrientationEnabled; // Corresponds to OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT private final boolean mIsOverrideToPortraitOrientationEnabled; // Corresponds to OVERRIDE_UNDEFINED_ORIENTATION_TO_NOSENSOR @@ -254,9 +257,8 @@ final class LetterboxUiController { // Counter for ActivityRecord#setRequestedOrientation private int mSetOrientationRequestCounter = 0; - // The min aspect ratio override set by user. Stores the last selected aspect ratio after - // {@link #shouldApplyUserFullscreenOverride} or {@link #shouldApplyUserMinAspectRatioOverride} - // have been invoked. + // TODO(b/315140179): Make mUserAspectRatio final + // The min aspect ratio override set by user @PackageManager.UserMinAspectRatio private int mUserAspectRatio = USER_MIN_ASPECT_RATIO_UNSET; @@ -355,6 +357,8 @@ final class LetterboxUiController { PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE); mIsOverrideAnyOrientationEnabled = isCompatChangeEnabled(OVERRIDE_ANY_ORIENTATION); + mIsOverrideToUserOrientationEnabled = + isCompatChangeEnabled(OVERRIDE_ANY_ORIENTATION_TO_USER); mIsOverrideToPortraitOrientationEnabled = isCompatChangeEnabled(OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT); mIsOverrideToReverseLandscapeOrientationEnabled = @@ -663,9 +667,11 @@ final class LetterboxUiController { @ScreenOrientation int overrideOrientationIfNeeded(@ScreenOrientation int candidate) { + final DisplayContent displayContent = mActivityRecord.mDisplayContent; + final boolean isIgnoreOrientationRequestEnabled = displayContent != null + && displayContent.getIgnoreOrientationRequest(); if (shouldApplyUserFullscreenOverride() - && mActivityRecord.mDisplayContent != null - && mActivityRecord.mDisplayContent.getIgnoreOrientationRequest()) { + && isIgnoreOrientationRequestEnabled) { Slog.v(TAG, "Requested orientation " + screenOrientationToString(candidate) + " for " + mActivityRecord + " is overridden to " + screenOrientationToString(SCREEN_ORIENTATION_USER) @@ -690,7 +696,6 @@ final class LetterboxUiController { return candidate; } - DisplayContent displayContent = mActivityRecord.mDisplayContent; if (mIsOverrideOrientationOnlyForCameraEnabled && displayContent != null && (displayContent.mDisplayRotationCompatPolicy == null || !displayContent.mDisplayRotationCompatPolicy @@ -698,6 +703,17 @@ final class LetterboxUiController { return candidate; } + // mUserAspectRatio is always initialized first in shouldApplyUserFullscreenOverride(), + // which will always come first before this check as user override > device + // manufacturer override. + if (mUserAspectRatio == PackageManager.USER_MIN_ASPECT_RATIO_UNSET + && mIsOverrideToUserOrientationEnabled && isIgnoreOrientationRequestEnabled) { + Slog.v(TAG, "Requested orientation " + screenOrientationToString(candidate) + " for " + + mActivityRecord + " is overridden to " + + screenOrientationToString(SCREEN_ORIENTATION_USER)); + return SCREEN_ORIENTATION_USER; + } + if (mIsOverrideToReverseLandscapeOrientationEnabled && (isFixedOrientationLandscape(candidate) || mIsOverrideAnyOrientationEnabled)) { Slog.w(TAG, "Requested orientation " + screenOrientationToString(candidate) + " for " diff --git a/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java index c6796dc9e90d..985be429d42b 100644 --- a/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java @@ -19,6 +19,7 @@ package com.android.server.wm; import static android.content.pm.ActivityInfo.FORCE_NON_RESIZE_APP; import static android.content.pm.ActivityInfo.FORCE_RESIZE_APP; import static android.content.pm.ActivityInfo.OVERRIDE_ANY_ORIENTATION; +import static android.content.pm.ActivityInfo.OVERRIDE_ANY_ORIENTATION_TO_USER; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_FORCE_ROTATION; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_REFRESH; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE; @@ -673,6 +674,47 @@ public class LetterboxUiControllerTest extends WindowTestsBase { } @Test + @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) + public void testOverrideOrientationIfNeeded_fullscreenOverrideEnabled_returnsUser() + throws Exception { + mDisplayContent.setIgnoreOrientationRequest(true); + assertEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded( + /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); + } + + @Test + @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) + public void testOverrideOrientationIfNeeded_fullscreenOverrideEnabled_optOut_returnsUnchanged() + throws Exception { + mockThatProperty(PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE, /* value */ false); + + mController = new LetterboxUiController(mWm, mActivity); + mDisplayContent.setIgnoreOrientationRequest(true); + + assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( + /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); + } + + @Test + @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) + public void testOverrideOrientationIfNeeded_fullscreenOverrideEnabled_returnsUnchanged() + throws Exception { + mDisplayContent.setIgnoreOrientationRequest(false); + assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( + /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); + } + + @Test + @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) + public void testOverrideOrientationIfNeeded_fullscreenAndUserOverrideEnabled_returnsUnchanged() + throws Exception { + prepareActivityThatShouldApplyUserMinAspectRatioOverride(); + + assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( + /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); + } + + @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT}) public void testOverrideOrientationIfNeeded_portraitOverrideEnabled_returnsPortrait() throws Exception { |