diff options
author | Elliott Hughes <enh@google.com> | 2015-04-16 22:54:44 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-04-16 22:54:44 -0700 |
commit | 7be29c819b4fb8bf9b1d4b69a4333f8765de0281 (patch) | |
tree | 8d5b1c0328310782acd5c735e9a42ecff24f49a3 | |
parent | a4802ca08bfcbf0124f5e9b959ed4e3a198d5f46 (diff) | |
download | system_core-7be29c819b4fb8bf9b1d4b69a4333f8765de0281.zip system_core-7be29c819b4fb8bf9b1d4b69a4333f8765de0281.tar.gz system_core-7be29c819b4fb8bf9b1d4b69a4333f8765de0281.tar.bz2 |
Show $ADB_VENDOR_KEYS if authentication fails.
Incorrectly set $ADB_VENDOR_KEYS is the most likely cause of failed
adb connections. Make it easier to debug such problems by including
the value in use in the error message.
Bug: 20165551
Change-Id: I64c1d98ae6d3fb40eea9e1f0ddcfcf4f2d9d7318
-rw-r--r-- | adb/adb.cpp | 16 | ||||
-rw-r--r-- | adb/services.cpp | 8 | ||||
-rw-r--r-- | adb/sockets.cpp | 7 | ||||
-rw-r--r-- | adb/transport.cpp | 46 | ||||
-rw-r--r-- | adb/transport.h | 13 |
5 files changed, 40 insertions, 50 deletions
diff --git a/adb/adb.cpp b/adb/adb.cpp index ad85184..b09e853 100644 --- a/adb/adb.cpp +++ b/adb/adb.cpp @@ -838,10 +838,10 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri } } - const char* err; - transport = acquire_one_transport(CS_ANY, ttype, serial, &err); + std::string error_msg; + transport = acquire_one_transport(CS_ANY, ttype, serial, &error_msg); if (!transport) { - sendfailmsg(reply_fd, err); + sendfailmsg(reply_fd, error_msg.c_str()); return 1; } @@ -910,14 +910,14 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r serial = service; } - const char* error_string = "unknown failure"; - transport = acquire_one_transport(CS_ANY, type, serial, &error_string); + std::string error_msg = "unknown failure"; + transport = acquire_one_transport(CS_ANY, type, serial, &error_msg); if (transport) { s->transport = transport; adb_write(reply_fd, "OKAY", 4); } else { - sendfailmsg(reply_fd, error_string); + sendfailmsg(reply_fd, error_msg.c_str()); } return 1; } @@ -975,7 +975,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r if(!strncmp(service,"get-serialno",strlen("get-serialno"))) { const char *out = "unknown"; transport = acquire_one_transport(CS_ANY, ttype, serial, NULL); - if (transport && transport->serial) { + if (transport && transport->serial) { out = transport->serial; } send_msg_with_okay(reply_fd, out, strlen(out)); @@ -984,7 +984,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r if(!strncmp(service,"get-devpath",strlen("get-devpath"))) { const char *out = "unknown"; transport = acquire_one_transport(CS_ANY, ttype, serial, NULL); - if (transport && transport->devpath) { + if (transport && transport->devpath) { out = transport->devpath; } send_msg_with_okay(reply_fd, out, strlen(out)); diff --git a/adb/services.cpp b/adb/services.cpp index 12eb406..e58100f 100644 --- a/adb/services.cpp +++ b/adb/services.cpp @@ -559,12 +559,12 @@ static void wait_for_state(int fd, void* cookie) D("wait_for_state %d\n", sinfo->state); - const char* err = "unknown error"; - atransport *t = acquire_one_transport(sinfo->state, sinfo->transport, sinfo->serial, &err); - if(t != 0) { + std::string error_msg = "unknown error"; + atransport* t = acquire_one_transport(sinfo->state, sinfo->transport, sinfo->serial, &error_msg); + if (t != 0) { WriteFdExactly(fd, "OKAY", 4); } else { - sendfailmsg(fd, err); + sendfailmsg(fd, error_msg.c_str()); } if (sinfo->serial) diff --git a/adb/sockets.cpp b/adb/sockets.cpp index 48d02d6..e52d6b1 100644 --- a/adb/sockets.cpp +++ b/adb/sockets.cpp @@ -827,12 +827,11 @@ static int smart_socket_enqueue(asocket *s, apacket *p) } #else /* !ADB_HOST */ if (s->transport == NULL) { - const char* error_string = "unknown failure"; - s->transport = acquire_one_transport (CS_ANY, - kTransportAny, NULL, &error_string); + std::string error_msg = "unknown failure"; + s->transport = acquire_one_transport(CS_ANY, kTransportAny, NULL, &error_msg); if (s->transport == NULL) { - sendfailmsg(s->peer->fd, error_string); + sendfailmsg(s->peer->fd, error_msg.c_str()); goto fail; } } diff --git a/adb/transport.cpp b/adb/transport.cpp index 4b9eeeb..f3e6461 100644 --- a/adb/transport.cpp +++ b/adb/transport.cpp @@ -800,22 +800,20 @@ static int qual_match(const char *to_test, return !*to_test; } -atransport *acquire_one_transport(int state, transport_type ttype, - const char* serial, const char** error_out) +atransport* acquire_one_transport(int state, transport_type ttype, + const char* serial, std::string* error_out) { atransport *t; atransport *result = NULL; int ambiguous = 0; retry: - if (error_out) - *error_out = "device not found"; + if (error_out) *error_out = "device not found"; adb_mutex_lock(&transport_lock); for (t = transport_list.next; t != &transport_list; t = t->next) { if (t->connection_state == CS_NOPERM) { - if (error_out) - *error_out = "insufficient permissions for device"; + if (error_out) *error_out = "insufficient permissions for device"; continue; } @@ -827,8 +825,7 @@ retry: qual_match(serial, "model:", t->model, true) || qual_match(serial, "device:", t->device, false)) { if (result) { - if (error_out) - *error_out = "more than one device"; + if (error_out) *error_out = "more than one device"; ambiguous = 1; result = NULL; break; @@ -838,8 +835,7 @@ retry: } else { if (ttype == kTransportUsb && t->type == kTransportUsb) { if (result) { - if (error_out) - *error_out = "more than one device"; + if (error_out) *error_out = "more than one device"; ambiguous = 1; result = NULL; break; @@ -847,8 +843,7 @@ retry: result = t; } else if (ttype == kTransportLocal && t->type == kTransportLocal) { if (result) { - if (error_out) - *error_out = "more than one emulator"; + if (error_out) *error_out = "more than one emulator"; ambiguous = 1; result = NULL; break; @@ -856,8 +851,7 @@ retry: result = t; } else if (ttype == kTransportAny) { if (result) { - if (error_out) - *error_out = "more than one device and emulator"; + if (error_out) *error_out = "more than one device and emulator"; ambiguous = 1; result = NULL; break; @@ -870,29 +864,33 @@ retry: if (result) { if (result->connection_state == CS_UNAUTHORIZED) { - if (error_out) - *error_out = "device unauthorized. Please check the confirmation dialog on your device."; + if (error_out) { + *error_out = "device unauthorized.\n"; + char* ADB_VENDOR_KEYS = getenv("ADB_VENDOR_KEYS"); + *error_out += "This adbd's $ADB_VENDOR_KEYS is "; + *error_out += ADB_VENDOR_KEYS ? ADB_VENDOR_KEYS : "not set"; + *error_out += "; try 'adb kill-server' if that seems wrong.\n"; + *error_out += "Otherwise check for a confirmation dialog on your device."; + } 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 == CS_OFFLINE) { - if (error_out) - *error_out = "device offline"; + if (error_out) *error_out = "device offline"; result = NULL; } - /* check for required connection state */ + + /* check for required connection state */ if (result && state != CS_ANY && result->connection_state != state) { - if (error_out) - *error_out = "invalid device state"; + if (error_out) *error_out = "invalid device state"; result = NULL; } } if (result) { /* found one that we can take */ - if (error_out) - *error_out = NULL; + if (error_out) *error_out = "success"; } else if (state != CS_ANY && (serial || !ambiguous)) { adb_sleep_ms(1000); goto retry; diff --git a/adb/transport.h b/adb/transport.h index 36a0e40..a2077e8 100644 --- a/adb/transport.h +++ b/adb/transport.h @@ -17,14 +17,11 @@ #ifndef __TRANSPORT_H #define __TRANSPORT_H -#include <stdbool.h> #include <sys/types.h> -#include "adb.h" +#include <string> -#ifdef __cplusplus -extern "C" { -#endif +#include "adb.h" #if ADB_TRACE void dump_hex(const unsigned char* ptr, size_t len); @@ -37,7 +34,7 @@ void dump_hex(const unsigned char* ptr, size_t len); * If no suitable transport is found, error is set. */ atransport* acquire_one_transport(int state, transport_type ttype, - const char* serial, const char** error_out); + const char* serial, std::string* error_out); void add_transport_disconnect(atransport* t, adisconnect* dis); void remove_transport_disconnect(atransport* t, adisconnect* dis); void kick_transport(atransport* t); @@ -74,8 +71,4 @@ void send_packet(apacket* p, atransport* t); asocket* create_device_tracker(void); -#ifdef __cplusplus -} -#endif - #endif /* __TRANSPORT_H */ |