2022-03-18 11:56:19 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
emu="$ANDROID_SDK_ROOT/emulator/emulator"
|
2022-04-16 14:21:02 +00:00
|
|
|
avd="$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager"
|
|
|
|
sdk="$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager"
|
2023-05-10 06:11:11 +00:00
|
|
|
emu_args='-no-window -gpu swiftshader_indirect -read-only -no-snapshot -noaudio -no-boot-anim -show-kernel'
|
2022-03-18 11:56:19 +00:00
|
|
|
|
2022-08-19 09:40:33 +00:00
|
|
|
# Should be either 'google_apis' or 'default'
|
|
|
|
type='google_apis'
|
|
|
|
|
2022-09-16 02:45:58 +00:00
|
|
|
# We test these API levels for the following reason
|
|
|
|
|
|
|
|
# API 23: legacy rootfs w/o Treble
|
|
|
|
# API 26: legacy rootfs with Treble
|
|
|
|
# API 28: legacy system-as-root
|
|
|
|
# API 29: 2 Stage Init
|
|
|
|
# API 33: latest Android
|
|
|
|
|
|
|
|
api_list='23 26 28 29 33'
|
|
|
|
|
|
|
|
cleanup() {
|
2023-04-24 20:46:25 +00:00
|
|
|
echo -e '\n\033[41;30m! An error occurred\033[0m\n'
|
2022-09-16 02:45:58 +00:00
|
|
|
|
|
|
|
for api in $api_list; do
|
|
|
|
set_api_env $api
|
|
|
|
restore_avd
|
|
|
|
done
|
|
|
|
|
|
|
|
"$avd" delete avd -n test
|
2023-05-10 06:11:11 +00:00
|
|
|
pkill -INT -P $$
|
|
|
|
wait
|
2022-09-16 02:45:58 +00:00
|
|
|
}
|
|
|
|
|
2022-03-18 11:56:19 +00:00
|
|
|
wait_for_boot() {
|
2023-05-10 06:11:11 +00:00
|
|
|
adb wait-for-device
|
2022-03-18 11:56:19 +00:00
|
|
|
while true; do
|
2023-04-24 20:54:46 +00:00
|
|
|
if [ "stopped" = "$(adb exec-out getprop init.svc.bootanim)" ]; then
|
2022-03-18 11:56:19 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 2
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-09-16 02:45:58 +00:00
|
|
|
set_api_env() {
|
2022-08-19 09:40:33 +00:00
|
|
|
pkg="system-images;android-$1;$type;$arch"
|
2022-09-16 02:45:58 +00:00
|
|
|
local img_dir="$ANDROID_SDK_ROOT/system-images/android-$1/$type/$arch"
|
2022-04-16 14:21:02 +00:00
|
|
|
ramdisk="$img_dir/ramdisk.img"
|
|
|
|
features="$img_dir/advancedFeatures.ini"
|
2022-09-16 02:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
restore_avd() {
|
2022-03-18 11:56:19 +00:00
|
|
|
if [ -f "${ramdisk}.bak" ]; then
|
|
|
|
cp "${ramdisk}.bak" "$ramdisk"
|
|
|
|
fi
|
2022-04-16 14:21:02 +00:00
|
|
|
if [ -f "${features}.bak" ]; then
|
|
|
|
cp "${features}.bak" "$features"
|
|
|
|
fi
|
2022-09-16 02:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
run_test() {
|
|
|
|
local pid
|
2023-05-10 06:11:11 +00:00
|
|
|
local api=$1
|
|
|
|
|
|
|
|
set_api_env $api
|
2022-09-16 02:45:58 +00:00
|
|
|
|
|
|
|
# Setup emulator
|
2023-04-24 20:46:25 +00:00
|
|
|
echo -e "\n\033[44;30m* Testing $pkg\033[0m\n"
|
2022-09-16 02:45:58 +00:00
|
|
|
"$sdk" $pkg
|
|
|
|
echo no | "$avd" create avd -f -n test -k $pkg
|
|
|
|
|
|
|
|
# Launch emulator and patch
|
|
|
|
restore_avd
|
2022-04-16 14:21:02 +00:00
|
|
|
"$emu" @test $emu_args &
|
2022-03-18 11:56:19 +00:00
|
|
|
pid=$!
|
2023-04-24 20:54:46 +00:00
|
|
|
timeout 180 bash -c wait_for_boot
|
|
|
|
|
2022-04-16 14:21:02 +00:00
|
|
|
./build.py avd_patch -s "$ramdisk"
|
2022-03-18 11:56:19 +00:00
|
|
|
kill -INT $pid
|
|
|
|
wait $pid
|
|
|
|
|
|
|
|
# Test if it boots properly
|
2022-04-16 14:21:02 +00:00
|
|
|
"$emu" @test $emu_args &
|
2022-03-18 11:56:19 +00:00
|
|
|
pid=$!
|
2023-04-24 20:54:46 +00:00
|
|
|
timeout 180 bash -c wait_for_boot
|
2022-03-18 11:56:19 +00:00
|
|
|
|
|
|
|
adb shell magisk -v
|
|
|
|
kill -INT $pid
|
|
|
|
wait $pid
|
2022-06-07 08:06:27 +00:00
|
|
|
|
2022-09-16 02:45:58 +00:00
|
|
|
restore_avd
|
2022-03-18 11:56:19 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 02:45:58 +00:00
|
|
|
trap cleanup EXIT
|
2022-03-18 11:56:19 +00:00
|
|
|
|
2022-09-16 02:45:58 +00:00
|
|
|
export -f wait_for_boot
|
2022-08-19 09:40:33 +00:00
|
|
|
|
2022-09-16 02:45:58 +00:00
|
|
|
set -xe
|
|
|
|
|
|
|
|
case $(uname -m) in
|
|
|
|
'arm64'|'aarch64')
|
|
|
|
arch=arm64-v8a
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
arch=x86_64
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2023-04-24 20:54:46 +00:00
|
|
|
yes | "$sdk" --licenses
|
|
|
|
"$sdk" --channel=3 --update
|
2022-03-18 11:56:19 +00:00
|
|
|
|
2023-05-10 06:11:11 +00:00
|
|
|
if [ -n "$1" ]; then
|
|
|
|
run_test $1
|
|
|
|
else
|
|
|
|
for api in $api_list; do
|
|
|
|
run_test $api
|
|
|
|
done
|
|
|
|
fi
|
2022-03-18 11:56:19 +00:00
|
|
|
|
2022-04-16 14:21:02 +00:00
|
|
|
"$avd" delete avd -n test
|
|
|
|
|
2022-03-18 11:56:19 +00:00
|
|
|
trap - EXIT
|