mobly icon indicating copy to clipboard operation
mobly copied to clipboard

wait-for-disconnect and then wait-for-device

Open jiyongp opened this issue 5 months ago • 3 comments

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

jiyongp avatar Jul 26 '25 00:07 jiyongp

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).

jiyongp avatar Jul 26 '25 00:07 jiyongp

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?

xpconanfan avatar Jul 26 '25 01:07 xpconanfan

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.

jiyongp avatar Jul 26 '25 04:07 jiyongp