adb: allow selection of a specific transport.
Extend device selection to allow selecting a specific transport via
monotonically increasing identifier (visible in devices -l).
This is useful when using multiple devices (like hikey960...) that
have identical bogus serial numbers like 0123456789ABCDEF.
Bug: http://b/37043226
Test: adb -t {1, 2, 9999999} {get-serialno, shell, features}
Change-Id: I55e5dc5a406a4eeee0012e39b52e8cd232e608a6
diff --git a/adb/sockets.cpp b/adb/sockets.cpp
index e0143c6..f28a3df 100644
--- a/adb/sockets.cpp
+++ b/adb/sockets.cpp
@@ -430,10 +430,11 @@
}
#if ADB_HOST
-static asocket* create_host_service_socket(const char* name, const char* serial) {
+static asocket* create_host_service_socket(const char* name, const char* serial,
+ TransportId transport_id) {
asocket* s;
- s = host_service_to_socket(name, serial);
+ s = host_service_to_socket(name, serial, transport_id);
if (s != NULL) {
D("LS(%d) bound to '%s'", s->id, name);
@@ -658,6 +659,7 @@
#if ADB_HOST
char* service = nullptr;
char* serial = nullptr;
+ TransportId transport_id = 0;
TransportType type = kTransportAny;
#endif
@@ -715,6 +717,14 @@
serial = service;
service = serial_end + 1;
}
+ } else if (!strncmp(service, "host-transport-id:", strlen("host-transport-id:"))) {
+ service += strlen("host-transport-id:");
+ transport_id = strtoll(service, &service, 10);
+
+ if (*service != ':') {
+ return -1;
+ }
+ service++;
} else if (!strncmp(service, "host-usb:", strlen("host-usb:"))) {
type = kTransportUsb;
service += strlen("host-usb:");
@@ -736,7 +746,7 @@
** the OKAY or FAIL message and all we have to do
** is clean up.
*/
- if (handle_host_request(service, type, serial, s->peer->fd, s) == 0) {
+ if (handle_host_request(service, type, serial, transport_id, s->peer->fd, s) == 0) {
/* XXX fail message? */
D("SS(%d): handled host service '%s'", s->id, service);
goto fail;
@@ -751,7 +761,7 @@
** if no such service exists, we'll fail out
** and tear down here.
*/
- s2 = create_host_service_socket(service, serial);
+ s2 = create_host_service_socket(service, serial, transport_id);
if (s2 == 0) {
D("SS(%d): couldn't create host service '%s'", s->id, service);
SendFail(s->peer->fd, "unknown host service");
@@ -783,7 +793,7 @@
#else /* !ADB_HOST */
if (s->transport == nullptr) {
std::string error_msg = "unknown failure";
- s->transport = acquire_one_transport(kTransportAny, nullptr, nullptr, &error_msg);
+ s->transport = acquire_one_transport(kTransportAny, nullptr, 0, nullptr, &error_msg);
if (s->transport == nullptr) {
SendFail(s->peer->fd, error_msg);
goto fail;