Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5223a708 authored by Ted Bauer's avatar Ted Bauer
Browse files

Add root check to aflags

aflags scans the apex/ dir, which requires root access to read.
Currently the command fails with "Error: Permission denied", which
doesn't tell the user how to fix the problem. This CL adds a more
descriptive error message.

Test: adb unroot && adb shell aflags list
Bug: 347692127
Change-Id: I98a7a1ba10ef52ec47035816fa66119ea84f281d
parent e7a2e599
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -233,8 +233,6 @@ fn format_flag_row(flag: &Flag, info: &PaddingInfo) -> String {
}

fn set_flag(qualified_name: &str, value: &str) -> Result<()> {
    ensure!(nix::unistd::Uid::current().is_root(), "must be root to mutate flags");

    let flags_binding = DeviceConfigSource::list_flags()?;
    let flag = flags_binding.iter().find(|f| f.qualified_name() == qualified_name).ok_or(
        anyhow!("no aconfig flag '{qualified_name}'. Does the flag have an .aconfig definition?"),
@@ -282,7 +280,9 @@ fn list(source_type: FlagSourceType, container: Option<String>) -> Result<String
    Ok(result)
}

fn main() {
fn main() -> Result<()> {
    ensure!(nix::unistd::Uid::current().is_root(), "must be root");

    let cli = Cli::parse();
    let output = match cli.command {
        Command::List { use_new_storage: true, container } => {
@@ -299,6 +299,8 @@ fn main() {
        Ok(None) => (),
        Err(message) => println!("Error: {message}"),
    }

    Ok(())
}

#[cfg(test)]