Introduce VirtualMachineAppConfig::CustomConfig struct
This struct contains all the parameters that require
USE_CUSTOM_VIRTUAL_MACHINE permission.
Bug: 286225150
Test: atest MicrodroidTestApp
Change-Id: I3d78459c47dc6848642692106847544268e9e4e0
diff --git a/virtualizationmanager/src/aidl.rs b/virtualizationmanager/src/aidl.rs
index 9cd70e6..968d2d2 100644
--- a/virtualizationmanager/src/aidl.rs
+++ b/virtualizationmanager/src/aidl.rs
@@ -317,15 +317,13 @@
VirtualMachineConfig::RawConfig(_) => true,
VirtualMachineConfig::AppConfig(config) => {
// Some features are reserved for platform apps only, even when using
- // VirtualMachineAppConfig:
+ // VirtualMachineAppConfig. Almost all of these features are grouped in the
+ // CustomConfig struct:
// - controlling CPUs;
- // - specifying a config file in the APK;
+ // - specifying a config file in the APK; (this one is not part of CustomConfig)
// - gdbPort is set, meaning that crosvm will start a gdb server;
// - using anything other than the default kernel.
- !config.taskProfiles.is_empty()
- || matches!(config.payload, Payload::ConfigPath(_))
- || config.gdbPort > 0
- || config.customKernelImage.as_ref().is_some()
+ config.customConfig.is_some() || matches!(config.payload, Payload::ConfigPath(_))
}
};
if is_custom {
@@ -606,8 +604,12 @@
let vm_config_file = File::open(vm_config_path)?;
let mut vm_config = VmConfig::load(&vm_config_file)?.to_parcelable()?;
- if let Some(file) = config.customKernelImage.as_ref() {
- vm_config.kernel = Some(ParcelFileDescriptor::new(clone_file(file)?))
+ if let Some(custom_config) = &config.customConfig {
+ if let Some(file) = custom_config.customKernelImage.as_ref() {
+ vm_config.kernel = Some(ParcelFileDescriptor::new(clone_file(file)?))
+ }
+ vm_config.taskProfiles = custom_config.taskProfiles.clone();
+ vm_config.gdbPort = custom_config.gdbPort;
}
if config.memoryMib > 0 {
@@ -617,8 +619,6 @@
vm_config.name = config.name.clone();
vm_config.protectedVm = config.protectedVm;
vm_config.cpuTopology = config.cpuTopology;
- vm_config.taskProfiles = config.taskProfiles.clone();
- vm_config.gdbPort = config.gdbPort;
// Microdroid takes additional init ramdisk & (optionally) storage image
add_microdroid_system_images(config, instance_file, storage_image, &mut vm_config)?;
@@ -1053,7 +1053,9 @@
fn extract_gdb_port(config: &VirtualMachineConfig) -> Option<NonZeroU16> {
match config {
VirtualMachineConfig::RawConfig(config) => NonZeroU16::new(config.gdbPort as u16),
- VirtualMachineConfig::AppConfig(config) => NonZeroU16::new(config.gdbPort as u16),
+ VirtualMachineConfig::AppConfig(config) => {
+ NonZeroU16::new(config.customConfig.as_ref().map(|c| c.gdbPort).unwrap_or(0) as u16)
+ }
}
}