2022-03-18 11:56:19 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -xe
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
echo -e '\n\033[41m! An error occurred\033[0m\n'
|
|
|
|
pkill -INT -P $$
|
|
|
|
wait
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
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"
|
2022-03-18 11:56:19 +00:00
|
|
|
type='google_apis'
|
|
|
|
emu_args='-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim'
|
|
|
|
|
|
|
|
wait_for_boot() {
|
|
|
|
while true; do
|
|
|
|
if [ -n "$(adb shell getprop sys.boot_completed)" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 2
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
export -f wait_for_boot
|
|
|
|
|
|
|
|
test_api() {
|
2022-04-16 14:21:02 +00:00
|
|
|
local pkg pid img_dir ramdisk features
|
2022-03-18 11:56:19 +00:00
|
|
|
|
|
|
|
# Setup emulator
|
|
|
|
pkg="system-images;android-$1;$type;x86_64"
|
|
|
|
|
|
|
|
echo -e "\n\033[44m* Testing $pkg\033[0m\n"
|
|
|
|
|
|
|
|
"$sdk" $pkg
|
|
|
|
echo no | "$avd" create avd -f -n test -k $pkg
|
|
|
|
|
|
|
|
# Launch emulator and patch
|
2022-04-16 14:21:02 +00:00
|
|
|
img_dir="$ANDROID_SDK_ROOT/system-images/android-$1/$type/x86_64"
|
|
|
|
ramdisk="$img_dir/ramdisk.img"
|
|
|
|
features="$img_dir/advancedFeatures.ini"
|
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
|
|
|
|
"$emu" @test $emu_args &
|
2022-03-18 11:56:19 +00:00
|
|
|
pid=$!
|
|
|
|
timeout 60 adb wait-for-device
|
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=$!
|
|
|
|
timeout 60 adb wait-for-device
|
|
|
|
timeout 60 bash -c wait_for_boot
|
|
|
|
|
|
|
|
adb shell magisk -v
|
|
|
|
kill -INT $pid
|
|
|
|
wait $pid
|
2022-06-07 08:06:27 +00:00
|
|
|
|
|
|
|
# Restore patches
|
|
|
|
if [ -f "${ramdisk}.bak" ]; then
|
|
|
|
cp "${ramdisk}.bak" "$ramdisk"
|
|
|
|
fi
|
|
|
|
if [ -f "${features}.bak" ]; then
|
|
|
|
cp "${features}.bak" "$features"
|
|
|
|
fi
|
2022-03-18 11:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Build our executables
|
|
|
|
./build.py binary
|
|
|
|
./build.py app
|
|
|
|
|
|
|
|
# We test the following 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 32: 2 Stage Init
|
|
|
|
|
|
|
|
for api in 23 26 28 32; do
|
|
|
|
test_api $api
|
|
|
|
done
|
|
|
|
|
2022-04-16 14:21:02 +00:00
|
|
|
"$avd" delete avd -n test
|
|
|
|
|
2022-03-18 11:56:19 +00:00
|
|
|
trap - EXIT
|