From 43aa15912891930833edfc101615a9c881de54a1 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Mon, 10 Sep 2012 17:36:31 -0700 Subject: [PATCH 1/3] 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 --- cmds/am/src/com/android/commands/am/Am.java | 24 ++++------ core/java/android/view/IWindowManager.aidl | 2 +- .../server/wm/WindowManagerService.java | 44 +++++++++---------- 3 files changed, 31 insertions(+), 39 deletions(-) diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index 89287ad9de5ca..bc9e74ed4c275 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -1187,32 +1187,26 @@ public class Am { private void runDisplaySize() throws Exception { String size = nextArgRequired(); - int m, n; + int w, h; if ("reset".equals(size)) { - m = n = -1; + w = h = -1; } else { int div = size.indexOf('x'); if (div <= 0 || div >= (size.length()-1)) { System.err.println("Error: bad size " + size); return; } - String mstr = size.substring(0, div); - String nstr = size.substring(div+1); + String wstr = size.substring(0, div); + String hstr = size.substring(div+1); try { - m = Integer.parseInt(mstr); - n = Integer.parseInt(nstr); + w = Integer.parseInt(wstr); + h = Integer.parseInt(hstr); } catch (NumberFormatException e) { System.err.println("Error: bad number " + e); return; } } - if (m < n) { - int tmp = m; - m = n; - n = tmp; - } - IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.checkService( Context.WINDOW_SERVICE)); if (wm == null) { @@ -1221,9 +1215,9 @@ public class Am { } try { - if (m >= 0 && n >= 0) { + if (w >= 0 && h >= 0) { // TODO(multidisplay): For now Configuration only applies to main screen. - wm.setForcedDisplaySize(Display.DEFAULT_DISPLAY, m, n); + wm.setForcedDisplaySize(Display.DEFAULT_DISPLAY, w, h); } else { wm.clearForcedDisplaySize(Display.DEFAULT_DISPLAY); } @@ -1444,7 +1438,7 @@ public class Am { " am clear-debug-app\n" + " am monitor [--gdb ]\n" + " am screen-compat [on|off] \n" + - " am display-size [reset|MxN]\n" + + " am display-size [reset|WxH]\n" + " am display-density [reset|DENSITY]\n" + " am to-uri [INTENT]\n" + " am to-intent-uri [INTENT]\n" + diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl index b9f39422da247..41fac4e3abb49 100644 --- a/core/java/android/view/IWindowManager.aidl +++ b/core/java/android/view/IWindowManager.aidl @@ -59,7 +59,7 @@ interface IWindowManager in IInputContext inputContext); boolean inputMethodClientHasFocus(IInputMethodClient client); - void setForcedDisplaySize(int displayId, int longDimen, int shortDimen); + void setForcedDisplaySize(int displayId, int width, int height); void clearForcedDisplaySize(int displayId); void setForcedDisplayDensity(int displayId, int density); void clearForcedDisplayDensity(int displayId); diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java index 17f4a96bf83ed..c2cec707cccf1 100755 --- a/services/java/com/android/server/wm/WindowManagerService.java +++ b/services/java/com/android/server/wm/WindowManagerService.java @@ -7775,24 +7775,22 @@ public class WindowManagerService extends IWindowManager.Stub } } - public void setForcedDisplaySize(int displayId, int longDimen, int shortDimen) { + public void setForcedDisplaySize(int displayId, int width, int height) { synchronized(mWindowMap) { + // Set some sort of reasonable bounds on the size of the display that we + // will try to emulate. + final int MIN_WIDTH = 200; + final int MIN_HEIGHT = 200; + final int MAX_SCALE = 2; final DisplayContent displayContent = getDisplayContent(displayId); - int width, height; - if (displayContent.mInitialDisplayWidth < displayContent.mInitialDisplayHeight) { - width = shortDimen < displayContent.mInitialDisplayWidth - ? shortDimen : displayContent.mInitialDisplayWidth; - height = longDimen < displayContent.mInitialDisplayHeight - ? longDimen : displayContent.mInitialDisplayHeight; - } else { - width = longDimen < displayContent.mInitialDisplayWidth - ? longDimen : displayContent.mInitialDisplayWidth; - height = shortDimen < displayContent.mInitialDisplayHeight - ? shortDimen : displayContent.mInitialDisplayHeight; - } + + width = Math.min(Math.max(width, MIN_WIDTH), + displayContent.mInitialDisplayWidth * MAX_SCALE); + height = Math.min(Math.max(height, MIN_HEIGHT), + displayContent.mInitialDisplayHeight * MAX_SCALE); setForcedDisplaySizeLocked(displayContent, width, height); - Settings.Secure.putString(mContext.getContentResolver(), - Settings.Secure.DISPLAY_SIZE_FORCED, width + "," + height); + Settings.Global.putString(mContext.getContentResolver(), + Settings.Global.DISPLAY_SIZE_FORCED, width + "," + height); } } @@ -7839,8 +7837,8 @@ public class WindowManagerService extends IWindowManager.Stub private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayContent) { boolean changed = false; - final String sizeStr = Settings.Secure.getString(mContext.getContentResolver(), - Settings.Secure.DISPLAY_SIZE_FORCED); + final String sizeStr = Settings.Global.getString(mContext.getContentResolver(), + Settings.Global.DISPLAY_SIZE_FORCED); if (sizeStr != null && sizeStr.length() > 0) { final int pos = sizeStr.indexOf(','); if (pos > 0 && sizeStr.lastIndexOf(',') == pos) { @@ -7861,8 +7859,8 @@ public class WindowManagerService extends IWindowManager.Stub } } } - final String densityStr = Settings.Secure.getString(mContext.getContentResolver(), - Settings.Secure.DISPLAY_DENSITY_FORCED); + final String densityStr = Settings.Global.getString(mContext.getContentResolver(), + Settings.Global.DISPLAY_DENSITY_FORCED); if (densityStr != null && densityStr.length() > 0) { int density; try { @@ -7897,8 +7895,8 @@ public class WindowManagerService extends IWindowManager.Stub final DisplayContent displayContent = getDisplayContent(displayId); setForcedDisplaySizeLocked(displayContent, displayContent.mInitialDisplayWidth, displayContent.mInitialDisplayHeight); - Settings.Secure.putString(mContext.getContentResolver(), - Settings.Secure.DISPLAY_SIZE_FORCED, ""); + Settings.Global.putString(mContext.getContentResolver(), + Settings.Global.DISPLAY_SIZE_FORCED, ""); } } @@ -7906,8 +7904,8 @@ public class WindowManagerService extends IWindowManager.Stub synchronized(mWindowMap) { final DisplayContent displayContent = getDisplayContent(displayId); setForcedDisplayDensityLocked(displayContent, density); - Settings.Secure.putString(mContext.getContentResolver(), - Settings.Secure.DISPLAY_DENSITY_FORCED, Integer.toString(density)); + Settings.Global.putString(mContext.getContentResolver(), + Settings.Global.DISPLAY_DENSITY_FORCED, Integer.toString(density)); } } From 0f68d166e6ca45fe27410ea520967275e0733757 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Tue, 11 Sep 2012 12:18:15 -0700 Subject: [PATCH 2/3] Use wfdInfo to filter available sinks. Change-Id: If056267738f70835af645a8c6e7a91c0c5407816 --- .../server/display/WifiDisplayController.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/services/java/com/android/server/display/WifiDisplayController.java b/services/java/com/android/server/display/WifiDisplayController.java index 67691dfd9838d..f5ec0b7750981 100644 --- a/services/java/com/android/server/display/WifiDisplayController.java +++ b/services/java/com/android/server/display/WifiDisplayController.java @@ -493,14 +493,8 @@ final class WifiDisplayController implements DumpUtils.Dump { return; // done } - int port = DEFAULT_CONTROL_PORT; - if (mConnectedDevice.deviceName.startsWith("DIRECT-") - && mConnectedDevice.deviceName.endsWith("Broadcom")) { - // These dongles ignore the port we broadcast in our WFD IE. - port = 8554; - } - final WifiDisplay display = createWifiDisplay(mConnectedDevice); + final int port = getPortNumber(mConnectedDevice); final String iface = addr.getHostAddress() + ":" + port; mPublishedDevice = mConnectedDevice; @@ -647,12 +641,24 @@ final class WifiDisplayController implements DumpUtils.Dump { return null; } + private static int getPortNumber(WifiP2pDevice device) { + if (device.deviceName.startsWith("DIRECT-") + && device.deviceName.endsWith("Broadcom")) { + // These dongles ignore the port we broadcast in our WFD IE. + return 8554; + } + return DEFAULT_CONTROL_PORT; + } + private static boolean isWifiDisplay(WifiP2pDevice device) { - // FIXME: the wfdInfo API doesn't work yet - return device.deviceName.startsWith("DWD-") - || device.deviceName.startsWith("DIRECT-") - || device.deviceName.startsWith("CAVM-"); - //device.wfdInfo != null && device.wfdInfo.isWfdEnabled(); + return device.wfdInfo != null + && device.wfdInfo.isWfdEnabled() + && isPrimarySinkDeviceType(device.wfdInfo.getDeviceType()); + } + + private static boolean isPrimarySinkDeviceType(int deviceType) { + return deviceType == WifiP2pWfdInfo.PRIMARY_SINK + || deviceType == WifiP2pWfdInfo.SOURCE_OR_PRIMARY_SINK; } private static String describeWifiP2pDevice(WifiP2pDevice device) { From 59c53c6224e2f84d31a56854ebe90d22055100d2 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Tue, 11 Sep 2012 12:21:55 -0700 Subject: [PATCH 3/3] Don't auto-discover peers until scan requested. Change-Id: I4ad08873567a5ac86e9bd46abd2375b183e2e95b --- .../com/android/server/display/WifiDisplayController.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/services/java/com/android/server/display/WifiDisplayController.java b/services/java/com/android/server/display/WifiDisplayController.java index f5ec0b7750981..144b3913e6268 100644 --- a/services/java/com/android/server/display/WifiDisplayController.java +++ b/services/java/com/android/server/display/WifiDisplayController.java @@ -179,7 +179,6 @@ final class WifiDisplayController implements DumpUtils.Dump { if (mWfdEnabling) { mWfdEnabling = false; setWfdEnabled(true); - discoverPeers(); } } @@ -511,9 +510,7 @@ final class WifiDisplayController implements DumpUtils.Dump { if (mWifiP2pEnabled != enabled) { mWifiP2pEnabled = enabled; if (enabled) { - if (mWfdEnabled) { - discoverPeers(); - } else { + if (!mWfdEnabled) { enableWfd(); } } else {