adb: fix `adb reverse` when adbd has multiple transports.
Plumb the transport that we received the adb reverse request on through
to reverse_service, instead of trying to get a unique transport on
devices that have multiple active transports (e.g. a device with USB
(even unplugged) connected via TCP).
Bug: http://b/37066218
Bug: http://b/71898863
Test: `echo foo | nc -l 12345 & adb reverse tcp:12345 tcp:12345; adb shell nc localhost 12345` on a device connected via TCP
Change-Id: Iae199ae787f2e344126bbcacca8544cfc9844a4c
diff --git a/adb/adb.cpp b/adb/adb.cpp
index 702a5a2..4fbfafb 100644
--- a/adb/adb.cpp
+++ b/adb/adb.cpp
@@ -933,8 +933,7 @@
// Try to handle a network forwarding request.
// This returns 1 on success, 0 on failure, and -1 to indicate this is not
// a forwarding-related request.
-int handle_forward_request(const char* service, TransportType type, const char* serial,
- TransportId transport_id, int reply_fd) {
+int handle_forward_request(const char* service, atransport* transport, int reply_fd) {
if (!strcmp(service, "list-forward")) {
// Create the list of forward redirections.
std::string listeners = format_listeners();
@@ -986,14 +985,6 @@
}
}
- std::string error_msg;
- atransport* transport =
- acquire_one_transport(type, serial, transport_id, nullptr, &error_msg);
- if (!transport) {
- SendFail(reply_fd, error_msg);
- return 1;
- }
-
std::string error;
InstallStatus r;
int resolved_tcp_port = 0;
@@ -1227,7 +1218,13 @@
return SendOkay(reply_fd, response);
}
- int ret = handle_forward_request(service, type, serial, transport_id, reply_fd);
+ std::string error;
+ atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
+ if (!t) {
+ return SendFail(reply_fd, error);
+ }
+
+ int ret = handle_forward_request(service, t, reply_fd);
if (ret >= 0)
return ret - 1;
return -1;