aconfig: add create-device-config-sysprops command
Add a new "create-device-config-sysprops" command that works like
"create-device-config-defaults" but for system properties.
DeviceConfig is a Java service, and will mirror (some of) its values by
setting system properties in the persist.device_config namespace. Native
code will access DeviceConfig (actually, the system properties) via the
server_configurable_flags library.
The new command writes a file that can be appended to /system/build.prop
to pre-populate persist.device_config before DeviceConfig has started.
Like create-device-config-defaults, the new command skips READ_ONLY
flags.
Bug: 285468565
Test: atest aconfig.test
Change-Id: I311c7c5e0b03dc897b09204137d43cc182324717
diff --git a/tools/aconfig/src/commands.rs b/tools/aconfig/src/commands.rs
index d5e47da..3ae72c6 100644
--- a/tools/aconfig/src/commands.rs
+++ b/tools/aconfig/src/commands.rs
@@ -123,6 +123,24 @@
Ok(output)
}
+pub fn create_device_config_sysprops(caches: Vec<Cache>) -> Result<Vec<u8>> {
+ let mut output = Vec::new();
+ for item in sort_and_iter_items(caches).filter(|item| item.permission == Permission::ReadWrite)
+ {
+ let line = format!(
+ "persist.device_config.{}.{}={}\n",
+ item.namespace,
+ item.name,
+ match item.state {
+ FlagState::Enabled => "true",
+ FlagState::Disabled => "false",
+ }
+ );
+ output.extend_from_slice(line.as_bytes());
+ }
+ Ok(output)
+}
+
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum DumpFormat {
Text,
@@ -235,6 +253,14 @@
}
#[test]
+ fn test_create_device_config_sysprops() {
+ let caches = vec![crate::test::create_cache()];
+ let bytes = create_device_config_sysprops(caches).unwrap();
+ let text = std::str::from_utf8(&bytes).unwrap();
+ assert_eq!("persist.device_config.test.disabled_rw=false\npersist.device_config.test.enabled_rw=true\n", text);
+ }
+
+ #[test]
fn test_dump_text_format() {
let caches = vec![create_test_cache_ns1()];
let bytes = dump_cache(caches, DumpFormat::Text).unwrap();