Enable Zygisk by default in emulators

Make sure CI tests Zygisk
This commit is contained in:
topjohnwu 2023-09-28 15:37:11 -07:00
parent 6e7a995716
commit 5c92d39498
5 changed files with 26 additions and 5 deletions

View File

@ -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<MagiskD> = OnceLock::new();
#[derive(Default)]
pub struct MagiskD {
pub logd: Mutex<RefCell<Option<File>>>,
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::*;

View File

@ -7,6 +7,8 @@
#include <socket.hpp>
#include <base.hpp>
#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 {

View File

@ -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;
}
}

View File

@ -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

View File

@ -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