Merge "Shrink default launch bounds on small display" into tm-qpr-dev am: 3f580f5b5b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19415031

Change-Id: I48e93b8565178dbe5164d142082067acf28a6cc2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Kazuki Takise
2022-11-21 13:22:01 +00:00
committed by Automerger Merge Worker
3 changed files with 73 additions and 23 deletions

View File

@@ -46,6 +46,8 @@ class LaunchParamsUtil {
private static final int DISPLAY_EDGE_OFFSET_DP = 27; private static final int DISPLAY_EDGE_OFFSET_DP = 27;
private static final Rect TMP_STABLE_BOUNDS = new Rect();
private LaunchParamsUtil() {} private LaunchParamsUtil() {}
/** /**
@@ -130,19 +132,43 @@ class LaunchParamsUtil {
return new Size(adjWidth, adjHeight); return new Size(adjWidth, adjHeight);
} }
static void adjustBoundsToFitInDisplayArea(@NonNull Rect stableBounds, int layoutDirection, static void adjustBoundsToFitInDisplayArea(@NonNull TaskDisplayArea displayArea,
int layoutDirection,
@NonNull ActivityInfo.WindowLayout layout, @NonNull ActivityInfo.WindowLayout layout,
@NonNull Rect inOutBounds) { @NonNull Rect inOutBounds) {
// Give a small margin between the window bounds and the display bounds.
final Rect stableBounds = TMP_STABLE_BOUNDS;
displayArea.getStableRect(stableBounds);
final float density = (float) displayArea.getConfiguration().densityDpi / DENSITY_DEFAULT;
final int displayEdgeOffset = (int) (DISPLAY_EDGE_OFFSET_DP * density + 0.5f);
stableBounds.inset(displayEdgeOffset, displayEdgeOffset);
if (stableBounds.width() < inOutBounds.width() if (stableBounds.width() < inOutBounds.width()
|| stableBounds.height() < inOutBounds.height()) { || stableBounds.height() < inOutBounds.height()) {
// There is no way for us to fit the bounds in the displayArea without changing width final float heightShrinkRatio = stableBounds.width() / (float) inOutBounds.width();
// or height. Just move the start to align with the displayArea. final float widthShrinkRatio =
stableBounds.height() / (float) inOutBounds.height();
final float shrinkRatio = Math.min(heightShrinkRatio, widthShrinkRatio);
// Minimum layout requirements.
final int layoutMinWidth = (layout == null) ? -1 : layout.minWidth;
final int layoutMinHeight = (layout == null) ? -1 : layout.minHeight;
int adjustedWidth = Math.max(layoutMinWidth, (int) (inOutBounds.width() * shrinkRatio));
int adjustedHeight = Math.max(layoutMinHeight,
(int) (inOutBounds.height() * shrinkRatio));
if (stableBounds.width() < adjustedWidth
|| stableBounds.height() < adjustedHeight) {
// There is no way for us to fit the bounds in the displayArea without breaking min
// size constraints. Set the min size to make visible as much content as possible.
final int left = layoutDirection == View.LAYOUT_DIRECTION_RTL final int left = layoutDirection == View.LAYOUT_DIRECTION_RTL
? stableBounds.right - inOutBounds.right + inOutBounds.left ? stableBounds.right - adjustedWidth
: stableBounds.left; : stableBounds.left;
inOutBounds.offsetTo(left, stableBounds.top); inOutBounds.set(left, stableBounds.top, left + adjustedWidth,
stableBounds.top + adjustedHeight);
return; return;
} }
inOutBounds.set(inOutBounds.left, inOutBounds.top,
inOutBounds.left + adjustedWidth, inOutBounds.top + adjustedHeight);
}
final int dx; final int dx;
if (inOutBounds.right > stableBounds.right) { if (inOutBounds.right > stableBounds.right) {

View File

@@ -785,9 +785,10 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
// to the center of suggested bounds (or the displayArea if no suggested bounds). The // to the center of suggested bounds (or the displayArea if no suggested bounds). The
// default size might be too big to center to source activity bounds in displayArea, so // default size might be too big to center to source activity bounds in displayArea, so
// we may need to move it back to the displayArea. // we may need to move it back to the displayArea.
adjustBoundsToFitInDisplayArea(displayArea, layout, mTmpBounds);
inOutBounds.setEmpty();
LaunchParamsUtil.centerBounds(displayArea, mTmpBounds.width(), mTmpBounds.height(), LaunchParamsUtil.centerBounds(displayArea, mTmpBounds.width(), mTmpBounds.height(),
inOutBounds); inOutBounds);
adjustBoundsToFitInDisplayArea(displayArea, layout, inOutBounds);
if (DEBUG) appendLog("freeform-size-mismatch=" + inOutBounds); if (DEBUG) appendLog("freeform-size-mismatch=" + inOutBounds);
} }
@@ -838,8 +839,7 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
@NonNull Rect inOutBounds) { @NonNull Rect inOutBounds) {
final int layoutDirection = mSupervisor.mRootWindowContainer.getConfiguration() final int layoutDirection = mSupervisor.mRootWindowContainer.getConfiguration()
.getLayoutDirection(); .getLayoutDirection();
displayArea.getStableRect(mTmpStableBounds); LaunchParamsUtil.adjustBoundsToFitInDisplayArea(displayArea, layoutDirection, layout,
LaunchParamsUtil.adjustBoundsToFitInDisplayArea(mTmpStableBounds, layoutDirection, layout,
inOutBounds); inOutBounds);
} }

View File

@@ -85,6 +85,11 @@ public class TaskLaunchParamsModifierTests extends WindowTestsBase {
private static final Rect DISPLAY_STABLE_BOUNDS = new Rect(/* left */ 100, private static final Rect DISPLAY_STABLE_BOUNDS = new Rect(/* left */ 100,
/* top */ 200, /* right */ 1620, /* bottom */ 680); /* top */ 200, /* right */ 1620, /* bottom */ 680);
private static final Rect SMALL_DISPLAY_BOUNDS = new Rect(/* left */ 0, /* top */ 0,
/* right */ 1000, /* bottom */ 500);
private static final Rect SMALL_DISPLAY_STABLE_BOUNDS = new Rect(/* left */ 100,
/* top */ 50, /* right */ 900, /* bottom */ 450);
private ActivityRecord mActivity; private ActivityRecord mActivity;
private TaskLaunchParamsModifier mTarget; private TaskLaunchParamsModifier mTarget;
@@ -1413,6 +1418,20 @@ public class TaskLaunchParamsModifierTests extends WindowTestsBase {
DISPLAY_STABLE_BOUNDS.bottom - mResult.mBounds.bottom, /* delta */ 1); DISPLAY_STABLE_BOUNDS.bottom - mResult.mBounds.bottom, /* delta */ 1);
} }
@Test
public void testDefaultFreeformSizeShrinksOnSmallDisplay() {
final TestDisplayContent freeformDisplay = createNewDisplayContent(
WINDOWING_MODE_FREEFORM, SMALL_DISPLAY_BOUNDS, SMALL_DISPLAY_STABLE_BOUNDS);
final ActivityOptions options = ActivityOptions.makeBasic();
options.setLaunchDisplayId(freeformDisplay.mDisplayId);
assertEquals(RESULT_CONTINUE, new CalculateRequestBuilder().setOptions(options)
.calculate());
assertEquals(new Rect(414, 77, 587, 423), mResult.mBounds);
}
@Test @Test
public void testDefaultFreeformSizeRespectsMinAspectRatio() { public void testDefaultFreeformSizeRespectsMinAspectRatio() {
final TestDisplayContent freeformDisplay = createNewDisplayContent( final TestDisplayContent freeformDisplay = createNewDisplayContent(
@@ -1603,16 +1622,15 @@ public class TaskLaunchParamsModifierTests extends WindowTestsBase {
options.setLaunchDisplayId(freeformDisplay.mDisplayId); options.setLaunchDisplayId(freeformDisplay.mDisplayId);
mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM; mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;
mCurrent.mBounds.set(100, 300, 1820, 1380); mCurrent.mBounds.set(0, 0, 3000, 2000);
mActivity.info.applicationInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP; mActivity.info.applicationInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP;
assertEquals(RESULT_CONTINUE, assertEquals(RESULT_CONTINUE,
new CalculateRequestBuilder().setOptions(options).calculate()); new CalculateRequestBuilder().setOptions(options).calculate());
assertTrue("Result bounds should start from app bounds's origin, but it's " // Must shrink to fit the display while reserving aspect ratio.
+ mResult.mBounds, assertEquals(new Rect(127, 227, 766, 653), mResult.mBounds);
mResult.mBounds.left == 100 && mResult.mBounds.top == 200);
} }
@Test @Test
@@ -1628,18 +1646,19 @@ public class TaskLaunchParamsModifierTests extends WindowTestsBase {
final ActivityOptions options = ActivityOptions.makeBasic(); final ActivityOptions options = ActivityOptions.makeBasic();
options.setLaunchDisplayId(freeformDisplay.mDisplayId); options.setLaunchDisplayId(freeformDisplay.mDisplayId);
final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
.setMinWidth(500).setMinHeight(500).build();
mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM; mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;
mCurrent.mBounds.set(100, 300, 1820, 1380); mCurrent.mBounds.set(0, 0, 2000, 3000);
mActivity.info.applicationInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP; mActivity.info.applicationInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP;
assertEquals(RESULT_CONTINUE, assertEquals(RESULT_CONTINUE,
new CalculateRequestBuilder().setOptions(options).calculate()); new CalculateRequestBuilder().setOptions(options).setLayout(layout).calculate());
assertTrue("Result bounds should start from top-right corner of app bounds, but " // Must shrink to fit the display while reserving aspect ratio.
+ "it's " + mResult.mBounds, assertEquals(new Rect(1093, 227, 1593, 727), mResult.mBounds);
mResult.mBounds.left == -100 && mResult.mBounds.top == 200);
} }
@Test @Test
@@ -1814,7 +1833,7 @@ public class TaskLaunchParamsModifierTests extends WindowTestsBase {
assertEquals(RESULT_CONTINUE, assertEquals(RESULT_CONTINUE,
new CalculateRequestBuilder().setOptions(options).calculate()); new CalculateRequestBuilder().setOptions(options).calculate());
assertEquals(new Rect(100, 200, 400, 500), mResult.mBounds); assertEquals(new Rect(127, 227, 427, 527), mResult.mBounds);
} }
@Test @Test
@@ -1867,13 +1886,18 @@ public class TaskLaunchParamsModifierTests extends WindowTestsBase {
} }
private TestDisplayContent createNewDisplayContent(int windowingMode) { private TestDisplayContent createNewDisplayContent(int windowingMode) {
return createNewDisplayContent(windowingMode, DISPLAY_BOUNDS, DISPLAY_STABLE_BOUNDS);
}
private TestDisplayContent createNewDisplayContent(int windowingMode, Rect displayBounds,
Rect displayStableBounds) {
final TestDisplayContent display = addNewDisplayContentAt(DisplayContent.POSITION_TOP); final TestDisplayContent display = addNewDisplayContentAt(DisplayContent.POSITION_TOP);
display.getDefaultTaskDisplayArea().setWindowingMode(windowingMode); display.getDefaultTaskDisplayArea().setWindowingMode(windowingMode);
display.setBounds(DISPLAY_BOUNDS); display.setBounds(displayBounds);
display.getConfiguration().densityDpi = DENSITY_DEFAULT; display.getConfiguration().densityDpi = DENSITY_DEFAULT;
display.getConfiguration().orientation = ORIENTATION_LANDSCAPE; display.getConfiguration().orientation = ORIENTATION_LANDSCAPE;
configInsetsState(display.getInsetsStateController().getRawInsetsState(), display, configInsetsState(display.getInsetsStateController().getRawInsetsState(), display,
DISPLAY_STABLE_BOUNDS); displayStableBounds);
return display; return display;
} }