From 129b81693740b9e4aee7855e5d993ae04ae9a70c Mon Sep 17 00:00:00 2001 From: Vali Calinescu Date: Mon, 15 Aug 2022 16:04:02 +0000 Subject: [PATCH] Adjust aspect ratio override portrait fullscreen We're defining a new compat framework change id that restricts the other aspect ratio overrides for devices in portrait fullscreen. Fix: 218959984 Test: As manual testing use 'adb shell am compat disable/enable OVERRIDE_MIN_ASPECT_RATIO_EXCLUDE_PORTRAIT_FULLSCREEN '. For the unit tests run 'atest WmTests:SizeCompatTests'. Change-Id: I84eaab4df045c93fb2c159a789852094caf9121a --- core/api/test-current.txt | 1 + .../java/android/content/pm/ActivityInfo.java | 11 +++ .../com/android/server/wm/ActivityRecord.java | 23 ++++++- .../android/server/wm/SizeCompatTests.java | 69 +++++++++++++++++++ 4 files changed, 101 insertions(+), 3 deletions(-) diff --git a/core/api/test-current.txt b/core/api/test-current.txt index d758dd52410b5..ee3b64fbcd97d 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -793,6 +793,7 @@ package android.content.pm { field public static final long FORCE_RESIZE_APP = 174042936L; // 0xa5faf38L field public static final long NEVER_SANDBOX_DISPLAY_APIS = 184838306L; // 0xb0468a2L field public static final long OVERRIDE_MIN_ASPECT_RATIO = 174042980L; // 0xa5faf64L + field public static final long OVERRIDE_MIN_ASPECT_RATIO_EXCLUDE_PORTRAIT_FULLSCREEN = 218959984L; // 0xd0d1070L field public static final long OVERRIDE_MIN_ASPECT_RATIO_LARGE = 180326787L; // 0xabf9183L field public static final float OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE = 1.7777778f; field public static final long OVERRIDE_MIN_ASPECT_RATIO_MEDIUM = 180326845L; // 0xabf91bdL diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java index e92be7cb64e29..26c947b5f916d 100644 --- a/core/java/android/content/pm/ActivityInfo.java +++ b/core/java/android/content/pm/ActivityInfo.java @@ -1119,6 +1119,17 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { @TestApi public static final long OVERRIDE_MIN_ASPECT_RATIO_TO_ALIGN_WITH_SPLIT_SCREEN = 208648326L; + /** + * Overrides the min aspect ratio restriction in portrait fullscreen in order to use all + * available screen space. + * @hide + */ + @ChangeId + @Disabled + @Overridable + @TestApi + public static final long OVERRIDE_MIN_ASPECT_RATIO_EXCLUDE_PORTRAIT_FULLSCREEN = 218959984L; + /** * Compares activity window layout min width/height with require space for multi window to * determine if it can be put into multi window mode. diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index d11adc13795d4..8f21257959adf 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -79,6 +79,7 @@ import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT; import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_ALLOWLISTED; import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER; import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO; +import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_EXCLUDE_PORTRAIT_FULLSCREEN; import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE; import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM; import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY; @@ -8757,9 +8758,25 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A * Returns the min aspect ratio of this activity. */ float getMinAspectRatio() { - if (info.applicationInfo == null || !info.isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO) || ( - info.isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY) - && !ActivityInfo.isFixedOrientationPortrait(getRequestedOrientation()))) { + if (info.applicationInfo == null) { + return info.getMinAspectRatio(); + } + + if (!info.isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO)) { + return info.getMinAspectRatio(); + } + + if (info.isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_ONLY) + && !ActivityInfo.isFixedOrientationPortrait(getRequestedOrientation())) { + return info.getMinAspectRatio(); + } + + if (info.isChangeEnabled(OVERRIDE_MIN_ASPECT_RATIO_EXCLUDE_PORTRAIT_FULLSCREEN) + && getParent().getConfiguration().orientation == ORIENTATION_PORTRAIT + && getParent().getWindowConfiguration().getWindowingMode() + == WINDOWING_MODE_FULLSCREEN) { + // We are using the parent configuration here as this is the most recent one that gets + // passed to onConfigurationChanged when a relevant change takes place return info.getMinAspectRatio(); } diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index 6d33aaffdf241..17387061a86e5 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -1639,6 +1639,75 @@ public class SizeCompatTests extends WindowTestsBase { Assert.assertEquals(expectedAspectRatio, afterAspectRatio, 0.001f); } + @Test + @EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO, + ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE, + ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_EXCLUDE_PORTRAIT_FULLSCREEN}) + public void testOverrideMinAspectRatioExcludePortraitFullscreen() { + setUpDisplaySizeWithApp(2600, 1600); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + mActivity.mWmService.mLetterboxConfiguration.setFixedOrientationLetterboxAspectRatio(1.33f); + + // Create a size compat activity on the same task. + final ActivityRecord activity = new ActivityBuilder(mAtm) + .setTask(mTask) + .setComponent(ComponentName.createRelative(mContext, + SizeCompatTests.class.getName())) + .setUid(android.os.Process.myUid()) + .build(); + + // Non-resizable portrait activity + prepareUnresizable(activity, 0f, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + + // At first, OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_FULLSCREEN does not apply, because the + // display is in landscape + assertEquals(1600, activity.getBounds().height()); + assertEquals(1600 / ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE, + activity.getBounds().width(), 0.5); + + rotateDisplay(activity.mDisplayContent, ROTATION_90); + prepareUnresizable(activity, /* maxAspect */ 0, SCREEN_ORIENTATION_PORTRAIT); + + // Now the display is in portrait fullscreen, so the override is applied making the content + // fullscreen + assertEquals(activity.getBounds(), activity.mDisplayContent.getBounds()); + } + + @Test + @EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO, + ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE, + ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_EXCLUDE_PORTRAIT_FULLSCREEN}) + public void testOverrideMinAspectRatioExcludePortraitFullscreenNotApplied() { + // In this test, the activity is not in fullscreen, so the override is not applied + setUpDisplaySizeWithApp(2600, 1600); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + mActivity.mWmService.mLetterboxConfiguration.setFixedOrientationLetterboxAspectRatio(1.33f); + + // Create a size compat activity on the same task. + final ActivityRecord activity = new ActivityBuilder(mAtm) + .setTask(mTask) + .setComponent(ComponentName.createRelative(mContext, + SizeCompatTests.class.getName())) + .setUid(android.os.Process.myUid()) + .build(); + + final TestSplitOrganizer organizer = + new TestSplitOrganizer(mAtm, activity.getDisplayContent()); + + // Move first activity to split screen which takes half of the screen. + organizer.mPrimary.setBounds(0, 0, 1300, 1600); + organizer.putTaskToPrimary(mTask, true); + + // Non-resizable portrait activity + prepareUnresizable(activity, /* maxAspect */ 0, SCREEN_ORIENTATION_PORTRAIT); + + // OVERRIDE_MIN_ASPECT_RATIO_PORTRAIT_FULLSCREEN does not apply here because the + // display is not in fullscreen, so OVERRIDE_MIN_ASPECT_RATIO_LARGE applies instead + assertEquals(1600, activity.getBounds().height()); + assertEquals(1600 / ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE, + activity.getBounds().width(), 0.5); + } + @Test public void testSplitAspectRatioForUnresizableLandscapeApps() { // Set up a display in portrait and ignoring orientation request.