Merge "Fix adb -d/-e error reporting."
This commit is contained in:
commit
1407b28628
7 changed files with 109 additions and 91 deletions
48
adb/adb.cpp
48
adb/adb.cpp
|
|
@ -904,7 +904,7 @@ int handle_forward_request(const char* service, TransportType type, const char*
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string error_msg;
|
std::string error_msg;
|
||||||
atransport* transport = acquire_one_transport(kCsAny, type, serial, &error_msg);
|
atransport* transport = acquire_one_transport(type, serial, nullptr, &error_msg);
|
||||||
if (!transport) {
|
if (!transport) {
|
||||||
SendFail(reply_fd, error_msg);
|
SendFail(reply_fd, error_msg);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -990,13 +990,13 @@ int handle_host_request(const char* service, TransportType type,
|
||||||
serial = service;
|
serial = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string error_msg;
|
std::string error;
|
||||||
atransport* t = acquire_one_transport(kCsAny, type, serial, &error_msg);
|
atransport* t = acquire_one_transport(type, serial, nullptr, &error);
|
||||||
if (t != nullptr) {
|
if (t != nullptr) {
|
||||||
s->transport = t;
|
s->transport = t;
|
||||||
SendOkay(reply_fd);
|
SendOkay(reply_fd);
|
||||||
} else {
|
} else {
|
||||||
SendFail(reply_fd, error_msg);
|
SendFail(reply_fd, error);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -1014,12 +1014,12 @@ int handle_host_request(const char* service, TransportType type,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(service, "features")) {
|
if (!strcmp(service, "features")) {
|
||||||
std::string error_msg;
|
std::string error;
|
||||||
atransport* t = acquire_one_transport(kCsAny, type, serial, &error_msg);
|
atransport* t = acquire_one_transport(type, serial, nullptr, &error);
|
||||||
if (t != nullptr) {
|
if (t != nullptr) {
|
||||||
SendOkay(reply_fd, FeatureSetToString(t->features()));
|
SendOkay(reply_fd, FeatureSetToString(t->features()));
|
||||||
} else {
|
} else {
|
||||||
SendFail(reply_fd, error_msg);
|
SendFail(reply_fd, error);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1049,29 +1049,41 @@ int handle_host_request(const char* service, TransportType type,
|
||||||
return SendOkay(reply_fd, android::base::StringPrintf("disconnected %s", address.c_str()));
|
return SendOkay(reply_fd, android::base::StringPrintf("disconnected %s", address.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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));
|
return SendOkay(reply_fd, android::base::StringPrintf("%04x", ADB_SERVER_VERSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
// These always report "unknown" rather than the actual error, for scripts.
|
// These always report "unknown" rather than the actual error, for scripts.
|
||||||
if (!strcmp(service, "get-serialno")) {
|
if (!strcmp(service, "get-serialno")) {
|
||||||
std::string ignored;
|
std::string error;
|
||||||
atransport* t = acquire_one_transport(kCsAny, type, serial, &ignored);
|
atransport* t = acquire_one_transport(type, serial, nullptr, &error);
|
||||||
return SendOkay(reply_fd, (t && t->serial) ? t->serial : "unknown");
|
if (t) {
|
||||||
|
return SendOkay(reply_fd, t->serial ? t->serial : "unknown");
|
||||||
|
} else {
|
||||||
|
return SendFail(reply_fd, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!strcmp(service, "get-devpath")) {
|
if (!strcmp(service, "get-devpath")) {
|
||||||
std::string ignored;
|
std::string error;
|
||||||
atransport* t = acquire_one_transport(kCsAny, type, serial, &ignored);
|
atransport* t = acquire_one_transport(type, serial, nullptr, &error);
|
||||||
return SendOkay(reply_fd, (t && t->devpath) ? t->devpath : "unknown");
|
if (t) {
|
||||||
|
return SendOkay(reply_fd, t->devpath ? t->devpath : "unknown");
|
||||||
|
} else {
|
||||||
|
return SendFail(reply_fd, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!strcmp(service, "get-state")) {
|
if (!strcmp(service, "get-state")) {
|
||||||
std::string ignored;
|
std::string error;
|
||||||
atransport* t = acquire_one_transport(kCsAny, type, serial, &ignored);
|
atransport* t = acquire_one_transport(type, serial, nullptr, &error);
|
||||||
return SendOkay(reply_fd, t ? t->connection_state_name() : "unknown");
|
if (t) {
|
||||||
|
return SendOkay(reply_fd, t->connection_state_name());
|
||||||
|
} else {
|
||||||
|
return SendFail(reply_fd, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
|
||||||
|
|
@ -209,9 +209,8 @@ int adb_connect(const std::string& service, std::string* error) {
|
||||||
adb_close(fd);
|
adb_close(fd);
|
||||||
|
|
||||||
if (sscanf(&version_string[0], "%04x", &version) != 1) {
|
if (sscanf(&version_string[0], "%04x", &version) != 1) {
|
||||||
*error = android::base::StringPrintf(
|
*error = android::base::StringPrintf("cannot parse version string: %s",
|
||||||
"cannot parse version string: %s",
|
version_string.c_str());
|
||||||
version_string.c_str());
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1093,8 +1093,6 @@ int adb_commandline(int argc, const char **argv) {
|
||||||
}
|
}
|
||||||
// TODO: also try TARGET_PRODUCT/TARGET_DEVICE as a hint
|
// TODO: also try TARGET_PRODUCT/TARGET_DEVICE as a hint
|
||||||
|
|
||||||
const char* serial = getenv("ANDROID_SERIAL");
|
|
||||||
|
|
||||||
/* Validate and assign the server port */
|
/* Validate and assign the server port */
|
||||||
const char* server_port_str = getenv("ANDROID_ADB_SERVER_PORT");
|
const char* server_port_str = getenv("ANDROID_ADB_SERVER_PORT");
|
||||||
int server_port = DEFAULT_ADB_PORT;
|
int server_port = DEFAULT_ADB_PORT;
|
||||||
|
|
@ -1108,7 +1106,9 @@ int adb_commandline(int argc, const char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* modifiers and flags */
|
// We need to check for -d and -e before we look at $ANDROID_SERIAL.
|
||||||
|
const char* serial = nullptr;
|
||||||
|
|
||||||
while (argc > 0) {
|
while (argc > 0) {
|
||||||
if (!strcmp(argv[0],"server")) {
|
if (!strcmp(argv[0],"server")) {
|
||||||
is_server = 1;
|
is_server = 1;
|
||||||
|
|
@ -1199,6 +1199,11 @@ int adb_commandline(int argc, const char **argv) {
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If none of -d, -e, or -s were specified, try $ANDROID_SERIAL.
|
||||||
|
if (transport_type == kTransportAny && serial == nullptr) {
|
||||||
|
serial = getenv("ANDROID_SERIAL");
|
||||||
|
}
|
||||||
|
|
||||||
adb_set_transport(transport_type, serial);
|
adb_set_transport(transport_type, serial);
|
||||||
adb_set_tcp_specifics(server_port);
|
adb_set_tcp_specifics(server_port);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -363,23 +363,31 @@ struct state_info {
|
||||||
ConnectionState state;
|
ConnectionState state;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void wait_for_state(int fd, void* cookie)
|
static void wait_for_state(int fd, void* cookie) {
|
||||||
{
|
|
||||||
state_info* sinfo = reinterpret_cast<state_info*>(cookie);
|
state_info* sinfo = reinterpret_cast<state_info*>(cookie);
|
||||||
|
|
||||||
D("wait_for_state %d", sinfo->state);
|
D("wait_for_state %d", sinfo->state);
|
||||||
|
|
||||||
std::string error_msg = "unknown error";
|
while (true) {
|
||||||
atransport* t = acquire_one_transport(sinfo->state, sinfo->transport_type, sinfo->serial,
|
bool is_ambiguous = false;
|
||||||
&error_msg);
|
std::string error = "unknown error";
|
||||||
if (t != nullptr) {
|
atransport* t = acquire_one_transport(sinfo->transport_type, sinfo->serial,
|
||||||
SendOkay(fd);
|
&is_ambiguous, &error);
|
||||||
} else {
|
if (t != nullptr && t->connection_state == sinfo->state) {
|
||||||
SendFail(fd, error_msg);
|
SendOkay(fd);
|
||||||
|
break;
|
||||||
|
} else if (!is_ambiguous) {
|
||||||
|
adb_sleep_ms(1000);
|
||||||
|
// Try again...
|
||||||
|
} else {
|
||||||
|
SendFail(fd, error);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sinfo->serial)
|
if (sinfo->serial) {
|
||||||
free(sinfo->serial);
|
free(sinfo->serial);
|
||||||
|
}
|
||||||
free(sinfo);
|
free(sinfo);
|
||||||
adb_close(fd);
|
adb_close(fd);
|
||||||
D("wait_for_state is done");
|
D("wait_for_state is done");
|
||||||
|
|
|
||||||
|
|
@ -671,8 +671,8 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
|
||||||
{
|
{
|
||||||
unsigned len;
|
unsigned len;
|
||||||
#if ADB_HOST
|
#if ADB_HOST
|
||||||
char *service = NULL;
|
char *service = nullptr;
|
||||||
char* serial = NULL;
|
char* serial = nullptr;
|
||||||
TransportType type = kTransportAny;
|
TransportType type = kTransportAny;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -739,7 +739,7 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
|
||||||
type = kTransportAny;
|
type = kTransportAny;
|
||||||
service += strlen("host:");
|
service += strlen("host:");
|
||||||
} else {
|
} else {
|
||||||
service = NULL;
|
service = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (service) {
|
if (service) {
|
||||||
|
|
@ -782,7 +782,7 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
|
||||||
SendOkay(s->peer->fd);
|
SendOkay(s->peer->fd);
|
||||||
|
|
||||||
s->peer->ready = local_socket_ready;
|
s->peer->ready = local_socket_ready;
|
||||||
s->peer->shutdown = NULL;
|
s->peer->shutdown = nullptr;
|
||||||
s->peer->close = local_socket_close;
|
s->peer->close = local_socket_close;
|
||||||
s->peer->peer = s2;
|
s->peer->peer = s2;
|
||||||
s2->peer = s->peer;
|
s2->peer = s->peer;
|
||||||
|
|
@ -795,12 +795,10 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else /* !ADB_HOST */
|
#else /* !ADB_HOST */
|
||||||
if (s->transport == NULL) {
|
if (s->transport == nullptr) {
|
||||||
std::string error_msg = "unknown failure";
|
std::string error_msg = "unknown failure";
|
||||||
s->transport =
|
s->transport = acquire_one_transport(kTransportAny, nullptr, nullptr, &error_msg);
|
||||||
acquire_one_transport(kCsAny, kTransportAny, NULL, &error_msg);
|
if (s->transport == nullptr) {
|
||||||
|
|
||||||
if (s->transport == NULL) {
|
|
||||||
SendFail(s->peer->fd, error_msg);
|
SendFail(s->peer->fd, error_msg);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
@ -822,7 +820,7 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
|
||||||
** tear down
|
** tear down
|
||||||
*/
|
*/
|
||||||
s->peer->ready = local_socket_ready_notify;
|
s->peer->ready = local_socket_ready_notify;
|
||||||
s->peer->shutdown = NULL;
|
s->peer->shutdown = nullptr;
|
||||||
s->peer->close = local_socket_close_notify;
|
s->peer->close = local_socket_close_notify;
|
||||||
s->peer->peer = 0;
|
s->peer->peer = 0;
|
||||||
/* give him our transport and upref it */
|
/* give him our transport and upref it */
|
||||||
|
|
|
||||||
|
|
@ -653,22 +653,28 @@ static int qual_match(const char *to_test,
|
||||||
return !*to_test;
|
return !*to_test;
|
||||||
}
|
}
|
||||||
|
|
||||||
atransport* acquire_one_transport(ConnectionState state, TransportType type,
|
atransport* acquire_one_transport(TransportType type, const char* serial,
|
||||||
const char* serial, std::string* error_out) {
|
bool* is_ambiguous, std::string* error_out) {
|
||||||
atransport *result = NULL;
|
atransport* result = nullptr;
|
||||||
int ambiguous = 0;
|
|
||||||
|
|
||||||
retry:
|
if (serial) {
|
||||||
*error_out = serial ? android::base::StringPrintf("device '%s' not found", serial) : "no devices found";
|
*error_out = android::base::StringPrintf("device '%s' not found", serial);
|
||||||
|
} else if (type == kTransportLocal) {
|
||||||
|
*error_out = "no emulators found";
|
||||||
|
} else if (type == kTransportAny) {
|
||||||
|
*error_out = "no devices/emulators found";
|
||||||
|
} else {
|
||||||
|
*error_out = "no devices found";
|
||||||
|
}
|
||||||
|
|
||||||
adb_mutex_lock(&transport_lock);
|
adb_mutex_lock(&transport_lock);
|
||||||
for (auto t : transport_list) {
|
for (const auto& t : transport_list) {
|
||||||
if (t->connection_state == kCsNoPerm) {
|
if (t->connection_state == kCsNoPerm) {
|
||||||
*error_out = "insufficient permissions for device";
|
*error_out = "insufficient permissions for device";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for matching serial number */
|
// Check for matching serial number.
|
||||||
if (serial) {
|
if (serial) {
|
||||||
if ((t->serial && !strcmp(serial, t->serial)) ||
|
if ((t->serial && !strcmp(serial, t->serial)) ||
|
||||||
(t->devpath && !strcmp(serial, t->devpath)) ||
|
(t->devpath && !strcmp(serial, t->devpath)) ||
|
||||||
|
|
@ -677,8 +683,8 @@ retry:
|
||||||
qual_match(serial, "device:", t->device, false)) {
|
qual_match(serial, "device:", t->device, false)) {
|
||||||
if (result) {
|
if (result) {
|
||||||
*error_out = "more than one device";
|
*error_out = "more than one device";
|
||||||
ambiguous = 1;
|
if (is_ambiguous) *is_ambiguous = true;
|
||||||
result = NULL;
|
result = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result = t;
|
result = t;
|
||||||
|
|
@ -687,24 +693,24 @@ retry:
|
||||||
if (type == kTransportUsb && t->type == kTransportUsb) {
|
if (type == kTransportUsb && t->type == kTransportUsb) {
|
||||||
if (result) {
|
if (result) {
|
||||||
*error_out = "more than one device";
|
*error_out = "more than one device";
|
||||||
ambiguous = 1;
|
if (is_ambiguous) *is_ambiguous = true;
|
||||||
result = NULL;
|
result = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result = t;
|
result = t;
|
||||||
} else if (type == kTransportLocal && t->type == kTransportLocal) {
|
} else if (type == kTransportLocal && t->type == kTransportLocal) {
|
||||||
if (result) {
|
if (result) {
|
||||||
*error_out = "more than one emulator";
|
*error_out = "more than one emulator";
|
||||||
ambiguous = 1;
|
if (is_ambiguous) *is_ambiguous = true;
|
||||||
result = NULL;
|
result = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result = t;
|
result = t;
|
||||||
} else if (type == kTransportAny) {
|
} else if (type == kTransportAny) {
|
||||||
if (result) {
|
if (result) {
|
||||||
*error_out = "more than one device/emulator";
|
*error_out = "more than one device/emulator";
|
||||||
ambiguous = 1;
|
if (is_ambiguous) *is_ambiguous = true;
|
||||||
result = NULL;
|
result = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result = t;
|
result = t;
|
||||||
|
|
@ -713,37 +719,26 @@ retry:
|
||||||
}
|
}
|
||||||
adb_mutex_unlock(&transport_lock);
|
adb_mutex_unlock(&transport_lock);
|
||||||
|
|
||||||
if (result) {
|
// Don't return unauthorized devices; the caller can't do anything with them.
|
||||||
if (result->connection_state == kCsUnauthorized) {
|
if (result && result->connection_state == kCsUnauthorized) {
|
||||||
*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 adb server's $ADB_VENDOR_KEYS is ";
|
*error_out += "This adb server'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 += "\n";
|
*error_out += "\n";
|
||||||
*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 = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* offline devices are ignored -- they are either being born or dying */
|
// Don't return offline devices; the caller can't do anything with them.
|
||||||
if (result && result->connection_state == kCsOffline) {
|
if (result && result->connection_state == kCsOffline) {
|
||||||
*error_out = "device offline";
|
*error_out = "device offline";
|
||||||
result = NULL;
|
result = nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
/* check for required connection state */
|
|
||||||
if (result && state != kCsAny && result->connection_state != state) {
|
|
||||||
*error_out = "invalid device state";
|
|
||||||
result = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
/* found one that we can take */
|
|
||||||
*error_out = "success";
|
*error_out = "success";
|
||||||
} else if (state != kCsAny && (serial || !ambiguous)) {
|
|
||||||
adb_sleep_ms(1000);
|
|
||||||
goto retry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -122,12 +122,13 @@ private:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Obtain a transport from the available transports.
|
* Obtain a transport from the available transports.
|
||||||
* If state is != kCsAny, only transports in that state are considered.
|
* If serial is non-null then only the device with that serial will be chosen.
|
||||||
* If serial is non-NULL then only the device with that serial will be chosen.
|
* If multiple devices/emulators would match, *is_ambiguous (if non-null)
|
||||||
* If no suitable transport is found, error is set.
|
* is set to true and nullptr returned.
|
||||||
|
* If no suitable transport is found, error is set and nullptr returned.
|
||||||
*/
|
*/
|
||||||
atransport* acquire_one_transport(ConnectionState state, TransportType type,
|
atransport* acquire_one_transport(TransportType type, const char* serial,
|
||||||
const char* serial, std::string* error_out);
|
bool* is_ambiguous, std::string* error_out);
|
||||||
void kick_transport(atransport* t);
|
void kick_transport(atransport* t);
|
||||||
void update_transports(void);
|
void update_transports(void);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue