MÃ¥rten Kongstad | 433fab9 | 2023-09-22 11:08:33 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //! `printflags` is a device binary to print feature flags. |
| 18 | |
| 19 | use aconfig_protos::aconfig::Parsed_flags as ProtoParsedFlags; |
| 20 | use anyhow::Result; |
| 21 | use std::collections::HashMap; |
| 22 | use std::fs; |
| 23 | |
| 24 | fn main() -> Result<()> { |
| 25 | let mut flags: HashMap<String, Vec<String>> = HashMap::new(); |
| 26 | for partition in ["system", "system_ext", "product", "vendor"] { |
| 27 | let path = format!("/{}/etc/aconfig_flags.pb", partition); |
| 28 | let Ok(bytes) = fs::read(&path) else { |
| 29 | eprintln!("warning: failed to read {}", path); |
| 30 | continue; |
| 31 | }; |
| 32 | let parsed_flags: ProtoParsedFlags = protobuf::Message::parse_from_bytes(&bytes)?; |
| 33 | for flag in parsed_flags.parsed_flag { |
| 34 | let key = format!("{}.{}", flag.package(), flag.name()); |
| 35 | let value = format!("{:?} + {:?} ({})", flag.permission(), flag.state(), partition); |
| 36 | flags.entry(key).or_default().push(value); |
| 37 | } |
| 38 | } |
| 39 | for (key, value) in flags { |
| 40 | // TODO: if the flag is READ_WRITE (for any partition), call "device_config get" to obtain |
| 41 | // the flag's current state, and append value to the output |
| 42 | println!("{}: {}", key, value.join(", ")); |
| 43 | } |
| 44 | Ok(()) |
| 45 | } |