OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # | 2 # |
3 # Wait for the device to be charged enough for testing. | 3 # Wait for the device to be charged enough for testing. |
4 | 4 |
5 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | 5 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
6 SKIP_TOOLCHAIN_SETUP="true" | 6 SKIP_TOOLCHAIN_SETUP="true" |
7 source $SCRIPT_DIR/android_setup.sh | 7 source $SCRIPT_DIR/android_setup.sh |
8 source $SCRIPT_DIR/utils/setup_adb.sh | 8 source $SCRIPT_DIR/utils/setup_adb.sh |
9 | 9 |
10 # Helper function used by get_battery_level. Parses the battery level from | 10 # Helper function used by get_battery_level. Parses the battery level from |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 if [ -n "$RV" ]; then | 47 if [ -n "$RV" ]; then |
48 echo "$RV" | 48 echo "$RV" |
49 return | 49 return |
50 fi | 50 fi |
51 | 51 |
52 echo "Battery level fallback..." 1>&2 | 52 echo "Battery level fallback..." 1>&2 |
53 | 53 |
54 STATS="$($ADB $DEVICE_SERIAL shell dumpsys battery)" | 54 STATS="$($ADB $DEVICE_SERIAL shell dumpsys battery)" |
55 SPLIT=( $STATS ) | 55 SPLIT=( $STATS ) |
56 RV="$(_parse_battery_level ${SPLIT[@]})" | 56 RV="$(_parse_battery_level ${SPLIT[@]})" |
57 if [ "$RV" != "-1" ]; then | 57 if [ -n "$RV" ] && [ "$RV" != "-1" ]; then |
58 echo "$RV" | 58 echo "$RV" |
59 return | 59 return |
60 fi | 60 fi |
61 | 61 |
62 echo "Could not determine battery level!" 1>&2 | 62 echo "Could not determine battery level!" 1>&2 |
63 # Just exit to prevent hanging forever or failing the build. | 63 # Just exit to prevent hanging forever or failing the build. |
64 echo "0" | 64 echo "0" |
65 } | 65 } |
66 | 66 |
67 # Wait for battery charge. | 67 # Wait for battery charge. |
68 DESIRED_BATTERY_LEVEL=80 | 68 DESIRED_BATTERY_LEVEL=80 |
69 CURRENT_BATTERY_LEVEL="$(get_battery_level)" | 69 CURRENT_BATTERY_LEVEL="$(get_battery_level)" |
70 while [ "${CURRENT_BATTERY_LEVEL}" -lt "${DESIRED_BATTERY_LEVEL}" ]; do | 70 while [ "${CURRENT_BATTERY_LEVEL}" -lt "${DESIRED_BATTERY_LEVEL}" ]; do |
71 echo "Battery level is ${CURRENT_BATTERY_LEVEL}; waiting to charge to ${DESIRE
D_BATTERY_LEVEL}" | 71 echo "Battery level is ${CURRENT_BATTERY_LEVEL}; waiting to charge to ${DESIRE
D_BATTERY_LEVEL}" |
72 sleep 5 | 72 sleep 5 |
73 CURRENT_BATTERY_LEVEL="$(get_battery_level)" | 73 CURRENT_BATTERY_LEVEL="$(get_battery_level)" |
74 done | 74 done |
75 | 75 |
76 echo "Charged!" | 76 echo "Charged!" |
OLD | NEW |