Merge "Letterbox positioning (2/4): Rename "task letterbox" to "fixed orientation letterbox"." into sc-dev

This commit is contained in:
Mariia Sandrikova
2021-03-05 23:47:11 +00:00
committed by Android (Google) Code Review
6 changed files with 145 additions and 58 deletions

View File

@@ -4668,11 +4668,11 @@
<!-- WindowsManager JetPack display features --> <!-- WindowsManager JetPack display features -->
<string name="config_display_features" translatable="false" /> <string name="config_display_features" translatable="false" />
<!-- Aspect ratio of task level letterboxing. Values <= 1.0 will be ignored. <!-- Aspect ratio of letterboxing for fixed orientation. Values <= 1.0 will be ignored.
Note: Activity min/max aspect ratio restrictions will still be respected by the Note: Activity min/max aspect ratio restrictions will still be respected.
activity-level letterboxing (size-compat mode). Therefore this override can control the Therefore this override can control the maximum screen area that can be occupied by
maximum screen area that can be occupied by the app in the letterbox mode. --> the app in the letterbox mode. -->
<item name="config_taskLetterboxAspectRatio" format="float" type="dimen">0.0</item> <item name="config_fixedOrientationLetterboxAspectRatio" format="float" type="dimen">0.0</item>
<!-- Corners radius for activity presented the letterbox mode. Values < 0 will be ignored and <!-- Corners radius for activity presented the letterbox mode. Values < 0 will be ignored and
corners of the activity won't be rounded. --> corners of the activity won't be rounded. -->

View File

@@ -4181,7 +4181,7 @@
<java-symbol type="dimen" name="controls_thumbnail_image_max_height" /> <java-symbol type="dimen" name="controls_thumbnail_image_max_height" />
<java-symbol type="dimen" name="controls_thumbnail_image_max_width" /> <java-symbol type="dimen" name="controls_thumbnail_image_max_width" />
<java-symbol type="dimen" name="config_taskLetterboxAspectRatio" /> <java-symbol type="dimen" name="config_fixedOrientationLetterboxAspectRatio" />
<java-symbol type="integer" name="config_letterboxActivityCornersRadius" /> <java-symbol type="integer" name="config_letterboxActivityCornersRadius" />
<java-symbol type="integer" name="config_letterboxBackgroundType" /> <java-symbol type="integer" name="config_letterboxBackgroundType" />
<java-symbol type="color" name="config_letterboxBackgroundColor" /> <java-symbol type="color" name="config_letterboxBackgroundColor" />

View File

@@ -211,7 +211,7 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowManagerService.LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND; import static com.android.server.wm.WindowManagerService.LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND;
import static com.android.server.wm.WindowManagerService.LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND_FLOATING; import static com.android.server.wm.WindowManagerService.LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND_FLOATING;
import static com.android.server.wm.WindowManagerService.LETTERBOX_BACKGROUND_SOLID_COLOR; import static com.android.server.wm.WindowManagerService.LETTERBOX_BACKGROUND_SOLID_COLOR;
import static com.android.server.wm.WindowManagerService.MIN_TASK_LETTERBOX_ASPECT_RATIO; import static com.android.server.wm.WindowManagerService.MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
import static com.android.server.wm.WindowManagerService.letterboxBackgroundTypeToString; import static com.android.server.wm.WindowManagerService.letterboxBackgroundTypeToString;
@@ -6994,6 +6994,13 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
float aspect = Math.max(parentWidth, parentHeight) float aspect = Math.max(parentWidth, parentHeight)
/ (float) Math.min(parentWidth, parentHeight); / (float) Math.min(parentWidth, parentHeight);
// Override from config_fixedOrientationLetterboxAspectRatio or via ADB with
// set-fixed-orientation-letterbox-aspect-ratio.
final float letterboxAspectRatioOverride =
mWmService.getFixedOrientationLetterboxAspectRatio();
aspect = letterboxAspectRatioOverride > MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO
? letterboxAspectRatioOverride : aspect;
// Adjust the fixed orientation letterbox bounds to fit the app request aspect ratio in // Adjust the fixed orientation letterbox bounds to fit the app request aspect ratio in
// order to use the extra available space. // order to use the extra available space.
final float maxAspectRatio = info.maxAspectRatio; final float maxAspectRatio = info.maxAspectRatio;
@@ -7004,16 +7011,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
aspect = minAspectRatio; aspect = minAspectRatio;
} }
// Override from config_letterboxAspectRatio or via ADB with set-letterbox-aspect-ratio.
// TODO(b/175212232): Rename getTaskLetterboxAspectRatio and all related methods since fixed
// orientation letterbox is on the activity level now.
final float letterboxAspectRatioOverride = mWmService.getTaskLetterboxAspectRatio();
// Activity min/max aspect ratio restrictions will be respected by the activity-level
// letterboxing (size-compat mode). Therefore this override can control the maximum screen
// area that can be occupied by the app in the letterbox mode.
aspect = letterboxAspectRatioOverride > MIN_TASK_LETTERBOX_ASPECT_RATIO
? letterboxAspectRatioOverride : aspect;
// Store the current bounds to be able to revert to size compat mode values below if needed. // Store the current bounds to be able to revert to size compat mode values below if needed.
Rect mTmpFullBounds = new Rect(resolvedBounds); Rect mTmpFullBounds = new Rect(resolvedBounds);
if (forcedOrientation == ORIENTATION_LANDSCAPE) { if (forcedOrientation == ORIENTATION_LANDSCAPE) {

View File

@@ -463,12 +463,12 @@ public class WindowManagerService extends IWindowManager.Stub
private static final int ANIMATION_COMPLETED_TIMEOUT_MS = 5000; private static final int ANIMATION_COMPLETED_TIMEOUT_MS = 5000;
/** /**
* Override of task letterbox aspect ratio that is set via ADB with * Override of aspect ratio for fixed orientation letterboxing that is set via ADB with
* set-task-letterbox-aspect-ratio or via {@link * set-fixed-orientation-letterbox-aspect-ratio or via {@link
* com.android.internal.R.dimen.config_taskLetterboxAspectRatio} will be ignored * com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio} will be ignored
* if it is <= this value. * if it is <= this value.
*/ */
static final float MIN_TASK_LETTERBOX_ASPECT_RATIO = 1.0f; static final float MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO = 1.0f;
@VisibleForTesting @VisibleForTesting
WindowManagerConstants mConstants; WindowManagerConstants mConstants;
@@ -1003,9 +1003,9 @@ public class WindowManagerService extends IWindowManager.Stub
private boolean mAnimationsDisabled = false; private boolean mAnimationsDisabled = false;
boolean mPointerLocationEnabled = false; boolean mPointerLocationEnabled = false;
// Aspect ratio of task level letterboxing, values <= MIN_TASK_LETTERBOX_ASPECT_RATIO will be // Aspect ratio of letterbox for fixed orientation, values <=
// ignored. // MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO will be ignored.
private volatile float mTaskLetterboxAspectRatio; private volatile float mFixedOrientationLetterboxAspectRatio;
/** Enum for Letterbox background type. */ /** Enum for Letterbox background type. */
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@@ -1256,8 +1256,8 @@ public class WindowManagerService extends IWindowManager.Stub
mAssistantOnTopOfDream = context.getResources().getBoolean( mAssistantOnTopOfDream = context.getResources().getBoolean(
com.android.internal.R.bool.config_assistantOnTopOfDream); com.android.internal.R.bool.config_assistantOnTopOfDream);
mTaskLetterboxAspectRatio = context.getResources().getFloat( mFixedOrientationLetterboxAspectRatio = context.getResources().getFloat(
com.android.internal.R.dimen.config_taskLetterboxAspectRatio); com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio);
mLetterboxActivityCornersRadius = context.getResources().getInteger( mLetterboxActivityCornersRadius = context.getResources().getInteger(
com.android.internal.R.integer.config_letterboxActivityCornersRadius); com.android.internal.R.integer.config_letterboxActivityCornersRadius);
mLetterboxBackgroundColor = Color.valueOf(context.getResources().getColor( mLetterboxBackgroundColor = Color.valueOf(context.getResources().getColor(
@@ -3853,29 +3853,29 @@ public class WindowManagerService extends IWindowManager.Stub
} }
/** /**
* Overrides the aspect ratio of task level letterboxing. If given value is <= {@link * Overrides the aspect ratio of letterbox for fixed orientation. If given value is <= {@link
* #MIN_TASK_LETTERBOX_ASPECT_RATIO}, both it and a value of {@link * #MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO}, both it and a value of {@link
* com.android.internal.R.dimen.config_taskLetterboxAspectRatio} will be ignored and * com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio} will be ignored and
* the framework implementation will be used to determine the aspect ratio. * the framework implementation will be used to determine the aspect ratio.
*/ */
void setTaskLetterboxAspectRatio(float aspectRatio) { void setFixedOrientationLetterboxAspectRatio(float aspectRatio) {
mTaskLetterboxAspectRatio = aspectRatio; mFixedOrientationLetterboxAspectRatio = aspectRatio;
} }
/** /**
* Resets the aspect ratio of task level letterboxing to {@link * Resets the aspect ratio of letterbox for fixed orientation to {@link
* com.android.internal.R.dimen.config_taskLetterboxAspectRatio}. * com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio}.
*/ */
void resetTaskLetterboxAspectRatio() { void resetFixedOrientationLetterboxAspectRatio() {
mTaskLetterboxAspectRatio = mContext.getResources().getFloat( mFixedOrientationLetterboxAspectRatio = mContext.getResources().getFloat(
com.android.internal.R.dimen.config_taskLetterboxAspectRatio); com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio);
} }
/** /**
* Gets the aspect ratio of task level letterboxing. * Gets the aspect ratio of letterbox for fixed orientation.
*/ */
float getTaskLetterboxAspectRatio() { float getFixedOrientationLetterboxAspectRatio() {
return mTaskLetterboxAspectRatio; return mFixedOrientationLetterboxAspectRatio;
} }
/** /**

View File

@@ -117,10 +117,10 @@ public class WindowManagerShellCommand extends ShellCommand {
return runGetIgnoreOrientationRequest(pw); return runGetIgnoreOrientationRequest(pw);
case "dump-visible-window-views": case "dump-visible-window-views":
return runDumpVisibleWindowViews(pw); return runDumpVisibleWindowViews(pw);
case "set-task-letterbox-aspect-ratio": case "set-fixed-orientation-letterbox-aspect-ratio":
return runSetTaskLetterboxAspectRatio(pw); return runSetFixedOrientationLetterboxAspectRatio(pw);
case "get-task-letterbox-aspect-ratio": case "get-fixed-orientation-letterbox-aspect-ratio":
return runGetTaskLetterboxAspectRatio(pw); return runGetFixedOrientationLetterboxAspectRatio(pw);
case "set-letterbox-activity-corners-radius": case "set-letterbox-activity-corners-radius":
return runSetLetterboxActivityCornersRadius(pw); return runSetLetterboxActivityCornersRadius(pw);
case "get-letterbox-activity-corners-radius": case "get-letterbox-activity-corners-radius":
@@ -531,12 +531,12 @@ public class WindowManagerShellCommand extends ShellCommand {
return 0; return 0;
} }
private int runSetTaskLetterboxAspectRatio(PrintWriter pw) throws RemoteException { private int runSetFixedOrientationLetterboxAspectRatio(PrintWriter pw) throws RemoteException {
final float aspectRatio; final float aspectRatio;
try { try {
String arg = getNextArgRequired(); String arg = getNextArgRequired();
if ("reset".equals(arg)) { if ("reset".equals(arg)) {
mInternal.resetTaskLetterboxAspectRatio(); mInternal.resetFixedOrientationLetterboxAspectRatio();
return 0; return 0;
} }
aspectRatio = Float.parseFloat(arg); aspectRatio = Float.parseFloat(arg);
@@ -549,13 +549,13 @@ public class WindowManagerShellCommand extends ShellCommand {
return -1; return -1;
} }
mInternal.setTaskLetterboxAspectRatio(aspectRatio); mInternal.setFixedOrientationLetterboxAspectRatio(aspectRatio);
return 0; return 0;
} }
private int runGetTaskLetterboxAspectRatio(PrintWriter pw) throws RemoteException { private int runGetFixedOrientationLetterboxAspectRatio(PrintWriter pw) throws RemoteException {
final float aspectRatio = mInternal.getTaskLetterboxAspectRatio(); final float aspectRatio = mInternal.getFixedOrientationLetterboxAspectRatio();
if (aspectRatio <= WindowManagerService.MIN_TASK_LETTERBOX_ASPECT_RATIO) { if (aspectRatio <= WindowManagerService.MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO) {
pw.println("Letterbox aspect ratio is not set"); pw.println("Letterbox aspect ratio is not set");
} else { } else {
pw.println("Letterbox aspect ratio is " + aspectRatio); pw.println("Letterbox aspect ratio is " + aspectRatio);
@@ -692,8 +692,8 @@ public class WindowManagerShellCommand extends ShellCommand {
// set-ignore-orientation-request // set-ignore-orientation-request
mInterface.setIgnoreOrientationRequest(displayId, false /* ignoreOrientationRequest */); mInterface.setIgnoreOrientationRequest(displayId, false /* ignoreOrientationRequest */);
// set-task-letterbox-aspect-ratio // set-fixed-orientation-letterbox-aspect-ratio
mInternal.resetTaskLetterboxAspectRatio(); mInternal.resetFixedOrientationLetterboxAspectRatio();
// set-letterbox-activity-corners-radius // set-letterbox-activity-corners-radius
mInternal.resetLetterboxActivityCornersRadius(); mInternal.resetLetterboxActivityCornersRadius();
@@ -734,12 +734,12 @@ public class WindowManagerShellCommand extends ShellCommand {
pw.println(" set-ignore-orientation-request [-d DISPLAY_ID] [true|1|false|0]"); pw.println(" set-ignore-orientation-request [-d DISPLAY_ID] [true|1|false|0]");
pw.println(" get-ignore-orientation-request [-d DISPLAY_ID] "); pw.println(" get-ignore-orientation-request [-d DISPLAY_ID] ");
pw.println(" If app requested orientation should be ignored."); pw.println(" If app requested orientation should be ignored.");
pw.println(" set-task-letterbox-aspect-ratio [reset|aspectRatio]"); pw.println(" set-fixed-orientation-letterbox-aspect-ratio [reset|aspectRatio]");
pw.println(" get-task-letterbox-aspect-ratio"); pw.println(" get-fixed-orientation-letterbox-aspect-ratio");
pw.println(" Aspect ratio of task level letterboxing. If aspectRatio <= " pw.println(" Aspect ratio of letterbox for fixed orientation. If aspectRatio <= "
+ WindowManagerService.MIN_TASK_LETTERBOX_ASPECT_RATIO); + WindowManagerService.MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO);
pw.println(" both it and R.dimen.config_taskLetterboxAspectRatio will be ignored"); pw.println(" both it and R.dimen.config_fixedOrientationLetterboxAspectRatio will be");
pw.println(" and framework implementation will be used to determine aspect ratio."); pw.println(" ignored and framework implementation will determine aspect ratio.");
pw.println(" set-letterbox-activity-corners-radius [reset|cornersRadius]"); pw.println(" set-letterbox-activity-corners-radius [reset|cornersRadius]");
pw.println(" get-letterbox-activity-corners-radius"); pw.println(" get-letterbox-activity-corners-radius");
pw.println(" Corners radius for activities in the letterbox mode. If radius < 0,"); pw.println(" Corners radius for activities in the letterbox mode. If radius < 0,");

View File

@@ -655,7 +655,7 @@ public class SizeCompatTests extends WindowTestsBase {
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
// Portrait fixed app without max aspect. // Portrait fixed app without max aspect.
prepareUnresizable(mActivity, 0, SCREEN_ORIENTATION_PORTRAIT); prepareUnresizable(mActivity, /* maxAspect= */ 0, SCREEN_ORIENTATION_PORTRAIT);
final Rect displayBounds = new Rect(mActivity.mDisplayContent.getBounds()); final Rect displayBounds = new Rect(mActivity.mDisplayContent.getBounds());
final Rect activityBounds = new Rect(mActivity.getBounds()); final Rect activityBounds = new Rect(mActivity.getBounds());
@@ -675,6 +675,96 @@ public class SizeCompatTests extends WindowTestsBase {
activityBounds.width()); activityBounds.width());
} }
@Test
public void testDisplayIgnoreOrientationRequest_fixedOrientationAppRespectMinAspectRatio() {
// Set up a display in landscape and ignoring orientation request.
setUpDisplaySizeWithApp(2800, 1400);
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
// Portrait fixed app with min aspect ratio higher that aspect ratio override for fixed
// orientation letterbox.
mActivity.mWmService.setFixedOrientationLetterboxAspectRatio(1.1f);
mActivity.info.minAspectRatio = 3;
prepareUnresizable(mActivity, /* maxAspect= */ 0, SCREEN_ORIENTATION_PORTRAIT);
final Rect displayBounds = new Rect(mActivity.mDisplayContent.getBounds());
final Rect activityBounds = new Rect(mActivity.getBounds());
// Display shouldn't be rotated.
assertEquals(SCREEN_ORIENTATION_UNSPECIFIED,
mActivity.mDisplayContent.getLastOrientation());
assertTrue(displayBounds.width() > displayBounds.height());
// App should launch in fixed orientation letterbox.
assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio());
assertFalse(mActivity.inSizeCompatMode());
// Activity bounds should respect minimum aspect ratio for activity.
assertEquals(displayBounds.height(), activityBounds.height());
assertEquals((int) Math.rint(displayBounds.height() / mActivity.info.minAspectRatio),
activityBounds.width());
}
@Test
public void testDisplayIgnoreOrientationRequest_fixedOrientationAppRespectMaxAspectRatio() {
// Set up a display in landscape and ignoring orientation request.
setUpDisplaySizeWithApp(2800, 1400);
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
// Portrait fixed app with max aspect ratio lower that aspect ratio override for fixed
// orientation letterbox.
mActivity.mWmService.setFixedOrientationLetterboxAspectRatio(3);
prepareUnresizable(mActivity, /* maxAspect= */ 2, SCREEN_ORIENTATION_PORTRAIT);
final Rect displayBounds = new Rect(mActivity.mDisplayContent.getBounds());
final Rect activityBounds = new Rect(mActivity.getBounds());
// Display shouldn't be rotated.
assertEquals(SCREEN_ORIENTATION_UNSPECIFIED,
mActivity.mDisplayContent.getLastOrientation());
assertTrue(displayBounds.width() > displayBounds.height());
// App should launch in fixed orientation letterbox.
assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio());
assertFalse(mActivity.inSizeCompatMode());
// Activity bounds should respect maximum aspect ratio for activity.
assertEquals(displayBounds.height(), activityBounds.height());
assertEquals((int) Math.rint(displayBounds.height() / mActivity.info.maxAspectRatio),
activityBounds.width());
}
@Test
public void testDisplayIgnoreOrientationRequest_fixedOrientationAppWithAspectRatioOverride() {
// Set up a display in landscape and ignoring orientation request.
setUpDisplaySizeWithApp(2800, 1400);
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
// Portrait fixed app with min aspect ratio higher that aspect ratio override for fixed
// orientation letterbox.
final float fixedOrientationLetterboxAspectRatio = 1.1f;
mActivity.mWmService.setFixedOrientationLetterboxAspectRatio(
fixedOrientationLetterboxAspectRatio);
prepareUnresizable(mActivity, 0, SCREEN_ORIENTATION_PORTRAIT);
final Rect displayBounds = new Rect(mActivity.mDisplayContent.getBounds());
final Rect activityBounds = new Rect(mActivity.getBounds());
// Display shouldn't be rotated.
assertEquals(SCREEN_ORIENTATION_UNSPECIFIED,
mActivity.mDisplayContent.getLastOrientation());
assertTrue(displayBounds.width() > displayBounds.height());
// App should launch in fixed orientation letterbox.
assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio());
assertFalse(mActivity.inSizeCompatMode());
// Activity bounds should respect aspect ratio override for fixed orientation letterbox.
assertEquals(displayBounds.height(), activityBounds.height());
assertEquals((int) Math.rint(displayBounds.height() / fixedOrientationLetterboxAspectRatio),
activityBounds.width());
}
@Test @Test
public void public void
testDisplayIgnoreOrientationRequest_orientationLetterboxBecameSizeCompatAfterRotate() { testDisplayIgnoreOrientationRequest_orientationLetterboxBecameSizeCompatAfterRotate() {