aboutsummaryrefslogtreecommitdiffstats
path: root/ddms/libs
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2012-06-12 12:04:25 -0700
committerSiva Velusamy <vsiva@google.com>2012-06-13 11:55:16 -0700
commitb7f70835c533f0f07a1f52f75a1bbe783c32e010 (patch)
tree6121a4a54241ee010a920525a505d345ad83e10d /ddms/libs
parentfa1f0bd43a50ea3e25b48607b7ef723f8f1365cd (diff)
downloadsdk-b7f70835c533f0f07a1f52f75a1bbe783c32e010.zip
sdk-b7f70835c533f0f07a1f52f75a1bbe783c32e010.tar.gz
sdk-b7f70835c533f0f07a1f52f75a1bbe783c32e010.tar.bz2
Provide readable device name rather than just serial number
There are a number of places where we need to display a device name. Currently, DDMS shows the serial number + manufacturer/model if available, but in other instances, we just show the serial number. This CL provides a getName() method in the IDevice interface so that all the locations which require a human readable name can use this. The name is typically of the form manufacturer-model-serial. If the manufacturer/model strings are not available, then those fields are omitted, so it will show just the serial number. Change-Id: I80ef7b48a4c7c8587042c1227c932251e18dba2e
Diffstat (limited to 'ddms/libs')
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/Device.java64
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java6
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java53
3 files changed, 71 insertions, 52 deletions
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java b/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java
index a60742d..0566275 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java
@@ -34,6 +34,8 @@ import java.util.regex.Pattern;
* A Device. It can be a physical device or an emulator.
*/
final class Device implements IDevice {
+ private static final String DEVICE_MODEL_PROPERTY = "ro.product.model"; //$NON-NLS-1$
+ private static final String DEVICE_MANUFACTURER_PROPERTY = "ro.product.manufacturer"; //$NON-NLS-1$
private final static int INSTALL_TIMEOUT = 2*60*1000; //2min
private static final int BATTERY_TIMEOUT = 2*1000; //2 seconds
@@ -59,6 +61,7 @@ final class Device implements IDevice {
private DeviceMonitor mMonitor;
private static final String LOG_TAG = "Device";
+ private static final char SEPARATOR = '-';
/**
* Socket for the connection monitoring client connection/disconnection.
@@ -70,6 +73,8 @@ final class Device implements IDevice {
private Integer mLastBatteryLevel = null;
private long mLastBatteryCheckTime = 0;
+ private String mName;
+
/**
* Output receiver for "pm install package.apk" command line.
*/
@@ -187,6 +192,65 @@ final class Device implements IDevice {
mAvdName = avdName;
}
+ @Override
+ public String getName() {
+ if (mName == null) {
+ mName = constructName();
+ }
+
+ return mName;
+ }
+
+ private String constructName() {
+ if (isEmulator()) {
+ String avdName = getAvdName();
+ if (avdName != null) {
+ return String.format("%s [%s]", avdName, getSerialNumber());
+ } else {
+ return getSerialNumber();
+ }
+ } else {
+ String manufacturer = cleanupStringForDisplay(
+ getProperty(DEVICE_MANUFACTURER_PROPERTY));
+ String model = cleanupStringForDisplay(
+ getProperty(DEVICE_MODEL_PROPERTY));
+
+ StringBuilder sb = new StringBuilder(20);
+
+ if (manufacturer != null) {
+ sb.append(manufacturer);
+ sb.append(SEPARATOR);
+ }
+
+ if (model != null) {
+ sb.append(model);
+ sb.append(SEPARATOR);
+ }
+
+ sb.append(getSerialNumber());
+ return sb.toString();
+ }
+ }
+
+ private String cleanupStringForDisplay(String s) {
+ if (s == null) {
+ return null;
+ }
+
+ StringBuilder sb = new StringBuilder(s.length());
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+
+ if (Character.isLetterOrDigit(c)) {
+ sb.append(Character.toLowerCase(c));
+ } else {
+ sb.append('_');
+ }
+ }
+
+ return sb.toString();
+ }
+
/*
* (non-Javadoc)
* @see com.android.ddmlib.IDevice#getState()
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java b/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java
index 41637e2..d81aea9 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java
@@ -115,6 +115,12 @@ public interface IDevice {
public String getAvdName();
/**
+ * Returns a (humanized) name for this device. Typically this is the AVD name for AVD's, and
+ * a combination of the manufacturer name, model name & serial number for devices.
+ */
+ public String getName();
+
+ /**
* Returns the state of the device.
*/
public DeviceState getState();
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java
index 68f23b7..27c844d 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java
@@ -158,9 +158,6 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen
* labels and images for {@link IDevice} and {@link Client} objects.
*/
private class LabelProvider implements ITableLabelProvider {
- private static final String DEVICE_MODEL_PROPERTY = "ro.product.model"; //$NON-NLS-1$
- private static final String DEVICE_MANUFACTURER_PROPERTY = "ro.product.manufacturer"; //$NON-NLS-1$
-
@Override
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex == DEVICE_COL_SERIAL && element instanceof IDevice) {
@@ -208,7 +205,7 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen
IDevice device = (IDevice)element;
switch (columnIndex) {
case DEVICE_COL_SERIAL:
- return getDeviceName(device);
+ return device.getName();
case DEVICE_COL_STATE:
return getStateString(device);
case DEVICE_COL_BUILD: {
@@ -271,54 +268,6 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen
return null;
}
- private String getDeviceName(IDevice device) {
- StringBuilder sb = new StringBuilder(20);
- sb.append(device.getSerialNumber());
-
- if (device.isEmulator()) {
- sb.append(String.format(" [%s]", device.getAvdName()));
- } else {
- String manufacturer = device.getProperty(DEVICE_MANUFACTURER_PROPERTY);
- manufacturer = cleanupStringForDisplay(manufacturer);
-
- String model = device.getProperty(DEVICE_MODEL_PROPERTY);
- model = cleanupStringForDisplay(model);
-
- boolean hasManufacturer = manufacturer.length() > 0;
- boolean hasModel = model.length() > 0;
- if (hasManufacturer || hasModel) {
- sb.append(" ["); //$NON-NLS-1$
- sb.append(manufacturer);
-
- if (hasManufacturer && hasModel) {
- sb.append(':');
- }
-
- sb.append(model);
- sb.append(']');
- }
- }
-
- return sb.toString();
- }
-
- private String cleanupStringForDisplay(String s) {
- if (s == null) {
- return "";
- }
-
- StringBuilder sb = new StringBuilder(s.length());
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
-
- if (Character.isLetterOrDigit(c)) {
- sb.append(c);
- }
- }
-
- return sb.toString();
- }
-
@Override
public void addListener(ILabelProviderListener listener) {
// pass