bin/vm run-microdroid supports --network-supported flag.
Bug: 340376951
Test: adb shell /apex/com.android.virt/bin/vm run-microdroid
--network-supported
Test: adb shell /apex/com.android.virt/bin/vm run-microdroid
--network-supported --protected
Change-Id: I1d88fe11d79b8ea46e12b6dfaab318aabdc0a2e0
diff --git a/virtualizationmanager/src/aidl.rs b/virtualizationmanager/src/aidl.rs
index 653281d..796ae21 100644
--- a/virtualizationmanager/src/aidl.rs
+++ b/virtualizationmanager/src/aidl.rs
@@ -14,7 +14,7 @@
//! Implementation of the AIDL interface of the VirtualizationService.
-use crate::{get_calling_pid, get_calling_uid};
+use crate::{get_calling_pid, get_calling_uid, get_this_pid};
use crate::atom::{write_vm_booted_stats, write_vm_creation_stats};
use crate::composite::make_composite_image;
use crate::crosvm::{CrosvmConfig, DiskFile, DisplayConfig, InputDeviceOption, PayloadState, VmContext, VmInstance, VmState};
@@ -606,6 +606,18 @@
vec![]
};
+ // Create TAP network interface if the VM supports network.
+ let _tap_fd = if cfg!(network) && config.networkSupported {
+ if *is_protected {
+ return Err(anyhow!("Network feature is not supported for pVM yet"))
+ .with_log()
+ .or_binder_exception(ExceptionCode::UNSUPPORTED_OPERATION)?;
+ }
+ Some(GLOBAL_SERVICE.createTapInterface(&get_this_pid().to_string())?)
+ } else {
+ None
+ };
+
// Actually start the VM.
let crosvm_config = CrosvmConfig {
cid,
@@ -913,6 +925,7 @@
}
vm_config.devices.clone_from(&custom_config.devices);
+ vm_config.networkSupported = custom_config.networkSupported;
}
if config.memoryMib > 0 {