aflags: add new storage mode
Add a mode that lets the user use the new aconfig storage.
Bug: 324436145
Test: adb shell aflags list --use-new-storage
Change-Id: I97d7a229a64c6ef1aea844281298ce5449b02570
diff --git a/tools/aconfig/aflags/src/main.rs b/tools/aconfig/aflags/src/main.rs
index 808ffa0..1c453c5 100644
--- a/tools/aconfig/aflags/src/main.rs
+++ b/tools/aconfig/aflags/src/main.rs
@@ -22,6 +22,9 @@
mod device_config_source;
use device_config_source::DeviceConfigSource;
+mod aconfig_storage_source;
+use aconfig_storage_source::AconfigStorageSource;
+
#[derive(Clone, PartialEq, Debug)]
enum FlagPermission {
ReadOnly,
@@ -109,6 +112,11 @@
fn override_flag(namespace: &str, qualified_name: &str, value: &str) -> Result<()>;
}
+enum FlagSourceType {
+ DeviceConfig,
+ AconfigStorage,
+}
+
const ABOUT_TEXT: &str = "Tool for reading and writing flags.
Rows in the table from the `list` command follow this format:
@@ -139,7 +147,11 @@
#[derive(Parser, Debug)]
enum Command {
/// List all aconfig flags on this device.
- List,
+ List {
+ /// Read from the new flag storage.
+ #[clap(long)]
+ use_new_storage: bool,
+ },
/// Enable an aconfig flag on this device, on the next boot.
Enable {
@@ -201,8 +213,11 @@
Ok(())
}
-fn list() -> Result<String> {
- let flags = DeviceConfigSource::list_flags()?;
+fn list(source_type: FlagSourceType) -> Result<String> {
+ let flags = match source_type {
+ FlagSourceType::DeviceConfig => DeviceConfigSource::list_flags()?,
+ FlagSourceType::AconfigStorage => AconfigStorageSource::list_flags()?,
+ };
let padding_info = PaddingInfo {
longest_flag_col: flags.iter().map(|f| f.qualified_name().len()).max().unwrap_or(0),
longest_val_col: flags.iter().map(|f| f.value.to_string().len()).max().unwrap_or(0),
@@ -234,7 +249,8 @@
fn main() {
let cli = Cli::parse();
let output = match cli.command {
- Command::List => list().map(Some),
+ Command::List { use_new_storage: true } => list(FlagSourceType::AconfigStorage).map(Some),
+ Command::List { use_new_storage: false } => list(FlagSourceType::DeviceConfig).map(Some),
Command::Enable { qualified_name } => set_flag(&qualified_name, "true").map(|_| None),
Command::Disable { qualified_name } => set_flag(&qualified_name, "false").map(|_| None),
};