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

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

Merge "Consolidate full-screen override and cache user aspect ratio" into main

parents 22d09a38 f1c25ec7
Loading
Loading
Loading
Loading
+35 −19
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import static com.android.server.wm.AppCompatConfiguration.MIN_FIXED_ORIENTATION
import static com.android.server.wm.AppCompatUtils.isChangeEnabled;

import android.annotation.NonNull;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -126,18 +127,18 @@ class AppCompatAspectRatioOverrides {
            return false;
        }

        mUserAspectRatioState.mUserAspectRatio = getUserMinAspectRatioOverrideCode();
        final int aspectRatio = getUserMinAspectRatioOverrideCode();

        return mUserAspectRatioState.mUserAspectRatio != USER_MIN_ASPECT_RATIO_UNSET
                && mUserAspectRatioState.mUserAspectRatio != USER_MIN_ASPECT_RATIO_APP_DEFAULT
                && mUserAspectRatioState.mUserAspectRatio != USER_MIN_ASPECT_RATIO_FULLSCREEN;
        return aspectRatio != USER_MIN_ASPECT_RATIO_UNSET
                && aspectRatio != USER_MIN_ASPECT_RATIO_APP_DEFAULT
                && aspectRatio != USER_MIN_ASPECT_RATIO_FULLSCREEN;
    }

    boolean shouldApplyUserFullscreenOverride() {
        if (isUserFullscreenOverrideEnabled()) {
            mUserAspectRatioState.mUserAspectRatio = getUserMinAspectRatioOverrideCode();
            final int aspectRatio = getUserMinAspectRatioOverrideCode();

            return mUserAspectRatioState.mUserAspectRatio == USER_MIN_ASPECT_RATIO_FULLSCREEN;
            return aspectRatio == USER_MIN_ASPECT_RATIO_FULLSCREEN;
        }

        return false;
@@ -153,10 +154,12 @@ class AppCompatAspectRatioOverrides {
    }

    boolean isSystemOverrideToFullscreenEnabled() {
        final int aspectRatio = getUserMinAspectRatioOverrideCode();

        return isChangeEnabled(mActivityRecord, OVERRIDE_ANY_ORIENTATION_TO_USER)
                && !mAllowOrientationOverrideOptProp.isFalse()
                && (mUserAspectRatioState.mUserAspectRatio == USER_MIN_ASPECT_RATIO_UNSET
                || mUserAspectRatioState.mUserAspectRatio == USER_MIN_ASPECT_RATIO_FULLSCREEN);
                && (aspectRatio == USER_MIN_ASPECT_RATIO_UNSET
                    || aspectRatio == USER_MIN_ASPECT_RATIO_FULLSCREEN);
    }

    /**
@@ -173,12 +176,11 @@ class AppCompatAspectRatioOverrides {
    }

    boolean hasFullscreenOverride() {
        // `mUserAspectRatio` is always initialized first in `shouldApplyUserFullscreenOverride()`.
        return shouldApplyUserFullscreenOverride() || isSystemOverrideToFullscreenEnabled();
    }

    float getUserMinAspectRatio() {
        switch (mUserAspectRatioState.mUserAspectRatio) {
        switch (getUserMinAspectRatioOverrideCode()) {
            case USER_MIN_ASPECT_RATIO_DISPLAY_SIZE:
                return getDisplaySizeMinAspectRatio();
            case USER_MIN_ASPECT_RATIO_SPLIT_SCREEN:
@@ -269,13 +271,7 @@ class AppCompatAspectRatioOverrides {
    }

    int getUserMinAspectRatioOverrideCode() {
        try {
            return mActivityRecord.mAtmService.getPackageManager()
                    .getUserMinAspectRatio(mActivityRecord.packageName, mActivityRecord.mUserId);
        } catch (RemoteException e) {
            Slog.w(TAG, "Exception thrown retrieving aspect ratio user override " + this, e);
        }
        return mUserAspectRatioState.mUserAspectRatio;
        return mUserAspectRatioState.getUserAspectRatio(mActivityRecord);
    }

    private float getDefaultMinAspectRatioForUnresizableApps() {
@@ -300,10 +296,30 @@ class AppCompatAspectRatioOverrides {
    }

    private static class UserAspectRatioState {
        // TODO(b/315140179): Make mUserAspectRatio final
        // The min aspect ratio override set by user
        // The min aspect ratio override set by the user.
        @PackageManager.UserMinAspectRatio
        private int mUserAspectRatio = USER_MIN_ASPECT_RATIO_UNSET;
        private boolean mHasBeenSet = false;

        @PackageManager.UserMinAspectRatio
        private int getUserAspectRatio(@NonNull ActivityRecord activityRecord) {
            // Package manager can be null at construction time, so access should be on demand.
            if (!mHasBeenSet) {
                try {
                    final IPackageManager pm = activityRecord.mAtmService.getPackageManager();
                    if (pm != null) {
                        mUserAspectRatio = pm.getUserMinAspectRatio(activityRecord.packageName,
                                activityRecord.mUserId);
                        mHasBeenSet = true;
                    }
                } catch (RemoteException e) {
                    Slog.w(TAG, "Exception thrown retrieving aspect ratio user override "
                            + this, e);
                }
            }

            return mUserAspectRatio;
        }
    }

    private Resources getResources() {
+4 −23
Original line number Diff line number Diff line
@@ -56,11 +56,11 @@ class AppCompatOrientationPolicy {
        final DisplayContent displayContent = mActivityRecord.mDisplayContent;
        final boolean isIgnoreOrientationRequestEnabled = displayContent != null
                && displayContent.getIgnoreOrientationRequest();
        final boolean shouldApplyUserFullscreenOverride = mAppCompatOverrides
                .getAppCompatAspectRatioOverrides().shouldApplyUserFullscreenOverride();
        final boolean hasFullscreenOverride = mAppCompatOverrides
                .getAppCompatAspectRatioOverrides().hasFullscreenOverride();
        final boolean shouldCameraCompatControlOrientation =
                AppCompatCameraPolicy.shouldCameraCompatControlOrientation(mActivityRecord);
        if (shouldApplyUserFullscreenOverride && isIgnoreOrientationRequestEnabled
        if (hasFullscreenOverride && isIgnoreOrientationRequestEnabled
                // Do not override orientation to fullscreen for camera activities.
                // Fixed-orientation activities are rarely tested in other orientations, and it
                // often results in sideways or stretched previews. As the camera compat treatment
@@ -69,8 +69,7 @@ class AppCompatOrientationPolicy {
                && !shouldCameraCompatControlOrientation) {
            Slog.v(TAG, "Requested orientation " + screenOrientationToString(candidate)
                    + " for " + mActivityRecord + " is overridden to "
                    + screenOrientationToString(SCREEN_ORIENTATION_USER)
                    + " by user aspect ratio settings.");
                    + screenOrientationToString(SCREEN_ORIENTATION_USER));
            return SCREEN_ORIENTATION_USER;
        }

@@ -101,24 +100,6 @@ class AppCompatOrientationPolicy {
            return candidate;
        }

        // mUserAspectRatio is always initialized first in shouldApplyUserFullscreenOverride(),
        // which will always come first before this check as user override > device
        // manufacturer override.
        final boolean isSystemOverrideToFullscreenEnabled = mAppCompatOverrides
                .getAppCompatAspectRatioOverrides().isSystemOverrideToFullscreenEnabled();
        if (isSystemOverrideToFullscreenEnabled && isIgnoreOrientationRequestEnabled
                // Do not override orientation to fullscreen for camera activities.
                // Fixed-orientation activities are rarely tested in other orientations, and it
                // often results in sideways or stretched previews. As the camera compat treatment
                // targets fixed-orientation activities, overriding the orientation disables the
                // treatment.
                && !shouldCameraCompatControlOrientation) {
            Slog.v(TAG, "Requested orientation  " + screenOrientationToString(candidate)
                    + " for " + mActivityRecord + " is overridden to "
                    + screenOrientationToString(SCREEN_ORIENTATION_USER));
            return SCREEN_ORIENTATION_USER;
        }

        final AppCompatOrientationOverrides.OrientationOverridesState capabilityState =
                mAppCompatOverrides.getAppCompatOrientationOverrides()
                        .mOrientationOverridesState;
+25 −28
Original line number Diff line number Diff line
@@ -63,9 +63,9 @@ import static com.android.server.wm.ActivityRecord.State.PAUSED;
import static com.android.server.wm.ActivityRecord.State.RESTARTING_PROCESS;
import static com.android.server.wm.ActivityRecord.State.RESUMED;
import static com.android.server.wm.ActivityRecord.State.STOPPED;
import static com.android.server.wm.AppCompatConfiguration.LETTERBOX_POSITION_MULTIPLIER_CENTER;
import static com.android.server.wm.AppCompatUtils.computeAspectRatio;
import static com.android.server.wm.DisplayContent.IME_TARGET_LAYERING;
import static com.android.server.wm.AppCompatConfiguration.LETTERBOX_POSITION_MULTIPLIER_CENTER;
import static com.android.server.wm.WindowContainer.POSITION_TOP;

import static com.google.common.truth.Truth.assertThat;
@@ -95,13 +95,11 @@ import android.compat.testing.PlatformCompatChangeRule;
import android.content.ComponentName;
import android.content.pm.ActivityInfo;
import android.content.pm.ActivityInfo.ScreenOrientation;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Insets;
import android.graphics.Rect;
import android.os.Binder;
import android.os.RemoteException;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
@@ -2392,13 +2390,11 @@ public class SizeCompatTests extends WindowTestsBase {
        spyOn(activity.mWmService.mAppCompatConfiguration);
        doReturn(enabled).when(activity.mWmService.mAppCompatConfiguration)
                .isUserAppAspectRatioSettingsEnabled();
        // Set user aspect ratio override
        final IPackageManager pm = mAtm.getPackageManager();
        try {
            doReturn(aspectRatio).when(pm)
                    .getUserMinAspectRatio(activity.packageName, activity.mUserId);
        } catch (RemoteException ignored) {
        }
        final AppCompatAspectRatioOverrides aspectRatioOverrides =
                activity.mAppCompatController.getAppCompatAspectRatioOverrides();
        spyOn(aspectRatioOverrides);
        // Set user aspect ratio override.
        doReturn(aspectRatio).when(aspectRatioOverrides).getUserMinAspectRatioOverrideCode();

        prepareLimitedBounds(activity, screenOrientation, isUnresizable);

@@ -4145,6 +4141,7 @@ public class SizeCompatTests extends WindowTestsBase {
        // can be aligned inside parentAppBounds
        assertEquals(activity.getBounds(), new Rect(175, 0, 2275, 1000));
    }

    @Test
    @DisableCompatChanges({ActivityInfo.INSETS_DECOUPLED_CONFIGURATION_ENFORCED})
    public void testApplyAspectRatio_activityCannotAlignWithParentAppHorizontal() {