Merge "Align the size calculation of task configuration" into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-05-18 07:05:14 +00:00
committed by Android (Google) Code Review
3 changed files with 23 additions and 20 deletions

View File

@@ -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_90, density, unrotDh, unrotDw, uiMode);
sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode); sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode);
sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, 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; outConfig.screenLayout = sl;
} }
@@ -2419,8 +2420,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
longSize = shortSize; longSize = shortSize;
shortSize = tmp; shortSize = tmp;
} }
longSize = (int)(longSize/density); longSize = (int) (longSize / density + 0.5f);
shortSize = (int)(shortSize/density); shortSize = (int) (shortSize / density + 0.5f);
return Configuration.reduceScreenLayout(curLayout, longSize, shortSize); return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
} }

View File

@@ -2039,13 +2039,14 @@ class TaskFragment 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 + 0.5f);
inOutConfig.screenWidthDp = (insideParentBounds && !customContainerPolicy) 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 + 0.5f);
inOutConfig.screenHeightDp = (insideParentBounds && !customContainerPolicy) inOutConfig.screenHeightDp = (insideParentBounds && !customContainerPolicy)
? Math.min(overrideScreenHeightDp, parentConfig.screenHeightDp) ? Math.min(overrideScreenHeightDp, parentConfig.screenHeightDp)
: overrideScreenHeightDp; : overrideScreenHeightDp;
@@ -2063,8 +2064,8 @@ class TaskFragment extends WindowContainer<WindowContainer> {
&& !mTmpFullBounds.isEmpty() && mTmpFullBounds.equals(parentBounds); && !mTmpFullBounds.isEmpty() && mTmpFullBounds.equals(parentBounds);
if (WindowConfiguration.isFloating(windowingMode) && !inPipTransition) { if (WindowConfiguration.isFloating(windowingMode) && !inPipTransition) {
// For floating tasks, calculate the smallest width from the bounds of the task // For floating tasks, calculate the smallest width from the bounds of the task
inOutConfig.smallestScreenWidthDp = (int) ( inOutConfig.smallestScreenWidthDp = (int) (0.5f
Math.min(mTmpFullBounds.width(), mTmpFullBounds.height()) / density); + Math.min(mTmpFullBounds.width(), mTmpFullBounds.height()) / density);
} }
// otherwise, it will just inherit // 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 // 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 // calculation for compatibility reasons, i.e. screen area without system bars that
// could never go away in Honeycomb. // could never go away in Honeycomb.
int compatScreenWidthDp = (int) (mTmpNonDecorBounds.width() / density); int compatScreenWidthDp = (int) (mTmpNonDecorBounds.width() / density + 0.5f);
int compatScreenHeightDp = (int) (mTmpNonDecorBounds.height() / density); int compatScreenHeightDp = (int) (mTmpNonDecorBounds.height() / density + 0.5f);
// Use overrides if provided. If both overrides are provided, mTmpNonDecorBounds is // Use overrides if provided. If both overrides are provided, mTmpNonDecorBounds is
// undefined so it can't be used. // undefined so it can't be used.
if (inOutConfig.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { if (inOutConfig.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) {

View File

@@ -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_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; 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.IWindowManager.FIXED_TO_USER_ROTATION_ENABLED;
import static android.view.Surface.ROTATION_0; import static android.view.Surface.ROTATION_0;
import static android.view.Surface.ROTATION_90; 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 Task task = new TaskBuilder(mSupervisor).setDisplay(display).build();
final Configuration inOutConfig = new Configuration(); final Configuration inOutConfig = new Configuration();
final Configuration parentConfig = 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 parentBounds = new Rect(0, 0, 250, 500);
final Rect parentAppBounds = new Rect(0, 0, 250, 480); final Rect parentAppBounds = new Rect(0, 0, 250, 480);
parentConfig.windowConfiguration.setBounds(parentBounds); 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 // 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();
final int longSide = 960;
final int shortSide = 540;
parentConfig.densityDpi = 192;
final Rect largerPortraitBounds = new Rect(0, 0, shortSide, longSide); final Rect largerPortraitBounds = new Rect(0, 0, shortSide, longSide);
inOutConfig.windowConfiguration.setBounds(largerPortraitBounds); 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 // The override bounds are beyond the parent, the out appBounds should not be intersected
// by parent appBounds. // by parent appBounds.
assertEquals(largerPortraitBounds, inOutConfig.windowConfiguration.getAppBounds()); assertEquals(largerPortraitBounds, inOutConfig.windowConfiguration.getAppBounds());
assertEquals(longSide, inOutConfig.screenHeightDp * parentConfig.densityDpi / 160); assertEquals(800, inOutConfig.screenHeightDp); // 960/(192/160) = 800
assertEquals(shortSide, inOutConfig.screenWidthDp * parentConfig.densityDpi / 160); assertEquals(450, inOutConfig.screenWidthDp); // 540/(192/160) = 450
inOutConfig.setToDefaults(); inOutConfig.setToDefaults();
// Landscape bounds. // 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 // Without limiting to be inside the parent bounds, the out screen size should keep relative
// to the input bounds. // to the input bounds.
final ActivityRecord activity = new ActivityBuilder(mAtm).setTask(task).build(); final ActivityRecord activity = new ActivityBuilder(mAtm).setTask(task).build();
final ActivityRecord.CompatDisplayInsets compatIntsets = final ActivityRecord.CompatDisplayInsets compatInsets =
new ActivityRecord.CompatDisplayInsets( new ActivityRecord.CompatDisplayInsets(
display, activity, /* fixedOrientationBounds= */ null); display, activity, /* fixedOrientationBounds= */ null);
task.computeConfigResourceOverrides(inOutConfig, parentConfig, compatIntsets); task.computeConfigResourceOverrides(inOutConfig, parentConfig, compatInsets);
assertEquals(largerLandscapeBounds, inOutConfig.windowConfiguration.getAppBounds()); assertEquals(largerLandscapeBounds, inOutConfig.windowConfiguration.getAppBounds());
assertEquals((shortSide - statusBarHeight) * DENSITY_DEFAULT / parentConfig.densityDpi, final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
inOutConfig.screenHeightDp); final int expectedHeightDp = (int) ((shortSide - statusBarHeight) / density + 0.5f);
assertEquals(longSide * DENSITY_DEFAULT / parentConfig.densityDpi, assertEquals(expectedHeightDp, inOutConfig.screenHeightDp);
inOutConfig.screenWidthDp); final int expectedWidthDp = (int) (longSide / density + 0.5f);
assertEquals(expectedWidthDp, inOutConfig.screenWidthDp);
assertEquals(Configuration.ORIENTATION_LANDSCAPE, inOutConfig.orientation); assertEquals(Configuration.ORIENTATION_LANDSCAPE, inOutConfig.orientation);
} }