Merge "Allow using split aspect ratio for unresizable apps" into tm-qpr-dev

This commit is contained in:
Mariia Sandrikova
2022-05-27 19:15:01 +00:00
committed by Android (Google) Code Review
8 changed files with 163 additions and 14 deletions

View File

@@ -5182,6 +5182,9 @@
An exception will be thrown if the given aspect ratio < 4:3. -->
<item name="config_letterboxDefaultMinAspectRatioForUnresizableApps" format="float" type="dimen">1.5</item>
<!-- Whether using split screen aspect ratio as a default aspect ratio for unresizable apps. -->
<bool name="config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled">false</bool>
<!-- Whether a camera compat controller is enabled to allow the user to apply or revert
treatment for stretched issues in camera viewfinder. -->
<bool name="config_isCameraCompatControlForStretchedIssuesEnabled">false</bool>

View File

@@ -4396,6 +4396,7 @@
<java-symbol type="integer" name="config_letterboxDefaultPositionForVerticalReachability" />
<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_isCameraCompatControlForStretchedIssuesEnabled" />
<java-symbol type="bool" name="config_hideDisplayCutoutWithDisplayArea" />

View File

@@ -8082,7 +8082,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
resolvedBounds.set(containingBounds);
final float letterboxAspectRatioOverride =
mLetterboxUiController.getFixedOrientationLetterboxAspectRatio(newParentConfig);
mWmService.mLetterboxConfiguration.getFixedOrientationLetterboxAspectRatio();
final float desiredAspectRatio =
letterboxAspectRatioOverride > MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO
? letterboxAspectRatioOverride : computeAspectRatio(parentBounds);
@@ -8645,7 +8645,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
// if an app sets orientation to portrait dynamically because of aspect ratio
// restriction applied here.
&& getRequestedConfigurationOrientation() != ORIENTATION_UNDEFINED
? mWmService.mLetterboxConfiguration.getDefaultMinAspectRatioForUnresizableApps()
? mLetterboxUiController.getDefaultMinAspectRatioForUnresizableApps()
: infoAspectRatio;
}

View File

@@ -187,6 +187,9 @@ final class LetterboxConfiguration {
// Whether education is allowed for letterboxed fullscreen apps.
private boolean mIsEducationEnabled;
// Whether using split screen aspect ratio as a default aspect ratio for unresizable apps.
private boolean mIsSplitScreenAspectRatioForUnresizableAppsEnabled;
LetterboxConfiguration(Context systemUiContext) {
mContext = systemUiContext;
mFixedOrientationLetterboxAspectRatio = mContext.getResources().getFloat(
@@ -216,6 +219,8 @@ final class LetterboxConfiguration {
R.bool.config_letterboxIsEducationEnabled);
setDefaultMinAspectRatioForUnresizableApps(mContext.getResources().getFloat(
R.dimen.config_letterboxDefaultMinAspectRatioForUnresizableApps));
mIsSplitScreenAspectRatioForUnresizableAppsEnabled = mContext.getResources().getBoolean(
R.bool.config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled);
}
/**
@@ -797,4 +802,28 @@ final class LetterboxConfiguration {
R.bool.config_letterboxIsEducationEnabled);
}
/**
* Whether using split screen aspect ratio as a default aspect ratio for unresizable apps.
*/
boolean getIsSplitScreenAspectRatioForUnresizableAppsEnabled() {
return mIsSplitScreenAspectRatioForUnresizableAppsEnabled;
}
/**
* Overrides whether using split screen aspect ratio as a default aspect ratio for unresizable
* apps.
*/
void setIsSplitScreenAspectRatioForUnresizableAppsEnabled(boolean enabled) {
mIsSplitScreenAspectRatioForUnresizableAppsEnabled = enabled;
}
/**
* Resets whether using split screen aspect ratio as a default aspect ratio for unresizable
* apps {@link R.bool.config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled}.
*/
void resetIsSplitScreenAspectRatioForUnresizableAppsEnabled() {
mIsSplitScreenAspectRatioForUnresizableAppsEnabled = mContext.getResources().getBoolean(
R.bool.config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled);
}
}

View File

@@ -211,12 +211,10 @@ final class LetterboxUiController {
: mLetterboxConfiguration.getLetterboxVerticalPositionMultiplier();
}
float getFixedOrientationLetterboxAspectRatio(Configuration parentConfiguration) {
// Don't check resolved windowing mode because it may not be updated yet during
// configuration change.
if (!isHorizontalReachabilityEnabled(parentConfiguration)
&& !isVerticalReachabilityEnabled(parentConfiguration)) {
return mLetterboxConfiguration.getFixedOrientationLetterboxAspectRatio();
float getDefaultMinAspectRatioForUnresizableApps() {
if (!mLetterboxConfiguration.getIsSplitScreenAspectRatioForUnresizableAppsEnabled()
|| mActivityRecord.getDisplayContent() == null) {
return mLetterboxConfiguration.getDefaultMinAspectRatioForUnresizableApps();
}
int dividerWindowWidth =
@@ -226,10 +224,14 @@ final class LetterboxUiController {
int dividerSize = dividerWindowWidth - dividerInsets * 2;
// Getting the same aspect ratio that apps get in split screen.
Rect bounds = new Rect(parentConfiguration.windowConfiguration.getAppBounds());
bounds.inset(dividerSize, /* dy */ 0);
bounds.right = bounds.centerX();
Rect bounds = new Rect(mActivityRecord.getDisplayContent().getBounds());
if (bounds.width() >= bounds.height()) {
bounds.inset(/* dx */ dividerSize, /* dy */ 0);
bounds.right = bounds.centerX();
} else {
bounds.inset(/* dx */ 0, /* dy */ dividerSize);
bounds.bottom = bounds.centerY();
}
return computeAspectRatio(bounds);
}
@@ -538,10 +540,11 @@ final class LetterboxUiController {
pw.println(prefix + " letterboxVerticalPositionMultiplier="
+ getVerticalPositionMultiplier(mActivityRecord.getParent().getConfiguration()));
pw.println(prefix + " fixedOrientationLetterboxAspectRatio="
+ getFixedOrientationLetterboxAspectRatio(
mActivityRecord.getParent().getConfiguration()));
+ mLetterboxConfiguration.getFixedOrientationLetterboxAspectRatio());
pw.println(prefix + " defaultMinAspectRatioForUnresizableApps="
+ mLetterboxConfiguration.getDefaultMinAspectRatioForUnresizableApps());
pw.println(prefix + " isSplitScreenAspectRatioForUnresizableAppsEnabled="
+ mLetterboxConfiguration.getIsSplitScreenAspectRatioForUnresizableAppsEnabled());
}
/**

View File

@@ -949,6 +949,30 @@ public class WindowManagerShellCommand extends ShellCommand {
return 0;
}
private int runSetLetterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled(PrintWriter pw)
throws RemoteException {
String arg = getNextArg();
final boolean enabled;
switch (arg) {
case "true":
case "1":
enabled = true;
break;
case "false":
case "0":
enabled = false;
break;
default:
getErrPrintWriter().println("Error: expected true, 1, false, 0, but got " + arg);
return -1;
}
synchronized (mInternal.mGlobalLock) {
mLetterboxConfiguration.setIsSplitScreenAspectRatioForUnresizableAppsEnabled(enabled);
}
return 0;
}
private int runSetLetterboxStyle(PrintWriter pw) throws RemoteException {
if (peekNextArg() == null) {
getErrPrintWriter().println("Error: No arguments provided.");
@@ -1001,6 +1025,9 @@ public class WindowManagerShellCommand extends ShellCommand {
case "--isEducationEnabled":
runSetLetterboxIsEducationEnabled(pw);
break;
case "--isSplitScreenAspectRatioForUnresizableAppsEnabled":
runSetLetterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled(pw);
break;
default:
getErrPrintWriter().println(
"Error: Unrecognized letterbox style option: " + arg);
@@ -1060,6 +1087,10 @@ public class WindowManagerShellCommand extends ShellCommand {
case "isEducationEnabled":
mLetterboxConfiguration.getIsEducationEnabled();
break;
case "isSplitScreenAspectRatioForUnresizableAppsEnabled":
mLetterboxConfiguration
.getIsSplitScreenAspectRatioForUnresizableAppsEnabled();
break;
default:
getErrPrintWriter().println(
"Error: Unrecognized letterbox style option: " + arg);
@@ -1159,6 +1190,7 @@ public class WindowManagerShellCommand extends ShellCommand {
mLetterboxConfiguration.resetDefaultPositionForHorizontalReachability();
mLetterboxConfiguration.resetDefaultPositionForVerticalReachability();
mLetterboxConfiguration.resetIsEducationEnabled();
mLetterboxConfiguration.resetIsSplitScreenAspectRatioForUnresizableAppsEnabled();
}
}
@@ -1186,6 +1218,9 @@ public class WindowManagerShellCommand extends ShellCommand {
mLetterboxConfiguration.getDefaultPositionForVerticalReachability()));
pw.println("Is education enabled: "
+ mLetterboxConfiguration.getIsEducationEnabled());
pw.println("Is using split screen aspect ratio as aspect ratio for unresizable apps: "
+ mLetterboxConfiguration
.getIsSplitScreenAspectRatioForUnresizableAppsEnabled());
pw.println("Background type: "
+ LetterboxConfiguration.letterboxBackgroundTypeToString(
@@ -1343,6 +1378,9 @@ public class WindowManagerShellCommand extends ShellCommand {
pw.println(" enabled.");
pw.println(" --isEducationEnabled [true|1|false|0]");
pw.println(" Whether education is allowed for letterboxed fullscreen apps.");
pw.println(" --isSplitScreenAspectRatioForUnresizableAppsEnabled [true|1|false|0]");
pw.println(" Whether using split screen aspect ratio as a default aspect ratio for");
pw.println(" unresizable apps.");
pw.println(" reset-letterbox-style [aspectRatio|cornerRadius|backgroundType");
pw.println(" |backgroundColor|wallpaperBlurRadius|wallpaperDarkScrimAlpha");
pw.println(" |horizontalPositionMultiplier|verticalPositionMultiplier");

View File

@@ -1483,6 +1483,72 @@ public class SizeCompatTests extends WindowTestsBase {
assertEquals(displayBounds.height() / defaultAspectRatio, activityBounds.width(), 0.5);
}
@Test
public void testSplitAspectRatioForUnresizablePortraitApps() {
// Set up a display in landscape and ignoring orientation request.
setUpDisplaySizeWithApp(1600, 1400);
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
mActivity.mWmService.mLetterboxConfiguration
.setIsSplitScreenAspectRatioForUnresizableAppsEnabled(true);
mActivity.mWmService.mLetterboxConfiguration.setFixedOrientationLetterboxAspectRatio(1.1f);
prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT);
final Rect displayBounds = new Rect(mActivity.mDisplayContent.getBounds());
final Rect activityBounds = new Rect(mActivity.getBounds());
// App should launch in fixed orientation letterbox.
assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio());
// Checking that there is no size compat mode.
assertFitted();
assertEquals(displayBounds.height(), activityBounds.height());
assertTrue(activityBounds.width() < displayBounds.width() / 2);
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");
assertEquals(WINDOWING_MODE_MULTI_WINDOW, mTask.getWindowingMode());
assertEquals(WINDOWING_MODE_MULTI_WINDOW, mActivity.getWindowingMode());
// Checking that there is no size compat mode.
assertFitted();
}
@Test
public void testSplitAspectRatioForUnresizableLandscapeApps() {
// Set up a display in landscape and ignoring orientation request.
setUpDisplaySizeWithApp(1400, 1600);
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
mActivity.mWmService.mLetterboxConfiguration
.setIsSplitScreenAspectRatioForUnresizableAppsEnabled(true);
mActivity.mWmService.mLetterboxConfiguration.setFixedOrientationLetterboxAspectRatio(1.1f);
prepareUnresizable(mActivity, SCREEN_ORIENTATION_LANDSCAPE);
final Rect displayBounds = new Rect(mActivity.mDisplayContent.getBounds());
final Rect activityBounds = new Rect(mActivity.getBounds());
// App should launch in fixed orientation letterbox.
assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio());
// Checking that there is no size compat mode.
assertFitted();
assertEquals(displayBounds.width(), activityBounds.width());
assertTrue(activityBounds.height() < displayBounds.height() / 2);
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");
assertEquals(WINDOWING_MODE_MULTI_WINDOW, mTask.getWindowingMode());
assertEquals(WINDOWING_MODE_MULTI_WINDOW, mActivity.getWindowingMode());
// Checking that there is no size compat mode.
assertFitted();
}
@Test
public void
testDisplayIgnoreOrientationRequest_orientationLetterboxBecameSizeCompatAfterRotate() {

View File

@@ -245,6 +245,12 @@ class WindowTestsBase extends SystemServiceTestsBase {
// {@link com.android.internal.R.bool.config_letterboxIsVerticalReachabilityEnabled},
// may be set on some device form factors.
mAtm.mWindowManager.mLetterboxConfiguration.setIsVerticalReachabilityEnabled(false);
// Ensure aspect ratio for unresizable apps isn't overridden on any device target.
// {@link com.android.internal.R.bool
// .config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled}, may be set on some
// device form factors.
mAtm.mWindowManager.mLetterboxConfiguration
.setIsSplitScreenAspectRatioForUnresizableAppsEnabled(false);
checkDeviceSpecificOverridesNotApplied();
}
@@ -254,8 +260,11 @@ class WindowTestsBase extends SystemServiceTestsBase {
// Revert back to device overrides.
mAtm.mWindowManager.mLetterboxConfiguration.resetFixedOrientationLetterboxAspectRatio();
mAtm.mWindowManager.mLetterboxConfiguration.resetLetterboxHorizontalPositionMultiplier();
mAtm.mWindowManager.mLetterboxConfiguration.resetLetterboxVerticalPositionMultiplier();
mAtm.mWindowManager.mLetterboxConfiguration.resetIsHorizontalReachabilityEnabled();
mAtm.mWindowManager.mLetterboxConfiguration.resetIsVerticalReachabilityEnabled();
mAtm.mWindowManager.mLetterboxConfiguration
.resetIsSplitScreenAspectRatioForUnresizableAppsEnabled();
}
/**