Merge "Letterbox positioning (2/4): Rename "task letterbox" to "fixed orientation letterbox"." into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8c2a7d06ff
@@ -4668,11 +4668,11 @@
|
||||
<!-- WindowsManager JetPack display features -->
|
||||
<string name="config_display_features" translatable="false" />
|
||||
|
||||
<!-- Aspect ratio of task level letterboxing. Values <= 1.0 will be ignored.
|
||||
Note: Activity min/max aspect ratio restrictions will still 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. -->
|
||||
<item name="config_taskLetterboxAspectRatio" format="float" type="dimen">0.0</item>
|
||||
<!-- Aspect ratio of letterboxing for fixed orientation. Values <= 1.0 will be ignored.
|
||||
Note: Activity min/max aspect ratio restrictions will still be respected.
|
||||
Therefore this override can control the maximum screen area that can be occupied by
|
||||
the app in the letterbox mode. -->
|
||||
<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 of the activity won't be rounded. -->
|
||||
|
||||
@@ -4181,7 +4181,7 @@
|
||||
<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="config_taskLetterboxAspectRatio" />
|
||||
<java-symbol type="dimen" name="config_fixedOrientationLetterboxAspectRatio" />
|
||||
<java-symbol type="integer" name="config_letterboxActivityCornersRadius" />
|
||||
<java-symbol type="integer" name="config_letterboxBackgroundType" />
|
||||
<java-symbol type="color" name="config_letterboxBackgroundColor" />
|
||||
|
||||
@@ -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_FLOATING;
|
||||
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_WILL_PLACE_SURFACES;
|
||||
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) 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
|
||||
// order to use the extra available space.
|
||||
final float maxAspectRatio = info.maxAspectRatio;
|
||||
@@ -7004,16 +7011,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
|
||||
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.
|
||||
Rect mTmpFullBounds = new Rect(resolvedBounds);
|
||||
if (forcedOrientation == ORIENTATION_LANDSCAPE) {
|
||||
|
||||
@@ -463,12 +463,12 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
private static final int ANIMATION_COMPLETED_TIMEOUT_MS = 5000;
|
||||
|
||||
/**
|
||||
* Override of task letterbox aspect ratio that is set via ADB with
|
||||
* set-task-letterbox-aspect-ratio or via {@link
|
||||
* com.android.internal.R.dimen.config_taskLetterboxAspectRatio} will be ignored
|
||||
* Override of aspect ratio for fixed orientation letterboxing that is set via ADB with
|
||||
* set-fixed-orientation-letterbox-aspect-ratio or via {@link
|
||||
* com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio} will be ignored
|
||||
* 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
|
||||
WindowManagerConstants mConstants;
|
||||
@@ -1003,9 +1003,9 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
private boolean mAnimationsDisabled = false;
|
||||
boolean mPointerLocationEnabled = false;
|
||||
|
||||
// Aspect ratio of task level letterboxing, values <= MIN_TASK_LETTERBOX_ASPECT_RATIO will be
|
||||
// ignored.
|
||||
private volatile float mTaskLetterboxAspectRatio;
|
||||
// Aspect ratio of letterbox for fixed orientation, values <=
|
||||
// MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO will be ignored.
|
||||
private volatile float mFixedOrientationLetterboxAspectRatio;
|
||||
|
||||
/** Enum for Letterbox background type. */
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@@ -1256,8 +1256,8 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
mAssistantOnTopOfDream = context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_assistantOnTopOfDream);
|
||||
|
||||
mTaskLetterboxAspectRatio = context.getResources().getFloat(
|
||||
com.android.internal.R.dimen.config_taskLetterboxAspectRatio);
|
||||
mFixedOrientationLetterboxAspectRatio = context.getResources().getFloat(
|
||||
com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio);
|
||||
mLetterboxActivityCornersRadius = context.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_letterboxActivityCornersRadius);
|
||||
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
|
||||
* #MIN_TASK_LETTERBOX_ASPECT_RATIO}, both it and a value of {@link
|
||||
* com.android.internal.R.dimen.config_taskLetterboxAspectRatio} will be ignored and
|
||||
* Overrides the aspect ratio of letterbox for fixed orientation. If given value is <= {@link
|
||||
* #MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO}, both it and a value of {@link
|
||||
* com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio} will be ignored and
|
||||
* the framework implementation will be used to determine the aspect ratio.
|
||||
*/
|
||||
void setTaskLetterboxAspectRatio(float aspectRatio) {
|
||||
mTaskLetterboxAspectRatio = aspectRatio;
|
||||
void setFixedOrientationLetterboxAspectRatio(float aspectRatio) {
|
||||
mFixedOrientationLetterboxAspectRatio = aspectRatio;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the aspect ratio of task level letterboxing to {@link
|
||||
* com.android.internal.R.dimen.config_taskLetterboxAspectRatio}.
|
||||
* Resets the aspect ratio of letterbox for fixed orientation to {@link
|
||||
* com.android.internal.R.dimen.config_fixedOrientationLetterboxAspectRatio}.
|
||||
*/
|
||||
void resetTaskLetterboxAspectRatio() {
|
||||
mTaskLetterboxAspectRatio = mContext.getResources().getFloat(
|
||||
com.android.internal.R.dimen.config_taskLetterboxAspectRatio);
|
||||
void resetFixedOrientationLetterboxAspectRatio() {
|
||||
mFixedOrientationLetterboxAspectRatio = mContext.getResources().getFloat(
|
||||
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() {
|
||||
return mTaskLetterboxAspectRatio;
|
||||
float getFixedOrientationLetterboxAspectRatio() {
|
||||
return mFixedOrientationLetterboxAspectRatio;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -117,10 +117,10 @@ public class WindowManagerShellCommand extends ShellCommand {
|
||||
return runGetIgnoreOrientationRequest(pw);
|
||||
case "dump-visible-window-views":
|
||||
return runDumpVisibleWindowViews(pw);
|
||||
case "set-task-letterbox-aspect-ratio":
|
||||
return runSetTaskLetterboxAspectRatio(pw);
|
||||
case "get-task-letterbox-aspect-ratio":
|
||||
return runGetTaskLetterboxAspectRatio(pw);
|
||||
case "set-fixed-orientation-letterbox-aspect-ratio":
|
||||
return runSetFixedOrientationLetterboxAspectRatio(pw);
|
||||
case "get-fixed-orientation-letterbox-aspect-ratio":
|
||||
return runGetFixedOrientationLetterboxAspectRatio(pw);
|
||||
case "set-letterbox-activity-corners-radius":
|
||||
return runSetLetterboxActivityCornersRadius(pw);
|
||||
case "get-letterbox-activity-corners-radius":
|
||||
@@ -531,12 +531,12 @@ public class WindowManagerShellCommand extends ShellCommand {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int runSetTaskLetterboxAspectRatio(PrintWriter pw) throws RemoteException {
|
||||
private int runSetFixedOrientationLetterboxAspectRatio(PrintWriter pw) throws RemoteException {
|
||||
final float aspectRatio;
|
||||
try {
|
||||
String arg = getNextArgRequired();
|
||||
if ("reset".equals(arg)) {
|
||||
mInternal.resetTaskLetterboxAspectRatio();
|
||||
mInternal.resetFixedOrientationLetterboxAspectRatio();
|
||||
return 0;
|
||||
}
|
||||
aspectRatio = Float.parseFloat(arg);
|
||||
@@ -549,13 +549,13 @@ public class WindowManagerShellCommand extends ShellCommand {
|
||||
return -1;
|
||||
}
|
||||
|
||||
mInternal.setTaskLetterboxAspectRatio(aspectRatio);
|
||||
mInternal.setFixedOrientationLetterboxAspectRatio(aspectRatio);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int runGetTaskLetterboxAspectRatio(PrintWriter pw) throws RemoteException {
|
||||
final float aspectRatio = mInternal.getTaskLetterboxAspectRatio();
|
||||
if (aspectRatio <= WindowManagerService.MIN_TASK_LETTERBOX_ASPECT_RATIO) {
|
||||
private int runGetFixedOrientationLetterboxAspectRatio(PrintWriter pw) throws RemoteException {
|
||||
final float aspectRatio = mInternal.getFixedOrientationLetterboxAspectRatio();
|
||||
if (aspectRatio <= WindowManagerService.MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO) {
|
||||
pw.println("Letterbox aspect ratio is not set");
|
||||
} else {
|
||||
pw.println("Letterbox aspect ratio is " + aspectRatio);
|
||||
@@ -692,8 +692,8 @@ public class WindowManagerShellCommand extends ShellCommand {
|
||||
// set-ignore-orientation-request
|
||||
mInterface.setIgnoreOrientationRequest(displayId, false /* ignoreOrientationRequest */);
|
||||
|
||||
// set-task-letterbox-aspect-ratio
|
||||
mInternal.resetTaskLetterboxAspectRatio();
|
||||
// set-fixed-orientation-letterbox-aspect-ratio
|
||||
mInternal.resetFixedOrientationLetterboxAspectRatio();
|
||||
|
||||
// set-letterbox-activity-corners-radius
|
||||
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(" get-ignore-orientation-request [-d DISPLAY_ID] ");
|
||||
pw.println(" If app requested orientation should be ignored.");
|
||||
pw.println(" set-task-letterbox-aspect-ratio [reset|aspectRatio]");
|
||||
pw.println(" get-task-letterbox-aspect-ratio");
|
||||
pw.println(" Aspect ratio of task level letterboxing. If aspectRatio <= "
|
||||
+ WindowManagerService.MIN_TASK_LETTERBOX_ASPECT_RATIO);
|
||||
pw.println(" both it and R.dimen.config_taskLetterboxAspectRatio will be ignored");
|
||||
pw.println(" and framework implementation will be used to determine aspect ratio.");
|
||||
pw.println(" set-fixed-orientation-letterbox-aspect-ratio [reset|aspectRatio]");
|
||||
pw.println(" get-fixed-orientation-letterbox-aspect-ratio");
|
||||
pw.println(" Aspect ratio of letterbox for fixed orientation. If aspectRatio <= "
|
||||
+ WindowManagerService.MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO);
|
||||
pw.println(" both it and R.dimen.config_fixedOrientationLetterboxAspectRatio will be");
|
||||
pw.println(" ignored and framework implementation will determine aspect ratio.");
|
||||
pw.println(" set-letterbox-activity-corners-radius [reset|cornersRadius]");
|
||||
pw.println(" get-letterbox-activity-corners-radius");
|
||||
pw.println(" Corners radius for activities in the letterbox mode. If radius < 0,");
|
||||
|
||||
@@ -655,7 +655,7 @@ public class SizeCompatTests extends WindowTestsBase {
|
||||
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
|
||||
|
||||
// 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 activityBounds = new Rect(mActivity.getBounds());
|
||||
@@ -675,6 +675,96 @@ public class SizeCompatTests extends WindowTestsBase {
|
||||
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
|
||||
public void
|
||||
testDisplayIgnoreOrientationRequest_orientationLetterboxBecameSizeCompatAfterRotate() {
|
||||
|
||||
Reference in New Issue
Block a user