diff options
author | Leo Sartre <leox.sartre@intel.com> | 2015-11-27 18:56:48 +0100 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-12-16 18:11:18 -0800 |
commit | 1fbc9dbd0f78d755e42a7100a8a24d2ff31c7f6a (patch) | |
tree | 73cf90e86064e8b4fdd58f7daeaede4cf643caca /adb/services.cpp | |
parent | 461a29540c01b44f07fc26ccb0d5bc7d0d92a974 (diff) | |
download | core-1fbc9dbd0f78d755e42a7100a8a24d2ff31c7f6a.tar.gz core-1fbc9dbd0f78d755e42a7100a8a24d2ff31c7f6a.tar.bz2 core-1fbc9dbd0f78d755e42a7100a8a24d2ff31c7f6a.zip |
adb host: add device state in "adb wait-for-*"
The current implementation of the host commands "adb wait-for-*" allows
to specify only the transport layer (local, usb or any).
This patch allows the specification of the expected device state
(bootloader, recovery, device or sideload), this is usefull for
scripting purposes.
Use case:
$ adb reboot sideload-auto-reboot
$ adb wait-for-usb-sideload && adb sideload package.zip
Change-Id: I276a6be4d82f8b7901f74e1e5395b86d16548e8f
Signed-off-by: Leo Sartre <leox.sartre@intel.com>
Diffstat (limited to 'adb/services.cpp')
-rw-r--r-- | adb/services.cpp | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/adb/services.cpp b/adb/services.cpp index 523353a46..20166cef7 100644 --- a/adb/services.cpp +++ b/adb/services.cpp @@ -356,19 +356,19 @@ int service_to_fd(const char* name, const atransport* transport) { #if ADB_HOST struct state_info { TransportType transport_type; - char* serial; + std::string serial; ConnectionState state; }; -static void wait_for_state(int fd, void* cookie) { - state_info* sinfo = reinterpret_cast<state_info*>(cookie); +static void wait_for_state(int fd, void* data) { + std::unique_ptr<state_info> sinfo(reinterpret_cast<state_info*>(data)); D("wait_for_state %d", sinfo->state); while (true) { bool is_ambiguous = false; std::string error = "unknown error"; - atransport* t = acquire_one_transport(sinfo->transport_type, sinfo->serial, + atransport* t = acquire_one_transport(sinfo->transport_type, sinfo->serial.c_str(), &is_ambiguous, &error); if (t != nullptr && t->connection_state == sinfo->state) { SendOkay(fd); @@ -382,10 +382,6 @@ static void wait_for_state(int fd, void* cookie) { } } - if (sinfo->serial) { - free(sinfo->serial); - } - free(sinfo); adb_close(fd); D("wait_for_state is done"); } @@ -491,38 +487,43 @@ static void connect_service(int fd, void* data) { asocket* host_service_to_socket(const char* name, const char* serial) { if (!strcmp(name,"track-devices")) { return create_device_tracker(); - } else if (!strncmp(name, "wait-for-", strlen("wait-for-"))) { - auto sinfo = reinterpret_cast<state_info*>(malloc(sizeof(state_info))); + } else if (android::base::StartsWith(name, "wait-for-")) { + name += strlen("wait-for-"); + + std::unique_ptr<state_info> sinfo(new state_info); if (sinfo == nullptr) { fprintf(stderr, "couldn't allocate state_info: %s", strerror(errno)); - return NULL; + return nullptr; } - if (serial) - sinfo->serial = strdup(serial); - else - sinfo->serial = NULL; - - name += strlen("wait-for-"); + if (serial) sinfo->serial = serial; - if (!strncmp(name, "local", strlen("local"))) { + if (android::base::StartsWith(name, "local")) { + name += strlen("local"); sinfo->transport_type = kTransportLocal; - sinfo->state = kCsDevice; - } else if (!strncmp(name, "usb", strlen("usb"))) { + } else if (android::base::StartsWith(name, "usb")) { + name += strlen("usb"); sinfo->transport_type = kTransportUsb; - sinfo->state = kCsDevice; - } else if (!strncmp(name, "any", strlen("any"))) { + } else if (android::base::StartsWith(name, "any")) { + name += strlen("any"); sinfo->transport_type = kTransportAny; + } else { + return nullptr; + } + + if (!strcmp(name, "-device")) { sinfo->state = kCsDevice; + } else if (!strcmp(name, "-recovery")) { + sinfo->state = kCsRecovery; + } else if (!strcmp(name, "-sideload")) { + sinfo->state = kCsSideload; + } else if (!strcmp(name, "-bootloader")) { + sinfo->state = kCsBootloader; } else { - if (sinfo->serial) { - free(sinfo->serial); - } - free(sinfo); - return NULL; + return nullptr; } - int fd = create_service_thread(wait_for_state, sinfo); + int fd = create_service_thread(wait_for_state, sinfo.release()); return create_local_socket(fd); } else if (!strncmp(name, "connect:", 8)) { char* host = strdup(name + 8); |