summaryrefslogtreecommitdiffstats
path: root/adb/sockets.c
diff options
context:
space:
mode:
authorScott Anderson <saa@android.com>2012-05-30 18:11:27 -0700
committerScott Anderson <saa@android.com>2012-06-05 11:13:40 -0700
commit2ca3e6b35f79136418ebc32fef57580698dbd045 (patch)
treee691312df3690d47d2066cd107449ee96a23ac5e /adb/sockets.c
parente82c2db05cae70a0490a1f84b7211ef42c329671 (diff)
downloadsystem_core-2ca3e6b35f79136418ebc32fef57580698dbd045.zip
system_core-2ca3e6b35f79136418ebc32fef57580698dbd045.tar.gz
system_core-2ca3e6b35f79136418ebc32fef57580698dbd045.tar.bz2
adb: Generalizing -s to take qualifiers.
Prior to this change, -s could take either a serial number or a device path (e.g. "-s 01498B1F02015015" or "-s usb:1-4.2"). This change extends -s to also allow product, model or device names (e.g. "-s product:mysid"). These new qualifiers will only be available on devices that are running an adb daemon that provides properties in the connect message per Change-Id: I09200decde4facb8fc9b4056fdae910155f2bcb9 The product, model and device are derived from the ro.product.name, ro.product.model and ro.product.device properties respectively. They are prefixed with "product:", "model:" or "device:" as appropriate. In addition, any non-alphanumerics in the model are changed to underscores. If the -s parameter matches multiple devices, the result will be the same as when multiple devices are connected but no -d, -e or -s option is specified. In general, this means the user will get "error: more than one device". However for get-state, get-devpath and get-serialno, they will get "unknown". The format of "devices -l" was changed to list all of the qualifiers that are available. The following example output (with the last digits of the serial numbers replaced with X's) is with a Galaxy Prime with an older adb daemon and another Galaxy Prime and Galaxy S both with the enhanced adb daemons: List of devices attached 016B75D60A0060XX device usb:2-5 product:mysid model:Galaxy_Nexus device:toro 3731B535FAC200XX device usb:1-4.2 product:soju model:Nexus_S device:crespo 01498B1F020150XX device usb:1-4.1 Note that the serial number and state are now column oriented instead of tab delimited. After the serial number and state, all qualifiers are listed with each preceded by a space. The output of the original devices command (without -l) is unchanged. Change-Id: Iceeb2789874effc25a630d514a375d6f1889dc56 Signed-off-by: Scott Anderson <saa@android.com>
Diffstat (limited to 'adb/sockets.c')
-rw-r--r--adb/sockets.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/adb/sockets.c b/adb/sockets.c
index a73fc62..830cf26 100644
--- a/adb/sockets.c
+++ b/adb/sockets.c
@@ -591,15 +591,29 @@ unsigned unhex(unsigned char *s, int len)
return n;
}
+#define PREFIX(str) { str, sizeof(str) - 1 }
+static const struct prefix_struct {
+ const char *str;
+ const size_t len;
+} prefixes[] = {
+ PREFIX("usb:"),
+ PREFIX("product:"),
+ PREFIX("model:"),
+ PREFIX("device:"),
+};
+static const int num_prefixes = (sizeof(prefixes) / sizeof(prefixes[0]));
+
/* skip_host_serial return the position in a string
skipping over the 'serial' parameter in the ADB protocol,
where parameter string may be a host:port string containing
the protocol delimiter (colon). */
char *skip_host_serial(char *service) {
char *first_colon, *serial_end;
+ int i;
- if (!strncmp(service, "usb:", 4)) {
- return strchr(service + 4, ':');
+ for (i = 0; i < num_prefixes; i++) {
+ if (!strncmp(service, prefixes[i].str, prefixes[i].len))
+ return strchr(service + prefixes[i].len, ':');
}
first_colon = strchr(service, ':');