Skip to content

Commit 9ba2a18

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge changes I4ad08873,If0562677,I5fe6ba32 into jb-mr1-dev
* changes: Don't auto-discover peers until scan requested. Use wfdInfo to filter available sinks. Allow adb shell am display-size to use bigger sizes.
2 parents faed98a + 59c53c6 commit 9ba2a18

File tree

4 files changed

+50
-55
lines changed

4 files changed

+50
-55
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/display/WifiDisplayController.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ public void onSuccess() {
179179
if (mWfdEnabling) {
180180
mWfdEnabling = false;
181181
setWfdEnabled(true);
182-
discoverPeers();
183182
}
184183
}
185184

@@ -493,14 +492,8 @@ public void onFailure(int reason) {
493492
return; // done
494493
}
495494

496-
int port = DEFAULT_CONTROL_PORT;
497-
if (mConnectedDevice.deviceName.startsWith("DIRECT-")
498-
&& mConnectedDevice.deviceName.endsWith("Broadcom")) {
499-
// These dongles ignore the port we broadcast in our WFD IE.
500-
port = 8554;
501-
}
502-
503495
final WifiDisplay display = createWifiDisplay(mConnectedDevice);
496+
final int port = getPortNumber(mConnectedDevice);
504497
final String iface = addr.getHostAddress() + ":" + port;
505498

506499
mPublishedDevice = mConnectedDevice;
@@ -517,9 +510,7 @@ private void handleStateChanged(boolean enabled) {
517510
if (mWifiP2pEnabled != enabled) {
518511
mWifiP2pEnabled = enabled;
519512
if (enabled) {
520-
if (mWfdEnabled) {
521-
discoverPeers();
522-
} else {
513+
if (!mWfdEnabled) {
523514
enableWfd();
524515
}
525516
} else {
@@ -647,12 +638,24 @@ private static Inet4Address getInterfaceAddress(WifiP2pGroup info) {
647638
return null;
648639
}
649640

641+
private static int getPortNumber(WifiP2pDevice device) {
642+
if (device.deviceName.startsWith("DIRECT-")
643+
&& device.deviceName.endsWith("Broadcom")) {
644+
// These dongles ignore the port we broadcast in our WFD IE.
645+
return 8554;
646+
}
647+
return DEFAULT_CONTROL_PORT;
648+
}
649+
650650
private static boolean isWifiDisplay(WifiP2pDevice device) {
651-
// FIXME: the wfdInfo API doesn't work yet
652-
return device.deviceName.startsWith("DWD-")
653-
|| device.deviceName.startsWith("DIRECT-")
654-
|| device.deviceName.startsWith("CAVM-");
655-
//device.wfdInfo != null && device.wfdInfo.isWfdEnabled();
651+
return device.wfdInfo != null
652+
&& device.wfdInfo.isWfdEnabled()
653+
&& isPrimarySinkDeviceType(device.wfdInfo.getDeviceType());
654+
}
655+
656+
private static boolean isPrimarySinkDeviceType(int deviceType) {
657+
return deviceType == WifiP2pWfdInfo.PRIMARY_SINK
658+
|| deviceType == WifiP2pWfdInfo.SOURCE_OR_PRIMARY_SINK;
656659
}
657660

658661
private static String describeWifiP2pDevice(WifiP2pDevice device) {

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

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7831,24 +7831,22 @@ public void getInitialDisplaySize(int displayId, Point size) {
78317831
}
78327832
}
78337833

7834-
public void setForcedDisplaySize(int displayId, int longDimen, int shortDimen) {
7834+
public void setForcedDisplaySize(int displayId, int width, int height) {
78357835
synchronized(mWindowMap) {
7836+
// Set some sort of reasonable bounds on the size of the display that we
7837+
// will try to emulate.
7838+
final int MIN_WIDTH = 200;
7839+
final int MIN_HEIGHT = 200;
7840+
final int MAX_SCALE = 2;
78367841
final DisplayContent displayContent = getDisplayContent(displayId);
7837-
int width, height;
7838-
if (displayContent.mInitialDisplayWidth < displayContent.mInitialDisplayHeight) {
7839-
width = shortDimen < displayContent.mInitialDisplayWidth
7840-
? shortDimen : displayContent.mInitialDisplayWidth;
7841-
height = longDimen < displayContent.mInitialDisplayHeight
7842-
? longDimen : displayContent.mInitialDisplayHeight;
7843-
} else {
7844-
width = longDimen < displayContent.mInitialDisplayWidth
7845-
? longDimen : displayContent.mInitialDisplayWidth;
7846-
height = shortDimen < displayContent.mInitialDisplayHeight
7847-
? shortDimen : displayContent.mInitialDisplayHeight;
7848-
}
7842+
7843+
width = Math.min(Math.max(width, MIN_WIDTH),
7844+
displayContent.mInitialDisplayWidth * MAX_SCALE);
7845+
height = Math.min(Math.max(height, MIN_HEIGHT),
7846+
displayContent.mInitialDisplayHeight * MAX_SCALE);
78497847
setForcedDisplaySizeLocked(displayContent, width, height);
7850-
Settings.Secure.putString(mContext.getContentResolver(),
7851-
Settings.Secure.DISPLAY_SIZE_FORCED, width + "," + height);
7848+
Settings.Global.putString(mContext.getContentResolver(),
7849+
Settings.Global.DISPLAY_SIZE_FORCED, width + "," + height);
78527850
}
78537851
}
78547852

@@ -7895,8 +7893,8 @@ private void rebuildBlackFrameLocked() {
78957893

78967894
private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayContent) {
78977895
boolean changed = false;
7898-
final String sizeStr = Settings.Secure.getString(mContext.getContentResolver(),
7899-
Settings.Secure.DISPLAY_SIZE_FORCED);
7896+
final String sizeStr = Settings.Global.getString(mContext.getContentResolver(),
7897+
Settings.Global.DISPLAY_SIZE_FORCED);
79007898
if (sizeStr != null && sizeStr.length() > 0) {
79017899
final int pos = sizeStr.indexOf(',');
79027900
if (pos > 0 && sizeStr.lastIndexOf(',') == pos) {
@@ -7917,8 +7915,8 @@ private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayC
79177915
}
79187916
}
79197917
}
7920-
final String densityStr = Settings.Secure.getString(mContext.getContentResolver(),
7921-
Settings.Secure.DISPLAY_DENSITY_FORCED);
7918+
final String densityStr = Settings.Global.getString(mContext.getContentResolver(),
7919+
Settings.Global.DISPLAY_DENSITY_FORCED);
79227920
if (densityStr != null && densityStr.length() > 0) {
79237921
int density;
79247922
try {
@@ -7953,17 +7951,17 @@ public void clearForcedDisplaySize(int displayId) {
79537951
final DisplayContent displayContent = getDisplayContent(displayId);
79547952
setForcedDisplaySizeLocked(displayContent, displayContent.mInitialDisplayWidth,
79557953
displayContent.mInitialDisplayHeight);
7956-
Settings.Secure.putString(mContext.getContentResolver(),
7957-
Settings.Secure.DISPLAY_SIZE_FORCED, "");
7954+
Settings.Global.putString(mContext.getContentResolver(),
7955+
Settings.Global.DISPLAY_SIZE_FORCED, "");
79587956
}
79597957
}
79607958

79617959
public void setForcedDisplayDensity(int displayId, int density) {
79627960
synchronized(mWindowMap) {
79637961
final DisplayContent displayContent = getDisplayContent(displayId);
79647962
setForcedDisplayDensityLocked(displayContent, density);
7965-
Settings.Secure.putString(mContext.getContentResolver(),
7966-
Settings.Secure.DISPLAY_DENSITY_FORCED, Integer.toString(density));
7963+
Settings.Global.putString(mContext.getContentResolver(),
7964+
Settings.Global.DISPLAY_DENSITY_FORCED, Integer.toString(density));
79677965
}
79687966
}
79697967

0 commit comments

Comments
 (0)