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

Commit bfe91020 authored by Graciela Putri's avatar Graciela Putri Committed by Android (Google) Code Review
Browse files

Merge changes from topic "fullscreen-override-appcompat" into main

* changes:
  [1/n] Create flag for PackageManager.USER_MIN_ASPECT_RATIO_APP_DEFAULT
  Add per-app config to override orientation to user
parents 4944756c 592e50d9
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1392,6 +1392,18 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
    @TestApi
    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.
+7 −0
Original line number Diff line number Diff line
@@ -36,3 +36,10 @@ flag {
  bug: "316139088"
  is_fixed_read_only: true
}

flag {
  name: "user_min_aspect_ratio_app_default"
  namespace: "large_screen_experiences_app_compat"
  description: "Whether the API PackageManager.USER_MIN_ASPECT_RATIO_APP_DEFAULT is available"
  bug: "310816437"
}
+22 −6
Original line number Diff line number Diff line
@@ -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 "
+42 −0
Original line number Diff line number Diff line
@@ -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;
@@ -672,6 +673,47 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
        verify(mWm).mapOrientationRequest(SCREEN_ORIENTATION_PORTRAIT);
    }

    @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()