Merge "adb: clean up handle_host_request."
This commit is contained in:
commit
f41897a66e
3 changed files with 41 additions and 34 deletions
61
adb/adb.cpp
61
adb/adb.cpp
|
|
@ -1044,7 +1044,7 @@ static int SendOkay(int fd, const std::string& s) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int handle_host_request(const char* service, TransportType type, const char* serial,
|
bool handle_host_request(const char* service, TransportType type, const char* serial,
|
||||||
TransportId transport_id, int reply_fd, asocket* s) {
|
TransportId transport_id, int reply_fd, asocket* s) {
|
||||||
if (strcmp(service, "kill") == 0) {
|
if (strcmp(service, "kill") == 0) {
|
||||||
fprintf(stderr, "adb server killed by remote request\n");
|
fprintf(stderr, "adb server killed by remote request\n");
|
||||||
|
|
@ -1070,7 +1070,7 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
||||||
transport_id = strtoll(service, const_cast<char**>(&service), 10);
|
transport_id = strtoll(service, const_cast<char**>(&service), 10);
|
||||||
if (*service != '\0') {
|
if (*service != '\0') {
|
||||||
SendFail(reply_fd, "invalid transport id");
|
SendFail(reply_fd, "invalid transport id");
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (!strncmp(service, "transport-usb", strlen("transport-usb"))) {
|
} else if (!strncmp(service, "transport-usb", strlen("transport-usb"))) {
|
||||||
type = kTransportUsb;
|
type = kTransportUsb;
|
||||||
|
|
@ -1088,10 +1088,13 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
||||||
if (t != nullptr) {
|
if (t != nullptr) {
|
||||||
s->transport = t;
|
s->transport = t;
|
||||||
SendOkay(reply_fd);
|
SendOkay(reply_fd);
|
||||||
|
|
||||||
|
// We succesfully handled the device selection, but there's another request coming.
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
SendFail(reply_fd, error);
|
SendFail(reply_fd, error);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a list of all connected devices
|
// return a list of all connected devices
|
||||||
|
|
@ -1101,9 +1104,9 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
||||||
D("Getting device list...");
|
D("Getting device list...");
|
||||||
std::string device_list = list_transports(long_listing);
|
std::string device_list = list_transports(long_listing);
|
||||||
D("Sending device list...");
|
D("Sending device list...");
|
||||||
return SendOkay(reply_fd, device_list);
|
SendOkay(reply_fd, device_list);
|
||||||
}
|
}
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(service, "reconnect-offline")) {
|
if (!strcmp(service, "reconnect-offline")) {
|
||||||
|
|
@ -1119,7 +1122,7 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
||||||
response.resize(response.size() - 1);
|
response.resize(response.size() - 1);
|
||||||
}
|
}
|
||||||
SendOkay(reply_fd, response);
|
SendOkay(reply_fd, response);
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(service, "features")) {
|
if (!strcmp(service, "features")) {
|
||||||
|
|
@ -1130,7 +1133,7 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
||||||
} else {
|
} else {
|
||||||
SendFail(reply_fd, error);
|
SendFail(reply_fd, error);
|
||||||
}
|
}
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(service, "host-features")) {
|
if (!strcmp(service, "host-features")) {
|
||||||
|
|
@ -1141,7 +1144,7 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
||||||
}
|
}
|
||||||
features.insert(kFeaturePushSync);
|
features.insert(kFeaturePushSync);
|
||||||
SendOkay(reply_fd, FeatureSetToString(features));
|
SendOkay(reply_fd, FeatureSetToString(features));
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove TCP transport
|
// remove TCP transport
|
||||||
|
|
@ -1149,7 +1152,8 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
||||||
const std::string address(service + 11);
|
const std::string address(service + 11);
|
||||||
if (address.empty()) {
|
if (address.empty()) {
|
||||||
kick_all_tcp_devices();
|
kick_all_tcp_devices();
|
||||||
return SendOkay(reply_fd, "disconnected everything");
|
SendOkay(reply_fd, "disconnected everything");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string serial;
|
std::string serial;
|
||||||
|
|
@ -1157,21 +1161,24 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
||||||
int port = DEFAULT_ADB_LOCAL_TRANSPORT_PORT;
|
int port = DEFAULT_ADB_LOCAL_TRANSPORT_PORT;
|
||||||
std::string error;
|
std::string error;
|
||||||
if (!android::base::ParseNetAddress(address, &host, &port, &serial, &error)) {
|
if (!android::base::ParseNetAddress(address, &host, &port, &serial, &error)) {
|
||||||
return SendFail(reply_fd, android::base::StringPrintf("couldn't parse '%s': %s",
|
SendFail(reply_fd, android::base::StringPrintf("couldn't parse '%s': %s",
|
||||||
address.c_str(), error.c_str()));
|
address.c_str(), error.c_str()));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
atransport* t = find_transport(serial.c_str());
|
atransport* t = find_transport(serial.c_str());
|
||||||
if (t == nullptr) {
|
if (t == nullptr) {
|
||||||
return SendFail(reply_fd, android::base::StringPrintf("no such device '%s'",
|
SendFail(reply_fd, android::base::StringPrintf("no such device '%s'", serial.c_str()));
|
||||||
serial.c_str()));
|
return true;
|
||||||
}
|
}
|
||||||
kick_transport(t);
|
kick_transport(t);
|
||||||
return SendOkay(reply_fd, android::base::StringPrintf("disconnected %s", address.c_str()));
|
SendOkay(reply_fd, android::base::StringPrintf("disconnected %s", address.c_str()));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns our value for ADB_SERVER_VERSION.
|
// Returns our value for ADB_SERVER_VERSION.
|
||||||
if (!strcmp(service, "version")) {
|
if (!strcmp(service, "version")) {
|
||||||
return SendOkay(reply_fd, android::base::StringPrintf("%04x", ADB_SERVER_VERSION));
|
SendOkay(reply_fd, android::base::StringPrintf("%04x", ADB_SERVER_VERSION));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// These always report "unknown" rather than the actual error, for scripts.
|
// These always report "unknown" rather than the actual error, for scripts.
|
||||||
|
|
@ -1179,28 +1186,31 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
||||||
std::string error;
|
std::string error;
|
||||||
atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
|
atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
|
||||||
if (t) {
|
if (t) {
|
||||||
return SendOkay(reply_fd, !t->serial.empty() ? t->serial : "unknown");
|
SendOkay(reply_fd, !t->serial.empty() ? t->serial : "unknown");
|
||||||
} else {
|
} else {
|
||||||
return SendFail(reply_fd, error);
|
SendFail(reply_fd, error);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (!strcmp(service, "get-devpath")) {
|
if (!strcmp(service, "get-devpath")) {
|
||||||
std::string error;
|
std::string error;
|
||||||
atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
|
atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
|
||||||
if (t) {
|
if (t) {
|
||||||
return SendOkay(reply_fd, !t->devpath.empty() ? t->devpath : "unknown");
|
SendOkay(reply_fd, !t->devpath.empty() ? t->devpath : "unknown");
|
||||||
} else {
|
} else {
|
||||||
return SendFail(reply_fd, error);
|
SendFail(reply_fd, error);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (!strcmp(service, "get-state")) {
|
if (!strcmp(service, "get-state")) {
|
||||||
std::string error;
|
std::string error;
|
||||||
atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
|
atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
|
||||||
if (t) {
|
if (t) {
|
||||||
return SendOkay(reply_fd, t->connection_state_name());
|
SendOkay(reply_fd, t->connection_state_name());
|
||||||
} else {
|
} else {
|
||||||
return SendFail(reply_fd, error);
|
SendFail(reply_fd, error);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indicates a new emulator instance has started.
|
// Indicates a new emulator instance has started.
|
||||||
|
|
@ -1208,7 +1218,7 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
||||||
int port = atoi(service+9);
|
int port = atoi(service+9);
|
||||||
local_connect(port);
|
local_connect(port);
|
||||||
/* we don't even need to send a reply */
|
/* we don't even need to send a reply */
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(service, "reconnect")) {
|
if (!strcmp(service, "reconnect")) {
|
||||||
|
|
@ -1219,7 +1229,8 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
||||||
response =
|
response =
|
||||||
"reconnecting " + t->serial_name() + " [" + t->connection_state_name() + "]\n";
|
"reconnecting " + t->serial_name() + " [" + t->connection_state_name() + "]\n";
|
||||||
}
|
}
|
||||||
return SendOkay(reply_fd, response);
|
SendOkay(reply_fd, response);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle_forward_request(service,
|
if (handle_forward_request(service,
|
||||||
|
|
@ -1228,10 +1239,10 @@ int handle_host_request(const char* service, TransportType type, const char* ser
|
||||||
error);
|
error);
|
||||||
},
|
},
|
||||||
reply_fd)) {
|
reply_fd)) {
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto& init_mutex = *new std::mutex();
|
static auto& init_mutex = *new std::mutex();
|
||||||
|
|
|
||||||
|
|
@ -210,8 +210,8 @@ extern const char* adb_device_banner;
|
||||||
#define USB_FFS_ADB_IN USB_FFS_ADB_EP(ep2)
|
#define USB_FFS_ADB_IN USB_FFS_ADB_EP(ep2)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int handle_host_request(const char* service, TransportType type, const char* serial,
|
bool handle_host_request(const char* service, TransportType type, const char* serial,
|
||||||
TransportId transport_id, int reply_fd, asocket* s);
|
TransportId transport_id, int reply_fd, asocket* s);
|
||||||
|
|
||||||
void handle_online(atransport* t);
|
void handle_online(atransport* t);
|
||||||
void handle_offline(atransport* t);
|
void handle_offline(atransport* t);
|
||||||
|
|
|
||||||
|
|
@ -685,13 +685,9 @@ static int smart_socket_enqueue(asocket* s, apacket::payload_type data) {
|
||||||
if (service) {
|
if (service) {
|
||||||
asocket* s2;
|
asocket* s2;
|
||||||
|
|
||||||
/* some requests are handled immediately -- in that
|
// Some requests are handled immediately -- in that case the handle_host_request() routine
|
||||||
** case the handle_host_request() routine has sent
|
// has sent the OKAY or FAIL message and all we have to do is clean up.
|
||||||
** the OKAY or FAIL message and all we have to do
|
if (handle_host_request(service, type, serial, transport_id, s->peer->fd, s)) {
|
||||||
** is clean up.
|
|
||||||
*/
|
|
||||||
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);
|
D("SS(%d): handled host service '%s'", s->id, service);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue