Index: platform_tools/android/bin/adb_wait_for_device |
diff --git a/platform_tools/android/bin/adb_wait_for_device b/platform_tools/android/bin/adb_wait_for_device |
index 0b640d22b42349aa841066b2b5d7cf8f6691652f..f742700e5e845d3b8d6bf9c7c81520cc48ad27ab 100755 |
--- a/platform_tools/android/bin/adb_wait_for_device |
+++ b/platform_tools/android/bin/adb_wait_for_device |
@@ -1,14 +1,40 @@ |
#!/bin/bash |
# |
-# Wait for the device to be both attached and booted. |
+# Wait for the device to be ready to run tests. |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
source $SCRIPT_DIR/android_setup.sh |
source $SCRIPT_DIR/utils/setup_adb.sh |
+BATTERY_LEVEL=0 |
rmistry
2015/12/14 13:35:05
Remove.
borenet
2015/12/14 13:42:09
Done.
|
+ |
+function get_battery_level { |
+ STATS="$($ADB $DEVICE_SERIAL shell dumpsys batteryproperties)" |
+ SPLIT=( $STATS ) |
+ for i in "${!SPLIT[@]}"; do |
+ if [ "${SPLIT[$i]}" = "level:" ]; then |
+ BATTERY_LEVEL="${SPLIT[$i+1]}" |
+ return |
+ fi |
+ done |
+ echo "No battery level found!" |
+} |
+ |
set -e |
-set -x |
+# Wait for the device to be connected and fully booted. |
while [ "$($ADB $DEVICE_SERIAL shell getprop sys.boot_completed | tr -d '\r')" != "1" ]; do |
+ echo "Waiting for the device to be connected and ready." |
+ sleep 5 |
+done |
+ |
+# Wait for battery charge. |
+DESIRED_BATTERY_LEVEL=30 |
+get_battery_level |
rmistry
2015/12/14 13:11:27
Working on the global BATTERY_LEVEL is confusing.
borenet
2015/12/14 13:26:56
I'm not aware of a way to do that in a bash script
rmistry
2015/12/14 13:35:05
Yes that is how you return values from bash functi
borenet
2015/12/14 13:42:09
No, but they don't hurt anything, and my bash para
|
+while [ "$BATTERY_LEVEL" -lt "$DESIRED_BATTERY_LEVEL" ]; do |
+ echo "Battery level is ${BATTERY_LEVEL}; waiting to charge to ${DESIRED_BATTERY_LEVEL}" |
sleep 5 |
rmistry
2015/12/14 13:11:27
5 seconds seems like a very short time to wait for
borenet
2015/12/14 13:26:56
The work we're doing every 5 seconds is cheap, and
rmistry
2015/12/14 13:35:05
Sounds good since the calls are cheap. Can always
|
+ get_battery_level |
done |
+ |
+echo "Ready!" |