何时使用adb shell getprop sys.boot_completed

问题描述

我正在调用如下的adb命令序列

"adb root"
adbd is already running as root
"adb wait-for-device"
"adb shell getprop sys.boot_completed"
1
boot_completed successful
"adb remount"
remount succeeded
"adb uninstall ..."
Success
"adb shell rm -rf ..."
"adb push ..."
9366 KB/s (46299481 bytes in 4.827s)
"adb push ..."
14 files pushed. 0 files skipped.
9701 KB/s (26658580 bytes in 2.683s)
"adb push ..."
14 files pushed. 0 files skipped.
9544 KB/s (33592272 bytes in 3.437s)
"adb reboot"
"adb wait-for-device"
"adb root"
error: protocol fault (no status)
error: protocol fault (no status)
Sleeping 2 sec. before retrying
increasing timeout by 180.0 seconds
"adb root"
error: device not found
error: device not found
Sleeping 2 sec. before retrying
increasing timeout by 270.0 seconds
"adb root"
error: device not found
error: device not found
Sleeping 2 sec. before retrying
increasing timeout by 405.0 seconds
"adb root"
error: device not found
error: device not found

但是,您可以看到android设备最后开始引发“找不到设备”错误。我知道“ adb重新启动”可能是这里的罪魁祸首,因为在下一个命令开始执行之前,重新启动可能尚未完全完成启动。为了检查这一点,我使用了“ adb等待设备”。但是似乎无法正确检测设备状态。
我还发现使用“ adb shell getprop sys.boot_completed”来纠正此错误Detect when Android emulator is fully booted

我不确定何时使用“ adb shell getprop sys.boot_completed”。是在设备每次重启时使用它,还是可以在每个“ adb wait-for-device”命令之后使用它?

解决方法

你应该在启动或重启后调用 getprop sys.boot_completed 一起adb wait-for-device 像这样:

adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82' 

当您只调用单个 adb wait-for-device 时,它不能保证启动完成,因为它只检查守护进程是否已正确启动。