Make screenLayout calculation consistent
Generally this reverts [1] that uses the smallest layout
in all rotations. Because
1. According to the definition to screenLayout, it is more like
the current size instead of smallest possible value.
2. Since [2][3], the configuration passed to app already only
calculates from current size.
This fixes the inconsistent calculation, e.g. for the same size,
the task may calculate landscape configuration with LARGE and
portrait configuration with NORMAL. But the display always gets
NORMAL for portrait and landscape.
[1]: I85f90a16294ef5a7de94d5b9231abbc6f914fe90
[2]: Ie27020616983646b274b073f17accea627399df0
[3]: I0fcec4f035e466fafedc31be5925c0b04a6580f7
Bug: 233855302
Bug: 253386061
Test: atest DisplayContentTests ConfigurationScreenLayoutTest
Change-Id: If806e2a42a6c3c548d93ba43c1aed69889901193
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 2232aa1..81bb3a1 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -8454,7 +8454,7 @@
getTaskFragment().computeConfigResourceOverrides(resolvedConfig, newParentConfiguration,
mCompatDisplayInsets);
// Use current screen layout as source because the size of app is independent to parent.
- resolvedConfig.screenLayout = TaskFragment.computeScreenLayoutOverride(
+ resolvedConfig.screenLayout = computeScreenLayout(
getConfiguration().screenLayout, resolvedConfig.screenWidthDp,
resolvedConfig.screenHeightDp);
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index 3c847ce..739f41f 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -2188,8 +2188,7 @@
mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
}
- computeSizeRangesAndScreenLayout(mDisplayInfo, rotated, dw, dh,
- mDisplayMetrics.density, outConfig);
+ computeSizeRanges(mDisplayInfo, rotated, dw, dh, mDisplayMetrics.density, outConfig);
mWmService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
mDisplayInfo);
@@ -2289,8 +2288,7 @@
displayInfo.appHeight = appBounds.height();
final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(rotation);
displayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
- computeSizeRangesAndScreenLayout(displayInfo, rotated, dw, dh,
- mDisplayMetrics.density, outConfig);
+ computeSizeRanges(displayInfo, rotated, dw, dh, mDisplayMetrics.density, outConfig);
return displayInfo;
}
@@ -2309,6 +2307,9 @@
outConfig.screenHeightDp = (int) (info.mConfigFrame.height() / density + 0.5f);
outConfig.compatScreenWidthDp = (int) (outConfig.screenWidthDp / mCompatibleScreenScale);
outConfig.compatScreenHeightDp = (int) (outConfig.screenHeightDp / mCompatibleScreenScale);
+ outConfig.screenLayout = computeScreenLayout(
+ Configuration.resetScreenLayout(outConfig.screenLayout),
+ outConfig.screenWidthDp, outConfig.screenHeightDp);
final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
outConfig.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, dw, dh);
@@ -2450,7 +2451,7 @@
return curSize;
}
- private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated,
+ private void computeSizeRanges(DisplayInfo displayInfo, boolean rotated,
int dw, int dh, float density, Configuration outConfig) {
// We need to determine the smallest width that will occur under normal
@@ -2477,31 +2478,8 @@
if (outConfig == null) {
return;
}
- int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
- sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh);
- sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw);
- sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh);
- sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw);
outConfig.smallestScreenWidthDp =
(int) (displayInfo.smallestNominalAppWidth / density + 0.5f);
- outConfig.screenLayout = sl;
- }
-
- private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh) {
- // Get the app screen size at this rotation.
- final Rect size = mDisplayPolicy.getDecorInsetsInfo(rotation, dw, dh).mNonDecorFrame;
-
- // Compute the screen layout size class for this rotation.
- int longSize = size.width();
- int shortSize = size.height();
- if (longSize < shortSize) {
- int tmp = longSize;
- longSize = shortSize;
- shortSize = tmp;
- }
- longSize = (int) (longSize / density + 0.5f);
- shortSize = (int) (shortSize / density + 0.5f);
- return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
}
private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, int dw, int dh) {
diff --git a/services/core/java/com/android/server/wm/TaskFragment.java b/services/core/java/com/android/server/wm/TaskFragment.java
index efb6302..230b760 100644
--- a/services/core/java/com/android/server/wm/TaskFragment.java
+++ b/services/core/java/com/android/server/wm/TaskFragment.java
@@ -2189,7 +2189,7 @@
compatScreenHeightDp = inOutConfig.screenHeightDp;
}
// Reducing the screen layout starting from its parent config.
- inOutConfig.screenLayout = computeScreenLayoutOverride(parentConfig.screenLayout,
+ inOutConfig.screenLayout = computeScreenLayout(parentConfig.screenLayout,
compatScreenWidthDp, compatScreenHeightDp);
}
}
@@ -2252,16 +2252,6 @@
}
}
- /** Computes LONG, SIZE and COMPAT parts of {@link Configuration#screenLayout}. */
- static int computeScreenLayoutOverride(int sourceScreenLayout, int screenWidthDp,
- int screenHeightDp) {
- sourceScreenLayout = sourceScreenLayout
- & (Configuration.SCREENLAYOUT_LONG_MASK | Configuration.SCREENLAYOUT_SIZE_MASK);
- final int longSize = Math.max(screenWidthDp, screenHeightDp);
- final int shortSize = Math.min(screenWidthDp, screenHeightDp);
- return Configuration.reduceScreenLayout(sourceScreenLayout, longSize, shortSize);
- }
-
@Override
public int getActivityType() {
final int applicationType = super.getActivityType();
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index 9763df6..c4c66d8 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -1607,6 +1607,16 @@
return false;
}
+ /** Computes LONG, SIZE and COMPAT parts of {@link Configuration#screenLayout}. */
+ static int computeScreenLayout(int sourceScreenLayout, int screenWidthDp,
+ int screenHeightDp) {
+ sourceScreenLayout = sourceScreenLayout
+ & (Configuration.SCREENLAYOUT_LONG_MASK | Configuration.SCREENLAYOUT_SIZE_MASK);
+ final int longSize = Math.max(screenWidthDp, screenHeightDp);
+ final int shortSize = Math.min(screenWidthDp, screenHeightDp);
+ return Configuration.reduceScreenLayout(sourceScreenLayout, longSize, shortSize);
+ }
+
// TODO: Users would have their own window containers under the display container?
void switchUser(int userId) {
for (int i = mChildren.size() - 1; i >= 0; --i) {
diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java
index 8055590..7c481f5 100644
--- a/services/core/java/com/android/server/wm/WindowToken.java
+++ b/services/core/java/com/android/server/wm/WindowToken.java
@@ -448,14 +448,8 @@
if (mFixedRotationTransformState != null) {
mFixedRotationTransformState.disassociate(this);
}
- // TODO(b/233855302): Remove TaskFragment override if the DisplayContent uses the same
- // bounds for screenLayout calculation.
- final Configuration overrideConfig = new Configuration(config);
- overrideConfig.screenLayout = TaskFragment.computeScreenLayoutOverride(
- overrideConfig.screenLayout, overrideConfig.screenWidthDp,
- overrideConfig.screenHeightDp);
mFixedRotationTransformState = new FixedRotationTransformState(info, displayFrames,
- overrideConfig, mDisplayContent.getRotation());
+ new Configuration(config), mDisplayContent.getRotation());
mFixedRotationTransformState.mAssociatedTokens.add(this);
mDisplayContent.getDisplayPolicy().simulateLayoutDisplay(displayFrames);
onFixedRotationStatePrepared();
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
index 11ae5d4..e69418b 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
@@ -2314,6 +2314,8 @@
assertEquals(displayWidth, windowConfig.getBounds().width());
assertEquals(displayHeight, windowConfig.getBounds().height());
assertEquals(windowingMode, windowConfig.getWindowingMode());
+ assertEquals(Configuration.SCREENLAYOUT_SIZE_NORMAL,
+ config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);
// test misc display overrides
assertEquals(ignoreOrientationRequests, testDisplayContent.mSetIgnoreOrientationRequest);
@@ -2355,6 +2357,8 @@
assertEquals(displayWidth, windowConfig.getBounds().width());
assertEquals(displayHeight, windowConfig.getBounds().height());
assertEquals(windowingMode, windowConfig.getWindowingMode());
+ assertEquals(Configuration.SCREENLAYOUT_SIZE_LARGE, testDisplayContent
+ .getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);
// test misc display overrides
assertEquals(ignoreOrientationRequests, testDisplayContent.mSetIgnoreOrientationRequest);