Merge "Improve the "device '(null)' not found" error."

This commit is contained in:
Elliott Hughes 2015-06-24 19:31:19 +00:00 committed by Gerrit Code Review
commit 9137d65e9b
3 changed files with 48 additions and 61 deletions

View file

@ -835,6 +835,14 @@ int handle_forward_request(const char* service, TransportType type, const char*
return 0; return 0;
} }
#if ADB_HOST
static int SendOkay(int fd, const std::string& s) {
SendOkay(fd);
SendProtocolString(fd, s);
return 0;
}
#endif
int handle_host_request(const char* service, TransportType type, int handle_host_request(const char* service, TransportType type,
const char* serial, int reply_fd, asocket* s) { const char* serial, int reply_fd, asocket* s) {
if (strcmp(service, "kill") == 0) { if (strcmp(service, "kill") == 0) {
@ -845,7 +853,6 @@ int handle_host_request(const char* service, TransportType type,
} }
#if ADB_HOST #if ADB_HOST
atransport *transport = NULL;
// "transport:" is used for switching transport with a specified serial number // "transport:" is used for switching transport with a specified serial number
// "transport-usb:" is used for switching transport to the only USB transport // "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-local:" is used for switching transport to the only local transport
@ -864,11 +871,10 @@ int handle_host_request(const char* service, TransportType type,
serial = service; serial = service;
} }
std::string error_msg = "unknown failure"; std::string error_msg;
transport = acquire_one_transport(kCsAny, type, serial, &error_msg); atransport* t = acquire_one_transport(kCsAny, type, serial, &error_msg);
if (t != nullptr) {
if (transport) { s->transport = t;
s->transport = transport;
SendOkay(reply_fd); SendOkay(reply_fd);
} else { } else {
SendFail(reply_fd, error_msg); SendFail(reply_fd, error_msg);
@ -883,9 +889,7 @@ int handle_host_request(const char* service, TransportType type,
D("Getting device list...\n"); D("Getting device list...\n");
std::string device_list = list_transports(long_listing); std::string device_list = list_transports(long_listing);
D("Sending device list...\n"); D("Sending device list...\n");
SendOkay(reply_fd); return SendOkay(reply_fd, device_list);
SendProtocolString(reply_fd, device_list);
return 0;
} }
return 1; return 1;
} }
@ -905,8 +909,7 @@ int handle_host_request(const char* service, TransportType type,
snprintf(hostbuf, sizeof(hostbuf) - 1, "%s:5555", serial); snprintf(hostbuf, sizeof(hostbuf) - 1, "%s:5555", serial);
serial = hostbuf; serial = hostbuf;
} }
atransport *t = find_transport(serial); atransport* t = find_transport(serial);
if (t) { if (t) {
unregister_transport(t); unregister_transport(t);
} else { } else {
@ -914,52 +917,38 @@ int handle_host_request(const char* service, TransportType type,
} }
} }
SendOkay(reply_fd); return SendOkay(reply_fd, buffer);
SendProtocolString(reply_fd, buffer);
return 0;
} }
// returns our value for ADB_SERVER_VERSION // returns our value for ADB_SERVER_VERSION
if (!strcmp(service, "version")) { if (!strcmp(service, "version")) {
SendOkay(reply_fd); return SendOkay(reply_fd, android::base::StringPrintf("%04x", ADB_SERVER_VERSION));
SendProtocolString(reply_fd, android::base::StringPrintf("%04x", ADB_SERVER_VERSION));
return 0;
} }
if(!strncmp(service,"get-serialno",strlen("get-serialno"))) { // These always report "unknown" rather than the actual error, for scripts.
const char *out = "unknown"; if (!strcmp(service, "get-serialno")) {
transport = acquire_one_transport(kCsAny, type, serial, NULL); std::string ignored;
if (transport && transport->serial) { atransport* t = acquire_one_transport(kCsAny, type, serial, &ignored);
out = transport->serial; return SendOkay(reply_fd, (t && t->serial) ? t->serial : "unknown");
}
SendOkay(reply_fd);
SendProtocolString(reply_fd, out);
return 0;
} }
if(!strncmp(service,"get-devpath",strlen("get-devpath"))) { if (!strcmp(service, "get-devpath")) {
const char *out = "unknown"; std::string ignored;
transport = acquire_one_transport(kCsAny, type, serial, NULL); atransport* t = acquire_one_transport(kCsAny, type, serial, &ignored);
if (transport && transport->devpath) { return SendOkay(reply_fd, (t && t->devpath) ? t->devpath : "unknown");
out = transport->devpath;
}
SendOkay(reply_fd);
SendProtocolString(reply_fd, out);
return 0;
} }
if (!strcmp(service, "get-state")) {
std::string ignored;
atransport* t = acquire_one_transport(kCsAny, type, serial, &ignored);
return SendOkay(reply_fd, t ? t->connection_state_name() : "unknown");
}
// indicates a new emulator instance has started // indicates a new emulator instance has started
if (!strncmp(service,"emulator:",9)) { if (!strncmp(service, "emulator:", 9)) {
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 0;
} }
if(!strncmp(service,"get-state",strlen("get-state"))) {
transport = acquire_one_transport(kCsAny, type, serial, NULL);
SendOkay(reply_fd);
SendProtocolString(reply_fd, transport->connection_state_name());
return 0;
}
#endif // ADB_HOST #endif // ADB_HOST
int ret = handle_forward_request(service, type, serial, reply_fd); int ret = handle_forward_request(service, type, serial, reply_fd);

View file

@ -528,7 +528,7 @@ static void wait_for_state(int fd, void* cookie)
std::string error_msg = "unknown error"; std::string error_msg = "unknown error";
atransport* t = acquire_one_transport(sinfo->state, sinfo->transport_type, sinfo->serial, atransport* t = acquire_one_transport(sinfo->state, sinfo->transport_type, sinfo->serial,
&error_msg); &error_msg);
if (t != 0) { if (t != nullptr) {
SendOkay(fd); SendOkay(fd);
} else { } else {
SendFail(fd, error_msg); SendFail(fd, error_msg);

View file

@ -731,12 +731,12 @@ atransport* acquire_one_transport(ConnectionState state, TransportType type,
int ambiguous = 0; int ambiguous = 0;
retry: retry:
if (error_out) *error_out = android::base::StringPrintf("device '%s' not found", serial); *error_out = serial ? android::base::StringPrintf("device '%s' not found", serial) : "no devices found";
adb_mutex_lock(&transport_lock); adb_mutex_lock(&transport_lock);
for (auto t : transport_list) { for (auto t : transport_list) {
if (t->connection_state == kCsNoPerm) { if (t->connection_state == kCsNoPerm) {
if (error_out) *error_out = "insufficient permissions for device"; *error_out = "insufficient permissions for device";
continue; continue;
} }
@ -748,7 +748,7 @@ retry:
qual_match(serial, "model:", t->model, true) || qual_match(serial, "model:", t->model, true) ||
qual_match(serial, "device:", t->device, false)) { qual_match(serial, "device:", t->device, false)) {
if (result) { if (result) {
if (error_out) *error_out = "more than one device"; *error_out = "more than one device";
ambiguous = 1; ambiguous = 1;
result = NULL; result = NULL;
break; break;
@ -758,7 +758,7 @@ retry:
} else { } else {
if (type == kTransportUsb && t->type == kTransportUsb) { if (type == kTransportUsb && t->type == kTransportUsb) {
if (result) { if (result) {
if (error_out) *error_out = "more than one device"; *error_out = "more than one device";
ambiguous = 1; ambiguous = 1;
result = NULL; result = NULL;
break; break;
@ -766,7 +766,7 @@ retry:
result = t; result = t;
} else if (type == kTransportLocal && t->type == kTransportLocal) { } else if (type == kTransportLocal && t->type == kTransportLocal) {
if (result) { if (result) {
if (error_out) *error_out = "more than one emulator"; *error_out = "more than one emulator";
ambiguous = 1; ambiguous = 1;
result = NULL; result = NULL;
break; break;
@ -774,7 +774,7 @@ retry:
result = t; result = t;
} else if (type == kTransportAny) { } else if (type == kTransportAny) {
if (result) { if (result) {
if (error_out) *error_out = "more than one device/emulator"; *error_out = "more than one device/emulator";
ambiguous = 1; ambiguous = 1;
result = NULL; result = NULL;
break; break;
@ -787,33 +787,31 @@ retry:
if (result) { if (result) {
if (result->connection_state == kCsUnauthorized) { if (result->connection_state == kCsUnauthorized) {
if (error_out) { *error_out = "device unauthorized.\n";
*error_out = "device unauthorized.\n"; char* ADB_VENDOR_KEYS = getenv("ADB_VENDOR_KEYS");
char* ADB_VENDOR_KEYS = getenv("ADB_VENDOR_KEYS"); *error_out += "This adbd's $ADB_VENDOR_KEYS is ";
*error_out += "This adbd's $ADB_VENDOR_KEYS is "; *error_out += ADB_VENDOR_KEYS ? ADB_VENDOR_KEYS : "not set";
*error_out += ADB_VENDOR_KEYS ? ADB_VENDOR_KEYS : "not set"; *error_out += "; try 'adb kill-server' if that seems wrong.\n";
*error_out += "; try 'adb kill-server' if that seems wrong.\n"; *error_out += "Otherwise check for a confirmation dialog on your device.";
*error_out += "Otherwise check for a confirmation dialog on your device.";
}
result = NULL; result = NULL;
} }
/* offline devices are ignored -- they are either being born or dying */ /* offline devices are ignored -- they are either being born or dying */
if (result && result->connection_state == kCsOffline) { if (result && result->connection_state == kCsOffline) {
if (error_out) *error_out = "device offline"; *error_out = "device offline";
result = NULL; result = NULL;
} }
/* check for required connection state */ /* check for required connection state */
if (result && state != kCsAny && result->connection_state != state) { if (result && state != kCsAny && result->connection_state != state) {
if (error_out) *error_out = "invalid device state"; *error_out = "invalid device state";
result = NULL; result = NULL;
} }
} }
if (result) { if (result) {
/* found one that we can take */ /* found one that we can take */
if (error_out) *error_out = "success"; *error_out = "success";
} else if (state != kCsAny && (serial || !ambiguous)) { } else if (state != kCsAny && (serial || !ambiguous)) {
adb_sleep_ms(1000); adb_sleep_ms(1000);
goto retry; goto retry;