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_rust.rs b/tools/aconfig/src/codegen_rust.rs
index e27aa9c..cfe7316 100644
--- a/tools/aconfig/src/codegen_rust.rs
+++ b/tools/aconfig/src/codegen_rust.rs
@@ -20,11 +20,13 @@
 
 use crate::aconfig::{FlagState, Permission};
 use crate::cache::{Cache, Item};
+use crate::codegen;
 use crate::commands::OutputFile;
 
 pub fn generate_rust_code(cache: &Cache) -> Result<OutputFile> {
     let package = cache.package();
-    let parsed_flags: Vec<TemplateParsedFlag> = cache.iter().map(|item| item.into()).collect();
+    let parsed_flags: Vec<TemplateParsedFlag> =
+        cache.iter().map(|item| TemplateParsedFlag::new(package, item)).collect();
     let context = TemplateContext {
         package: package.to_string(),
         parsed_flags,
@@ -47,6 +49,8 @@
 #[derive(Serialize)]
 struct TemplateParsedFlag {
     pub name: String,
+    pub device_config_namespace: String,
+    pub device_config_flag: String,
 
     // TinyTemplate's conditionals are limited to single <bool> expressions; list all options here
     // Invariant: exactly one of these fields will be true
@@ -55,11 +59,14 @@
     pub is_read_write: bool,
 }
 
-impl From<&Item> for TemplateParsedFlag {
+impl TemplateParsedFlag {
     #[allow(clippy::nonminimal_bool)]
-    fn from(item: &Item) -> Self {
+    fn new(package: &str, item: &Item) -> Self {
         let template = TemplateParsedFlag {
             name: item.name.clone(),
+            device_config_namespace: item.namespace.to_string(),
+            device_config_flag: codegen::create_device_config_ident(package, &item.name)
+                .expect("values checked at cache creation time"),
             is_read_only_enabled: item.permission == Permission::ReadOnly
                 && item.state == FlagState::Enabled,
             is_read_only_disabled: item.permission == Permission::ReadOnly
@@ -101,7 +108,7 @@
 
 #[inline(always)]
 pub fn r#disabled_rw() -> bool {
-    flags_rust::GetServerConfigurableFlag("com.android.aconfig.test", "disabled_rw", "false") == "true"
+    flags_rust::GetServerConfigurableFlag("aconfig_test", "com.android.aconfig.test.disabled_rw", "false") == "true"
 }
 
 #[inline(always)]
@@ -111,7 +118,7 @@
 
 #[inline(always)]
 pub fn r#enabled_rw() -> bool {
-    flags_rust::GetServerConfigurableFlag("com.android.aconfig.test", "enabled_rw", "false") == "true"
+    flags_rust::GetServerConfigurableFlag("aconfig_test", "com.android.aconfig.test.enabled_rw", "false") == "true"
 }
 
 }