diff --git a/core/java/android/app/TaskInfo.java b/core/java/android/app/TaskInfo.java index c4e49954f7457..2b5175ca6659c 100644 --- a/core/java/android/app/TaskInfo.java +++ b/core/java/android/app/TaskInfo.java @@ -241,6 +241,18 @@ public class TaskInfo { */ public boolean isLetterboxDoubleTapEnabled; + /** + * Whether the user aspect ratio settings button is enabled + * @hide + */ + public boolean topActivityEligibleForUserAspectRatioButton; + + /** + * Hint about the letterbox state of the top activity. + * @hide + */ + public boolean topActivityBoundsLetterboxed; + /** * Whether the update comes from a letterbox double-tap action from the user or not. * @hide @@ -460,7 +472,8 @@ public class TaskInfo { public boolean hasCompatUI() { return hasCameraCompatControl() || topActivityInSizeCompat || topActivityEligibleForLetterboxEducation - || isLetterboxDoubleTapEnabled; + || isLetterboxDoubleTapEnabled + || topActivityEligibleForUserAspectRatioButton; } /** @@ -510,6 +523,8 @@ public class TaskInfo { && supportsMultiWindow == that.supportsMultiWindow && displayAreaFeatureId == that.displayAreaFeatureId && isFromLetterboxDoubleTap == that.isFromLetterboxDoubleTap + && topActivityEligibleForUserAspectRatioButton + == that.topActivityEligibleForUserAspectRatioButton && topActivityLetterboxVerticalPosition == that.topActivityLetterboxVerticalPosition && topActivityLetterboxWidth == that.topActivityLetterboxWidth && topActivityLetterboxHeight == that.topActivityLetterboxHeight @@ -543,6 +558,8 @@ public class TaskInfo { && taskId == that.taskId && topActivityInSizeCompat == that.topActivityInSizeCompat && isFromLetterboxDoubleTap == that.isFromLetterboxDoubleTap + && topActivityEligibleForUserAspectRatioButton + == that.topActivityEligibleForUserAspectRatioButton && topActivityEligibleForLetterboxEducation == that.topActivityEligibleForLetterboxEducation && topActivityLetterboxVerticalPosition == that.topActivityLetterboxVerticalPosition @@ -606,6 +623,8 @@ public class TaskInfo { displayAreaFeatureId = source.readInt(); cameraCompatControlState = source.readInt(); isLetterboxDoubleTapEnabled = source.readBoolean(); + topActivityEligibleForUserAspectRatioButton = source.readBoolean(); + topActivityBoundsLetterboxed = source.readBoolean(); isFromLetterboxDoubleTap = source.readBoolean(); topActivityLetterboxVerticalPosition = source.readInt(); topActivityLetterboxHorizontalPosition = source.readInt(); @@ -660,6 +679,8 @@ public class TaskInfo { dest.writeInt(displayAreaFeatureId); dest.writeInt(cameraCompatControlState); dest.writeBoolean(isLetterboxDoubleTapEnabled); + dest.writeBoolean(topActivityEligibleForUserAspectRatioButton); + dest.writeBoolean(topActivityBoundsLetterboxed); dest.writeBoolean(isFromLetterboxDoubleTap); dest.writeInt(topActivityLetterboxVerticalPosition); dest.writeInt(topActivityLetterboxHorizontalPosition); @@ -701,8 +722,11 @@ public class TaskInfo { + " topActivityInSizeCompat=" + topActivityInSizeCompat + " topActivityEligibleForLetterboxEducation= " + topActivityEligibleForLetterboxEducation - + " topActivityLetterboxed= " + isLetterboxDoubleTapEnabled - + " isFromDoubleTap= " + isFromLetterboxDoubleTap + + " isLetterboxDoubleTapEnabled= " + isLetterboxDoubleTapEnabled + + " topActivityEligibleForUserAspectRatioButton= " + + topActivityEligibleForUserAspectRatioButton + + " topActivityBoundsLetterboxed= " + topActivityBoundsLetterboxed + + " isFromLetterboxDoubleTap= " + isFromLetterboxDoubleTap + " topActivityLetterboxVerticalPosition= " + topActivityLetterboxVerticalPosition + " topActivityLetterboxHorizontalPosition= " + topActivityLetterboxHorizontalPosition diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 39772dda4792c..9c23beb21a921 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -3473,6 +3473,11 @@ class Task extends TaskFragment { top.mLetterboxUiController.getLetterboxPositionForVerticalReachability(); } } + // User Aspect Ratio Settings is enabled if the app is not in SCM + info.topActivityEligibleForUserAspectRatioButton = + mWmService.mLetterboxConfiguration.isUserAppAspectRatioSettingsEnabled() + && top != null && !info.topActivityInSizeCompat; + info.topActivityBoundsLetterboxed = top != null && top.areBoundsLetterboxed(); } /** diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java index 28241d30e1680..f332b6988da0b 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java @@ -563,6 +563,36 @@ public class TaskTests extends WindowTestsBase { assertEquals(freeformBounds, task.getBounds()); } + @Test + public void testTopActivityEligibleForUserAspectRatioButton() { + DisplayContent display = mAtm.mRootWindowContainer.getDefaultDisplay(); + final Task rootTask = new TaskBuilder(mSupervisor).setCreateActivity(true) + .setWindowingMode(WINDOWING_MODE_FULLSCREEN).setDisplay(display).build(); + final Task task = rootTask.getBottomMostTask(); + final ActivityRecord root = task.getTopNonFinishingActivity(); + spyOn(mWm.mLetterboxConfiguration); + + // When device config flag is disabled the button is not enabled + doReturn(false).when(mWm.mLetterboxConfiguration) + .isUserAppAspectRatioSettingsEnabled(); + doReturn(false).when(mWm.mLetterboxConfiguration) + .isTranslucentLetterboxingEnabled(); + assertFalse(task.getTaskInfo().topActivityEligibleForUserAspectRatioButton); + + // The flag is enabled + doReturn(true).when(mWm.mLetterboxConfiguration) + .isUserAppAspectRatioSettingsEnabled(); + spyOn(root); + doReturn(task).when(root).getOrganizedTask(); + // When the flag is enabled and the top activity is not in size compat mode. + doReturn(false).when(root).inSizeCompatMode(); + assertTrue(task.getTaskInfo().topActivityEligibleForUserAspectRatioButton); + + // When in size compat mode the button is not enabled + doReturn(true).when(root).inSizeCompatMode(); + assertFalse(task.getTaskInfo().topActivityEligibleForUserAspectRatioButton); + } + /** * Tests that a task with forced orientation has orientation-consistent bounds within the * parent.