ksud: Disable modules when magisk installed

This commit is contained in:
tiann
2023-03-01 11:39:48 +08:00
parent 1c65048813
commit c34a5ae2a6
4 changed files with 28 additions and 1 deletions

View File

@@ -808,6 +808,7 @@ dependencies = [
"serde",
"serde_json",
"sys-mount",
"which",
"zip 0.6.4",
"zip-extensions",
]
@@ -1568,6 +1569,17 @@ version = "0.2.84"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
[[package]]
name = "which"
version = "4.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269"
dependencies = [
"either",
"libc",
"once_cell",
]
[[package]]
name = "winapi"
version = "0.3.9"

View File

@@ -31,6 +31,7 @@ rust-embed = { version = "6.4.2", features = [
"debug-embed",
"compression", # must clean build after updating binaries
] }
which = "4.2.2"
[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
sys-mount = { git = "https://github.com/tiann/sys-mount" }

View File

@@ -115,6 +115,11 @@ pub fn mount_systemlessly(module_dir: &str) -> Result<()> {
pub fn on_post_data_fs() -> Result<()> {
crate::ksu::report_post_fs_data();
if utils::has_magisk() {
warn!("Magisk detected, skip post-fs-data!");
return Ok(());
}
utils::umask(0);
let module_update_img = defs::MODULE_UPDATE_IMG;
@@ -203,11 +208,16 @@ pub fn on_post_data_fs() -> Result<()> {
pub fn on_services() -> Result<()> {
utils::umask(0);
// check safe mode first.
if utils::has_magisk() {
warn!("Magisk detected, skip services!");
return Ok(());
}
if crate::utils::is_safe_mode() {
warn!("safe mode, skip module service scripts");
return Ok(());
}
if let Err(e) = crate::module::exec_common_scripts("service.d", false) {
warn!("Failed to exec common service scripts: {}", e);
}

View File

@@ -125,3 +125,7 @@ pub fn umask(mask: u32) {
pub fn umask(_mask: u32) {
unimplemented!("umask is not supported on this platform")
}
pub fn has_magisk() -> bool {
which::which("magisk").is_ok()
}