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
(cherry picked from commit 44899eeb53)
This commit is contained in:
parent
217b8fcf86
commit
a98aab2a72
5 changed files with 17 additions and 23 deletions
19
adb/adb.cpp
19
adb/adb.cpp
|
|
@ -934,8 +934,7 @@ int launch_server(const std::string& socket_spec) {
|
|||
// 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();
|
||||
|
|
@ -987,14 +986,6 @@ int handle_forward_request(const char* service, TransportType type, const char*
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
@ -1228,7 +1219,13 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ atransport* find_emulator_transport_by_adb_port(int adb_port);
|
|||
atransport* find_emulator_transport_by_console_port(int console_port);
|
||||
#endif
|
||||
|
||||
int service_to_fd(const char* name, const atransport* transport);
|
||||
int service_to_fd(const char* name, atransport* transport);
|
||||
#if ADB_HOST
|
||||
asocket* host_service_to_socket(const char* name, const char* serial, TransportId transport_id);
|
||||
#endif
|
||||
|
|
@ -152,8 +152,7 @@ asocket* create_jdwp_tracker_service_socket();
|
|||
int create_jdwp_connection_fd(int jdwp_pid);
|
||||
#endif
|
||||
|
||||
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 !ADB_HOST
|
||||
void framebuffer_service(int fd, void* cookie);
|
||||
|
|
|
|||
|
|
@ -181,14 +181,14 @@ static void reconnect_service(int fd, void* arg) {
|
|||
kick_transport(t);
|
||||
}
|
||||
|
||||
int reverse_service(const char* command) {
|
||||
int reverse_service(const char* command, atransport* transport) {
|
||||
int s[2];
|
||||
if (adb_socketpair(s)) {
|
||||
PLOG(ERROR) << "cannot create service socket pair.";
|
||||
return -1;
|
||||
}
|
||||
VLOG(SERVICES) << "service socketpair: " << s[0] << ", " << s[1];
|
||||
if (handle_forward_request(command, kTransportAny, nullptr, 0, s[1]) < 0) {
|
||||
if (handle_forward_request(command, transport, s[1]) < 0) {
|
||||
SendFail(s[1], "not a reverse forwarding command");
|
||||
}
|
||||
adb_close(s[1]);
|
||||
|
|
@ -268,7 +268,7 @@ static int create_service_thread(const char* service_name, void (*func)(int, voi
|
|||
return s[0];
|
||||
}
|
||||
|
||||
int service_to_fd(const char* name, const atransport* transport) {
|
||||
int service_to_fd(const char* name, atransport* transport) {
|
||||
int ret = -1;
|
||||
|
||||
if (is_socket_spec(name)) {
|
||||
|
|
@ -317,7 +317,7 @@ int service_to_fd(const char* name, const atransport* transport) {
|
|||
} else if(!strncmp(name, "usb:", 4)) {
|
||||
ret = create_service_thread("usb", restart_usb_service, nullptr);
|
||||
} else if (!strncmp(name, "reverse:", 8)) {
|
||||
ret = reverse_service(name + 8);
|
||||
ret = reverse_service(name + 8, transport);
|
||||
} else if(!strncmp(name, "disable-verity:", 15)) {
|
||||
ret = create_service_thread("verity-on", set_verity_enabled_state_service,
|
||||
reinterpret_cast<void*>(0));
|
||||
|
|
@ -325,8 +325,7 @@ int service_to_fd(const char* name, const atransport* transport) {
|
|||
ret = create_service_thread("verity-off", set_verity_enabled_state_service,
|
||||
reinterpret_cast<void*>(1));
|
||||
} else if (!strcmp(name, "reconnect")) {
|
||||
ret = create_service_thread("reconnect", reconnect_service,
|
||||
const_cast<atransport*>(transport));
|
||||
ret = create_service_thread("reconnect", reconnect_service, transport);
|
||||
#endif
|
||||
}
|
||||
if (ret >= 0) {
|
||||
|
|
|
|||
|
|
@ -104,8 +104,7 @@ void remove_socket(asocket *s);
|
|||
void close_all_sockets(atransport *t);
|
||||
|
||||
asocket *create_local_socket(int fd);
|
||||
asocket *create_local_service_socket(const char* destination,
|
||||
const atransport* transport);
|
||||
asocket* create_local_service_socket(const char* destination, atransport* transport);
|
||||
|
||||
asocket *create_remote_socket(unsigned id, atransport *t);
|
||||
void connect_to_remote(asocket *s, const char *destination);
|
||||
|
|
|
|||
|
|
@ -348,7 +348,7 @@ asocket* create_local_socket(int fd) {
|
|||
return s;
|
||||
}
|
||||
|
||||
asocket* create_local_service_socket(const char* name, const atransport* transport) {
|
||||
asocket* create_local_service_socket(const char* name, atransport* transport) {
|
||||
#if !ADB_HOST
|
||||
if (!strcmp(name, "jdwp")) {
|
||||
return create_jdwp_service_socket();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue