Unify OS APIs into one API
There are two APIs to specify a custom OS.
* 'os' field in a payload config json inside an APK
* 'osName' field in VirtualMachinePayloadConfig aidl parcelable
But that results in confusing and tricky APIs. For example
* VirtualMachineConfig.Builder.setOs() can be called only with
VirtualMachineConfig.Builder.setPayloadBinaryName() because a payload
config json already has its own OS field. It's confusing because users
may misunderstand that customOS is only available to payload binaries.
* We need one payload config file per one supported VM, even when they
are exactly same VMs except for the OS. This makes duplicated config
files (especially for tests).
This change unifies those two OS APIs into one, under
VirtualMachineAppConfig.
* AIDL API users and VM APK developers: 'os' field in the json config
will be deprecated and it will have no effect.
* Java API users: setOs must be called if they want to use OSes other
than "microdroid".
Bug: 321130996
Test: atest MicrodroidHostTests MicrodroidTests AuthFsHostTest \
CustomPvmfwHostTestCases DebugPolicyHostTests \
ComposHostTestCases AVFHostTestCase PvmfwImgTest
Change-Id: I41a526c7001b4b9ff23a52bf612a996e114f292c
diff --git a/virtualizationmanager/src/aidl.rs b/virtualizationmanager/src/aidl.rs
index 22bea58..7679eba 100644
--- a/virtualizationmanager/src/aidl.rs
+++ b/virtualizationmanager/src/aidl.rs
@@ -70,7 +70,7 @@
use glob::glob;
use lazy_static::lazy_static;
use log::{debug, error, info, warn};
-use microdroid_payload_config::{ApkConfig, OsConfig, Task, TaskType, VmPayloadConfig};
+use microdroid_payload_config::{ApkConfig, Task, TaskType, VmPayloadConfig};
use nix::unistd::pipe;
use rpcbinder::RpcServer;
use rustutils::system_properties;
@@ -622,13 +622,10 @@
// - specifying a config file;
// - specifying extra APKs;
// - specifying an OS other than Microdroid.
- match &config.payload {
+ (match &config.payload {
Payload::ConfigPath(_) => true,
- Payload::PayloadConfig(payload_config) => {
- !payload_config.extraApks.is_empty()
- || payload_config.osName != MICRODROID_OS_NAME
- }
- }
+ Payload::PayloadConfig(payload_config) => !payload_config.extraApks.is_empty(),
+ }) || config.osName != MICRODROID_OS_NAME
}
}
}
@@ -813,8 +810,13 @@
}
};
+ let payload_config_os = vm_payload_config.os.name.as_str();
+ if !payload_config_os.is_empty() && payload_config_os != "microdroid" {
+ bail!("'os' in payload config is deprecated");
+ }
+
// For now, the only supported OS is Microdroid and Microdroid GKI
- let os_name = vm_payload_config.os.name.as_str();
+ let os_name = config.osName.as_str();
if !is_valid_os(os_name) {
bail!("Unknown OS \"{}\"", os_name);
}
@@ -916,22 +918,13 @@
}
let task = Task { type_: TaskType::MicrodroidLauncher, command: payload_binary_name.clone() };
- let name = payload_config.osName.clone();
// The VM only cares about how many there are, these names are actually ignored.
let extra_apk_count = payload_config.extraApks.len();
let extra_apks =
(0..extra_apk_count).map(|i| ApkConfig { path: format!("extra-apk-{i}") }).collect();
- Ok(VmPayloadConfig {
- os: OsConfig { name },
- task: Some(task),
- apexes: vec![],
- extra_apks,
- prefer_staged: false,
- export_tombstones: None,
- enable_authfs: false,
- })
+ Ok(VmPayloadConfig { task: Some(task), extra_apks, ..Default::default() })
}
/// Generates a unique filename to use for a composite disk image.