Merge "Fix size compat bounds in close-to-square display" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-05-26 15:14:10 +00:00
committed by Android (Google) Code Review
2 changed files with 15 additions and 8 deletions

View File

@@ -6535,14 +6535,14 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
final Configuration resolvedConfig = getResolvedOverrideConfiguration();
final Rect resolvedBounds = resolvedConfig.windowConfiguration.getBounds();
final int requestedOrientation = getRequestedConfigurationOrientation();
final boolean orientationRequested = requestedOrientation != ORIENTATION_UNDEFINED;
final boolean orientationRequested = requestedOrientation != ORIENTATION_UNDEFINED
&& !mDisplayContent.ignoreRotationForApps();
final int orientation = orientationRequested
? requestedOrientation
: newParentConfiguration.orientation;
int rotation = newParentConfiguration.windowConfiguration.getRotation();
final boolean canChangeOrientation = handlesOrientationChangeFromDescendant();
if (canChangeOrientation && mCompatDisplayInsets.mIsRotatable
&& !mCompatDisplayInsets.mIsFloating) {
if (canChangeOrientation && !mCompatDisplayInsets.mIsFloating) {
// Use parent rotation because the original display can rotate by requested orientation.
resolvedConfig.windowConfiguration.setRotation(rotation);
} else {
@@ -7628,7 +7628,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
private final int mWidth;
private final int mHeight;
final boolean mIsFloating;
final boolean mIsRotatable;
/**
* The nonDecorInsets for each rotation. Includes the navigation bar and cutout insets. It
@@ -7645,7 +7644,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
/** Constructs the environment to simulate the bounds behavior of the given container. */
CompatDisplayInsets(DisplayContent display, WindowContainer container) {
mIsFloating = container.getWindowConfiguration().tasksAreFloating();
mIsRotatable = !mIsFloating && !display.ignoreRotationForApps();
if (mIsFloating) {
final Rect containerBounds = container.getWindowConfiguration().getBounds();
mWidth = containerBounds.width();
@@ -7702,7 +7700,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
return;
}
if (mIsRotatable && canChangeOrientation) {
if (canChangeOrientation) {
getBoundsByRotation(outBounds, rotation);
if (orientationRequested) {
getFrameByOrientation(outAppBounds, orientation);

View File

@@ -138,7 +138,7 @@ public class SizeCompatTests extends ActivityTestsBase {
// Rotation is ignored so because the display size is close to square (700/600<1.333).
assertTrue(mActivity.mDisplayContent.ignoreRotationForApps());
final Rect displayBounds = mActivity.mDisplayContent.getBounds();
final Rect displayBounds = mActivity.mDisplayContent.getWindowConfiguration().getBounds();
final float aspectRatio = 1.2f;
mActivity.info.minAspectRatio = mActivity.info.maxAspectRatio = aspectRatio;
prepareUnresizable(-1f, SCREEN_ORIENTATION_UNSPECIFIED);
@@ -160,13 +160,22 @@ public class SizeCompatTests extends ActivityTestsBase {
assertFitted();
// After the orientation of activity is changed, even display is not rotated, the aspect
// ratio should be the same (bounds=[0, 0 - 600, 600], appBounds=[0, 100 - 600, 600]).
// ratio should be the same (appBounds=[9, 100 - 592, 800], x-offset=round((600-583)/2)=9).
assertEquals(appBounds.width(), appBounds.height() * aspectRatio, 0.5f /* delta */);
// The notch is still on top.
assertEquals(mActivity.getBounds().height(), appBounds.height() + notchHeight);
mActivity.setRequestedOrientation(SCREEN_ORIENTATION_PORTRAIT);
assertFitted();
// Close-to-square display can rotate without being restricted by the requested orientation.
// The notch becomes on the left side. The activity is horizontal centered in 100 ~ 800.
// So the bounds and appBounds will be [200, 0 - 700, 600] (500x600) that is still fitted.
// Left = 100 + (800 - 100 - 500) / 2 = 200.
rotateDisplay(mActivity.mDisplayContent, ROTATION_90);
assertFitted();
assertEquals(appBounds.left,
notchHeight + (displayBounds.width() - notchHeight - appBounds.width()) / 2);
}
@Test