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

Commit 739fe786 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas Committed by Android (Google) Code Review
Browse files

Merge "Fix non-resizeable app letterboxing when entering desktop windowing" into main

parents 88bd95e4 5d2bcb87
Loading
Loading
Loading
Loading
+10 −19
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;

/**
 * Stores App Compat information about a particular Task.
@@ -58,16 +59,11 @@ public class AppCompatTaskInfo implements Parcelable {
    public int topActivityLetterboxHeight = PROPERTY_VALUE_UNSET;

    /**
     * Contains the current app height of the letterboxed activity if available or
     * {@link TaskInfo#PROPERTY_VALUE_UNSET} otherwise.
     * Contains the app bounds of the top activity or size compat mode
     * bounds when in size compat mode. If null, contains bounds.
     */
    public int topActivityLetterboxAppHeight = PROPERTY_VALUE_UNSET;

    /**
     * Contains the current app  width of the letterboxed activity if available or
     * {@link TaskInfo#PROPERTY_VALUE_UNSET} otherwise.
     */
    public int topActivityLetterboxAppWidth = PROPERTY_VALUE_UNSET;
    @NonNull
    public final Rect topActivityAppBounds = new Rect();

    /**
     * Contains the top activity bounds when the activity is letterboxed.
@@ -350,8 +346,7 @@ public class AppCompatTaskInfo implements Parcelable {
                && topActivityLetterboxVerticalPosition == that.topActivityLetterboxVerticalPosition
                && topActivityLetterboxWidth == that.topActivityLetterboxWidth
                && topActivityLetterboxHeight == that.topActivityLetterboxHeight
                && topActivityLetterboxAppWidth == that.topActivityLetterboxAppWidth
                && topActivityLetterboxAppHeight == that.topActivityLetterboxAppHeight
                && topActivityAppBounds.equals(that.topActivityAppBounds)
                && topActivityLetterboxHorizontalPosition
                    == that.topActivityLetterboxHorizontalPosition
                && cameraCompatTaskInfo.equalsForTaskOrganizer(that.cameraCompatTaskInfo);
@@ -371,8 +366,7 @@ public class AppCompatTaskInfo implements Parcelable {
                    == that.topActivityLetterboxHorizontalPosition
                && topActivityLetterboxWidth == that.topActivityLetterboxWidth
                && topActivityLetterboxHeight == that.topActivityLetterboxHeight
                && topActivityLetterboxAppWidth == that.topActivityLetterboxAppWidth
                && topActivityLetterboxAppHeight == that.topActivityLetterboxAppHeight
                && topActivityAppBounds.equals(that.topActivityAppBounds)
                && cameraCompatTaskInfo.equalsForCompatUi(that.cameraCompatTaskInfo);
    }

@@ -385,8 +379,7 @@ public class AppCompatTaskInfo implements Parcelable {
        topActivityLetterboxHorizontalPosition = source.readInt();
        topActivityLetterboxWidth = source.readInt();
        topActivityLetterboxHeight = source.readInt();
        topActivityLetterboxAppWidth = source.readInt();
        topActivityLetterboxAppHeight = source.readInt();
        topActivityAppBounds.set(Objects.requireNonNull(source.readTypedObject(Rect.CREATOR)));
        topActivityLetterboxBounds = source.readTypedObject(Rect.CREATOR);
        cameraCompatTaskInfo = source.readTypedObject(CameraCompatTaskInfo.CREATOR);
    }
@@ -401,8 +394,7 @@ public class AppCompatTaskInfo implements Parcelable {
        dest.writeInt(topActivityLetterboxHorizontalPosition);
        dest.writeInt(topActivityLetterboxWidth);
        dest.writeInt(topActivityLetterboxHeight);
        dest.writeInt(topActivityLetterboxAppWidth);
        dest.writeInt(topActivityLetterboxAppHeight);
        dest.writeTypedObject(topActivityAppBounds, flags);
        dest.writeTypedObject(topActivityLetterboxBounds, flags);
        dest.writeTypedObject(cameraCompatTaskInfo, flags);
    }
@@ -421,8 +413,7 @@ public class AppCompatTaskInfo implements Parcelable {
                + topActivityLetterboxHorizontalPosition
                + " topActivityLetterboxWidth=" + topActivityLetterboxWidth
                + " topActivityLetterboxHeight=" + topActivityLetterboxHeight
                + " topActivityLetterboxAppWidth=" + topActivityLetterboxAppWidth
                + " topActivityLetterboxAppHeight=" + topActivityLetterboxAppHeight
                + " topActivityAppBounds=" + topActivityAppBounds
                + " isUserFullscreenOverrideEnabled=" + isUserFullscreenOverrideEnabled()
                + " isSystemFullscreenOverrideEnabled=" + isSystemFullscreenOverrideEnabled()
                + " hasMinAspectRatioOverride=" + hasMinAspectRatioOverride()
+4 −9
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ fun calculateInitialBounds(
                        // For portrait resizeable activities, respect apps fullscreen width but
                        // apply ideal size height.
                        Size(
                            taskInfo.appCompatTaskInfo.topActivityLetterboxAppWidth,
                            taskInfo.appCompatTaskInfo.topActivityAppBounds.width(),
                            idealSize.height,
                        )
                    } else {
@@ -104,7 +104,7 @@ fun calculateInitialBounds(
                        // apply custom app width.
                        Size(
                            customPortraitWidthForLandscapeApp,
                            taskInfo.appCompatTaskInfo.topActivityLetterboxAppHeight,
                            taskInfo.appCompatTaskInfo.topActivityAppBounds.height(),
                        )
                    } else {
                        // For portrait resizeable activities, simply apply ideal size.
@@ -196,13 +196,8 @@ fun maximizeSizeGivenAspectRatio(

/** Calculates the aspect ratio of an activity from its fullscreen bounds. */
fun calculateAspectRatio(taskInfo: RunningTaskInfo): Float {
    val appLetterboxWidth = taskInfo.appCompatTaskInfo.topActivityLetterboxAppWidth
    val appLetterboxHeight = taskInfo.appCompatTaskInfo.topActivityLetterboxAppHeight
    if (taskInfo.appCompatTaskInfo.isTopActivityLetterboxed || !taskInfo.canChangeAspectRatio) {
        return maxOf(appLetterboxWidth, appLetterboxHeight) /
            minOf(appLetterboxWidth, appLetterboxHeight).toFloat()
    }
    val appBounds = taskInfo.configuration.windowConfiguration.appBounds ?: return 1f
    if (taskInfo.appCompatTaskInfo.topActivityAppBounds.isEmpty) return 1f
    val appBounds = taskInfo.appCompatTaskInfo.topActivityAppBounds
    return maxOf(appBounds.height(), appBounds.width()) /
        minOf(appBounds.height(), appBounds.width()).toFloat()
}
+17 −16
Original line number Diff line number Diff line
@@ -4160,8 +4160,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
                        screenOrientation = SCREEN_ORIENTATION_LANDSCAPE
                        configuration.windowConfiguration.appBounds = bounds
                    }
                appCompatTaskInfo.topActivityLetterboxAppWidth = bounds.width()
                appCompatTaskInfo.topActivityLetterboxAppHeight = bounds.height()
                appCompatTaskInfo.topActivityAppBounds.set(0, 0, bounds.width(), bounds.height())
                isResizeable = false
            }

@@ -4879,15 +4878,19 @@ class DesktopTasksControllerTest : ShellTestCase() {
            appCompatTaskInfo.isSystemFullscreenOverrideEnabled = enableSystemFullscreenOverride

            if (deviceOrientation == ORIENTATION_LANDSCAPE) {
                configuration.windowConfiguration.appBounds =
                    Rect(0, 0, DISPLAY_DIMENSION_LONG, DISPLAY_DIMENSION_SHORT)
                appCompatTaskInfo.topActivityLetterboxAppWidth = DISPLAY_DIMENSION_LONG
                appCompatTaskInfo.topActivityLetterboxAppHeight = DISPLAY_DIMENSION_SHORT
                appCompatTaskInfo.topActivityAppBounds.set(
                    0,
                    0,
                    DISPLAY_DIMENSION_LONG,
                    DISPLAY_DIMENSION_SHORT,
                )
            } else {
                configuration.windowConfiguration.appBounds =
                    Rect(0, 0, DISPLAY_DIMENSION_SHORT, DISPLAY_DIMENSION_LONG)
                appCompatTaskInfo.topActivityLetterboxAppWidth = DISPLAY_DIMENSION_SHORT
                appCompatTaskInfo.topActivityLetterboxAppHeight = DISPLAY_DIMENSION_LONG
                appCompatTaskInfo.topActivityAppBounds.set(
                    0,
                    0,
                    DISPLAY_DIMENSION_SHORT,
                    DISPLAY_DIMENSION_LONG,
                )
            }

            if (shouldLetterbox) {
@@ -4897,17 +4900,15 @@ class DesktopTasksControllerTest : ShellTestCase() {
                        screenOrientation == SCREEN_ORIENTATION_PORTRAIT
                ) {
                    // Letterbox to portrait size
                    appCompatTaskInfo.setTopActivityLetterboxed(true)
                    appCompatTaskInfo.topActivityLetterboxAppWidth = 1200
                    appCompatTaskInfo.topActivityLetterboxAppHeight = 1600
                    appCompatTaskInfo.isTopActivityLetterboxed = true
                    appCompatTaskInfo.topActivityAppBounds.set(0, 0, 1200, 1600)
                } else if (
                    deviceOrientation == ORIENTATION_PORTRAIT &&
                        screenOrientation == SCREEN_ORIENTATION_LANDSCAPE
                ) {
                    // Letterbox to landscape size
                    appCompatTaskInfo.setTopActivityLetterboxed(true)
                    appCompatTaskInfo.topActivityLetterboxAppWidth = 1600
                    appCompatTaskInfo.topActivityLetterboxAppHeight = 1200
                    appCompatTaskInfo.isTopActivityLetterboxed = true
                    appCompatTaskInfo.topActivityAppBounds.set(0, 0, 1600, 1200)
                }
            }
        }
+2 −5
Original line number Diff line number Diff line
@@ -164,15 +164,13 @@ final class AppCompatUtils {

        appCompatTaskInfo.setIsFromLetterboxDoubleTap(reachabilityOverrides.isFromDoubleTap());

        appCompatTaskInfo.topActivityAppBounds.set(getAppBounds(top));
        final boolean isTopActivityLetterboxed = top.areBoundsLetterboxed();
        appCompatTaskInfo.setTopActivityLetterboxed(isTopActivityLetterboxed);
        if (isTopActivityLetterboxed) {
            final Rect bounds = top.getBounds();
            final Rect appBounds = getAppBounds(top);
            appCompatTaskInfo.topActivityLetterboxWidth = bounds.width();
            appCompatTaskInfo.topActivityLetterboxHeight = bounds.height();
            appCompatTaskInfo.topActivityLetterboxAppWidth = appBounds.width();
            appCompatTaskInfo.topActivityLetterboxAppHeight = appBounds.height();
            // TODO(b/379824541) Remove duplicate information.
            appCompatTaskInfo.topActivityLetterboxBounds = bounds;
            // We need to consider if letterboxed or pillarboxed.
@@ -281,8 +279,7 @@ final class AppCompatUtils {
        info.topActivityLetterboxHorizontalPosition = TaskInfo.PROPERTY_VALUE_UNSET;
        info.topActivityLetterboxWidth = TaskInfo.PROPERTY_VALUE_UNSET;
        info.topActivityLetterboxHeight = TaskInfo.PROPERTY_VALUE_UNSET;
        info.topActivityLetterboxAppHeight = TaskInfo.PROPERTY_VALUE_UNSET;
        info.topActivityLetterboxAppWidth = TaskInfo.PROPERTY_VALUE_UNSET;
        info.topActivityAppBounds.setEmpty();
        info.topActivityLetterboxBounds = null;
        info.cameraCompatTaskInfo.freeformCameraCompatMode =
                CameraCompatTaskInfo.CAMERA_COMPAT_FREEFORM_UNSPECIFIED;