Make extra APKs easier to specify
Allow extra APKs to be specified in VirtualMachineAppConfig as an
alternative to the config file, so the paths don't need to be fixed.
This involves adding:
- the extra_apk_count to the metadata proto, which is persisted in the
instance image.
- the extra APK fds to VirtualMachinePayloadConfig, so it can be
included in VirtualMachineAppConfig iff there is no config file.
And then a whole lot of plumbing to make it all work.
Using this requires the USE_CUSTOM_VIRTUAL_MACHINE permission, and is
behind the multi-tenant feature flag.
I've not attempted to add API yet (this CL is already big), but I have
extended the vm command to allow it to be exercised.
Bug: 303201498
Test: Start a VM with an extra APK specified on the `vm run-app`
command line.
Change-Id: Ib5da40a33960fd9639b62e8d77e865aeb1f6398b
diff --git a/vm/src/run.rs b/vm/src/run.rs
index cfc5454..1d2f48b 100644
--- a/vm/src/run.rs
+++ b/vm/src/run.rs
@@ -48,7 +48,7 @@
let extra_apks = match config.config_path.as_deref() {
Some(path) => parse_extra_apk_list(&config.apk, path)?,
- None => vec![],
+ None => config.extra_apks().to_vec(),
};
if extra_apks.len() != config.extra_idsigs.len() {
@@ -101,8 +101,7 @@
let vendor =
config.microdroid.vendor().as_ref().map(|p| open_parcel_file(p, false)).transpose()?;
- let extra_idsig_files: Result<Vec<File>, _> =
- config.extra_idsigs.iter().map(File::open).collect();
+ let extra_idsig_files: Result<Vec<_>, _> = config.extra_idsigs.iter().map(File::open).collect();
let extra_idsig_fds = extra_idsig_files?.into_iter().map(ParcelFileDescriptor::new).collect();
let payload = if let Some(config_path) = config.config_path {
@@ -119,9 +118,14 @@
} else {
"microdroid".to_owned()
};
+
+ let extra_apk_files: Result<Vec<_>, _> = extra_apks.iter().map(File::open).collect();
+ let extra_apk_fds = extra_apk_files?.into_iter().map(ParcelFileDescriptor::new).collect();
+
Payload::PayloadConfig(VirtualMachinePayloadConfig {
payloadBinaryName: payload_binary_name,
osName: os_name,
+ extraApks: extra_apk_fds,
})
} else {
bail!("Either --config-path or --payload-binary-name must be defined")
@@ -208,9 +212,8 @@
apk,
idsig,
instance: instance_img,
- config_path: None,
payload_binary_name: Some("MicrodroidEmptyPayloadJniLib.so".to_owned()),
- extra_idsigs: [].to_vec(),
+ ..Default::default()
};
command_run_app(app_config)
}
@@ -310,11 +313,11 @@
Ok(())
}
-fn parse_extra_apk_list(apk: &Path, config_path: &str) -> Result<Vec<String>, Error> {
+fn parse_extra_apk_list(apk: &Path, config_path: &str) -> Result<Vec<PathBuf>, Error> {
let mut archive = ZipArchive::new(File::open(apk)?)?;
let config_file = archive.by_name(config_path)?;
let config: VmPayloadConfig = serde_json::from_reader(config_file)?;
- Ok(config.extra_apks.into_iter().map(|x| x.path).collect())
+ Ok(config.extra_apks.into_iter().map(|x| x.path.into()).collect())
}
struct Callback {}