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

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

Merge "Respect aspect ratio overrides for desktop mode initial bounds" into main

parents 1051fd4f 974e117a
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -95,6 +95,8 @@ public class AppCompatTaskInfo implements Parcelable {
    private static final int FLAG_FULLSCREEN_OVERRIDE_SYSTEM = FLAG_BASE << 7;
    /** Top activity flag for whether has activity has been overridden to fullscreen by user. */
    private static final int FLAG_FULLSCREEN_OVERRIDE_USER = FLAG_BASE << 8;
    /** Top activity flag for whether min aspect ratio of the activity has been overridden.*/
    public static final int FLAG_HAS_MIN_ASPECT_RATIO_OVERRIDE = FLAG_BASE << 9;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef(flag = true, value = {
@@ -108,7 +110,8 @@ public class AppCompatTaskInfo implements Parcelable {
            FLAG_IS_FROM_LETTERBOX_DOUBLE_TAP,
            FLAG_ELIGIBLE_FOR_USER_ASPECT_RATIO_BUTTON,
            FLAG_FULLSCREEN_OVERRIDE_SYSTEM,
            FLAG_FULLSCREEN_OVERRIDE_USER
            FLAG_FULLSCREEN_OVERRIDE_USER,
            FLAG_HAS_MIN_ASPECT_RATIO_OVERRIDE
    })
    public @interface TopActivityFlag {}

@@ -118,7 +121,7 @@ public class AppCompatTaskInfo implements Parcelable {
    @TopActivityFlag
    private static final int FLAGS_ORGANIZER_INTERESTED = FLAG_IS_FROM_LETTERBOX_DOUBLE_TAP
            | FLAG_ELIGIBLE_FOR_USER_ASPECT_RATIO_BUTTON | FLAG_FULLSCREEN_OVERRIDE_SYSTEM
            | FLAG_FULLSCREEN_OVERRIDE_USER;
            | FLAG_FULLSCREEN_OVERRIDE_USER | FLAG_HAS_MIN_ASPECT_RATIO_OVERRIDE;

    @TopActivityFlag
    private static final int FLAGS_COMPAT_UI_INTERESTED = FLAGS_ORGANIZER_INTERESTED
@@ -301,6 +304,21 @@ public class AppCompatTaskInfo implements Parcelable {
        setTopActivityFlag(FLAG_LETTERBOXED, enable);
    }

    /**
     * @return {@code true} if the top activity's min aspect ratio has been overridden.
     */
    public boolean hasMinAspectRatioOverride() {
        return isTopActivityFlagEnabled(FLAG_HAS_MIN_ASPECT_RATIO_OVERRIDE);
    }

    /**
     * Sets the top activity flag for whether the min aspect ratio of the activity has been
     * overridden.
     */
    public void setHasMinAspectRatioOverride(boolean enable) {
        setTopActivityFlag(FLAG_HAS_MIN_ASPECT_RATIO_OVERRIDE, enable);
    }

    /** Clear all top activity flags and set to false. */
    public void clearTopActivityFlags() {
        mTopActivityFlags = FLAG_UNDEFINED;
@@ -392,6 +410,7 @@ public class AppCompatTaskInfo implements Parcelable {
                + " topActivityLetterboxAppHeight=" + topActivityLetterboxAppHeight
                + " isUserFullscreenOverrideEnabled=" + isUserFullscreenOverrideEnabled()
                + " isSystemFullscreenOverrideEnabled=" + isSystemFullscreenOverrideEnabled()
                + " hasMinAspectRatioOverride=" + hasMinAspectRatioOverride()
                + " cameraCompatTaskInfo=" + cameraCompatTaskInfo.toString()
                + "}";
    }
+10 −3
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ fun calculateInitialBounds(
    val initialSize: Size =
        when (taskInfo.configuration.orientation) {
            ORIENTATION_LANDSCAPE -> {
                if (taskInfo.isResizeable) {
                if (taskInfo.canChangeAspectRatio) {
                    if (isFixedOrientationPortrait(topActivityInfo.screenOrientation)) {
                        // For portrait resizeable activities, respect apps fullscreen width but
                        // apply ideal size height.
@@ -85,7 +85,7 @@ fun calculateInitialBounds(
            ORIENTATION_PORTRAIT -> {
                val customPortraitWidthForLandscapeApp =
                    screenBounds.width() - (DESKTOP_MODE_LANDSCAPE_APP_PADDING * 2)
                if (taskInfo.isResizeable) {
                if (taskInfo.canChangeAspectRatio) {
                    if (isFixedOrientationLandscape(topActivityInfo.screenOrientation)) {
                        // For landscape resizeable activities, respect apps fullscreen height and
                        // apply custom app width.
@@ -188,6 +188,13 @@ private fun positionInScreen(desiredSize: Size, stableBounds: Rect): Rect =
        offsetTo(offset.x, offset.y)
    }

/**
 * Whether the activity's aspect ratio can be changed or if it should be maintained as if it was
 * unresizeable.
 */
private val TaskInfo.canChangeAspectRatio: Boolean
    get() = isResizeable && !appCompatTaskInfo.hasMinAspectRatioOverride()

/**
 * Adjusts bounds to be positioned in the middle of the area provided, not necessarily the
 * entire screen, as area can be offset by left and top start.
@@ -204,7 +211,7 @@ fun centerInArea(desiredSize: Size, areaBounds: Rect, leftStart: Int, topStart:
    return Rect(newLeft, newTop, newRight, newBottom)
}

fun TaskInfo.hasPortraitTopActivity(): Boolean {
private fun TaskInfo.hasPortraitTopActivity(): Boolean {
    val topActivityScreenOrientation =
        topActivityInfo?.screenOrientation ?: SCREEN_ORIENTATION_UNSPECIFIED
    val appBounds = configuration.windowConfiguration.appBounds
+28 −1
Original line number Diff line number Diff line
@@ -865,6 +865,18 @@ class DesktopTasksControllerTest : ShellTestCase() {
    assertThat(findBoundsChange(wct, task)).isEqualTo(DEFAULT_LANDSCAPE_BOUNDS)
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS)
  fun addMoveToDesktopChanges_landscapeDevice_portraitResizableApp_aspectRatioOverridden() {
    setUpLandscapeDisplay()
    val task = setUpFullscreenTask(screenOrientation = SCREEN_ORIENTATION_PORTRAIT,
      shouldLetterbox = true, aspectRatioOverrideApplied = true)
    val wct = WindowContainerTransaction()
    controller.addMoveToDesktopChanges(wct, task)

    assertThat(findBoundsChange(wct, task)).isEqualTo(UNRESIZABLE_PORTRAIT_BOUNDS)
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS)
  fun addMoveToDesktopChanges_portraitDevice_userFullscreenOverride_defaultPortraitBounds() {
@@ -887,6 +899,19 @@ class DesktopTasksControllerTest : ShellTestCase() {
    assertThat(findBoundsChange(wct, task)).isEqualTo(DEFAULT_PORTRAIT_BOUNDS)
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS)
  fun addMoveToDesktopChanges_portraitDevice_landscapeResizableApp_aspectRatioOverridden() {
    setUpPortraitDisplay()
    val task = setUpFullscreenTask(screenOrientation = SCREEN_ORIENTATION_LANDSCAPE,
      deviceOrientation = ORIENTATION_PORTRAIT,
      shouldLetterbox = true, aspectRatioOverrideApplied = true)
    val wct = WindowContainerTransaction()
    controller.addMoveToDesktopChanges(wct, task)

    assertThat(findBoundsChange(wct, task)).isEqualTo(UNRESIZABLE_LANDSCAPE_BOUNDS)
  }

  @Test
  fun moveToDesktop_tdaFullscreen_windowingModeSetToFreeform() {
    val task = setUpFullscreenTask()
@@ -2896,7 +2921,8 @@ class DesktopTasksControllerTest : ShellTestCase() {
    shouldLetterbox: Boolean = false,
    gravity: Int = Gravity.NO_GRAVITY,
    enableUserFullscreenOverride: Boolean = false,
    enableSystemFullscreenOverride: Boolean = false
    enableSystemFullscreenOverride: Boolean = false,
    aspectRatioOverrideApplied: Boolean = false
  ): RunningTaskInfo {
    val task = createFullscreenTask(displayId)
    val activityInfo = ActivityInfo()
@@ -2911,6 +2937,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
      appCompatTaskInfo.isSystemFullscreenOverrideEnabled = enableSystemFullscreenOverride

      if (shouldLetterbox) {
        appCompatTaskInfo.setHasMinAspectRatioOverride(aspectRatioOverrideApplied)
        if (deviceOrientation == ORIENTATION_LANDSCAPE &&
            screenOrientation == SCREEN_ORIENTATION_PORTRAIT) {
          // Letterbox to portrait size
+2 −2
Original line number Diff line number Diff line
@@ -233,7 +233,8 @@ class AppCompatAspectRatioOverrides {
        return mAppCompatConfiguration.getIsSplitScreenAspectRatioForUnresizableAppsEnabled();
    }

    private float getDisplaySizeMinAspectRatio() {
    @VisibleForTesting
    float getDisplaySizeMinAspectRatio() {
        final DisplayArea displayArea = mActivityRecord.getDisplayArea();
        if (displayArea == null) {
            return mActivityRecord.info.getMinAspectRatio();
@@ -270,7 +271,6 @@ class AppCompatAspectRatioOverrides {
        return !mAllowUserAspectRatioOverrideOptProp.isFalse();
    }

    @VisibleForTesting
    int getUserMinAspectRatioOverrideCode() {
        try {
            return mActivityRecord.mAtmService.getPackageManager()
+2 −0
Original line number Diff line number Diff line
@@ -187,6 +187,8 @@ final class AppCompatUtils {
        appCompatTaskInfo.setTopActivityLetterboxed(top.areBoundsLetterboxed());
        appCompatTaskInfo.cameraCompatTaskInfo.freeformCameraCompatMode = top.mAppCompatController
                .getAppCompatCameraOverrides().getFreeformCameraCompatMode();
        appCompatTaskInfo.setHasMinAspectRatioOverride(top.mAppCompatController
                .getDesktopAppCompatAspectRatioPolicy().hasMinAspectRatioOverride(task));
    }

    /**
Loading