Merge "Revert "Adjust smallestScreenWidthDp for letterbox"" into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-07-21 20:01:21 +00:00
committed by Android (Google) Code Review
4 changed files with 18 additions and 101 deletions

View File

@@ -7738,6 +7738,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
// relatively fixed. // relatively fixed.
overrideConfig.colorMode = fullConfig.colorMode; overrideConfig.colorMode = fullConfig.colorMode;
overrideConfig.densityDpi = fullConfig.densityDpi; overrideConfig.densityDpi = fullConfig.densityDpi;
// The smallest screen width is the short side of screen bounds. Because the bounds
// and density won't be changed, smallestScreenWidthDp is also fixed.
overrideConfig.smallestScreenWidthDp = fullConfig.smallestScreenWidthDp;
if (info.isFixedOrientation()) { if (info.isFixedOrientation()) {
// lock rotation too. When in size-compat, onConfigurationChanged will watch for and // lock rotation too. When in size-compat, onConfigurationChanged will watch for and
// apply runtime rotation changes. // apply runtime rotation changes.
@@ -7834,7 +7837,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
// computed accordingly. // computed accordingly.
if (!matchParentBounds()) { if (!matchParentBounds()) {
getTaskFragment().computeConfigResourceOverrides(resolvedConfig, getTaskFragment().computeConfigResourceOverrides(resolvedConfig,
newParentConfiguration, areBoundsLetterboxed()); newParentConfiguration);
} }
// If activity in fullscreen mode is letterboxed because of fixed orientation then bounds // If activity in fullscreen mode is letterboxed because of fixed orientation then bounds
// are already calculated in resolveFixedOrientationConfiguration. // are already calculated in resolveFixedOrientationConfiguration.
@@ -8005,8 +8008,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
} }
// Since bounds has changed, the configuration needs to be computed accordingly. // Since bounds has changed, the configuration needs to be computed accordingly.
getTaskFragment().computeConfigResourceOverrides(resolvedConfig, newParentConfiguration, getTaskFragment().computeConfigResourceOverrides(resolvedConfig, newParentConfiguration);
areBoundsLetterboxed());
} }
void recomputeConfiguration() { void recomputeConfiguration() {
@@ -8222,7 +8224,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
// Calculate app bounds using fixed orientation bounds because they will be needed later // Calculate app bounds using fixed orientation bounds because they will be needed later
// for comparison with size compat app bounds in {@link resolveSizeCompatModeConfiguration}. // for comparison with size compat app bounds in {@link resolveSizeCompatModeConfiguration}.
getTaskFragment().computeConfigResourceOverrides(getResolvedOverrideConfiguration(), getTaskFragment().computeConfigResourceOverrides(getResolvedOverrideConfiguration(),
newParentConfig, mCompatDisplayInsets, areBoundsLetterboxed()); newParentConfig);
mLetterboxBoundsForFixedOrientationAndAspectRatio = new Rect(resolvedBounds); mLetterboxBoundsForFixedOrientationAndAspectRatio = new Rect(resolvedBounds);
} }
@@ -8250,7 +8252,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
// Compute the configuration based on the resolved bounds. If aspect ratio doesn't // Compute the configuration based on the resolved bounds. If aspect ratio doesn't
// restrict, the bounds should be the requested override bounds. // restrict, the bounds should be the requested override bounds.
getTaskFragment().computeConfigResourceOverrides(resolvedConfig, newParentConfiguration, getTaskFragment().computeConfigResourceOverrides(resolvedConfig, newParentConfiguration,
getFixedRotationTransformDisplayInfo(), areBoundsLetterboxed()); getFixedRotationTransformDisplayInfo());
} }
} }
@@ -8314,7 +8316,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
// are calculated in compat container space. The actual position on screen will be applied // are calculated in compat container space. The actual position on screen will be applied
// later, so the calculation is simpler that doesn't need to involve offset from parent. // later, so the calculation is simpler that doesn't need to involve offset from parent.
getTaskFragment().computeConfigResourceOverrides(resolvedConfig, newParentConfiguration, getTaskFragment().computeConfigResourceOverrides(resolvedConfig, newParentConfiguration,
mCompatDisplayInsets, areBoundsLetterboxed()); mCompatDisplayInsets);
// Use current screen layout as source because the size of app is independent to parent. // Use current screen layout as source because the size of app is independent to parent.
resolvedConfig.screenLayout = TaskFragment.computeScreenLayoutOverride( resolvedConfig.screenLayout = TaskFragment.computeScreenLayoutOverride(
getConfiguration().screenLayout, resolvedConfig.screenWidthDp, getConfiguration().screenLayout, resolvedConfig.screenWidthDp,

View File

@@ -1957,37 +1957,29 @@ class TaskFragment extends WindowContainer<WindowContainer> {
void computeConfigResourceOverrides(@NonNull Configuration inOutConfig, void computeConfigResourceOverrides(@NonNull Configuration inOutConfig,
@NonNull Configuration parentConfig) { @NonNull Configuration parentConfig) {
computeConfigResourceOverrides(inOutConfig, parentConfig, null /* overrideDisplayInfo */, computeConfigResourceOverrides(inOutConfig, parentConfig, null /* overrideDisplayInfo */,
null /* compatInsets */, false /* areBoundsLetterboxed */); null /* compatInsets */);
} }
void computeConfigResourceOverrides(@NonNull Configuration inOutConfig, void computeConfigResourceOverrides(@NonNull Configuration inOutConfig,
@NonNull Configuration parentConfig, boolean areBoundsLetterboxed) { @NonNull Configuration parentConfig, @Nullable DisplayInfo overrideDisplayInfo) {
computeConfigResourceOverrides(inOutConfig, parentConfig, null /* overrideDisplayInfo */,
null /* compatInsets */, areBoundsLetterboxed);
}
void computeConfigResourceOverrides(@NonNull Configuration inOutConfig,
@NonNull Configuration parentConfig, @Nullable DisplayInfo overrideDisplayInfo,
boolean areBoundsLetterboxed) {
if (overrideDisplayInfo != null) { if (overrideDisplayInfo != null) {
// Make sure the screen related configs can be computed by the provided display info. // Make sure the screen related configs can be computed by the provided display info.
inOutConfig.screenLayout = Configuration.SCREENLAYOUT_UNDEFINED; inOutConfig.screenLayout = Configuration.SCREENLAYOUT_UNDEFINED;
invalidateAppBoundsConfig(inOutConfig); invalidateAppBoundsConfig(inOutConfig);
} }
computeConfigResourceOverrides(inOutConfig, parentConfig, overrideDisplayInfo, computeConfigResourceOverrides(inOutConfig, parentConfig, overrideDisplayInfo,
null /* compatInsets */, areBoundsLetterboxed); null /* compatInsets */);
} }
void computeConfigResourceOverrides(@NonNull Configuration inOutConfig, void computeConfigResourceOverrides(@NonNull Configuration inOutConfig,
@NonNull Configuration parentConfig, @NonNull Configuration parentConfig,
@Nullable ActivityRecord.CompatDisplayInsets compatInsets, @Nullable ActivityRecord.CompatDisplayInsets compatInsets) {
boolean areBoundsLetterboxed) {
if (compatInsets != null) { if (compatInsets != null) {
// Make sure the app bounds can be computed by the compat insets. // Make sure the app bounds can be computed by the compat insets.
invalidateAppBoundsConfig(inOutConfig); invalidateAppBoundsConfig(inOutConfig);
} }
computeConfigResourceOverrides(inOutConfig, parentConfig, null /* overrideDisplayInfo */, computeConfigResourceOverrides(inOutConfig, parentConfig, null /* overrideDisplayInfo */,
compatInsets, areBoundsLetterboxed); compatInsets);
} }
/** /**
@@ -2014,8 +2006,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
**/ **/
void computeConfigResourceOverrides(@NonNull Configuration inOutConfig, void computeConfigResourceOverrides(@NonNull Configuration inOutConfig,
@NonNull Configuration parentConfig, @Nullable DisplayInfo overrideDisplayInfo, @NonNull Configuration parentConfig, @Nullable DisplayInfo overrideDisplayInfo,
@Nullable ActivityRecord.CompatDisplayInsets compatInsets, @Nullable ActivityRecord.CompatDisplayInsets compatInsets) {
boolean areBoundsLetterboxed) {
int windowingMode = inOutConfig.windowConfiguration.getWindowingMode(); int windowingMode = inOutConfig.windowConfiguration.getWindowingMode();
if (windowingMode == WINDOWING_MODE_UNDEFINED) { if (windowingMode == WINDOWING_MODE_UNDEFINED) {
windowingMode = parentConfig.windowConfiguration.getWindowingMode(); windowingMode = parentConfig.windowConfiguration.getWindowingMode();
@@ -2122,7 +2113,6 @@ class TaskFragment extends WindowContainer<WindowContainer> {
: overrideScreenHeightDp; : overrideScreenHeightDp;
} }
// TODO(b/238331848): Consider simplifying logic that computes smallestScreenWidthDp.
if (inOutConfig.smallestScreenWidthDp if (inOutConfig.smallestScreenWidthDp
== Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { == Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
// When entering to or exiting from Pip, the PipTaskOrganizer will set the // When entering to or exiting from Pip, the PipTaskOrganizer will set the
@@ -2138,10 +2128,9 @@ class TaskFragment extends WindowContainer<WindowContainer> {
// task, because they should not be affected by insets. // task, because they should not be affected by insets.
inOutConfig.smallestScreenWidthDp = (int) (0.5f inOutConfig.smallestScreenWidthDp = (int) (0.5f
+ Math.min(mTmpFullBounds.width(), mTmpFullBounds.height()) / density); + Math.min(mTmpFullBounds.width(), mTmpFullBounds.height()) / density);
} else if (isEmbedded() || areBoundsLetterboxed || customContainerPolicy) { } else if (isEmbedded()) {
// For embedded TFs and activities that are letteboxed or eligible for size // For embedded TFs, the smallest width should be updated. Otherwise, inherit
// compat mode, the smallest width should be updated. Otherwise, inherit from // from the parent task would result in applications loaded wrong resource.
// the parent task would result in applications loaded wrong resource.
inOutConfig.smallestScreenWidthDp = inOutConfig.smallestScreenWidthDp =
Math.min(inOutConfig.screenWidthDp, inOutConfig.screenHeightDp); Math.min(inOutConfig.screenWidthDp, inOutConfig.screenHeightDp);
} }

View File

@@ -1495,79 +1495,6 @@ public class SizeCompatTests extends WindowTestsBase {
assertEquals(displayBounds.height() / defaultAspectRatio, activityBounds.width(), 0.5); assertEquals(displayBounds.height() / defaultAspectRatio, activityBounds.width(), 0.5);
} }
@Test
public void testComputeConfigResourceOverrides_unresizableApp() {
// Set up a display in landscape and ignoring orientation request.
setUpDisplaySizeWithApp(2800, 1400);
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT);
final Rect activityBounds = new Rect(mActivity.getBounds());
int originalScreenWidthDp = mActivity.getConfiguration().screenWidthDp;
int originalScreenHeighthDp = mActivity.getConfiguration().screenHeightDp;
// App should launch in fixed orientation letterbox.
// Activity bounds should be 700x1400 with the ratio as the display.
assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio());
assertFitted();
assertEquals(originalScreenWidthDp, mActivity.getConfiguration().smallestScreenWidthDp);
assertTrue(originalScreenWidthDp < originalScreenHeighthDp);
// Rotate display to portrait.
rotateDisplay(mActivity.mDisplayContent, ROTATION_90);
// After we rotate, the activity should go in the size-compat mode and report the same
// configuration values.
assertScaled();
assertEquals(originalScreenWidthDp, mActivity.getConfiguration().smallestScreenWidthDp);
assertEquals(originalScreenWidthDp, mActivity.getConfiguration().screenWidthDp);
assertEquals(originalScreenHeighthDp, mActivity.getConfiguration().screenHeightDp);
// Restart activity
mActivity.restartProcessIfVisible();
// Now configuration should be updated
assertFitted();
assertNotEquals(originalScreenWidthDp, mActivity.getConfiguration().screenWidthDp);
assertNotEquals(originalScreenHeighthDp, mActivity.getConfiguration().screenHeightDp);
assertEquals(mActivity.getConfiguration().screenWidthDp,
mActivity.getConfiguration().smallestScreenWidthDp);
}
@Test
public void testComputeConfigResourceOverrides_resizableFixedOrientationActivity() {
// Set up a display in landscape and ignoring orientation request.
setUpDisplaySizeWithApp(2800, 1400);
mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
// Portrait fixed app without max aspect.
prepareLimitedBounds(mActivity, SCREEN_ORIENTATION_PORTRAIT, false /* isUnresizable */);
final Rect activityBounds = new Rect(mActivity.getBounds());
int originalScreenWidthDp = mActivity.getConfiguration().screenWidthDp;
int originalScreenHeighthDp = mActivity.getConfiguration().screenHeightDp;
// App should launch in fixed orientation letterbox.
// Activity bounds should be 700x1400 with the ratio as the display.
assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio());
assertFitted();
assertEquals(originalScreenWidthDp, mActivity.getConfiguration().smallestScreenWidthDp);
assertTrue(originalScreenWidthDp < originalScreenHeighthDp);
// Rotate display to portrait.
rotateDisplay(mActivity.mDisplayContent, ROTATION_90);
// Now configuration should be updated
assertFitted();
assertNotEquals(originalScreenWidthDp, mActivity.getConfiguration().screenWidthDp);
assertNotEquals(originalScreenHeighthDp, mActivity.getConfiguration().screenHeightDp);
assertEquals(mActivity.getConfiguration().screenWidthDp,
mActivity.getConfiguration().smallestScreenWidthDp);
}
@Test @Test
public void testSplitAspectRatioForUnresizablePortraitApps() { public void testSplitAspectRatioForUnresizablePortraitApps() {
// Set up a display in landscape and ignoring orientation request. // Set up a display in landscape and ignoring orientation request.

View File

@@ -705,8 +705,7 @@ public class TaskTests extends WindowTestsBase {
final ActivityRecord.CompatDisplayInsets compatInsets = final ActivityRecord.CompatDisplayInsets compatInsets =
new ActivityRecord.CompatDisplayInsets( new ActivityRecord.CompatDisplayInsets(
display, activity, /* fixedOrientationBounds= */ null); display, activity, /* fixedOrientationBounds= */ null);
task.computeConfigResourceOverrides( task.computeConfigResourceOverrides(inOutConfig, parentConfig, compatInsets);
inOutConfig, parentConfig, compatInsets, /* areBoundsLetterboxed */ true);
assertEquals(largerLandscapeBounds, inOutConfig.windowConfiguration.getAppBounds()); assertEquals(largerLandscapeBounds, inOutConfig.windowConfiguration.getAppBounds());
final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE; final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;