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

Commit 65ffba75 authored by Mariia Sandrikova's avatar Mariia Sandrikova
Browse files

Letterbox positioning (2/4): Rename "task letterbox" to "fixed orientation letterbox".

This is a follow up for ag/13575049 which moved task level letterbox to activity level.

Also, change order of aspect ratio overrides in resolveFixedOrientationConfiguration to ensure that aspect ratio restrictions for the activity will be respected and adding corresponding tests to prevent regressions.

Bug: 175212232
Test: atest SizeCompatTests
Change-Id: Ib911731781895495760001a1f9af1e8d37b1ded4
parent 8e7ced4d
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -4666,11 +4666,11 @@
    <!-- WindowsManager JetPack display features -->
    <string name="config_display_features" translatable="false" />

    <!-- Aspect ratio of task level letterboxing. Values <= 1.0 will be ignored.
         Note: Activity min/max aspect ratio restrictions will still be respected by the
         activity-level letterboxing (size-compat mode). Therefore this override can control the
         maximum screen area that can be occupied by the app in the letterbox mode. -->
    <item name="config_taskLetterboxAspectRatio" format="float" type="dimen">0.0</item>
    <!-- Aspect ratio of letterboxing for fixed orientation. Values <= 1.0 will be ignored.
         Note: Activity min/max aspect ratio restrictions will still be respected.
         Therefore this override can control the maximum screen area that can be occupied by
         the app in the letterbox mode. -->
    <item name="config_fixedOrientationLetterboxAspectRatio" format="float" type="dimen">0.0</item>

    <!-- Corners radius for activity presented the letterbox mode. Values < 0 will be ignored and
         corners of the activity won't be rounded. -->
+1 −1
Original line number Diff line number Diff line
@@ -4181,7 +4181,7 @@
  <java-symbol type="dimen" name="controls_thumbnail_image_max_height" />
  <java-symbol type="dimen" name="controls_thumbnail_image_max_width" />

  <java-symbol type="dimen" name="config_taskLetterboxAspectRatio" />
  <java-symbol type="dimen" name="config_fixedOrientationLetterboxAspectRatio" />
  <java-symbol type="integer" name="config_letterboxActivityCornersRadius" />
  <java-symbol type="integer" name="config_letterboxBackgroundType" />
  <java-symbol type="color" name="config_letterboxBackgroundColor" />
+8 −11
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowManagerService.LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND;
import static com.android.server.wm.WindowManagerService.LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND_FLOATING;
import static com.android.server.wm.WindowManagerService.LETTERBOX_BACKGROUND_SOLID_COLOR;
import static com.android.server.wm.WindowManagerService.MIN_TASK_LETTERBOX_ASPECT_RATIO;
import static com.android.server.wm.WindowManagerService.MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
import static com.android.server.wm.WindowManagerService.letterboxBackgroundTypeToString;
@@ -6994,6 +6994,13 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        float aspect = Math.max(parentWidth, parentHeight)
                / (float) Math.min(parentWidth, parentHeight);

        // Override from config_fixedOrientationLetterboxAspectRatio or via ADB with
        // set-fixed-orientation-letterbox-aspect-ratio.
        final float letterboxAspectRatioOverride =
                mWmService.getFixedOrientationLetterboxAspectRatio();
        aspect = letterboxAspectRatioOverride > MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO
                ? letterboxAspectRatioOverride : aspect;

        // Adjust the fixed orientation letterbox bounds to fit the app request aspect ratio in
        // order to use the extra available space.
        final float maxAspectRatio = info.maxAspectRatio;
@@ -7004,16 +7011,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            aspect = minAspectRatio;
        }

        // Override from config_letterboxAspectRatio or via ADB with set-letterbox-aspect-ratio.
        // TODO(b/175212232): Rename getTaskLetterboxAspectRatio and all related methods since fixed
        // orientation letterbox is on the activity level now.
        final float letterboxAspectRatioOverride = mWmService.getTaskLetterboxAspectRatio();
        // Activity min/max aspect ratio restrictions will be respected by the activity-level
        // letterboxing (size-compat mode). Therefore this override can control the maximum screen
        // area that can be occupied by the app in the letterbox mode.
        aspect = letterboxAspectRatioOverride > MIN_TASK_LETTERBOX_ASPECT_RATIO
                ? letterboxAspectRatioOverride : aspect;

        // Store the current bounds to be able to revert to size compat mode values below if needed.
        Rect mTmpFullBounds = new Rect(resolvedBounds);
        if (forcedOrientation == ORIENTATION_LANDSCAPE) {
+22 −22
Original line number Diff line number Diff line
@@ -463,12 +463,12 @@ public class WindowManagerService extends IWindowManager.Stub
    private static final int ANIMATION_COMPLETED_TIMEOUT_MS = 5000;

    /**
     * Override of task letterbox aspect ratio that is set via ADB with
     * set-task-letterbox-aspect-ratio or via {@link
     * com.android.internal.R.dimen.config_taskLetterboxAspectRatio} will be ignored
     * Override of aspect ratio for fixed orientation letterboxing that is set via ADB with
     * set-fixed-orientation-letterbox-aspect-ratio or via {@link
     * com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio} will be ignored
     * if it is <= this value.
     */
    static final float MIN_TASK_LETTERBOX_ASPECT_RATIO = 1.0f;
    static final float MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO = 1.0f;

    @VisibleForTesting
    WindowManagerConstants mConstants;
@@ -1003,9 +1003,9 @@ public class WindowManagerService extends IWindowManager.Stub
    private boolean mAnimationsDisabled = false;
    boolean mPointerLocationEnabled = false;

    // Aspect ratio of task level letterboxing, values <= MIN_TASK_LETTERBOX_ASPECT_RATIO will be
    // ignored.
    private volatile float mTaskLetterboxAspectRatio;
    // Aspect ratio of letterbox for fixed orientation, values <=
    // MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO will be ignored.
    private volatile float mFixedOrientationLetterboxAspectRatio;

    /** Enum for Letterbox background type. */
    @Retention(RetentionPolicy.SOURCE)
@@ -1256,8 +1256,8 @@ public class WindowManagerService extends IWindowManager.Stub
        mAssistantOnTopOfDream = context.getResources().getBoolean(
                com.android.internal.R.bool.config_assistantOnTopOfDream);

        mTaskLetterboxAspectRatio = context.getResources().getFloat(
                com.android.internal.R.dimen.config_taskLetterboxAspectRatio);
        mFixedOrientationLetterboxAspectRatio = context.getResources().getFloat(
                com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio);
        mLetterboxActivityCornersRadius = context.getResources().getInteger(
                com.android.internal.R.integer.config_letterboxActivityCornersRadius);
        mLetterboxBackgroundColor = Color.valueOf(context.getResources().getColor(
@@ -3853,29 +3853,29 @@ public class WindowManagerService extends IWindowManager.Stub
    }

    /**
     * Overrides the aspect ratio of task level letterboxing. If given value is <= {@link
     * #MIN_TASK_LETTERBOX_ASPECT_RATIO}, both it and a value of {@link
     * com.android.internal.R.dimen.config_taskLetterboxAspectRatio} will be ignored and
     * 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
     * com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio} will be ignored and
     * the framework implementation will be used to determine the aspect ratio.
     */
    void setTaskLetterboxAspectRatio(float aspectRatio) {
        mTaskLetterboxAspectRatio = aspectRatio;
    void setFixedOrientationLetterboxAspectRatio(float aspectRatio) {
        mFixedOrientationLetterboxAspectRatio = aspectRatio;
    }

    /**
     * Resets the aspect ratio of task level letterboxing to {@link
     * com.android.internal.R.dimen.config_taskLetterboxAspectRatio}.
     * Resets the aspect ratio of letterbox for fixed orientation to {@link
     * com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio}.
     */
    void resetTaskLetterboxAspectRatio() {
        mTaskLetterboxAspectRatio = mContext.getResources().getFloat(
                com.android.internal.R.dimen.config_taskLetterboxAspectRatio);
    void resetFixedOrientationLetterboxAspectRatio() {
        mFixedOrientationLetterboxAspectRatio = mContext.getResources().getFloat(
                com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio);
    }

    /**
     * Gets the aspect ratio of task level letterboxing.
     * Gets the aspect ratio of letterbox for fixed orientation.
     */
    float getTaskLetterboxAspectRatio() {
        return mTaskLetterboxAspectRatio;
    float getFixedOrientationLetterboxAspectRatio() {
        return mFixedOrientationLetterboxAspectRatio;
    }

    /**
+18 −18
Original line number Diff line number Diff line
@@ -117,10 +117,10 @@ public class WindowManagerShellCommand extends ShellCommand {
                    return runGetIgnoreOrientationRequest(pw);
                case "dump-visible-window-views":
                    return runDumpVisibleWindowViews(pw);
                case "set-task-letterbox-aspect-ratio":
                    return runSetTaskLetterboxAspectRatio(pw);
                case "get-task-letterbox-aspect-ratio":
                    return runGetTaskLetterboxAspectRatio(pw);
                case "set-fixed-orientation-letterbox-aspect-ratio":
                    return runSetFixedOrientationLetterboxAspectRatio(pw);
                case "get-fixed-orientation-letterbox-aspect-ratio":
                    return runGetFixedOrientationLetterboxAspectRatio(pw);
                case "set-letterbox-activity-corners-radius":
                    return runSetLetterboxActivityCornersRadius(pw);
                case "get-letterbox-activity-corners-radius":
@@ -531,12 +531,12 @@ public class WindowManagerShellCommand extends ShellCommand {
        return 0;
    }

    private int runSetTaskLetterboxAspectRatio(PrintWriter pw) throws RemoteException {
    private int runSetFixedOrientationLetterboxAspectRatio(PrintWriter pw) throws RemoteException {
        final float aspectRatio;
        try {
            String arg = getNextArgRequired();
            if ("reset".equals(arg)) {
                mInternal.resetTaskLetterboxAspectRatio();
                mInternal.resetFixedOrientationLetterboxAspectRatio();
                return 0;
            }
            aspectRatio = Float.parseFloat(arg);
@@ -549,13 +549,13 @@ public class WindowManagerShellCommand extends ShellCommand {
            return -1;
        }

        mInternal.setTaskLetterboxAspectRatio(aspectRatio);
        mInternal.setFixedOrientationLetterboxAspectRatio(aspectRatio);
        return 0;
    }

    private int runGetTaskLetterboxAspectRatio(PrintWriter pw) throws RemoteException {
        final float aspectRatio = mInternal.getTaskLetterboxAspectRatio();
        if (aspectRatio <= WindowManagerService.MIN_TASK_LETTERBOX_ASPECT_RATIO) {
    private int runGetFixedOrientationLetterboxAspectRatio(PrintWriter pw) throws RemoteException {
        final float aspectRatio = mInternal.getFixedOrientationLetterboxAspectRatio();
        if (aspectRatio <= WindowManagerService.MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO) {
            pw.println("Letterbox aspect ratio is not set");
        } else {
            pw.println("Letterbox aspect ratio is " + aspectRatio);
@@ -692,8 +692,8 @@ public class WindowManagerShellCommand extends ShellCommand {
        // set-ignore-orientation-request
        mInterface.setIgnoreOrientationRequest(displayId, false /* ignoreOrientationRequest */);

        // set-task-letterbox-aspect-ratio
        mInternal.resetTaskLetterboxAspectRatio();
        // set-fixed-orientation-letterbox-aspect-ratio
        mInternal.resetFixedOrientationLetterboxAspectRatio();

        // set-letterbox-activity-corners-radius
        mInternal.resetLetterboxActivityCornersRadius();
@@ -734,12 +734,12 @@ public class WindowManagerShellCommand extends ShellCommand {
        pw.println("  set-ignore-orientation-request [-d DISPLAY_ID] [true|1|false|0]");
        pw.println("  get-ignore-orientation-request [-d DISPLAY_ID] ");
        pw.println("    If app requested orientation should be ignored.");
        pw.println("  set-task-letterbox-aspect-ratio [reset|aspectRatio]");
        pw.println("  get-task-letterbox-aspect-ratio");
        pw.println("    Aspect ratio of task level letterboxing. If aspectRatio <= "
                + WindowManagerService.MIN_TASK_LETTERBOX_ASPECT_RATIO);
        pw.println("    both it and R.dimen.config_taskLetterboxAspectRatio will be ignored");
        pw.println("    and framework implementation will be used to determine aspect ratio.");
        pw.println("  set-fixed-orientation-letterbox-aspect-ratio [reset|aspectRatio]");
        pw.println("  get-fixed-orientation-letterbox-aspect-ratio");
        pw.println("    Aspect ratio of letterbox for fixed orientation. If aspectRatio <= "
                + WindowManagerService.MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO);
        pw.println("    both it and R.dimen.config_fixedOrientationLetterboxAspectRatio will be");
        pw.println("    ignored and framework implementation will determine aspect ratio.");
        pw.println("  set-letterbox-activity-corners-radius [reset|cornersRadius]");
        pw.println("  get-letterbox-activity-corners-radius");
        pw.println("    Corners radius for activities in the letterbox mode. If radius < 0,");
Loading