From 1ff7b9055fb401c31e09623372ca12952469b169 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 16 Nov 2023 14:29:45 -0800 Subject: [PATCH] Add LSPosed launch test --- scripts/avd_test.sh | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/scripts/avd_test.sh b/scripts/avd_test.sh index edf5a64c1..e61a606b5 100755 --- a/scripts/avd_test.sh +++ b/scripts/avd_test.sh @@ -3,22 +3,25 @@ emu="$ANDROID_SDK_ROOT/emulator/emulator" avd="$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager" sdk="$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" -emu_args='-no-window -gpu swiftshader_indirect -read-only -no-snapshot -no-audio -no-boot-anim -show-kernel' +emu_args='-no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -read-only -no-snapshot -show-kernel -memory 8192' +lsposed_url='https://github.com/LSPosed/LSPosed/releases/download/v1.9.2/LSPosed-v1.9.2-7024-zygisk-release.zip' boot_timeout=600 emu_pid= -# Should be either 'google_apis' or 'default' -type='default' - # 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 with ATD image # API 34: latest Android -api_list='23 26 28 29 34' +api_list='23 26 28 29 33 34' + +atd_min_api=30 +atd_max_api=33 +lsposed_min_api=27 print_title() { echo -e "\n\033[44;39m${1}\033[0m\n" @@ -70,6 +73,11 @@ wait_for_boot() { } set_api_env() { + local type='default' + if [ $1 -ge $atd_min_api -a $1 -le $atd_max_api ]; then + # Use the lightweight ATD images if possible + type='aosp_atd' + fi pkg="system-images;android-$1;$type;$arch" local img_dir="$ANDROID_SDK_ROOT/system-images/android-$1/$type/$arch" ramdisk="$img_dir/ramdisk.img" @@ -112,6 +120,7 @@ run_content_cmd() { test_emu() { local variant=$1 + local api=$2 print_title "* Testing $pkg ($variant)" @@ -126,12 +135,27 @@ test_emu() { # Use the app to run setup and reboot run_content_cmd setup + + # Install LSPosed + if [ $api -ge $lsposed_min_api -a $api -le $atd_max_api ]; then + adb push out/lsposed.zip /data/local/tmp/lsposed.zip + adb shell echo 'magisk --install-module /data/local/tmp/lsposed.zip' \| /system/xbin/su + fi + adb reboot wait_emu wait_for_boot # Run app tests run_content_cmd test - adb shell echo "'su -c id'" \| /system/xbin/su 2000 | tee /dev/fd/2 | grep -q 'uid=0' + adb shell echo 'su -c id' \| /system/xbin/su 2000 | tee /dev/fd/2 | grep -q 'uid=0' + + # Try to launch LSPosed + if [ $api -ge $lsposed_min_api -a $api -le $atd_max_api ]; then + adb shell am start -c org.lsposed.manager.LAUNCH_MANAGER com.android.shell/.BugreportWarningActivity + sleep 10 + adb shell uiautomator dump + adb shell grep -q org.lsposed.manager /sdcard/window_dump.xml + fi } @@ -141,7 +165,7 @@ run_test() { set_api_env $api # Setup emulator - "$sdk" $pkg + "$sdk" --channel=3 $pkg echo no | "$avd" create avd -f -n test -k $pkg # Launch stock emulator @@ -155,13 +179,13 @@ run_test() { ./build.py avd_patch -s "$ramdisk" kill -INT $emu_pid wait $emu_pid - test_emu debug + test_emu debug $api # Re-patch and test release build ./build.py -r avd_patch -s "$ramdisk" kill -INT $emu_pid wait $emu_pid - test_emu release + test_emu release $api # Cleanup kill -INT $emu_pid @@ -185,8 +209,9 @@ case $(uname -m) in ;; esac -yes | "$sdk" --licenses +yes | "$sdk" --licenses > /dev/null "$sdk" --channel=3 --update +curl -L $lsposed_url -o out/lsposed.zip if [ -n "$1" ]; then run_test $1