Skip to content

Conversation

@jiyongp
Copy link

@jiyongp jiyongp commented Jul 26, 2025

Previously, right after we do adb reboot, we immediately executed adb wait-for-device. This is problematic because the device may still be in
the process of shutting down (shutdown itself is taking some time), in
which case adb wait-for-device would immediately return, giving a
false signal that the reboot was finished.

Fixing this issue by firstly waiting for the adb connection to be lost
(via adb wait-for-disconnect) and when executing adb-wait-for-device.

Note that other test hardness like tradefed already has had this. ex:
https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/main/src/com/android/tradefed/device/NativeDevice.java#4023

Test: tox passed


This change is Reviewable

Previously, right after we do `adb reboot`, we immediately executed `adb
wait-for-device`. This is problematic because the device may still be in
the process of shutting down (shutdown itself is taking some time), in
which case `adb wait-for-device` would immediately return, giving a
false signal that the reboot was finished.

Fixing this issue by firstly waiting for the adb connection to be lost
(via adb wait-for-disconnect) and when executing adb-wait-for-device.

Note that other test hardness like tradefed already has had this. ex:
https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/main/src/com/android/tradefed/device/NativeDevice.java#4023

Test: tox passed
@jiyongp
Copy link
Author

jiyongp commented Jul 26, 2025

Please note that this isn't specific to virtual devices though this time it was manifested in cf_wear. For any Android device, we shouldn't assume that adb reboot will immediately cut the adb connection. The connection is cut only after adbd process in the device is killed and the killing of the process takes some time (though in most cases it's very short, but it never is 0).

@xpconanfan
Copy link
Collaborator

Since the problem is related to timing, what if the device immediately disconnected before the cmd wait-for-disconnect finished, we'd be stuck at wait-for-disconnect for a while until timeout?

@jiyongp
Copy link
Author

jiyongp commented Jul 26, 2025

Since the problem is related to timing, what if the device immediately disconnected before the cmd wait-for-disconnect finished, we'd be stuck at wait-for-disconnect for a while until timeout?

No. It returns immediately if the device is already disconnected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants