-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_emu_headless.sh
105 lines (90 loc) · 3.16 KB
/
start_emu_headless.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# Credit to this android emulator workflow guide https://medium.com/innovies-club/run-android-emulator-out-of-the-box-with-github-actions-b84cba766e62
BL='\033[0;34m'
G='\033[0;32m'
RED='\033[0;31m'
YE='\033[1;33m'
NC='\033[0m' # No Color
emulator_name=${EMULATOR_NAME}
function check_hardware_acceleration() {
if [[ "$HW_ACCEL_OVERRIDE" != "" ]]; then
hw_accel_flag="$HW_ACCEL_OVERRIDE"
else
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS-specific hardware acceleration check
HW_ACCEL_SUPPORT=$(sysctl -a | grep -E -c '(vmx|svm)')
else
# generic Linux hardware acceleration check
HW_ACCEL_SUPPORT=$(grep -E -c '(vmx|svm)' /proc/cpuinfo)
fi
if [[ $HW_ACCEL_SUPPORT == 0 ]]; then
hw_accel_flag="-accel off"
else
hw_accel_flag="-accel on"
fi
fi
echo "$hw_accel_flag"
}
hw_accel_flag=$(check_hardware_acceleration)
function launch_emulator () {
adb devices | grep emulator | cut -f1 | xargs -I {} adb -s "{}" emu kill
options="@${emulator_name} -no-window -no-snapshot -screen no-touch -noaudio -memory 2048 -no-boot-anim ${hw_accel_flag} -camera-back none"
if [[ "$OSTYPE" == *linux* ]]; then
echo "${OSTYPE}: emulator ${options} -gpu off"
nohup emulator $options -gpu off &
fi
if [[ "$OSTYPE" == *darwin* ]] || [[ "$OSTYPE" == *macos* ]]; then
echo "im here"
echo "${OSTYPE}: emulator ${options} -gpu swiftshader_indirect"
nohup emulator $options -gpu swiftshader_indirect &
fi
if [ $? -ne 0 ]; then
echo "Error launching emulator"
return 1
fi
}
function check_emulator_status () {
printf "${G}==> ${BL}Checking emulator booting up status 🧐${NC}\n"
start_time=$(date +%s)
spinner=( "⠹" "⠺" "⠼" "⠶" "⠦" "⠧" "⠇" "⠏" )
i=0
# Get the timeout value from the environment variable or use the default value of 300 seconds (5 minutes)
timeout=${EMULATOR_TIMEOUT:-300}
while true; do
result=$(adb shell getprop sys.boot_completed 2>&1)
if [ "$result" == "1" ]; then
printf "\e[K${G}==> \u2713 Emulator is ready : '$result' ${NC}\n"
adb devices -l
adb shell input keyevent 82
break
elif [ "$result" == "" ]; then
printf "${YE}==> Emulator is partially Booted! 😕 ${spinner[$i]} ${NC}\r"
else
printf "${RED}==> $result, please wait ${spinner[$i]} ${NC}\r"
i=$(( (i+1) % 8 ))
fi
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ $elapsed_time -gt $timeout ]; then
printf "${RED}==> Timeout after ${timeout} seconds elapsed 🕛.. ${NC}\n"
break
fi
sleep 4
done
};
function disable_animation() {
adb shell "settings put global window_animation_scale 0.0"
adb shell "settings put global transition_animation_scale 0.0"
adb shell "settings put global animator_duration_scale 0.0"
};
function hidden_policy() {
adb shell "settings put global hidden_api_policy_pre_p_apps 1;settings put global hidden_api_policy_p_apps 1;settings put global hidden_api_policy 1"
};
launch_emulator
sleep 2
check_emulator_status
sleep 1
disable_animation
sleep 1
hidden_policy
sleep 1