Merge "Respect parent bounds if it can contain the override bounds" into rvc-dev am: 0e42093cfa

Change-Id: I6ccacafe6d934ac2f7d88200fb50fdde5f48ae33
This commit is contained in:
Riddle Hsu
2020-04-23 07:28:51 +00:00
committed by Automerger Merge Worker
2 changed files with 36 additions and 27 deletions

View File

@@ -2285,16 +2285,18 @@ class Task extends WindowContainer<WindowContainer> {
} }
density *= DisplayMetrics.DENSITY_DEFAULT_SCALE; density *= DisplayMetrics.DENSITY_DEFAULT_SCALE;
// If bounds have been overridden at this level, restrict config resources to these bounds // The bounds may have been overridden at this level. If the parent cannot cover these
// rather than the parent because the overridden bounds can be larger than the parent. // bounds, the configuration is still computed according to the override bounds.
boolean hasOverrideBounds = false; final boolean insideParentBounds;
final Rect parentBounds = parentConfig.windowConfiguration.getBounds();
final Rect resolvedBounds = inOutConfig.windowConfiguration.getBounds(); final Rect resolvedBounds = inOutConfig.windowConfiguration.getBounds();
if (resolvedBounds == null || resolvedBounds.isEmpty()) { if (resolvedBounds == null || resolvedBounds.isEmpty()) {
mTmpFullBounds.set(parentConfig.windowConfiguration.getBounds()); mTmpFullBounds.set(parentBounds);
insideParentBounds = true;
} else { } else {
mTmpFullBounds.set(resolvedBounds); mTmpFullBounds.set(resolvedBounds);
hasOverrideBounds = true; insideParentBounds = parentBounds.contains(resolvedBounds);
} }
Rect outAppBounds = inOutConfig.windowConfiguration.getAppBounds(); Rect outAppBounds = inOutConfig.windowConfiguration.getAppBounds();
@@ -2303,30 +2305,30 @@ class Task extends WindowContainer<WindowContainer> {
outAppBounds = inOutConfig.windowConfiguration.getAppBounds(); outAppBounds = inOutConfig.windowConfiguration.getAppBounds();
} }
// Non-null compatibility insets means the activity prefers to keep its original size, so // Non-null compatibility insets means the activity prefers to keep its original size, so
// the out bounds doesn't need to be restricted by the parent. // the out bounds doesn't need to be restricted by the parent or current display.
final boolean insideParentBounds = compatInsets == null; final boolean customContainerPolicy = compatInsets != null;
if (insideParentBounds && windowingMode != WINDOWING_MODE_FREEFORM) { if (!customContainerPolicy && windowingMode != WINDOWING_MODE_FREEFORM) {
Rect parentAppBounds; final Rect containingAppBounds;
if (hasOverrideBounds) { if (insideParentBounds) {
// Since we overrode the bounds, restrict appBounds to display non-decor rather containingAppBounds = parentConfig.windowConfiguration.getAppBounds();
// than parent. Otherwise, it won't match the overridden bounds.
final TaskDisplayArea displayArea = getDisplayArea();
parentAppBounds = displayArea != null
? displayArea.getConfiguration().windowConfiguration.getAppBounds() : null;
} else { } else {
parentAppBounds = parentConfig.windowConfiguration.getAppBounds(); // Restrict appBounds to display non-decor rather than parent because the override
// bounds are beyond the parent. Otherwise, it won't match the overridden bounds.
final TaskDisplayArea displayArea = getDisplayArea();
containingAppBounds = displayArea != null
? displayArea.getWindowConfiguration().getAppBounds() : null;
} }
if (parentAppBounds != null && !parentAppBounds.isEmpty()) { if (containingAppBounds != null && !containingAppBounds.isEmpty()) {
outAppBounds.intersect(parentAppBounds); outAppBounds.intersect(containingAppBounds);
} }
} }
if (inOutConfig.screenWidthDp == Configuration.SCREEN_WIDTH_DP_UNDEFINED if (inOutConfig.screenWidthDp == Configuration.SCREEN_WIDTH_DP_UNDEFINED
|| inOutConfig.screenHeightDp == Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { || inOutConfig.screenHeightDp == Configuration.SCREEN_HEIGHT_DP_UNDEFINED) {
if (insideParentBounds && WindowConfiguration.isFloating(windowingMode)) { if (!customContainerPolicy && WindowConfiguration.isFloating(windowingMode)) {
mTmpNonDecorBounds.set(mTmpFullBounds); mTmpNonDecorBounds.set(mTmpFullBounds);
mTmpStableBounds.set(mTmpFullBounds); mTmpStableBounds.set(mTmpFullBounds);
} else if (insideParentBounds } else if (!customContainerPolicy
&& (overrideDisplayInfo != null || getDisplayContent() != null)) { && (overrideDisplayInfo != null || getDisplayContent() != null)) {
final DisplayInfo di = overrideDisplayInfo != null final DisplayInfo di = overrideDisplayInfo != null
? overrideDisplayInfo ? overrideDisplayInfo
@@ -2344,7 +2346,7 @@ class Task extends WindowContainer<WindowContainer> {
if (rotation == ROTATION_UNDEFINED) { if (rotation == ROTATION_UNDEFINED) {
rotation = parentConfig.windowConfiguration.getRotation(); rotation = parentConfig.windowConfiguration.getRotation();
} }
if (rotation != ROTATION_UNDEFINED && compatInsets != null) { if (rotation != ROTATION_UNDEFINED && customContainerPolicy) {
mTmpNonDecorBounds.set(mTmpFullBounds); mTmpNonDecorBounds.set(mTmpFullBounds);
mTmpStableBounds.set(mTmpFullBounds); mTmpStableBounds.set(mTmpFullBounds);
compatInsets.getBoundsByRotation(mTmpBounds, rotation); compatInsets.getBoundsByRotation(mTmpBounds, rotation);
@@ -2362,13 +2364,13 @@ class Task extends WindowContainer<WindowContainer> {
if (inOutConfig.screenWidthDp == Configuration.SCREEN_WIDTH_DP_UNDEFINED) { if (inOutConfig.screenWidthDp == Configuration.SCREEN_WIDTH_DP_UNDEFINED) {
final int overrideScreenWidthDp = (int) (mTmpStableBounds.width() / density); final int overrideScreenWidthDp = (int) (mTmpStableBounds.width() / density);
inOutConfig.screenWidthDp = (insideParentBounds && !hasOverrideBounds) inOutConfig.screenWidthDp = (insideParentBounds && !customContainerPolicy)
? Math.min(overrideScreenWidthDp, parentConfig.screenWidthDp) ? Math.min(overrideScreenWidthDp, parentConfig.screenWidthDp)
: overrideScreenWidthDp; : overrideScreenWidthDp;
} }
if (inOutConfig.screenHeightDp == Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { if (inOutConfig.screenHeightDp == Configuration.SCREEN_HEIGHT_DP_UNDEFINED) {
final int overrideScreenHeightDp = (int) (mTmpStableBounds.height() / density); final int overrideScreenHeightDp = (int) (mTmpStableBounds.height() / density);
inOutConfig.screenHeightDp = (insideParentBounds && !hasOverrideBounds) inOutConfig.screenHeightDp = (insideParentBounds && !customContainerPolicy)
? Math.min(overrideScreenHeightDp, parentConfig.screenHeightDp) ? Math.min(overrideScreenHeightDp, parentConfig.screenHeightDp)
: overrideScreenHeightDp; : overrideScreenHeightDp;
} }

View File

@@ -372,7 +372,9 @@ public class TaskRecordTests extends ActivityTestsBase {
final int longSide = 1200; final int longSide = 1200;
final int shortSide = 600; final int shortSide = 600;
final Rect parentBounds = new Rect(0, 0, 250, 500); final Rect parentBounds = new Rect(0, 0, 250, 500);
final Rect parentAppBounds = new Rect(0, 0, 250, 480);
parentConfig.windowConfiguration.setBounds(parentBounds); parentConfig.windowConfiguration.setBounds(parentBounds);
parentConfig.windowConfiguration.setAppBounds(parentAppBounds);
parentConfig.densityDpi = 400; parentConfig.densityDpi = 400;
parentConfig.screenHeightDp = (parentBounds.bottom * 160) / parentConfig.densityDpi; // 200 parentConfig.screenHeightDp = (parentBounds.bottom * 160) / parentConfig.densityDpi; // 200
parentConfig.screenWidthDp = (parentBounds.right * 160) / parentConfig.densityDpi; // 100 parentConfig.screenWidthDp = (parentBounds.right * 160) / parentConfig.densityDpi; // 100
@@ -383,21 +385,25 @@ public class TaskRecordTests extends ActivityTestsBase {
assertEquals(parentConfig.screenHeightDp, inOutConfig.screenHeightDp); assertEquals(parentConfig.screenHeightDp, inOutConfig.screenHeightDp);
assertEquals(parentConfig.screenWidthDp, inOutConfig.screenWidthDp); assertEquals(parentConfig.screenWidthDp, inOutConfig.screenWidthDp);
assertEquals(parentAppBounds, inOutConfig.windowConfiguration.getAppBounds());
assertEquals(Configuration.ORIENTATION_PORTRAIT, inOutConfig.orientation); assertEquals(Configuration.ORIENTATION_PORTRAIT, inOutConfig.orientation);
// If bounds are overridden, config properties should be made to match. Surface hierarchy // If bounds are overridden, config properties should be made to match. Surface hierarchy
// will crop for policy. // will crop for policy.
inOutConfig.setToDefaults(); inOutConfig.setToDefaults();
inOutConfig.windowConfiguration.getBounds().set(0, 0, shortSide, longSide); final Rect largerPortraitBounds = new Rect(0, 0, shortSide, longSide);
// By default, the parent bounds should limit the existing input bounds. inOutConfig.windowConfiguration.setBounds(largerPortraitBounds);
task.computeConfigResourceOverrides(inOutConfig, parentConfig); task.computeConfigResourceOverrides(inOutConfig, parentConfig);
// The override bounds are beyond the parent, the out appBounds should not be intersected
// by parent appBounds.
assertEquals(largerPortraitBounds, inOutConfig.windowConfiguration.getAppBounds());
assertEquals(longSide, inOutConfig.screenHeightDp * parentConfig.densityDpi / 160); assertEquals(longSide, inOutConfig.screenHeightDp * parentConfig.densityDpi / 160);
assertEquals(shortSide, inOutConfig.screenWidthDp * parentConfig.densityDpi / 160); assertEquals(shortSide, inOutConfig.screenWidthDp * parentConfig.densityDpi / 160);
inOutConfig.setToDefaults(); inOutConfig.setToDefaults();
// Landscape bounds. // Landscape bounds.
inOutConfig.windowConfiguration.getBounds().set(0, 0, longSide, shortSide); final Rect largerLandscapeBounds = new Rect(0, 0, longSide, shortSide);
inOutConfig.windowConfiguration.setBounds(largerLandscapeBounds);
// Setup the display with a top stable inset. The later assertion will ensure the inset is // Setup the display with a top stable inset. The later assertion will ensure the inset is
// excluded from screenHeightDp. // excluded from screenHeightDp.
@@ -415,6 +421,7 @@ public class TaskRecordTests extends ActivityTestsBase {
new ActivityRecord.CompatDisplayInsets(display, task); new ActivityRecord.CompatDisplayInsets(display, task);
task.computeConfigResourceOverrides(inOutConfig, parentConfig, compatIntsets); task.computeConfigResourceOverrides(inOutConfig, parentConfig, compatIntsets);
assertEquals(largerLandscapeBounds, inOutConfig.windowConfiguration.getAppBounds());
assertEquals((shortSide - statusBarHeight) * DENSITY_DEFAULT / parentConfig.densityDpi, assertEquals((shortSide - statusBarHeight) * DENSITY_DEFAULT / parentConfig.densityDpi,
inOutConfig.screenHeightDp); inOutConfig.screenHeightDp);
assertEquals(longSide * DENSITY_DEFAULT / parentConfig.densityDpi, assertEquals(longSide * DENSITY_DEFAULT / parentConfig.densityDpi,