Skip to content

Commit

Permalink
Enable Zygisk by default in emulators
Browse files Browse the repository at this point in the history
Make sure CI tests Zygisk
  • Loading branch information
topjohnwu committed Sep 29, 2023
1 parent 6e7a995 commit 5c92d39
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
21 changes: 18 additions & 3 deletions native/src/core/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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();
Expand All @@ -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::*;
Expand Down
4 changes: 3 additions & 1 deletion native/src/core/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <socket.hpp>
#include <base.hpp>

#include "core.hpp"

#define DB_VERSION 12

using namespace std;
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions native/src/core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
3 changes: 3 additions & 0 deletions scripts/avd_magisk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/avd_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c92d39

Please sign in to comment.