If I develop in Eclipse I often press on the green run Button. A popup named Android Device Chooser appears and lets me choose from a list of my connected devices. There is no problem with that in general, as any phone is showing up. I just observed that the Serial Number column is showing two different things:
Normally it shows just the Serial Number, but sometimes the device-name i.e Asus Nexus 7 is showing up. This is extremly helpful, especially if you have more than one device to test on, and you can't (or won't) remember all these serials (even more confusing if you have more than one Device with the famous serial 0x0123456789ABCDEF).
I don't know why and when eclipse shows the device-names, but I'd like to find a way to kind of force eclipse to gather these device-names instead of their serials and show them in the device-chooser.
Check out the source com.android.ddmlib.Device to see how DDMS generate the deivce name/serial number:
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 static final char SEPARATOR = '-';
... ...
@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();
}
If you want to see how DDMS render this device name/serial number, see com.android.ddmuilib.DevicePanel.
The ro.product.manufacturer and ro.product.model are in /system/build.prop, you can use adb -e shell getprop|grep "\[ro.product" to see the current value:
[ro.product.manufacturer]: [samsung]
[ro.product.model]: [GT-I9100]
Then the device name/serial number shown in DDMS perspective is samsung-gt_i9100-0x0123456789ABCDEF. Note that some kludge vendors doesn't set these two properties properly, that is why for those devices, it only shows the serial number.
There is no configuration in Eclipse that can let you simply tick and force it shown. If your device is rooted, you can edit these properties so that the device's manufacturer and model are shown properly in DDMS perspective, for example, using adb shell setprop <key> <value> or directly editing build.prop in file system.
The way DDMS used to retrieve device info is quite complicated, in general, when AndroidDebugBridge is up and running, it starts a DeviceMonitor in a separate thread, which keep listening income device connection and issue an remote shell command getprop to the specific device to query device info like ro.product.manufacturer and ro.product.model, this remote shell command execution is unreliable (which may be affected by several factors), and it does not guarantee to grab the properties all the time. See com.android.ddmlib.DeviceMonitor:
/**
* Queries a device for its build info.
* @param device the device to query.
*/
private void queryNewDeviceForInfo(Device device) {
// TODO: do this in a separate thread.
try {
// first get the list of properties.
device.executeShellCommand(GetPropReceiver.GETPROP_COMMAND,
new GetPropReceiver(device));
queryNewDeviceForMountingPoint(device, IDevice.MNT_EXTERNAL_STORAGE);
queryNewDeviceForMountingPoint(device, IDevice.MNT_DATA);
queryNewDeviceForMountingPoint(device, IDevice.MNT_ROOT);
// now get the emulator Virtual Device name (if applicable).
if (device.isEmulator()) {
EmulatorConsole console = EmulatorConsole.getConsole(device);
if (console != null) {
device.setAvdName(console.getAvdName());
}
}
} catch (TimeoutException e) {
Log.w("DeviceMonitor", String.format("Connection timeout getting info for device %s",
device.getSerialNumber()));
} catch (AdbCommandRejectedException e) {
// This should never happen as we only do this once the device is online.
Log.w("DeviceMonitor", String.format(
"Adb rejected command to get device %1$s info: %2$s",
device.getSerialNumber(), e.getMessage()));
} catch (ShellCommandUnresponsiveException e) {
Log.w("DeviceMonitor", String.format(
"Adb shell command took too long returning info for device %s",
device.getSerialNumber()));
} catch (IOException e) {
Log.w("DeviceMonitor", String.format(
"IO Error getting info for device %s",
device.getSerialNumber()));
}
}
Notice all exceptions device.executeShellCommand() thrown and handled by DeviceMonitor.queryNewDeviceForInfo(), If any of these occurred, DDMS will not get the properties properly.
If you want to read the full source, check out here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With