From 800f66467c4ddcc69ce4905997aaf92bb45bdfe6 Mon Sep 17 00:00:00 2001 From: tiann Date: Thu, 5 Jan 2023 13:52:39 +0800 Subject: [PATCH] ksud: add is_safe_mode --- userspace/ksud/src/utils.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/userspace/ksud/src/utils.rs b/userspace/ksud/src/utils.rs index 5577cba4..05094b76 100644 --- a/userspace/ksud/src/utils.rs +++ b/userspace/ksud/src/utils.rs @@ -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)?) -} \ No newline at end of file +} + +pub fn getprop(prop: &str) -> Result { + 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 { + Ok(getprop("persist.sys.safemode")?.eq("1") || getprop("ro.sys.safemode")?.eq("1")) +}