DebugPortProviderpublic class DebugPortProvider extends Object implements com.android.ddmlib.DebugPortManager.IDebugPortProviderDDMS implementation of the IDebugPortProvider interface.
This class handles saving/loading the list of static debug port from
the preference store and provides the port number to the Device Monitor. |
Fields Summary |
---|
private static DebugPortProvider | sThis | public static final String | PREFS_STATIC_PORT_LISTPreference name for the static port list. | private Map | mMapMapping device serial numbers to maps. The embedded maps are mapping application names to
debugger ports. |
Constructors Summary |
---|
private DebugPortProvider()
computePortList();
|
Methods Summary |
---|
private void | computePortList()Create the map member from the values contained in the Preference Store.
mMap = new HashMap<String, Map<String, Integer>>();
// get the prefs store
IPreferenceStore store = PrefsDialog.getStore();
String value = store.getString(PREFS_STATIC_PORT_LIST);
if (value != null && value.length() > 0) {
// format is
// port1|port2|port3|...
// where port# is
// appPackageName:appPortNumber:device-serial-number
String[] portSegments = value.split("\\|"); //$NON-NLS-1$
for (String seg : portSegments) {
String[] entry = seg.split(":"); //$NON-NLS-1$
// backward compatibility support. if we have only 2 entry, we default
// to the first emulator.
String deviceName = null;
if (entry.length == 3) {
deviceName = entry[2];
} else {
deviceName = Device.FIRST_EMULATOR_SN;
}
// get the device map
Map<String, Integer> deviceMap = mMap.get(deviceName);
if (deviceMap == null) {
deviceMap = new HashMap<String, Integer>();
mMap.put(deviceName, deviceMap);
}
deviceMap.put(entry[0], Integer.valueOf(entry[1]));
}
}
| public static com.android.ddms.DebugPortProvider | getInstance()
return sThis;
| public int | getPort(com.android.ddmlib.Device device, java.lang.String appName)Returns a static debug port for the specified application running on the
specified {@link Device}.
if (mMap != null) {
Map<String, Integer> deviceMap = mMap.get(device.getSerialNumber());
if (deviceMap != null) {
Integer i = deviceMap.get(appName);
if (i != null) {
return i.intValue();
}
}
}
return IDebugPortProvider.NO_STATIC_PORT;
| public java.util.Map | getPortList()Returns the map of Static debugger ports. The map links device serial numbers to
a map linking application name to debugger ports.
return mMap;
| public void | setPortList(java.util.Map map)Sets new [device, app, port] values.
The values are also sync'ed in the preference store.
// update the member map.
mMap.clear();
mMap.putAll(map);
// create the value to store in the preference store.
// see format definition in getPortList
StringBuilder sb = new StringBuilder();
Set<String> deviceKeys = map.keySet();
for (String deviceKey : deviceKeys) {
Map<String, Integer> deviceMap = map.get(deviceKey);
if (deviceMap != null) {
Set<String> appKeys = deviceMap.keySet();
for (String appKey : appKeys) {
Integer port = deviceMap.get(appKey);
if (port != null) {
sb.append(appKey).append(':").append(port.intValue()).append(':").
append(deviceKey).append('|");
}
}
}
}
String value = sb.toString();
// get the prefs store.
IPreferenceStore store = PrefsDialog.getStore();
// and give it the new value.
store.setValue(PREFS_STATIC_PORT_LIST, value);
|
|