Make port numbers aidl constants
Test: atest MicrodroidHostTestCases
Change-Id: I5e1bcfc8f76bf4f4e7ac2441d5947e37f42bc58a
diff --git a/microdroid_manager/src/main.rs b/microdroid_manager/src/main.rs
index 278a14d..62af791 100644
--- a/microdroid_manager/src/main.rs
+++ b/microdroid_manager/src/main.rs
@@ -36,7 +36,9 @@
use std::time::Duration;
use vsock::VsockStream;
-use android_system_virtualmachineservice::aidl::android::system::virtualmachineservice::IVirtualMachineService::IVirtualMachineService;
+use android_system_virtualmachineservice::aidl::android::system::virtualmachineservice::IVirtualMachineService::{
+ VM_BINDER_SERVICE_PORT, VM_STREAM_SERVICE_PORT, IVirtualMachineService,
+};
const WAIT_TIMEOUT: Duration = Duration::from_secs(10);
const DM_MOUNTED_APK_PATH: &str = "/dev/block/mapper/microdroid-apk";
@@ -44,18 +46,13 @@
/// The CID representing the host VM
const VMADDR_CID_HOST: u32 = 2;
-/// Port number that virtualizationservice listens on connections from the guest VMs for the
-/// VirtualMachineService binder service
-/// Sync with virtualizationservice/src/aidl.rs
-const PORT_VM_BINDER_SERVICE: u32 = 5000;
-
fn get_vms_rpc_binder() -> Result<Strong<dyn IVirtualMachineService>> {
// SAFETY: AIBinder returned by RpcClient has correct reference count, and the ownership can be
// safely taken by new_spibinder.
let ibinder = unsafe {
new_spibinder(binder_rpc_unstable_bindgen::RpcClient(
VMADDR_CID_HOST,
- PORT_VM_BINDER_SERVICE,
+ VM_BINDER_SERVICE_PORT as u32,
) as *mut AIBinder)
};
if let Some(ibinder) = ibinder {
@@ -183,7 +180,6 @@
fn build_command(task: &Task) -> Result<Command> {
const VMADDR_CID_HOST: u32 = 2;
- const PORT_VIRT_SVC: u32 = 3000;
let mut command = match task.type_ {
TaskType::Executable => {
@@ -198,7 +194,7 @@
}
};
- match VsockStream::connect_with_cid_port(VMADDR_CID_HOST, PORT_VIRT_SVC) {
+ match VsockStream::connect_with_cid_port(VMADDR_CID_HOST, VM_STREAM_SERVICE_PORT as u32) {
Ok(stream) => {
// SAFETY: the ownership of the underlying file descriptor is transferred from stream
// to the file object, and then into the Command object. When the command is finished,
diff --git a/virtualizationservice/aidl/android/system/virtualmachineservice/IVirtualMachineService.aidl b/virtualizationservice/aidl/android/system/virtualmachineservice/IVirtualMachineService.aidl
index 10b14e0..fba83c8 100644
--- a/virtualizationservice/aidl/android/system/virtualmachineservice/IVirtualMachineService.aidl
+++ b/virtualizationservice/aidl/android/system/virtualmachineservice/IVirtualMachineService.aidl
@@ -18,6 +18,18 @@
/** {@hide} */
interface IVirtualMachineService {
/**
+ * Port number that VirtualMachineService listens on connections from the guest VMs for the
+ * payload input and output.
+ */
+ const int VM_STREAM_SERVICE_PORT = 3000;
+
+ /**
+ * Port number that VirtualMachineService listens on connections from the guest VMs for the
+ * VirtualMachineService binder service.
+ */
+ const int VM_BINDER_SERVICE_PORT = 5000;
+
+ /**
* Notifies that the payload has started.
* TODO(b/191845268): remove cid parameter
*/
diff --git a/virtualizationservice/src/aidl.rs b/virtualizationservice/src/aidl.rs
index 6b60da3..3cf7ca3 100644
--- a/virtualizationservice/src/aidl.rs
+++ b/virtualizationservice/src/aidl.rs
@@ -37,7 +37,7 @@
self, BinderFeatures, ExceptionCode, Interface, ParcelFileDescriptor, Status, Strong, ThreadState,
};
use android_system_virtualmachineservice::aidl::android::system::virtualmachineservice::IVirtualMachineService::{
- BnVirtualMachineService, IVirtualMachineService,
+ VM_BINDER_SERVICE_PORT, VM_STREAM_SERVICE_PORT, BnVirtualMachineService, IVirtualMachineService,
};
use anyhow::{bail, Context, Result};
use ::binder::unstable_api::AsNative;
@@ -65,15 +65,6 @@
/// The CID representing the host VM
const VMADDR_CID_HOST: u32 = 2;
-/// Port number that virtualizationservice listens on connections from the guest VMs for the
-/// payload input and output
-const PORT_VIRT_STREAM_SERVICE: u32 = 3000;
-
-/// Port number that virtualizationservice listens on connections from the guest VMs for the
-/// VirtualMachineService binder service
-/// Sync with microdroid_manager/src/main.rs
-const PORT_VM_BINDER_SERVICE: u32 = 5000;
-
/// The size of zero.img.
/// Gaps in composite disk images are filled with a shared zero.img.
const ZERO_FILLER_SIZE: u64 = 4096;
@@ -323,7 +314,7 @@
let retval = unsafe {
binder_rpc_unstable_bindgen::RunRpcServer(
service.as_native_mut() as *mut binder_rpc_unstable_bindgen::AIBinder,
- PORT_VM_BINDER_SERVICE,
+ VM_BINDER_SERVICE_PORT as u32,
)
};
if retval {
@@ -341,7 +332,8 @@
/// Waits for incoming connections from VM. If a new connection is made, notify the event to the
/// client via the callback (if registered).
fn handle_stream_connection_from_vm(state: Arc<Mutex<State>>) -> Result<()> {
- let listener = VsockListener::bind_with_cid_port(VMADDR_CID_HOST, PORT_VIRT_STREAM_SERVICE)?;
+ let listener =
+ VsockListener::bind_with_cid_port(VMADDR_CID_HOST, VM_STREAM_SERVICE_PORT as u32)?;
for stream in listener.incoming() {
let stream = match stream {
Err(e) => {