-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwaitForEmu.sh
executable file
·72 lines (61 loc) · 2.09 KB
/
waitForEmu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# https://github.com/reddit/docker-android-build/blob/master/tools/android-wait-for-emulator.sh
#echo "Waiting for EMU"
sec=${TIME_TOOL_SEC}
time_inter_emu_boot=120
emu_log_path=${1:-EMU_LOG_PATH}
restart=${2:-"1"}
function msg() {
local tab=${1}
local opt=${2}
local msg_str=${3}
local error_color="\e[31m"
local warn_color="\e[33m"
local info_color="\033[0;36m"
local reset_color="\e[0m"
local color=${reset_color}
local str=""
case ${opt} in
e|error) color=${error_color} ;;
w|warn) color=${warn_color} ;;
i|info) color=${info_color} ;;
d|debug) str="${NAME}: DEBUG: "; color=${info_color} ;;
*) color=${reset_color} ;;
esac
v=$(printf "%0.s\t" {1..${tab}})
str=${v}${str}${msg_str}
echo -e "${color}${str}${reset_color}"
}
function wait_for_boot_complete {
# https://gist.github.com/stackedsax/2639601
local boot_property=$1
local boot_property_test=$2
echo -n "[emulator] Checking: ${boot_property} ... "
local result=`adb shell ${boot_property} 2>/dev/null | grep "${boot_property_test}"`
s=0
while [ -z $result ]; do
sleep 1
result=`adb shell ${boot_property} 2>/dev/null | grep "${boot_property_test}"`
if [[ ${restart} -eq 1 ]] && [[ ${s} -eq ${time_inter_emu_boot} ]]; then
echo ""; echo "[emulator] Restarting..."
echo "[emulator] Restarting..." >> ${emu_log_path}
kill -9 `ps | grep emulator | awk '{print $1}'` &> /dev/null
${ANDROTEST_SCRIPTS_RUNEMU_FILEPATH} ${emu_log_path}
fi
s=$((${s}+1))
done
# echo "[emulator] Checking: ${boot_property} ... OK"
echo "OK"
}
date1=$(date +"%s")
echo "[emulator] Waiting for emulator to boot completely"
adb wait-for-device
wait_for_boot_complete "getprop dev.bootcomplete" 1
wait_for_boot_complete "getprop sys.boot_completed" 1
#wait_for_boot_complete "getprop init.svc.bootanim" "stopped"
echo "[emulator] All boot properties succesful"
echo -n " OK emulator is running... "
date2=$(date +"%s")
diff=$(($date2-$date1))
echo "took $(($diff / 60)) minutes and $(($diff % 60)) seconds."
exit 0