diff options
author | Josh Gao <jmgao@google.com> | 2019-03-11 21:17:46 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-03-11 21:17:46 -0700 |
commit | 8c73ee5afc621fafa734e043a344afb7958e80b7 (patch) | |
tree | b09987894030121279b069e720170e4e85e58f80 /adb | |
parent | 9c9913ff6af04cb51ed72421d6bb6c79a9cf21cc (diff) | |
parent | 2ef1948cd05e7e3ec7243e0cfeb7d269eec2c4f9 (diff) | |
download | system_core-8c73ee5afc621fafa734e043a344afb7958e80b7.tar.gz system_core-8c73ee5afc621fafa734e043a344afb7958e80b7.tar.bz2 system_core-8c73ee5afc621fafa734e043a344afb7958e80b7.zip |
Merge "adb: make root/unroot wait for the device to come back." am: 59d4c8a352 am: 983e1a5af2
am: 2ef1948cd0
Change-Id: I7b0b6974ad6e90b8143515d486299d75ca8d1a64
Diffstat (limited to 'adb')
-rw-r--r-- | adb/client/commandline.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/adb/client/commandline.cpp b/adb/client/commandline.cpp index 2b328ab53..3d5d9db32 100644 --- a/adb/client/commandline.cpp +++ b/adb/client/commandline.cpp @@ -1005,7 +1005,8 @@ static int ppp(int argc, const char** argv) { #endif /* !defined(_WIN32) */ } -static bool wait_for_device(const char* service) { +static bool wait_for_device(const char* service, + std::optional<std::chrono::milliseconds> timeout = std::nullopt) { 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); @@ -1043,6 +1044,13 @@ static bool wait_for_device(const char* service) { } std::string cmd = format_host_command(android::base::Join(components, "-").c_str()); + if (timeout) { + std::thread([timeout]() { + std::this_thread::sleep_for(*timeout); + fprintf(stderr, "timeout expired while waiting for device\n"); + _exit(1); + }).detach(); + } return adb_command(cmd); } @@ -1084,8 +1092,21 @@ static bool adb_root(const char* command) { } // Wait for the device to go away. + TransportType previous_type; + const char* previous_serial; + TransportId previous_id; + adb_get_transport(&previous_type, &previous_serial, &previous_id); + adb_set_transport(kTransportAny, nullptr, transport_id); wait_for_device("wait-for-disconnect"); + + // Wait for the device to come back. + // If we were using a specific transport ID, there's nothing we can wait for. + if (previous_id == 0) { + adb_set_transport(previous_type, previous_serial, 0); + wait_for_device("wait-for-device", 3000ms); + } + return true; } |