diff options
-rw-r--r-- | adb/adb.cpp | 19 | ||||
-rw-r--r-- | adb/adb.h | 5 | ||||
-rw-r--r-- | adb/services.cpp | 11 | ||||
-rw-r--r-- | adb/socket.h | 3 | ||||
-rw-r--r-- | adb/sockets.cpp | 2 |
5 files changed, 17 insertions, 23 deletions
diff --git a/adb/adb.cpp b/adb/adb.cpp index c4df5c4b9..70e083b5f 100644 --- a/adb/adb.cpp +++ b/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); diff --git a/adb/services.cpp b/adb/services.cpp index fe74eb6e4..0b0c1612c 100644 --- a/adb/services.cpp +++ b/adb/services.cpp @@ -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) { diff --git a/adb/socket.h b/adb/socket.h index 2f0908050..88499b55a 100644 --- a/adb/socket.h +++ b/adb/socket.h @@ -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); diff --git a/adb/sockets.cpp b/adb/sockets.cpp index e05a3dbc6..04bd0804e 100644 --- a/adb/sockets.cpp +++ b/adb/sockets.cpp @@ -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(); |