From 5c92d39498ee0b27cfd6005d42b6bab0301aba21 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 28 Sep 2023 15:37:11 -0700 Subject: [PATCH] Enable Zygisk by default in emulators Make sure CI tests Zygisk --- native/src/core/daemon.rs | 21 ++++++++++++++++++--- native/src/core/db.cpp | 4 +++- native/src/core/lib.rs | 1 + scripts/avd_magisk.sh | 3 +++ scripts/avd_test.sh | 2 +- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/native/src/core/daemon.rs b/native/src/core/daemon.rs index 2e612797a..14bb6602e 100644 --- a/native/src/core/daemon.rs +++ b/native/src/core/daemon.rs @@ -3,6 +3,7 @@ use std::fs::File; use std::io; use std::sync::{Mutex, OnceLock}; +use crate::get_prop; use base::{cstr, Directory, ResultExt, Utf8CStr, Utf8CStrBuf, Utf8CStrBufRef, WalkResult}; use crate::logging::{magisk_logging, zygisk_logging}; @@ -13,10 +14,20 @@ pub static MAGISKD: OnceLock = OnceLock::new(); #[derive(Default)] pub struct MagiskD { pub logd: Mutex>>, + is_emulator: bool, } pub fn daemon_entry() { - let magiskd = MagiskD::default(); + let mut qemu = get_prop(cstr!("ro.kernel.qemu"), false); + if qemu.is_empty() { + qemu = get_prop(cstr!("ro.boot.qemu"), false); + } + let is_emulator = qemu == "1"; + + let magiskd = MagiskD { + logd: Default::default(), + is_emulator, + }; magiskd.start_log_daemon(); MAGISKD.set(magiskd).ok(); magisk_logging(); @@ -29,10 +40,14 @@ pub fn zygisk_entry() { } pub fn get_magiskd() -> &'static MagiskD { - MAGISKD.get().unwrap() + unsafe { MAGISKD.get().unwrap_unchecked() } } -impl MagiskD {} +impl MagiskD { + pub fn is_emulator(&self) -> bool { + self.is_emulator + } +} pub fn find_apk_path(pkg: &[u8], data: &mut [u8]) -> usize { use WalkResult::*; diff --git a/native/src/core/db.cpp b/native/src/core/db.cpp index 73b43d85b..b55c93110 100644 --- a/native/src/core/db.cpp +++ b/native/src/core/db.cpp @@ -7,6 +7,8 @@ #include #include +#include "core.hpp" + #define DB_VERSION 12 using namespace std; @@ -116,7 +118,7 @@ db_settings::db_settings() { data[SU_MULTIUSER_MODE] = MULTIUSER_MODE_OWNER_ONLY; data[SU_MNT_NS] = NAMESPACE_MODE_REQUESTER; data[DENYLIST_CONFIG] = false; - data[ZYGISK_CONFIG] = false; + data[ZYGISK_CONFIG] = rust::get_magiskd().is_emulator(); } int db_settings::get_idx(string_view key) const { diff --git a/native/src/core/lib.rs b/native/src/core/lib.rs index 279230585..3e1310a5d 100644 --- a/native/src/core/lib.rs +++ b/native/src/core/lib.rs @@ -48,6 +48,7 @@ pub mod ffi { fn get_log_pipe(self: &MagiskD) -> i32; fn close_log_pipe(self: &MagiskD); fn setup_logfile(self: &MagiskD); + fn is_emulator(self: &MagiskD) -> bool; } } diff --git a/scripts/avd_magisk.sh b/scripts/avd_magisk.sh index b50bb5684..62f948047 100755 --- a/scripts/avd_magisk.sh +++ b/scripts/avd_magisk.sh @@ -66,6 +66,9 @@ if [ -d /dev/avd-magisk ]; then rm -rf /dev/avd-magisk 2>/dev/null fi +# Make sure boot completed props are not set to 1 +setprop sys.boot_completed 0 + # Mount /cache if not already mounted if ! grep -q ' /cache ' /proc/mounts; then mount -t tmpfs -o 'mode=0755' tmpfs /cache diff --git a/scripts/avd_test.sh b/scripts/avd_test.sh index 6b700a1f3..39fde5685 100755 --- a/scripts/avd_test.sh +++ b/scripts/avd_test.sh @@ -35,7 +35,7 @@ cleanup() { wait_for_boot() { adb wait-for-device while true; do - if [ "stopped" = "$(adb exec-out getprop init.svc.bootanim)" ]; then + if [ "1" = "$(adb exec-out getprop sys.boot_completed)" ]; then break fi sleep 2