adb: add support for 'wait-for-any'.
Allow waiting for a device in any state.
Bug: http://b/28168212
Change-Id: I1876ecd70089ca88f2da5de4182e13724ec50501
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index 411b0ba..6c3a1a5 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -1049,11 +1049,11 @@
return false;
}
- if (components[3] != "bootloader" && components[3] != "device" && components[3] != "recovery" &&
- components[3] != "sideload") {
+ if (components[3] != "any" && 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",
+ "expected 'any', 'bootloader', 'device', 'recovery', or 'sideload'\n",
components[3].c_str());
return false;
}
diff --git a/adb/services.cpp b/adb/services.cpp
index d5e963b..67e8e41 100644
--- a/adb/services.cpp
+++ b/adb/services.cpp
@@ -370,7 +370,7 @@
std::string error = "unknown error";
const char* serial = sinfo->serial.length() ? sinfo->serial.c_str() : NULL;
atransport* t = acquire_one_transport(sinfo->transport_type, serial, &is_ambiguous, &error);
- if (t != nullptr && t->connection_state == sinfo->state) {
+ if (t != nullptr && (sinfo->state == kCsAny || sinfo->state == t->connection_state)) {
SendOkay(fd);
break;
} else if (!is_ambiguous) {
@@ -534,6 +534,8 @@
sinfo->state = kCsSideload;
} else if (!strcmp(name, "-bootloader")) {
sinfo->state = kCsBootloader;
+ } else if (!strcmp(name, "-any")) {
+ sinfo->state = kCsAny;
} else {
return nullptr;
}