Loading adb/adb.cpp +46 −41 Original line number Diff line number Diff line Loading @@ -1018,9 +1018,9 @@ static int SendOkay(int fd, const std::string& s) { return 0; } bool handle_host_request(const char* service, TransportType type, const char* serial, bool handle_host_request(std::string_view service, TransportType type, const char* serial, TransportId transport_id, int reply_fd, asocket* s) { if (strcmp(service, "kill") == 0) { if (service == "kill") { fprintf(stderr, "adb server killed by remote request\n"); fflush(stdout); Loading @@ -1036,25 +1036,25 @@ bool handle_host_request(const char* service, TransportType type, const char* se // "transport-usb:" is used for switching transport to the only USB transport // "transport-local:" is used for switching transport to the only local transport // "transport-any:" is used for switching transport to the only transport if (!strncmp(service, "transport", strlen("transport"))) { if (service.starts_with("transport")) { TransportType type = kTransportAny; if (!strncmp(service, "transport-id:", strlen("transport-id:"))) { service += strlen("transport-id:"); transport_id = strtoll(service, const_cast<char**>(&service), 10); if (*service != '\0') { std::string serial_storage; if (ConsumePrefix(&service, "transport-id:")) { if (!ParseUint(&transport_id, service)) { SendFail(reply_fd, "invalid transport id"); return true; } } else if (!strncmp(service, "transport-usb", strlen("transport-usb"))) { } else if (service == "transport-usb") { type = kTransportUsb; } else if (!strncmp(service, "transport-local", strlen("transport-local"))) { } else if (service == "transport-local") { type = kTransportLocal; } else if (!strncmp(service, "transport-any", strlen("transport-any"))) { } else if (service == "transport-any") { type = kTransportAny; } else if (!strncmp(service, "transport:", strlen("transport:"))) { service += strlen("transport:"); serial = service; } else if (ConsumePrefix(&service, "transport:")) { serial_storage = service; serial = serial_storage.c_str(); } std::string error; Loading @@ -1072,18 +1072,16 @@ bool handle_host_request(const char* service, TransportType type, const char* se } // return a list of all connected devices if (!strncmp(service, "devices", 7)) { bool long_listing = (strcmp(service+7, "-l") == 0); if (long_listing || service[7] == 0) { if (service == "devices" || service == "devices-l") { bool long_listing = service == "devices-l"; D("Getting device list..."); std::string device_list = list_transports(long_listing); D("Sending device list..."); SendOkay(reply_fd, device_list); } return true; } if (!strcmp(service, "reconnect-offline")) { if (service == "reconnect-offline") { std::string response; close_usb_devices([&response](const atransport* transport) { if (!ConnectionStateIsOnline(transport->GetConnectionState())) { Loading @@ -1099,7 +1097,7 @@ bool handle_host_request(const char* service, TransportType type, const char* se return true; } if (!strcmp(service, "features")) { if (service == "features") { std::string error; atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error); if (t != nullptr) { Loading @@ -1110,7 +1108,7 @@ bool handle_host_request(const char* service, TransportType type, const char* se return true; } if (!strcmp(service, "host-features")) { if (service == "host-features") { FeatureSet features = supported_features(); // Abuse features to report libusb status. if (should_use_libusb()) { Loading @@ -1122,8 +1120,8 @@ bool handle_host_request(const char* service, TransportType type, const char* se } // remove TCP transport if (!strncmp(service, "disconnect:", 11)) { const std::string address(service + 11); if (service.starts_with("disconnect:")) { std::string address(service.substr(11)); if (address.empty()) { kick_all_tcp_devices(); SendOkay(reply_fd, "disconnected everything"); Loading Loading @@ -1152,13 +1150,13 @@ bool handle_host_request(const char* service, TransportType type, const char* se } // Returns our value for ADB_SERVER_VERSION. if (!strcmp(service, "version")) { if (service == "version") { SendOkay(reply_fd, android::base::StringPrintf("%04x", ADB_SERVER_VERSION)); return true; } // These always report "unknown" rather than the actual error, for scripts. if (!strcmp(service, "get-serialno")) { if (service == "get-serialno") { std::string error; atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error); if (t) { Loading @@ -1168,7 +1166,7 @@ bool handle_host_request(const char* service, TransportType type, const char* se } return true; } if (!strcmp(service, "get-devpath")) { if (service == "get-devpath") { std::string error; atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error); if (t) { Loading @@ -1178,7 +1176,7 @@ bool handle_host_request(const char* service, TransportType type, const char* se } return true; } if (!strcmp(service, "get-state")) { if (service == "get-state") { std::string error; atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error); if (t) { Loading @@ -1190,14 +1188,19 @@ bool handle_host_request(const char* service, TransportType type, const char* se } // Indicates a new emulator instance has started. if (!strncmp(service, "emulator:", 9)) { int port = atoi(service+9); if (ConsumePrefix(&service, "emulator:")) { unsigned int port; if (!ParseUint(&port, service)) { LOG(ERROR) << "received invalid port for emulator: " << service; } else { local_connect(port); } /* we don't even need to send a reply */ return true; } if (!strcmp(service, "reconnect")) { if (service == "reconnect") { std::string response; atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &response, true); if (t != nullptr) { Loading @@ -1209,10 +1212,12 @@ bool handle_host_request(const char* service, TransportType type, const char* se return true; } if (handle_forward_request(service, // TODO: Switch handle_forward_request to string_view. std::string service_str(service); if (handle_forward_request( service_str.c_str(), [=](std::string* error) { return acquire_one_transport(type, serial, transport_id, nullptr, error); return acquire_one_transport(type, serial, transport_id, nullptr, error); }, reply_fd)) { return true; Loading adb/adb.h +1 −1 Original line number Diff line number Diff line Loading @@ -218,7 +218,7 @@ extern const char* adb_device_banner; #define USB_FFS_ADB_IN USB_FFS_ADB_EP(ep2) #endif bool handle_host_request(const char* service, TransportType type, const char* serial, bool handle_host_request(std::string_view service, TransportType type, const char* serial, TransportId transport_id, int reply_fd, asocket* s); void handle_online(atransport* t); Loading adb/sockets.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -808,8 +808,7 @@ static int smart_socket_enqueue(asocket* s, apacket::payload_type data) { // Some requests are handled immediately -- in that case the handle_host_request() routine // has sent the OKAY or FAIL message and all we have to do is clean up. // TODO: Convert to string_view. if (handle_host_request(std::string(service).c_str(), type, if (handle_host_request(service, type, serial.empty() ? nullptr : std::string(serial).c_str(), transport_id, s->peer->fd, s)) { LOG(VERBOSE) << "SS(" << s->id << "): handled host service '" << service << "'"; Loading Loading
adb/adb.cpp +46 −41 Original line number Diff line number Diff line Loading @@ -1018,9 +1018,9 @@ static int SendOkay(int fd, const std::string& s) { return 0; } bool handle_host_request(const char* service, TransportType type, const char* serial, bool handle_host_request(std::string_view service, TransportType type, const char* serial, TransportId transport_id, int reply_fd, asocket* s) { if (strcmp(service, "kill") == 0) { if (service == "kill") { fprintf(stderr, "adb server killed by remote request\n"); fflush(stdout); Loading @@ -1036,25 +1036,25 @@ bool handle_host_request(const char* service, TransportType type, const char* se // "transport-usb:" is used for switching transport to the only USB transport // "transport-local:" is used for switching transport to the only local transport // "transport-any:" is used for switching transport to the only transport if (!strncmp(service, "transport", strlen("transport"))) { if (service.starts_with("transport")) { TransportType type = kTransportAny; if (!strncmp(service, "transport-id:", strlen("transport-id:"))) { service += strlen("transport-id:"); transport_id = strtoll(service, const_cast<char**>(&service), 10); if (*service != '\0') { std::string serial_storage; if (ConsumePrefix(&service, "transport-id:")) { if (!ParseUint(&transport_id, service)) { SendFail(reply_fd, "invalid transport id"); return true; } } else if (!strncmp(service, "transport-usb", strlen("transport-usb"))) { } else if (service == "transport-usb") { type = kTransportUsb; } else if (!strncmp(service, "transport-local", strlen("transport-local"))) { } else if (service == "transport-local") { type = kTransportLocal; } else if (!strncmp(service, "transport-any", strlen("transport-any"))) { } else if (service == "transport-any") { type = kTransportAny; } else if (!strncmp(service, "transport:", strlen("transport:"))) { service += strlen("transport:"); serial = service; } else if (ConsumePrefix(&service, "transport:")) { serial_storage = service; serial = serial_storage.c_str(); } std::string error; Loading @@ -1072,18 +1072,16 @@ bool handle_host_request(const char* service, TransportType type, const char* se } // return a list of all connected devices if (!strncmp(service, "devices", 7)) { bool long_listing = (strcmp(service+7, "-l") == 0); if (long_listing || service[7] == 0) { if (service == "devices" || service == "devices-l") { bool long_listing = service == "devices-l"; D("Getting device list..."); std::string device_list = list_transports(long_listing); D("Sending device list..."); SendOkay(reply_fd, device_list); } return true; } if (!strcmp(service, "reconnect-offline")) { if (service == "reconnect-offline") { std::string response; close_usb_devices([&response](const atransport* transport) { if (!ConnectionStateIsOnline(transport->GetConnectionState())) { Loading @@ -1099,7 +1097,7 @@ bool handle_host_request(const char* service, TransportType type, const char* se return true; } if (!strcmp(service, "features")) { if (service == "features") { std::string error; atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error); if (t != nullptr) { Loading @@ -1110,7 +1108,7 @@ bool handle_host_request(const char* service, TransportType type, const char* se return true; } if (!strcmp(service, "host-features")) { if (service == "host-features") { FeatureSet features = supported_features(); // Abuse features to report libusb status. if (should_use_libusb()) { Loading @@ -1122,8 +1120,8 @@ bool handle_host_request(const char* service, TransportType type, const char* se } // remove TCP transport if (!strncmp(service, "disconnect:", 11)) { const std::string address(service + 11); if (service.starts_with("disconnect:")) { std::string address(service.substr(11)); if (address.empty()) { kick_all_tcp_devices(); SendOkay(reply_fd, "disconnected everything"); Loading Loading @@ -1152,13 +1150,13 @@ bool handle_host_request(const char* service, TransportType type, const char* se } // Returns our value for ADB_SERVER_VERSION. if (!strcmp(service, "version")) { if (service == "version") { SendOkay(reply_fd, android::base::StringPrintf("%04x", ADB_SERVER_VERSION)); return true; } // These always report "unknown" rather than the actual error, for scripts. if (!strcmp(service, "get-serialno")) { if (service == "get-serialno") { std::string error; atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error); if (t) { Loading @@ -1168,7 +1166,7 @@ bool handle_host_request(const char* service, TransportType type, const char* se } return true; } if (!strcmp(service, "get-devpath")) { if (service == "get-devpath") { std::string error; atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error); if (t) { Loading @@ -1178,7 +1176,7 @@ bool handle_host_request(const char* service, TransportType type, const char* se } return true; } if (!strcmp(service, "get-state")) { if (service == "get-state") { std::string error; atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error); if (t) { Loading @@ -1190,14 +1188,19 @@ bool handle_host_request(const char* service, TransportType type, const char* se } // Indicates a new emulator instance has started. if (!strncmp(service, "emulator:", 9)) { int port = atoi(service+9); if (ConsumePrefix(&service, "emulator:")) { unsigned int port; if (!ParseUint(&port, service)) { LOG(ERROR) << "received invalid port for emulator: " << service; } else { local_connect(port); } /* we don't even need to send a reply */ return true; } if (!strcmp(service, "reconnect")) { if (service == "reconnect") { std::string response; atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &response, true); if (t != nullptr) { Loading @@ -1209,10 +1212,12 @@ bool handle_host_request(const char* service, TransportType type, const char* se return true; } if (handle_forward_request(service, // TODO: Switch handle_forward_request to string_view. std::string service_str(service); if (handle_forward_request( service_str.c_str(), [=](std::string* error) { return acquire_one_transport(type, serial, transport_id, nullptr, error); return acquire_one_transport(type, serial, transport_id, nullptr, error); }, reply_fd)) { return true; Loading
adb/adb.h +1 −1 Original line number Diff line number Diff line Loading @@ -218,7 +218,7 @@ extern const char* adb_device_banner; #define USB_FFS_ADB_IN USB_FFS_ADB_EP(ep2) #endif bool handle_host_request(const char* service, TransportType type, const char* serial, bool handle_host_request(std::string_view service, TransportType type, const char* serial, TransportId transport_id, int reply_fd, asocket* s); void handle_online(atransport* t); Loading
adb/sockets.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -808,8 +808,7 @@ static int smart_socket_enqueue(asocket* s, apacket::payload_type data) { // Some requests are handled immediately -- in that case the handle_host_request() routine // has sent the OKAY or FAIL message and all we have to do is clean up. // TODO: Convert to string_view. if (handle_host_request(std::string(service).c_str(), type, if (handle_host_request(service, type, serial.empty() ? nullptr : std::string(serial).c_str(), transport_id, s->peer->fd, s)) { LOG(VERBOSE) << "SS(" << s->id << "): handled host service '" << service << "'"; Loading