Merge "[Letterbox] Remove multi-window restriction from aspect ratio logic." into tm-qpr-dev

This commit is contained in:
Mariia Sandrikova
2022-05-18 17:59:37 +00:00
committed by Android (Google) Code Review
2 changed files with 39 additions and 14 deletions

View File

@@ -8070,7 +8070,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
? letterboxAspectRatioOverride : computeAspectRatio(parentBounds);
// Apply aspect ratio to resolved bounds
mIsAspectRatioApplied = applyAspectRatio(resolvedBounds, containingBoundsWithInsets,
containingBounds, desiredAspectRatio, true);
containingBounds, desiredAspectRatio);
if (mCompatDisplayInsets != null) {
mCompatDisplayInsets.getBoundsByRotation(
@@ -8496,7 +8496,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
private boolean applyAspectRatio(Rect outBounds, Rect containingAppBounds,
Rect containingBounds) {
return applyAspectRatio(outBounds, containingAppBounds, containingBounds,
0 /* desiredAspectRatio */, false /* fixedOrientationLetterboxed */);
0 /* desiredAspectRatio */);
}
/**
@@ -8507,23 +8507,18 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
*/
// TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
private boolean applyAspectRatio(Rect outBounds, Rect containingAppBounds,
Rect containingBounds, float desiredAspectRatio, boolean fixedOrientationLetterboxed) {
Rect containingBounds, float desiredAspectRatio) {
final float maxAspectRatio = info.getMaxAspectRatio();
final Task rootTask = getRootTask();
final float minAspectRatio = getMinAspectRatio();
// Not using ActivityRecord#isResizeable() directly because app compatibility testing
// showed that android:supportsPictureInPicture="true" alone is not sufficient signal for
// not letterboxing an app.
// TODO(214602463): Remove multi-window check since orientation and aspect ratio
// restrictions should always be applied in multi-window.
final TaskFragment organizedTf = getOrganizedTaskFragment();
if (task == null || rootTask == null
|| (inMultiWindowMode() && isResizeable(/* checkPictureInPictureSupport */ false)
&& !fixedOrientationLetterboxed)
|| (maxAspectRatio < 1 && minAspectRatio < 1 && desiredAspectRatio < 1)
|| isInVrUiMode(getConfiguration())) {
// We don't enforce aspect ratio if the activity task is in multiwindow unless it is in
// size-compat mode or is letterboxed from fixed orientation. We also don't set it if we
// are in VR mode.
// Don't set aspect ratio if we are in VR mode.
|| isInVrUiMode(getConfiguration())
// TODO(b/232898850): Always respect aspect ratio requests.
// Don't set aspect ratio for activity in ActivityEmbedding split.
|| (organizedTf != null && !organizedTf.fillsParent())) {
return false;
}

View File

@@ -1248,6 +1248,36 @@ public class SizeCompatTests extends WindowTestsBase {
assertEquals(1000, activity.getBounds().width());
}
@Test
@EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE})
public void testOverrideMinAspectRatioLargeForResizableAppInSplitScreen() {
setUpDisplaySizeWithApp(/* dw= */ 1000, /* dh= */ 2800);
// Create a size compat activity on the same task.
final ActivityRecord activity = new ActivityBuilder(mAtm)
.setTask(mTask)
.setScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
.setComponent(ComponentName.createRelative(mContext,
SizeCompatTests.class.getName()))
.setUid(android.os.Process.myUid())
.build();
final TestSplitOrganizer organizer =
new TestSplitOrganizer(mAtm, activity.getDisplayContent());
// Move activity to split screen which takes half of the screen.
mTask.reparent(organizer.mPrimary, POSITION_TOP, /* moveParents= */ false , "test");
organizer.mPrimary.setBounds(0, 0, 1000, 1400);
assertEquals(WINDOWING_MODE_MULTI_WINDOW, mTask.getWindowingMode());
assertEquals(WINDOWING_MODE_MULTI_WINDOW, activity.getWindowingMode());
// The per-package override forces the activity into a 16:9 aspect ratio
assertEquals(1400, activity.getBounds().height());
assertEquals(1400 / ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE,
activity.getBounds().width(), 0.5);
}
@Test
public void testLaunchWithFixedRotationTransform() {
final int dw = 1000;