aconfig: add namespace field to flag_declaration and parsed_flag
Add a new field to the proto messages flag_declaration and parsed_flag.
The new field will be used verbatim as a parameter when calling
DeviceConfig.getBoolean to read the value of a READ_WRITE flag. See the
DeviceConfig API for more info.
Note: not to be confused with the old namespace field, which has been
renamed to package.
Bug: 285211724
Test: atest aconfig.test
Change-Id: I2181be7b5e98fc334e5277fb5f7e386f1fe0b550
diff --git a/tools/aconfig/src/codegen.rs b/tools/aconfig/src/codegen.rs
index 8ef0e0b..fea9961 100644
--- a/tools/aconfig/src/codegen.rs
+++ b/tools/aconfig/src/codegen.rs
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+use anyhow::{ensure, Result};
+
pub fn is_valid_name_ident(s: &str) -> bool {
// Identifiers must match [a-z][a-z0-9_]*
let mut chars = s.chars();
@@ -30,6 +32,12 @@
s.split('.').all(is_valid_name_ident)
}
+pub fn create_device_config_ident(package: &str, flag_name: &str) -> Result<String> {
+ ensure!(is_valid_package_ident(package), "bad package");
+ ensure!(is_valid_package_ident(flag_name), "bad flag name");
+ Ok(format!("{}.{}", package, flag_name))
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -62,4 +70,12 @@
assert!(!is_valid_package_ident("."));
assert!(!is_valid_package_ident("foo..bar"));
}
+
+ #[test]
+ fn test_create_device_config_ident() {
+ assert_eq!(
+ "com.foo.bar.some_flag",
+ create_device_config_ident("com.foo.bar", "some_flag").unwrap()
+ );
+ }
}