diff options
author | borenet <borenet@google.com> | 2015-12-14 10:07:36 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-14 10:07:37 -0800 |
commit | c9730831fcff6016279b304f246740b3cf53f9e4 (patch) | |
tree | 3eb06e3a6c607853a31b1540179ffaaee6461d45 /platform_tools | |
parent | 7d1c3e6361ab2ebd795642816c8cc385fc30ce46 (diff) |
adb_wait_for_device: Add battery fallback, support no battery
BUG=skia:4690
TBR=rmistry
Review URL: https://codereview.chromium.org/1528563002
Diffstat (limited to 'platform_tools')
-rwxr-xr-x | platform_tools/android/bin/adb_wait_for_device | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/platform_tools/android/bin/adb_wait_for_device b/platform_tools/android/bin/adb_wait_for_device index 914b5fb5ce..fc8a0f118d 100755 --- a/platform_tools/android/bin/adb_wait_for_device +++ b/platform_tools/android/bin/adb_wait_for_device @@ -6,18 +6,58 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $SCRIPT_DIR/android_setup.sh source $SCRIPT_DIR/utils/setup_adb.sh -function get_battery_level { - STATS="$($ADB $DEVICE_SERIAL shell dumpsys batteryproperties)" - SPLIT=( $STATS ) +function _get_battery_level { + SPLIT=( $@ ) + + HAS_BATTERY=1 + LEVEL="" + for i in "${!SPLIT[@]}"; do if [ "${SPLIT[$i]}" = "level:" ]; then - echo "${SPLIT[$i+1]}" - return + LEVEL="${SPLIT[$i+1]}" + fi + if [ "${SPLIT[$i]}" = "present:" ]; then + PRESENT="$(echo "${SPLIT[$i+1]}" | tr -d '\r')" + if [ "$PRESENT" -eq "0" ]; then + HAS_BATTERY=0 + fi + if [ "$PRESENT" = "false" ]; then + HAS_BATTERY=0 + fi fi done + + if [ "$HAS_BATTERY" = "1" ]; then + echo "$LEVEL" | tr -d '\r' + return + fi + # If there's no battery, report a full battery. + echo "Device has no battery." 1>&2 + echo "100" +} + +function get_battery_level { + STATS="$($ADB $DEVICE_SERIAL shell dumpsys batteryproperties)" + SPLIT=( $STATS ) + RV="$(_get_battery_level ${SPLIT[@]})" + if [ -n "$RV" ]; then + echo "$RV" + return + fi + + echo "Battery level fallback..." 1>&2 + + STATS="$($ADB $DEVICE_SERIAL shell dumpsys battery)" + SPLIT=( $STATS ) + RV="$(_get_battery_level ${SPLIT[@]})" + if [ "$RV" != "-1" ]; then + echo "$RV" + return + fi + echo "Could not determine battery level!" 1>&2 # Just exit to prevent hanging forever or failing the build. - exit 0 + echo "0" } set -e |