diff options
author | Josh Gao <jmgao@google.com> | 2016-04-13 12:14:16 -0700 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2016-04-13 12:28:04 -0700 |
commit | 08881e72f4b01302742e027225145b061202c528 (patch) | |
tree | a081593e9ae73c6dbf4126872be3209f5892fb41 /adb | |
parent | adf1cdeda07acfa6fc96627f8d4fca5b98bb7428 (diff) | |
download | core-08881e72f4b01302742e027225145b061202c528.tar.gz core-08881e72f4b01302742e027225145b061202c528.tar.bz2 core-08881e72f4b01302742e027225145b061202c528.zip |
adb: make 'wait-for-{recovery,sideload,bootloader} work.
The help for wait-for-* documents this as working, but we only had a
special case for 'wait-for-device'. Make the others work as well.
Bug: http://b/28170823
Change-Id: I57d70f8b9a383947c4f761919bfbd8515a013520
Diffstat (limited to 'adb')
-rw-r--r-- | adb/commandline.cpp | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/adb/commandline.cpp b/adb/commandline.cpp index a856672eb..411b0ba07 100644 --- a/adb/commandline.cpp +++ b/adb/commandline.cpp @@ -1025,50 +1025,40 @@ static int ppp(int argc, const char** argv) { #endif /* !defined(_WIN32) */ } -static bool check_wait_for_device_syntax(const char* service) { - // TODO: when we have libc++ for Windows, use a regular expression instead. - // wait-for-((any|local|usb)-)?(bootloader|device|recovery|sideload) - - char type[20 + 1]; // sscanf's %20[...] doesn't include the NUL. - char state[20 + 1]; - int length = 0; - if (sscanf(service, "wait-for-%20[a-z]-%20[a-z]%n", type, state, &length) < 2 || - length != static_cast<int>(strlen(service))) { +static bool wait_for_device(const char* service, TransportType t, const char* serial) { + std::vector<std::string> components = android::base::Split(service, "-"); + if (components.size() < 3 || components.size() > 4) { fprintf(stderr, "adb: couldn't parse 'wait-for' command: %s\n", service); return false; } - if (strcmp(type, "any") != 0 && strcmp(type, "local") != 0 && strcmp(type, "usb") != 0) { - fprintf(stderr, "adb: unknown type %s; expected 'any', 'local', or 'usb'\n", type); - return false; - } - if (strcmp(state, "bootloader") != 0 && strcmp(state, "device") != 0 && - strcmp(state, "recovery") != 0 && strcmp(state, "sideload") != 0) { - fprintf(stderr, "adb: unknown state %s; " - "expected 'bootloader', 'device', 'recovery', or 'sideload'\n", state); - return false; - } - return true; -} - -static bool wait_for_device(const char* service, TransportType t, const char* serial) { // Was the caller vague about what they'd like us to wait for? // If so, check they weren't more specific in their choice of transport type. - if (strcmp(service, "wait-for-device") == 0) { + if (components.size() == 3) { + auto it = components.begin() + 2; if (t == kTransportUsb) { - service = "wait-for-usb-device"; + components.insert(it, "usb"); } else if (t == kTransportLocal) { - service = "wait-for-local-device"; + components.insert(it, "local"); } else { - service = "wait-for-any-device"; + components.insert(it, "any"); } + } else if (components[2] != "any" && components[2] != "local" && components[2] != "usb") { + fprintf(stderr, "adb: unknown type %s; expected 'any', 'local', or 'usb'\n", + components[2].c_str()); + return false; } - if (!check_wait_for_device_syntax(service)) { + if (components[3] != "bootloader" && components[3] != "device" && components[3] != "recovery" && + components[3] != "sideload") { + fprintf(stderr, + "adb: unknown state %s; " + "expected 'bootloader', 'device', 'recovery', or 'sideload'\n", + components[3].c_str()); return false; } - std::string cmd = format_host_command(service, t, serial); + std::string cmd = format_host_command(android::base::Join(components, "-").c_str(), t, serial); return adb_command(cmd); } |