OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # | 2 # |
3 # Wait for the device to be ready to run tests. | 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 function get_battery_level { | 9 function get_battery_level { |
10 STATS="$($ADB $DEVICE_SERIAL shell dumpsys batteryproperties)" | 10 STATS="$($ADB $DEVICE_SERIAL shell dumpsys batteryproperties)" |
11 SPLIT=( $STATS ) | 11 SPLIT=( $STATS ) |
12 for i in "${!SPLIT[@]}"; do | 12 for i in "${!SPLIT[@]}"; do |
13 if [ "${SPLIT[$i]}" = "level:" ]; then | 13 if [ "${SPLIT[$i]}" = "level:" ]; then |
14 echo "${SPLIT[$i+1]}" | 14 echo "${SPLIT[$i+1]}" |
15 return | 15 return |
16 fi | 16 fi |
17 done | 17 done |
18 echo "Could not determine battery level!" 1>&2 | 18 echo "Could not determine battery level!" 1>&2 |
19 echo "0" | 19 # Just exit to prevent hanging forever or failing the build. |
| 20 exit 0 |
20 } | 21 } |
21 | 22 |
22 set -e | 23 set -e |
23 | 24 |
24 # Wait for the device to be connected and fully booted. | 25 # Wait for the device to be connected and fully booted. |
25 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 |
26 echo "Waiting for the device to be connected and ready." | 27 echo "Waiting for the device to be connected and ready." |
27 sleep 5 | 28 sleep 5 |
28 done | 29 done |
29 | 30 |
30 # Wait for battery charge. | 31 # Wait for battery charge. |
31 DESIRED_BATTERY_LEVEL=30 | 32 DESIRED_BATTERY_LEVEL=30 |
32 CURRENT_BATTERY_LEVEL="$(get_battery_level)" | 33 CURRENT_BATTERY_LEVEL="$(get_battery_level)" |
33 while [ "${CURRENT_BATTERY_LEVEL}" -lt "${DESIRED_BATTERY_LEVEL}" ]; do | 34 while [ "${CURRENT_BATTERY_LEVEL}" -lt "${DESIRED_BATTERY_LEVEL}" ]; do |
34 echo "Battery level is ${CURRENT_BATTERY_LEVEL}; waiting to charge to ${DESIRE
D_BATTERY_LEVEL}" | 35 echo "Battery level is ${CURRENT_BATTERY_LEVEL}; waiting to charge to ${DESIRE
D_BATTERY_LEVEL}" |
35 sleep 5 | 36 sleep 5 |
36 CURRENT_BATTERY_LEVEL="$(get_battery_level)" | 37 CURRENT_BATTERY_LEVEL="$(get_battery_level)" |
37 done | 38 done |
38 | 39 |
39 echo "Ready!" | 40 echo "Ready!" |
OLD | NEW |