ksud: add is_safe_mode

This commit is contained in:
tiann
2023-01-05 13:52:39 +08:00
parent df2a9a8a75
commit 800f66467c

View File

@@ -1,6 +1,9 @@
use std::path::Path;
use std::{
path::Path,
process::{Command, Stdio},
};
use anyhow::{Result, ensure};
use anyhow::{ensure, Result};
use subprocess::Exec;
pub fn mount_image(src: &str, target: &str) -> Result<()> {
@@ -21,4 +24,17 @@ pub fn ensure_clean_dir(dir: &str) -> Result<()> {
std::fs::remove_dir_all(path)?;
}
Ok(std::fs::create_dir_all(path)?)
}
}
pub fn getprop(prop: &str) -> Result<String> {
let output = Command::new("getprop")
.arg(prop)
.stdout(Stdio::piped())
.output()?;
let output = String::from_utf8_lossy(&output.stdout);
Ok(output.trim().to_string())
}
pub fn is_safe_mode() -> Result<bool> {
Ok(getprop("persist.sys.safemode")?.eq("1") || getprop("ro.sys.safemode")?.eq("1"))
}