Skip to content

Commit 2a30547

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Work on issue #6949468: android.dpi.cts.ConfigurationScreenLayoutTest..." into jb-mr1-dev
2 parents 2b58c1b + fe37f8f commit 2a30547

File tree

3 files changed

+84
-70
lines changed

3 files changed

+84
-70
lines changed

core/java/android/app/ActivityThread.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3872,14 +3872,20 @@ final boolean applyConfigurationToResourcesLocked(Configuration config,
38723872

38733873
final void applyNonDefaultDisplayMetricsToConfigurationLocked(
38743874
DisplayMetrics dm, Configuration config) {
3875-
config.screenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE
3876-
| Configuration.SCREENLAYOUT_LONG_NO;
38773875
config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
3878-
config.orientation = (dm.widthPixels >= dm.heightPixels) ?
3879-
Configuration.ORIENTATION_LANDSCAPE : Configuration.ORIENTATION_PORTRAIT;
38803876
config.densityDpi = dm.densityDpi;
38813877
config.screenWidthDp = (int)(dm.widthPixels / dm.density);
38823878
config.screenHeightDp = (int)(dm.heightPixels / dm.density);
3879+
int sl = Configuration.resetScreenLayout(config.screenLayout);
3880+
if (dm.widthPixels > dm.heightPixels) {
3881+
config.orientation = Configuration.ORIENTATION_LANDSCAPE;
3882+
config.screenLayout = Configuration.reduceScreenLayout(sl,
3883+
config.screenWidthDp, config.screenHeightDp);
3884+
} else {
3885+
config.orientation = Configuration.ORIENTATION_PORTRAIT;
3886+
config.screenLayout = Configuration.reduceScreenLayout(sl,
3887+
config.screenHeightDp, config.screenWidthDp);
3888+
}
38833889
config.smallestScreenWidthDp = config.screenWidthDp; // assume screen does not rotate
38843890
config.compatScreenWidthDp = config.screenWidthDp;
38853891
config.compatScreenHeightDp = config.screenHeightDp;

core/java/android/content/res/Configuration.java

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,77 @@ public final class Configuration implements Parcelable, Comparable<Configuration
172172
* Multiple Screens</a> for more information.
173173
*/
174174
public int screenLayout;
175-
175+
176+
/** @hide */
177+
static public int resetScreenLayout(int curLayout) {
178+
return (curLayout&~(SCREENLAYOUT_LONG_MASK | SCREENLAYOUT_SIZE_MASK
179+
| SCREENLAYOUT_COMPAT_NEEDED))
180+
| (SCREENLAYOUT_LONG_YES | SCREENLAYOUT_SIZE_XLARGE);
181+
}
182+
183+
/** @hide */
184+
static public int reduceScreenLayout(int curLayout, int longSizeDp, int shortSizeDp) {
185+
int screenLayoutSize;
186+
boolean screenLayoutLong;
187+
boolean screenLayoutCompatNeeded;
188+
189+
// These semi-magic numbers define our compatibility modes for
190+
// applications with different screens. These are guarantees to
191+
// app developers about the space they can expect for a particular
192+
// configuration. DO NOT CHANGE!
193+
if (longSizeDp < 470) {
194+
// This is shorter than an HVGA normal density screen (which
195+
// is 480 pixels on its long side).
196+
screenLayoutSize = SCREENLAYOUT_SIZE_SMALL;
197+
screenLayoutLong = false;
198+
screenLayoutCompatNeeded = false;
199+
} else {
200+
// What size is this screen screen?
201+
if (longSizeDp >= 960 && shortSizeDp >= 720) {
202+
// 1.5xVGA or larger screens at medium density are the point
203+
// at which we consider it to be an extra large screen.
204+
screenLayoutSize = SCREENLAYOUT_SIZE_XLARGE;
205+
} else if (longSizeDp >= 640 && shortSizeDp >= 480) {
206+
// VGA or larger screens at medium density are the point
207+
// at which we consider it to be a large screen.
208+
screenLayoutSize = SCREENLAYOUT_SIZE_LARGE;
209+
} else {
210+
screenLayoutSize = SCREENLAYOUT_SIZE_NORMAL;
211+
}
212+
213+
// If this screen is wider than normal HVGA, or taller
214+
// than FWVGA, then for old apps we want to run in size
215+
// compatibility mode.
216+
if (shortSizeDp > 321 || longSizeDp > 570) {
217+
screenLayoutCompatNeeded = true;
218+
} else {
219+
screenLayoutCompatNeeded = false;
220+
}
221+
222+
// Is this a long screen?
223+
if (((longSizeDp*3)/5) >= (shortSizeDp-1)) {
224+
// Anything wider than WVGA (5:3) is considering to be long.
225+
screenLayoutLong = true;
226+
} else {
227+
screenLayoutLong = false;
228+
}
229+
}
230+
231+
// Now reduce the last screenLayout to not be better than what we
232+
// have found.
233+
if (!screenLayoutLong) {
234+
curLayout = (curLayout&~SCREENLAYOUT_LONG_MASK) | SCREENLAYOUT_LONG_NO;
235+
}
236+
if (screenLayoutCompatNeeded) {
237+
curLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
238+
}
239+
int curSize = curLayout&SCREENLAYOUT_SIZE_MASK;
240+
if (screenLayoutSize < curSize) {
241+
curLayout = (curLayout&~SCREENLAYOUT_SIZE_MASK) | screenLayoutSize;
242+
}
243+
return curLayout;
244+
}
245+
176246
/**
177247
* Check if the Configuration's current {@link #screenLayout} is at
178248
* least the given size.

services/java/com/android/server/wm/WindowManagerService.java

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6676,9 +6676,6 @@ private int reduceConfigLayout(int curLayout, int rotation, float density,
66766676
int h = mPolicy.getNonDecorDisplayHeight(dw, dh, rotation);
66776677

66786678
// Compute the screen layout size class for this rotation.
6679-
int screenLayoutSize;
6680-
boolean screenLayoutLong;
6681-
boolean screenLayoutCompatNeeded;
66826679
int longSize = w;
66836680
int shortSize = h;
66846681
if (longSize < shortSize) {
@@ -6688,64 +6685,7 @@ private int reduceConfigLayout(int curLayout, int rotation, float density,
66886685
}
66896686
longSize = (int)(longSize/density);
66906687
shortSize = (int)(shortSize/density);
6691-
6692-
// These semi-magic numbers define our compatibility modes for
6693-
// applications with different screens. These are guarantees to
6694-
// app developers about the space they can expect for a particular
6695-
// configuration. DO NOT CHANGE!
6696-
if (longSize < 470) {
6697-
// This is shorter than an HVGA normal density screen (which
6698-
// is 480 pixels on its long side).
6699-
screenLayoutSize = Configuration.SCREENLAYOUT_SIZE_SMALL;
6700-
screenLayoutLong = false;
6701-
screenLayoutCompatNeeded = false;
6702-
} else {
6703-
// What size is this screen screen?
6704-
if (longSize >= 960 && shortSize >= 720) {
6705-
// 1.5xVGA or larger screens at medium density are the point
6706-
// at which we consider it to be an extra large screen.
6707-
screenLayoutSize = Configuration.SCREENLAYOUT_SIZE_XLARGE;
6708-
} else if (longSize >= 640 && shortSize >= 480) {
6709-
// VGA or larger screens at medium density are the point
6710-
// at which we consider it to be a large screen.
6711-
screenLayoutSize = Configuration.SCREENLAYOUT_SIZE_LARGE;
6712-
} else {
6713-
screenLayoutSize = Configuration.SCREENLAYOUT_SIZE_NORMAL;
6714-
}
6715-
6716-
// If this screen is wider than normal HVGA, or taller
6717-
// than FWVGA, then for old apps we want to run in size
6718-
// compatibility mode.
6719-
if (shortSize > 321 || longSize > 570) {
6720-
screenLayoutCompatNeeded = true;
6721-
} else {
6722-
screenLayoutCompatNeeded = false;
6723-
}
6724-
6725-
// Is this a long screen?
6726-
if (((longSize*3)/5) >= (shortSize-1)) {
6727-
// Anything wider than WVGA (5:3) is considering to be long.
6728-
screenLayoutLong = true;
6729-
} else {
6730-
screenLayoutLong = false;
6731-
}
6732-
}
6733-
6734-
// Now reduce the last screenLayout to not be better than what we
6735-
// have found.
6736-
if (!screenLayoutLong) {
6737-
curLayout = (curLayout&~Configuration.SCREENLAYOUT_LONG_MASK)
6738-
| Configuration.SCREENLAYOUT_LONG_NO;
6739-
}
6740-
if (screenLayoutCompatNeeded) {
6741-
curLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
6742-
}
6743-
int curSize = curLayout&Configuration.SCREENLAYOUT_SIZE_MASK;
6744-
if (screenLayoutSize < curSize) {
6745-
curLayout = (curLayout&~Configuration.SCREENLAYOUT_SIZE_MASK)
6746-
| screenLayoutSize;
6747-
}
6748-
return curLayout;
6688+
return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
67496689
}
67506690

67516691
private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated,
@@ -6772,15 +6712,13 @@ private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean r
67726712
adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, unrotDh, unrotDw);
67736713
adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, unrotDw, unrotDh);
67746714
adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, unrotDh, unrotDw);
6775-
int sl = Configuration.SCREENLAYOUT_SIZE_XLARGE
6776-
| Configuration.SCREENLAYOUT_LONG_YES;
6715+
int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
67776716
sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh);
67786717
sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw);
67796718
sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh);
67806719
sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw);
67816720
outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
6782-
outConfig.screenLayout =
6783-
sl|(outConfig.screenLayout&Configuration.SCREENLAYOUT_LAYOUTDIR_MASK);
6721+
outConfig.screenLayout = sl;
67846722
}
67856723

67866724
private int reduceCompatConfigWidthSize(int curSize, int rotation, DisplayMetrics dm,

0 commit comments

Comments
 (0)