Skip to content

Commit 43aa159

Browse files
author
Jeff Brown
committed
Allow adb shell am display-size to use bigger sizes.
We now support scaling the logical display to fit the physical display, whatever size it is. So we can allow adb shell am display-size to use more or less arbitrary sizes although we do enforce an upper and lower bound to protect the user. Change-Id: I5fe6ba32ad1f9e4fbcd6915f7d36850b987bbcc0
1 parent df46c63 commit 43aa159

File tree

3 files changed

+31
-39
lines changed

3 files changed

+31
-39
lines changed

cmds/am/src/com/android/commands/am/Am.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,32 +1187,26 @@ private void runScreenCompat() throws Exception {
11871187

11881188
private void runDisplaySize() throws Exception {
11891189
String size = nextArgRequired();
1190-
int m, n;
1190+
int w, h;
11911191
if ("reset".equals(size)) {
1192-
m = n = -1;
1192+
w = h = -1;
11931193
} else {
11941194
int div = size.indexOf('x');
11951195
if (div <= 0 || div >= (size.length()-1)) {
11961196
System.err.println("Error: bad size " + size);
11971197
return;
11981198
}
1199-
String mstr = size.substring(0, div);
1200-
String nstr = size.substring(div+1);
1199+
String wstr = size.substring(0, div);
1200+
String hstr = size.substring(div+1);
12011201
try {
1202-
m = Integer.parseInt(mstr);
1203-
n = Integer.parseInt(nstr);
1202+
w = Integer.parseInt(wstr);
1203+
h = Integer.parseInt(hstr);
12041204
} catch (NumberFormatException e) {
12051205
System.err.println("Error: bad number " + e);
12061206
return;
12071207
}
12081208
}
12091209

1210-
if (m < n) {
1211-
int tmp = m;
1212-
m = n;
1213-
n = tmp;
1214-
}
1215-
12161210
IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.checkService(
12171211
Context.WINDOW_SERVICE));
12181212
if (wm == null) {
@@ -1221,9 +1215,9 @@ private void runDisplaySize() throws Exception {
12211215
}
12221216

12231217
try {
1224-
if (m >= 0 && n >= 0) {
1218+
if (w >= 0 && h >= 0) {
12251219
// TODO(multidisplay): For now Configuration only applies to main screen.
1226-
wm.setForcedDisplaySize(Display.DEFAULT_DISPLAY, m, n);
1220+
wm.setForcedDisplaySize(Display.DEFAULT_DISPLAY, w, h);
12271221
} else {
12281222
wm.clearForcedDisplaySize(Display.DEFAULT_DISPLAY);
12291223
}
@@ -1444,7 +1438,7 @@ private static void showUsage() {
14441438
" am clear-debug-app\n" +
14451439
" am monitor [--gdb <port>]\n" +
14461440
" am screen-compat [on|off] <PACKAGE>\n" +
1447-
" am display-size [reset|MxN]\n" +
1441+
" am display-size [reset|WxH]\n" +
14481442
" am display-density [reset|DENSITY]\n" +
14491443
" am to-uri [INTENT]\n" +
14501444
" am to-intent-uri [INTENT]\n" +

core/java/android/view/IWindowManager.aidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ interface IWindowManager
5959
in IInputContext inputContext);
6060
boolean inputMethodClientHasFocus(IInputMethodClient client);
6161

62-
void setForcedDisplaySize(int displayId, int longDimen, int shortDimen);
62+
void setForcedDisplaySize(int displayId, int width, int height);
6363
void clearForcedDisplaySize(int displayId);
6464
void setForcedDisplayDensity(int displayId, int density);
6565
void clearForcedDisplayDensity(int displayId);

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

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7775,24 +7775,22 @@ public void getInitialDisplaySize(int displayId, Point size) {
77757775
}
77767776
}
77777777

7778-
public void setForcedDisplaySize(int displayId, int longDimen, int shortDimen) {
7778+
public void setForcedDisplaySize(int displayId, int width, int height) {
77797779
synchronized(mWindowMap) {
7780+
// Set some sort of reasonable bounds on the size of the display that we
7781+
// will try to emulate.
7782+
final int MIN_WIDTH = 200;
7783+
final int MIN_HEIGHT = 200;
7784+
final int MAX_SCALE = 2;
77807785
final DisplayContent displayContent = getDisplayContent(displayId);
7781-
int width, height;
7782-
if (displayContent.mInitialDisplayWidth < displayContent.mInitialDisplayHeight) {
7783-
width = shortDimen < displayContent.mInitialDisplayWidth
7784-
? shortDimen : displayContent.mInitialDisplayWidth;
7785-
height = longDimen < displayContent.mInitialDisplayHeight
7786-
? longDimen : displayContent.mInitialDisplayHeight;
7787-
} else {
7788-
width = longDimen < displayContent.mInitialDisplayWidth
7789-
? longDimen : displayContent.mInitialDisplayWidth;
7790-
height = shortDimen < displayContent.mInitialDisplayHeight
7791-
? shortDimen : displayContent.mInitialDisplayHeight;
7792-
}
7786+
7787+
width = Math.min(Math.max(width, MIN_WIDTH),
7788+
displayContent.mInitialDisplayWidth * MAX_SCALE);
7789+
height = Math.min(Math.max(height, MIN_HEIGHT),
7790+
displayContent.mInitialDisplayHeight * MAX_SCALE);
77937791
setForcedDisplaySizeLocked(displayContent, width, height);
7794-
Settings.Secure.putString(mContext.getContentResolver(),
7795-
Settings.Secure.DISPLAY_SIZE_FORCED, width + "," + height);
7792+
Settings.Global.putString(mContext.getContentResolver(),
7793+
Settings.Global.DISPLAY_SIZE_FORCED, width + "," + height);
77967794
}
77977795
}
77987796

@@ -7839,8 +7837,8 @@ private void rebuildBlackFrameLocked() {
78397837

78407838
private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayContent) {
78417839
boolean changed = false;
7842-
final String sizeStr = Settings.Secure.getString(mContext.getContentResolver(),
7843-
Settings.Secure.DISPLAY_SIZE_FORCED);
7840+
final String sizeStr = Settings.Global.getString(mContext.getContentResolver(),
7841+
Settings.Global.DISPLAY_SIZE_FORCED);
78447842
if (sizeStr != null && sizeStr.length() > 0) {
78457843
final int pos = sizeStr.indexOf(',');
78467844
if (pos > 0 && sizeStr.lastIndexOf(',') == pos) {
@@ -7861,8 +7859,8 @@ private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayC
78617859
}
78627860
}
78637861
}
7864-
final String densityStr = Settings.Secure.getString(mContext.getContentResolver(),
7865-
Settings.Secure.DISPLAY_DENSITY_FORCED);
7862+
final String densityStr = Settings.Global.getString(mContext.getContentResolver(),
7863+
Settings.Global.DISPLAY_DENSITY_FORCED);
78667864
if (densityStr != null && densityStr.length() > 0) {
78677865
int density;
78687866
try {
@@ -7897,17 +7895,17 @@ public void clearForcedDisplaySize(int displayId) {
78977895
final DisplayContent displayContent = getDisplayContent(displayId);
78987896
setForcedDisplaySizeLocked(displayContent, displayContent.mInitialDisplayWidth,
78997897
displayContent.mInitialDisplayHeight);
7900-
Settings.Secure.putString(mContext.getContentResolver(),
7901-
Settings.Secure.DISPLAY_SIZE_FORCED, "");
7898+
Settings.Global.putString(mContext.getContentResolver(),
7899+
Settings.Global.DISPLAY_SIZE_FORCED, "");
79027900
}
79037901
}
79047902

79057903
public void setForcedDisplayDensity(int displayId, int density) {
79067904
synchronized(mWindowMap) {
79077905
final DisplayContent displayContent = getDisplayContent(displayId);
79087906
setForcedDisplayDensityLocked(displayContent, density);
7909-
Settings.Secure.putString(mContext.getContentResolver(),
7910-
Settings.Secure.DISPLAY_DENSITY_FORCED, Integer.toString(density));
7907+
Settings.Global.putString(mContext.getContentResolver(),
7908+
Settings.Global.DISPLAY_DENSITY_FORCED, Integer.toString(density));
79117909
}
79127910
}
79137911

0 commit comments

Comments
 (0)