Introduce config to use display aspect ratio for letterbox

Bug: 264654821
Test: atest WmTests:SizeCompatTests#testDisplayAspectRatioForResizablePortraitApps
Change-Id: If5ef64ac478a705fc334d5f4f81b901ccb0d5ba4
This commit is contained in:
Vali Calinescu
2023-01-11 14:44:14 +00:00
parent 04f7a3b26e
commit 23b2b2fe42
7 changed files with 199 additions and 3 deletions

View File

@@ -5356,6 +5356,9 @@
<!-- Whether using split screen aspect ratio as a default aspect ratio for unresizable apps. -->
<bool name="config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled">false</bool>
<!-- Whether using display aspect ratio as a default aspect ratio for all letterboxed apps. -->
<bool name="config_letterboxIsDisplayAspectRatioForFixedOrientationLetterboxEnabled">false</bool>
<!-- Whether the specific behaviour for translucent activities letterboxing is enabled.
TODO(b/255532890) Enable when ignoreOrientationRequest is set -->
<bool name="config_letterboxIsEnabledForTranslucentActivities">false</bool>

View File

@@ -4463,6 +4463,7 @@
<java-symbol type="bool" name="config_letterboxIsEducationEnabled" />
<java-symbol type="dimen" name="config_letterboxDefaultMinAspectRatioForUnresizableApps" />
<java-symbol type="bool" name="config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled" />
<java-symbol type="bool" name="config_letterboxIsDisplayAspectRatioForFixedOrientationLetterboxEnabled" />
<java-symbol type="bool" name="config_isCompatFakeFocusEnabled" />
<java-symbol type="bool" name="config_isWindowManagerCameraCompatTreatmentEnabled" />
<java-symbol type="bool" name="config_isCameraCompatControlForStretchedIssuesEnabled" />

View File

@@ -197,6 +197,12 @@ final class LetterboxConfiguration {
// Whether using split screen aspect ratio as a default aspect ratio for unresizable apps.
private boolean mIsSplitScreenAspectRatioForUnresizableAppsEnabled;
// Whether using display aspect ratio as a default aspect ratio for all letterboxed apps.
// mIsSplitScreenAspectRatioForUnresizableAppsEnabled and
// config_letterboxDefaultMinAspectRatioForUnresizableApps take priority over this for
// unresizable apps
private boolean mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox;
// Whether letterboxing strategy is enabled for translucent activities. If {@value false}
// all the feature is disabled
private boolean mTranslucentLetterboxingEnabled;
@@ -288,6 +294,9 @@ final class LetterboxConfiguration {
R.dimen.config_letterboxDefaultMinAspectRatioForUnresizableApps));
mIsSplitScreenAspectRatioForUnresizableAppsEnabled = mContext.getResources().getBoolean(
R.bool.config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled);
mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox = mContext.getResources()
.getBoolean(R.bool
.config_letterboxIsDisplayAspectRatioForFixedOrientationLetterboxEnabled);
mTranslucentLetterboxingEnabled = mContext.getResources().getBoolean(
R.bool.config_letterboxIsEnabledForTranslucentActivities);
mIsCameraCompatTreatmentEnabled = mContext.getResources().getBoolean(
@@ -942,6 +951,13 @@ final class LetterboxConfiguration {
return mIsSplitScreenAspectRatioForUnresizableAppsEnabled;
}
/**
* Whether using display aspect ratio as a default aspect ratio for all letterboxed apps.
*/
boolean getIsDisplayAspectRatioEnabledForFixedOrientationLetterbox() {
return mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox;
}
/**
* Overrides whether using split screen aspect ratio as a default aspect ratio for unresizable
* apps.
@@ -950,6 +966,14 @@ final class LetterboxConfiguration {
mIsSplitScreenAspectRatioForUnresizableAppsEnabled = enabled;
}
/**
* Overrides whether using display aspect ratio as a default aspect ratio for all letterboxed
* apps.
*/
void setIsDisplayAspectRatioEnabledForFixedOrientationLetterbox(boolean enabled) {
mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox = enabled;
}
/**
* Resets whether using split screen aspect ratio as a default aspect ratio for unresizable
* apps {@link R.bool.config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled}.
@@ -959,6 +983,16 @@ final class LetterboxConfiguration {
R.bool.config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled);
}
/**
* Resets whether using display aspect ratio as a default aspect ratio for all letterboxed
* apps {@link R.bool.config_letterboxIsDisplayAspectRatioForFixedOrientationLetterboxEnabled}.
*/
void resetIsDisplayAspectRatioEnabledForFixedOrientationLetterbox() {
mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox = mContext.getResources()
.getBoolean(R.bool
.config_letterboxIsDisplayAspectRatioForFixedOrientationLetterboxEnabled);
}
boolean isTranslucentLetterboxingEnabled() {
return mTranslucentLetterboxingOverrideEnabled || (mTranslucentLetterboxingEnabled
&& isTranslucentLetterboxingAllowed());

View File

@@ -584,7 +584,7 @@ final class LetterboxUiController {
? getSplitScreenAspectRatio()
: mActivityRecord.shouldCreateCompatDisplayInsets()
? getDefaultMinAspectRatioForUnresizableApps()
: mLetterboxConfiguration.getFixedOrientationLetterboxAspectRatio();
: getDefaultMinAspectRatio();
}
private float getDefaultMinAspectRatioForUnresizableApps() {
@@ -593,7 +593,7 @@ final class LetterboxUiController {
return mLetterboxConfiguration.getDefaultMinAspectRatioForUnresizableApps()
> MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO
? mLetterboxConfiguration.getDefaultMinAspectRatioForUnresizableApps()
: mLetterboxConfiguration.getFixedOrientationLetterboxAspectRatio();
: getDefaultMinAspectRatio();
}
return getSplitScreenAspectRatio();
@@ -621,6 +621,16 @@ final class LetterboxUiController {
return computeAspectRatio(bounds);
}
private float getDefaultMinAspectRatio() {
final DisplayContent displayContent = mActivityRecord.getDisplayContent();
if (displayContent == null
|| !mLetterboxConfiguration
.getIsDisplayAspectRatioEnabledForFixedOrientationLetterbox()) {
return mLetterboxConfiguration.getFixedOrientationLetterboxAspectRatio();
}
return computeAspectRatio(new Rect(displayContent.getBounds()));
}
Resources getResources() {
return mActivityRecord.mWmService.mContext.getResources();
}
@@ -1014,6 +1024,9 @@ final class LetterboxUiController {
+ mLetterboxConfiguration.getDefaultMinAspectRatioForUnresizableApps());
pw.println(prefix + " isSplitScreenAspectRatioForUnresizableAppsEnabled="
+ mLetterboxConfiguration.getIsSplitScreenAspectRatioForUnresizableAppsEnabled());
pw.println(prefix + " isDisplayAspectRatioEnabledForFixedOrientationLetterbox="
+ mLetterboxConfiguration
.getIsDisplayAspectRatioEnabledForFixedOrientationLetterbox());
}
/**

View File

@@ -955,6 +955,10 @@ public class WindowManagerShellCommand extends ShellCommand {
runSetBooleanFlag(pw, mLetterboxConfiguration
::setIsSplitScreenAspectRatioForUnresizableAppsEnabled);
break;
case "--isDisplayAspectRatioEnabledForFixedOrientationLetterbox":
runSetBooleanFlag(pw, mLetterboxConfiguration
::setIsDisplayAspectRatioEnabledForFixedOrientationLetterbox);
break;
case "--isTranslucentLetterboxingEnabled":
runSetBooleanFlag(pw, mLetterboxConfiguration
::setTranslucentLetterboxingOverrideEnabled);
@@ -1030,6 +1034,10 @@ public class WindowManagerShellCommand extends ShellCommand {
mLetterboxConfiguration
.resetIsSplitScreenAspectRatioForUnresizableAppsEnabled();
break;
case "IsDisplayAspectRatioEnabledForFixedOrientationLetterbox":
mLetterboxConfiguration
.resetIsDisplayAspectRatioEnabledForFixedOrientationLetterbox();
break;
case "isTranslucentLetterboxingEnabled":
mLetterboxConfiguration.resetTranslucentLetterboxingEnabled();
break;
@@ -1140,6 +1148,7 @@ public class WindowManagerShellCommand extends ShellCommand {
mLetterboxConfiguration.resetDefaultPositionForVerticalReachability();
mLetterboxConfiguration.resetIsEducationEnabled();
mLetterboxConfiguration.resetIsSplitScreenAspectRatioForUnresizableAppsEnabled();
mLetterboxConfiguration.resetIsDisplayAspectRatioEnabledForFixedOrientationLetterbox();
mLetterboxConfiguration.resetTranslucentLetterboxingEnabled();
mLetterboxConfiguration.resetCameraCompatRefreshEnabled();
mLetterboxConfiguration.resetCameraCompatRefreshCycleThroughStopEnabled();
@@ -1187,7 +1196,9 @@ public class WindowManagerShellCommand extends ShellCommand {
pw.println("Is using split screen aspect ratio as aspect ratio for unresizable apps: "
+ mLetterboxConfiguration
.getIsSplitScreenAspectRatioForUnresizableAppsEnabled());
pw.println("Is using display aspect ratio as aspect ratio for all letterboxed apps: "
+ mLetterboxConfiguration
.getIsDisplayAspectRatioEnabledForFixedOrientationLetterbox());
pw.println(" Is activity \"refresh\" in camera compatibility treatment enabled: "
+ mLetterboxConfiguration.isCameraCompatRefreshEnabled());
pw.println(" Refresh using \"stopped -> resumed\" cycle: "

View File

@@ -1911,6 +1911,132 @@ public class SizeCompatTests extends WindowTestsBase {
assertFitted();
}
@Test
public void testDisplayAspectRatioForResizablePortraitApps() {
// Set up a display in portrait and ignoring orientation request.
int displayWidth = 1400;
int displayHeight = 1600;
setUpDisplaySizeWithApp(displayWidth, displayHeight);
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
mWm.mLetterboxConfiguration.setFixedOrientationLetterboxAspectRatio(2f);
// Enable display aspect ratio to take precedence before
// fixedOrientationLetterboxAspectRatio
mWm.mLetterboxConfiguration
.setIsDisplayAspectRatioEnabledForFixedOrientationLetterbox(true);
// Set up resizable app in portrait
prepareLimitedBounds(mActivity, SCREEN_ORIENTATION_PORTRAIT, false /* isUnresizable */);
final TestSplitOrganizer organizer =
new TestSplitOrganizer(mAtm, mActivity.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, displayWidth, getExpectedSplitSize(displayHeight));
assertEquals(WINDOWING_MODE_MULTI_WINDOW, mTask.getWindowingMode());
assertEquals(WINDOWING_MODE_MULTI_WINDOW, mActivity.getWindowingMode());
// App should launch in fixed orientation letterbox.
assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio());
// Checking that there is no size compat mode.
assertFitted();
// Check that the display aspect ratio is used by the app.
final float targetMinAspectRatio = 1f * displayHeight / displayWidth;
final float delta = 0.01f;
assertEquals(targetMinAspectRatio, ActivityRecord
.computeAspectRatio(mActivity.getBounds()), delta);
}
@Test
public void testDisplayAspectRatioForResizableLandscapeApps() {
// Set up a display in landscape and ignoring orientation request.
int displayWidth = 1600;
int displayHeight = 1400;
setUpDisplaySizeWithApp(displayWidth, displayHeight);
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
mWm.mLetterboxConfiguration.setFixedOrientationLetterboxAspectRatio(2f);
// Enable display aspect ratio to take precedence before
// fixedOrientationLetterboxAspectRatio
mWm.mLetterboxConfiguration
.setIsDisplayAspectRatioEnabledForFixedOrientationLetterbox(true);
// Set up resizable app in landscape
prepareLimitedBounds(mActivity, SCREEN_ORIENTATION_LANDSCAPE, false /* isUnresizable */);
final TestSplitOrganizer organizer =
new TestSplitOrganizer(mAtm, mActivity.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, getExpectedSplitSize(displayWidth), displayHeight);
assertEquals(WINDOWING_MODE_MULTI_WINDOW, mTask.getWindowingMode());
assertEquals(WINDOWING_MODE_MULTI_WINDOW, mActivity.getWindowingMode());
// App should launch in fixed orientation letterbox.
assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio());
// Checking that there is no size compat mode.
assertFitted();
// Check that the display aspect ratio is used by the app.
final float targetMinAspectRatio = 1f * displayWidth / displayHeight;
final float delta = 0.01f;
assertEquals(targetMinAspectRatio, ActivityRecord
.computeAspectRatio(mActivity.getBounds()), delta);
}
@Test
public void testDisplayAspectRatioForUnresizableLandscapeApps() {
// Set up a display in portrait and ignoring orientation request.
int displayWidth = 1400;
int displayHeight = 1600;
setUpDisplaySizeWithApp(displayWidth, displayHeight);
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
mActivity.mWmService.mLetterboxConfiguration.setFixedOrientationLetterboxAspectRatio(1.1f);
// Enable display aspect ratio to take precedence before
// fixedOrientationLetterboxAspectRatio
mWm.mLetterboxConfiguration
.setIsDisplayAspectRatioEnabledForFixedOrientationLetterbox(true);
prepareUnresizable(mActivity, SCREEN_ORIENTATION_LANDSCAPE);
// App should launch in fixed orientation letterbox.
assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio());
// Checking that there is no size compat mode.
assertFitted();
// Check that the display aspect ratio is used by the app.
final float targetMinAspectRatio = 1f * displayHeight / displayWidth;
final float delta = 0.01f;
assertEquals(targetMinAspectRatio, ActivityRecord
.computeAspectRatio(mActivity.getBounds()), delta);
}
@Test
public void testDisplayAspectRatioForUnresizablePortraitApps() {
// Set up a display in landscape and ignoring orientation request.
int displayWidth = 1600;
int displayHeight = 1400;
setUpDisplaySizeWithApp(displayWidth, displayHeight);
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
mActivity.mWmService.mLetterboxConfiguration.setFixedOrientationLetterboxAspectRatio(1.1f);
// Enable display aspect ratio to take precedence before
// fixedOrientationLetterboxAspectRatio
mWm.mLetterboxConfiguration
.setIsDisplayAspectRatioEnabledForFixedOrientationLetterbox(true);
prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT);
// App should launch in fixed orientation letterbox.
assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio());
// Checking that there is no size compat mode.
assertFitted();
// Check that the display aspect ratio is used by the app.
final float targetMinAspectRatio = 1f * displayWidth / displayHeight;
final float delta = 0.01f;
assertEquals(targetMinAspectRatio, ActivityRecord
.computeAspectRatio(mActivity.getBounds()), delta);
}
@Test
public void
testDisplayIgnoreOrientationRequest_orientationLetterboxBecameSizeCompatAfterRotate() {

View File

@@ -253,6 +253,12 @@ class WindowTestsBase extends SystemServiceTestsBase {
// device form factors.
mAtm.mWindowManager.mLetterboxConfiguration
.setIsSplitScreenAspectRatioForUnresizableAppsEnabled(false);
// Ensure aspect ratio for al apps isn't overridden on any device target.
// {@link com.android.internal.R.bool
// .config_letterboxIsDisplayAspectRatioForFixedOrientationLetterboxEnabled}, may be set on
// some device form factors.
mAtm.mWindowManager.mLetterboxConfiguration
.setIsDisplayAspectRatioEnabledForFixedOrientationLetterbox(false);
checkDeviceSpecificOverridesNotApplied();
}
@@ -267,6 +273,8 @@ class WindowTestsBase extends SystemServiceTestsBase {
mAtm.mWindowManager.mLetterboxConfiguration.resetIsVerticalReachabilityEnabled();
mAtm.mWindowManager.mLetterboxConfiguration
.resetIsSplitScreenAspectRatioForUnresizableAppsEnabled();
mAtm.mWindowManager.mLetterboxConfiguration
.resetIsDisplayAspectRatioEnabledForFixedOrientationLetterbox();
}
/**