Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Unified Diff: platform_tools/android/bin/adb_wait_for_device

Issue 1528563002: adb_wait_for_device: Add battery fallback, support no battery (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 914b5fb5cef076d664d5e6cdacff5ea27d594877..fc8a0f118dd5402ff2ec345104febf0be58c02d4 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 {
rmistry 2015/12/14 18:16:09 Maybe better name is parse_battery_level (or somet
borenet 2015/12/14 18:26:31 Done in https://codereview.chromium.org/1527713002
+ 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698