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

Side by Side Diff: platform_tools/android/bin/adb_wait_for_device

Issue 1829753004: Splitting up wait_for_device into two pieces (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 9 months 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 unified diff | Download patch
OLDNEW
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 connected.
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 # Helper function used by get_battery_level. Parses the battery level from
10 # dumpsys output.
11 function _parse_battery_level {
12 SPLIT=( $@ )
13
14 HAS_BATTERY=1
15 LEVEL=""
16
17 for i in "${!SPLIT[@]}"; do
18 if [ "${SPLIT[$i]}" = "level:" ]; then
19 LEVEL="${SPLIT[$i+1]}"
20 fi
21 if [ "${SPLIT[$i]}" = "present:" ]; then
22 PRESENT="$(echo "${SPLIT[$i+1]}" | tr -d '\r')"
23 if [ "$PRESENT" = "0" ]; then
24 HAS_BATTERY=0
25 fi
26 if [ "$PRESENT" = "false" ]; then
27 HAS_BATTERY=0
28 fi
29 fi
30 done
31
32 if [ "$HAS_BATTERY" = "1" ]; then
33 echo "$LEVEL" | tr -d '\r'
34 return
35 fi
36 # If there's no battery, report a full battery.
37 echo "Device has no battery." 1>&2
38 echo "100"
39 }
40
41 # Echo the battery level percentage of the attached Android device.
42 function get_battery_level {
43 STATS="$($ADB $DEVICE_SERIAL shell dumpsys batteryproperties)"
44 SPLIT=( $STATS )
45 RV="$(_parse_battery_level ${SPLIT[@]})"
46 if [ -n "$RV" ]; then
47 echo "$RV"
48 return
49 fi
50
51 echo "Battery level fallback..." 1>&2
52
53 STATS="$($ADB $DEVICE_SERIAL shell dumpsys battery)"
54 SPLIT=( $STATS )
55 RV="$(_parse_battery_level ${SPLIT[@]})"
56 if [ "$RV" != "-1" ]; then
57 echo "$RV"
58 return
59 fi
60
61 echo "Could not determine battery level!" 1>&2
62 # Just exit to prevent hanging forever or failing the build.
63 echo "0"
64 }
65
66 set -e 9 set -e
67 10
68 # Wait for the device to be connected and fully booted. 11 # Wait for the device to be connected and fully booted.
69 while [ "$($ADB $DEVICE_SERIAL shell getprop sys.boot_completed | tr -d '\r')" ! = "1" ]; do 12 while [ "$($ADB $DEVICE_SERIAL shell getprop sys.boot_completed | tr -d '\r')" ! = "1" ]; do
70 echo "Waiting for the device to be connected and ready." 13 echo "Waiting for the device to be connected and ready."
71 sleep 5 14 sleep 5
72 done 15 done
73 16
74 # Wait for battery charge. 17 echo "Connected!"
75 DESIRED_BATTERY_LEVEL=80
76 CURRENT_BATTERY_LEVEL="$(get_battery_level)"
77 while [ "${CURRENT_BATTERY_LEVEL}" -lt "${DESIRED_BATTERY_LEVEL}" ]; do
78 echo "Battery level is ${CURRENT_BATTERY_LEVEL}; waiting to charge to ${DESIRE D_BATTERY_LEVEL}"
79 sleep 5
80 CURRENT_BATTERY_LEVEL="$(get_battery_level)"
81 done
82
83 echo "Ready!"
OLDNEW
« infra/bots/flavor/android_flavor.py ('K') | « platform_tools/android/bin/adb_wait_for_charge ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698