Align the size calculation of task configuration
Since [1], screen dp size is rounded as px/density+0.5f. So the task configuration should use the same calculation for consistency. Which also avoids triggering unnecessary 1dp diff configuration change. [1]: I8f78d9bd14b7fb9d12a20a662ad4ec04f82ce7f2 Bug: 204481252 Test: TaskTests#testComputeConfigResourceOverrides Change-Id: I0fcd661551f38ce7f336b1319de5ae34826838a2
This commit is contained in:
@@ -2397,7 +2397,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
|
||||
sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode);
|
||||
sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode);
|
||||
sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode);
|
||||
outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
|
||||
outConfig.smallestScreenWidthDp =
|
||||
(int) (displayInfo.smallestNominalAppWidth / density + 0.5f);
|
||||
outConfig.screenLayout = sl;
|
||||
}
|
||||
|
||||
@@ -2419,8 +2420,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
|
||||
longSize = shortSize;
|
||||
shortSize = tmp;
|
||||
}
|
||||
longSize = (int)(longSize/density);
|
||||
shortSize = (int)(shortSize/density);
|
||||
longSize = (int) (longSize / density + 0.5f);
|
||||
shortSize = (int) (shortSize / density + 0.5f);
|
||||
return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
|
||||
}
|
||||
|
||||
|
||||
@@ -2039,13 +2039,14 @@ class TaskFragment extends WindowContainer<WindowContainer> {
|
||||
}
|
||||
|
||||
if (inOutConfig.screenWidthDp == Configuration.SCREEN_WIDTH_DP_UNDEFINED) {
|
||||
final int overrideScreenWidthDp = (int) (mTmpStableBounds.width() / density);
|
||||
final int overrideScreenWidthDp = (int) (mTmpStableBounds.width() / density + 0.5f);
|
||||
inOutConfig.screenWidthDp = (insideParentBounds && !customContainerPolicy)
|
||||
? Math.min(overrideScreenWidthDp, parentConfig.screenWidthDp)
|
||||
: overrideScreenWidthDp;
|
||||
}
|
||||
if (inOutConfig.screenHeightDp == Configuration.SCREEN_HEIGHT_DP_UNDEFINED) {
|
||||
final int overrideScreenHeightDp = (int) (mTmpStableBounds.height() / density);
|
||||
final int overrideScreenHeightDp =
|
||||
(int) (mTmpStableBounds.height() / density + 0.5f);
|
||||
inOutConfig.screenHeightDp = (insideParentBounds && !customContainerPolicy)
|
||||
? Math.min(overrideScreenHeightDp, parentConfig.screenHeightDp)
|
||||
: overrideScreenHeightDp;
|
||||
@@ -2063,8 +2064,8 @@ class TaskFragment extends WindowContainer<WindowContainer> {
|
||||
&& !mTmpFullBounds.isEmpty() && mTmpFullBounds.equals(parentBounds);
|
||||
if (WindowConfiguration.isFloating(windowingMode) && !inPipTransition) {
|
||||
// For floating tasks, calculate the smallest width from the bounds of the task
|
||||
inOutConfig.smallestScreenWidthDp = (int) (
|
||||
Math.min(mTmpFullBounds.width(), mTmpFullBounds.height()) / density);
|
||||
inOutConfig.smallestScreenWidthDp = (int) (0.5f
|
||||
+ Math.min(mTmpFullBounds.width(), mTmpFullBounds.height()) / density);
|
||||
}
|
||||
// otherwise, it will just inherit
|
||||
}
|
||||
@@ -2078,8 +2079,8 @@ class TaskFragment extends WindowContainer<WindowContainer> {
|
||||
// For calculating screen layout, we need to use the non-decor inset screen area for the
|
||||
// calculation for compatibility reasons, i.e. screen area without system bars that
|
||||
// could never go away in Honeycomb.
|
||||
int compatScreenWidthDp = (int) (mTmpNonDecorBounds.width() / density);
|
||||
int compatScreenHeightDp = (int) (mTmpNonDecorBounds.height() / density);
|
||||
int compatScreenWidthDp = (int) (mTmpNonDecorBounds.width() / density + 0.5f);
|
||||
int compatScreenHeightDp = (int) (mTmpNonDecorBounds.height() / density + 0.5f);
|
||||
// Use overrides if provided. If both overrides are provided, mTmpNonDecorBounds is
|
||||
// undefined so it can't be used.
|
||||
if (inOutConfig.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) {
|
||||
|
||||
@@ -31,7 +31,6 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
|
||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
import static android.util.DisplayMetrics.DENSITY_DEFAULT;
|
||||
import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_ENABLED;
|
||||
import static android.view.Surface.ROTATION_0;
|
||||
import static android.view.Surface.ROTATION_90;
|
||||
@@ -667,8 +666,6 @@ public class TaskTests extends WindowTestsBase {
|
||||
final Task task = new TaskBuilder(mSupervisor).setDisplay(display).build();
|
||||
final Configuration inOutConfig = new Configuration();
|
||||
final Configuration parentConfig = new Configuration();
|
||||
final int longSide = 1200;
|
||||
final int shortSide = 600;
|
||||
final Rect parentBounds = new Rect(0, 0, 250, 500);
|
||||
final Rect parentAppBounds = new Rect(0, 0, 250, 480);
|
||||
parentConfig.windowConfiguration.setBounds(parentBounds);
|
||||
@@ -689,14 +686,17 @@ public class TaskTests extends WindowTestsBase {
|
||||
// If bounds are overridden, config properties should be made to match. Surface hierarchy
|
||||
// will crop for policy.
|
||||
inOutConfig.setToDefaults();
|
||||
final int longSide = 960;
|
||||
final int shortSide = 540;
|
||||
parentConfig.densityDpi = 192;
|
||||
final Rect largerPortraitBounds = new Rect(0, 0, shortSide, longSide);
|
||||
inOutConfig.windowConfiguration.setBounds(largerPortraitBounds);
|
||||
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(shortSide, inOutConfig.screenWidthDp * parentConfig.densityDpi / 160);
|
||||
assertEquals(800, inOutConfig.screenHeightDp); // 960/(192/160) = 800
|
||||
assertEquals(450, inOutConfig.screenWidthDp); // 540/(192/160) = 450
|
||||
|
||||
inOutConfig.setToDefaults();
|
||||
// Landscape bounds.
|
||||
@@ -716,16 +716,17 @@ public class TaskTests extends WindowTestsBase {
|
||||
// Without limiting to be inside the parent bounds, the out screen size should keep relative
|
||||
// to the input bounds.
|
||||
final ActivityRecord activity = new ActivityBuilder(mAtm).setTask(task).build();
|
||||
final ActivityRecord.CompatDisplayInsets compatIntsets =
|
||||
final ActivityRecord.CompatDisplayInsets compatInsets =
|
||||
new ActivityRecord.CompatDisplayInsets(
|
||||
display, activity, /* fixedOrientationBounds= */ null);
|
||||
task.computeConfigResourceOverrides(inOutConfig, parentConfig, compatIntsets);
|
||||
task.computeConfigResourceOverrides(inOutConfig, parentConfig, compatInsets);
|
||||
|
||||
assertEquals(largerLandscapeBounds, inOutConfig.windowConfiguration.getAppBounds());
|
||||
assertEquals((shortSide - statusBarHeight) * DENSITY_DEFAULT / parentConfig.densityDpi,
|
||||
inOutConfig.screenHeightDp);
|
||||
assertEquals(longSide * DENSITY_DEFAULT / parentConfig.densityDpi,
|
||||
inOutConfig.screenWidthDp);
|
||||
final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
|
||||
final int expectedHeightDp = (int) ((shortSide - statusBarHeight) / density + 0.5f);
|
||||
assertEquals(expectedHeightDp, inOutConfig.screenHeightDp);
|
||||
final int expectedWidthDp = (int) (longSide / density + 0.5f);
|
||||
assertEquals(expectedWidthDp, inOutConfig.screenWidthDp);
|
||||
assertEquals(Configuration.ORIENTATION_LANDSCAPE, inOutConfig.orientation);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user