Merge "Add all apexes to apex_info" into main
diff --git a/target/product/generic_system.mk b/target/product/generic_system.mk
index 38efde4..19ec86d 100644
--- a/target/product/generic_system.mk
+++ b/target/product/generic_system.mk
@@ -103,6 +103,12 @@
     libaudiopolicyengineconfigurable \
     libpolicy-subsystem
 
+# Add all of the packages used to support older/upgrading devices
+# These can be removed as we drop support for the older API levels
+PRODUCT_PACKAGES += \
+    $(PRODUCT_PACKAGES_SHIPPING_API_LEVEL_29) \
+    $(PRODUCT_PACKAGES_SHIPPING_API_LEVEL_33) \
+    $(PRODUCT_PACKAGES_SHIPPING_API_LEVEL_34)
 
 # Include all zygote init scripts. "ro.zygote" will select one of them.
 PRODUCT_COPY_FILES += \
diff --git a/tools/aconfig/src/commands.rs b/tools/aconfig/src/commands.rs
index f7a6417..a35ad08 100644
--- a/tools/aconfig/src/commands.rs
+++ b/tools/aconfig/src/commands.rs
@@ -30,7 +30,8 @@
     ParsedFlagExt, ProtoFlagMetadata, ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag,
     ProtoParsedFlags, ProtoTracepoint,
 };
-use crate::storage::generate_storage_files;
+use crate::storage::generate_storage_file;
+use crate::storage::StorageFileSelection;
 
 pub struct Input {
     pub source: String,
@@ -223,7 +224,7 @@
     generate_rust_code(&package, modified_parsed_flags.into_iter(), codegen_mode)
 }
 
-pub fn create_storage(caches: Vec<Input>, container: &str) -> Result<Vec<OutputFile>> {
+pub fn create_storage(caches: Vec<Input>, container: &str, file: &StorageFileSelection) -> Result<Vec<u8>> {
     let parsed_flags_vec: Vec<ProtoParsedFlags> = caches
         .into_iter()
         .map(|mut input| input.try_parse_flags())
@@ -231,7 +232,7 @@
         .into_iter()
         .filter(|pfs| find_unique_container(pfs) == Some(container))
         .collect();
-    generate_storage_files(container, parsed_flags_vec.iter())
+    generate_storage_file(container, parsed_flags_vec.iter(), file)
 }
 
 pub fn create_device_config_defaults(mut input: Input) -> Result<Vec<u8>> {
diff --git a/tools/aconfig/src/main.rs b/tools/aconfig/src/main.rs
index 7d719f0..120e98c 100644
--- a/tools/aconfig/src/main.rs
+++ b/tools/aconfig/src/main.rs
@@ -32,6 +32,7 @@
 
 use codegen::CodegenMode;
 use dump::DumpFormat;
+use storage::StorageFileSelection;
 
 #[cfg(test)]
 mod test;
@@ -135,6 +136,11 @@
                         .required(true)
                         .help("The target container for the generated storage file."),
                 )
+                .arg(
+                    Arg::new("file")
+                        .long("file")
+                        .value_parser(|s: &str| StorageFileSelection::try_from(s)),
+                )
                 .arg(Arg::new("cache").long("cache").action(ArgAction::Append).required(true))
                 .arg(Arg::new("out").long("out").required(true)),
         )
@@ -278,14 +284,14 @@
             write_output_to_file_or_stdout(path, &output)?;
         }
         Some(("create-storage", sub_matches)) => {
+            let file = get_required_arg::<StorageFileSelection>(sub_matches, "file")
+                .context("Invalid storage file selection")?;
             let cache = open_zero_or_more_files(sub_matches, "cache")?;
             let container = get_required_arg::<String>(sub_matches, "container")?;
-            let dir = PathBuf::from(get_required_arg::<String>(sub_matches, "out")?);
-            let generated_files = commands::create_storage(cache, container)
+            let path = get_required_arg::<String>(sub_matches, "out")?;
+            let output = commands::create_storage(cache, container, file)
                 .context("failed to create storage files")?;
-            generated_files
-                .iter()
-                .try_for_each(|file| write_output_file_realtive_to_dir(&dir, file))?;
+            write_output_to_file_or_stdout(path, &output)?;
         }
         _ => unreachable!(),
     }
diff --git a/tools/aconfig/src/storage/mod.rs b/tools/aconfig/src/storage/mod.rs
index 36ea309..b4a8b5e 100644
--- a/tools/aconfig/src/storage/mod.rs
+++ b/tools/aconfig/src/storage/mod.rs
@@ -21,14 +21,32 @@
 use anyhow::{anyhow, Result};
 use std::collections::{hash_map::DefaultHasher, HashMap, HashSet};
 use std::hash::{Hash, Hasher};
-use std::path::PathBuf;
 
-use crate::commands::OutputFile;
 use crate::protos::{ProtoParsedFlag, ProtoParsedFlags};
 use crate::storage::{
     flag_table::FlagTable, flag_value::FlagValueList, package_table::PackageTable,
 };
 
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub enum StorageFileSelection {
+    PackageMap,
+    FlagMap,
+    FlagVal,
+}
+
+impl TryFrom<&str> for StorageFileSelection {
+    type Error = anyhow::Error;
+
+    fn try_from(value: &str) -> std::result::Result<Self, Self::Error> {
+        match value {
+            "package_map" => Ok(Self::PackageMap),
+            "flag_map" => Ok(Self::FlagMap),
+            "flag_val" => Ok(Self::FlagVal),
+            _ => Err(anyhow!("Invalid storage file to create")),
+        }
+    }
+}
+
 pub const FILE_VERSION: u32 = 1;
 
 pub const HASH_PRIMES: [u32; 29] = [
@@ -110,34 +128,30 @@
     packages
 }
 
-pub fn generate_storage_files<'a, I>(
+pub fn generate_storage_file<'a, I>(
     container: &str,
     parsed_flags_vec_iter: I,
-) -> Result<Vec<OutputFile>>
+    file: &StorageFileSelection,
+) -> Result<Vec<u8>>
 where
     I: Iterator<Item = &'a ProtoParsedFlags>,
 {
     let packages = group_flags_by_package(parsed_flags_vec_iter);
 
-    // create and serialize package map
-    let package_table = PackageTable::new(container, &packages)?;
-    let package_table_file_path = PathBuf::from("package.map");
-    let package_table_file =
-        OutputFile { contents: package_table.as_bytes(), path: package_table_file_path };
-
-    // create and serialize flag map
-    let flag_table = FlagTable::new(container, &packages)?;
-    let flag_table_file_path = PathBuf::from("flag.map");
-    let flag_table_file =
-        OutputFile { contents: flag_table.as_bytes(), path: flag_table_file_path };
-
-    // create and serialize flag value
-    let flag_value = FlagValueList::new(container, &packages)?;
-    let flag_value_file_path = PathBuf::from("flag.val");
-    let flag_value_file =
-        OutputFile { contents: flag_value.as_bytes(), path: flag_value_file_path };
-
-    Ok(vec![package_table_file, flag_table_file, flag_value_file])
+    match file {
+        StorageFileSelection::PackageMap => {
+            let package_table = PackageTable::new(container, &packages)?;
+            Ok(package_table.as_bytes())
+        }
+        StorageFileSelection::FlagMap => {
+            let flag_table = FlagTable::new(container, &packages)?;
+            Ok(flag_table.as_bytes())
+        }
+        StorageFileSelection::FlagVal => {
+            let flag_value = FlagValueList::new(container, &packages)?;
+            Ok(flag_value.as_bytes())
+        }
+    }
 }
 
 #[cfg(test)]