Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 # | 2 # |
| 3 # Wait for the device to be both attached and booted. | 3 # Wait for the device to be ready to run tests. |
| 4 | 4 |
| 5 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | 5 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 6 source $SCRIPT_DIR/android_setup.sh | 6 source $SCRIPT_DIR/android_setup.sh |
| 7 source $SCRIPT_DIR/utils/setup_adb.sh | 7 source $SCRIPT_DIR/utils/setup_adb.sh |
| 8 | 8 |
| 9 BATTERY_LEVEL=0 | |
|
rmistry
2015/12/14 13:35:05
Remove.
borenet
2015/12/14 13:42:09
Done.
| |
| 10 | |
| 11 function get_battery_level { | |
| 12 STATS="$($ADB $DEVICE_SERIAL shell dumpsys batteryproperties)" | |
| 13 SPLIT=( $STATS ) | |
| 14 for i in "${!SPLIT[@]}"; do | |
| 15 if [ "${SPLIT[$i]}" = "level:" ]; then | |
| 16 BATTERY_LEVEL="${SPLIT[$i+1]}" | |
| 17 return | |
| 18 fi | |
| 19 done | |
| 20 echo "No battery level found!" | |
| 21 } | |
| 22 | |
| 9 set -e | 23 set -e |
| 10 set -x | |
| 11 | 24 |
| 25 # Wait for the device to be connected and fully booted. | |
| 12 while [ "$($ADB $DEVICE_SERIAL shell getprop sys.boot_completed | tr -d '\r')" ! = "1" ]; do | 26 while [ "$($ADB $DEVICE_SERIAL shell getprop sys.boot_completed | tr -d '\r')" ! = "1" ]; do |
| 27 echo "Waiting for the device to be connected and ready." | |
| 13 sleep 5 | 28 sleep 5 |
| 14 done | 29 done |
| 30 | |
| 31 # Wait for battery charge. | |
| 32 DESIRED_BATTERY_LEVEL=30 | |
| 33 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
| |
| 34 while [ "$BATTERY_LEVEL" -lt "$DESIRED_BATTERY_LEVEL" ]; do | |
| 35 echo "Battery level is ${BATTERY_LEVEL}; waiting to charge to ${DESIRED_BATTER Y_LEVEL}" | |
| 36 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
| |
| 37 get_battery_level | |
| 38 done | |
| 39 | |
| 40 echo "Ready!" | |
| OLD | NEW |