Make ErrorCode an enum
Change the VS AIDL to define it as an enum. Added a new common AIDL
module to hold it, since this is needed by both existing AIDLs, and we
don't want either directly depending on the other.
Modify vmclient to also have Rust enum for ErrorCode, with translation
logic, in the same way as we did for DeathReason. Switch to Debug
rather than Display for these enums.
Also fixed a couple of AIDL warnings (enum-explicit-default).
We also need translation in the Java API, but I'll do that as part of
https://r.android.com/2192077.
Bug: 236811123
Test: atest MicrodroidTests MicrodroidHostTestCases
Test: composd_cmd test-compile
Change-Id: I561e5f43f0f1c74d1318dc41782ed390bb5f0337
diff --git a/virtualizationservice/Android.bp b/virtualizationservice/Android.bp
index b6b7b09..1493cb8 100644
--- a/virtualizationservice/Android.bp
+++ b/virtualizationservice/Android.bp
@@ -20,6 +20,7 @@
},
prefer_rlib: true,
rustlibs: [
+ "android.system.virtualizationcommon-rust",
"android.system.virtualizationservice-rust",
"android.system.virtualmachineservice-rust",
"android.os.permissions_aidl-rust",
diff --git a/virtualizationservice/aidl/Android.bp b/virtualizationservice/aidl/Android.bp
index 30a4b03..4d5326a 100644
--- a/virtualizationservice/aidl/Android.bp
+++ b/virtualizationservice/aidl/Android.bp
@@ -5,6 +5,7 @@
aidl_interface {
name: "android.system.virtualizationservice",
srcs: ["android/system/virtualizationservice/**/*.aidl"],
+ imports: ["android.system.virtualizationcommon"],
// This is never accessed directly. Apps are expected to use this indirectly via the Java
// wrapper android.system.virtualmachine.
unstable: true,
@@ -35,6 +36,7 @@
aidl_interface {
name: "android.system.virtualmachineservice",
srcs: ["android/system/virtualmachineservice/**/*.aidl"],
+ imports: ["android.system.virtualizationcommon"],
unstable: true,
backend: {
rust: {
@@ -46,3 +48,27 @@
},
},
}
+
+aidl_interface {
+ name: "android.system.virtualizationcommon",
+ srcs: ["android/system/virtualizationcommon/**/*.aidl"],
+ unstable: true,
+ backend: {
+ java: {
+ apex_available: ["com.android.virt"],
+ },
+ ndk: {
+ apex_available: [
+ "com.android.virt",
+ "com.android.compos",
+ ],
+ },
+ rust: {
+ enabled: true,
+ apex_available: [
+ "com.android.virt",
+ "com.android.compos",
+ ],
+ },
+ },
+}
diff --git a/virtualizationservice/aidl/android/system/virtualizationcommon/ErrorCode.aidl b/virtualizationservice/aidl/android/system/virtualizationcommon/ErrorCode.aidl
new file mode 100644
index 0000000..04b9749
--- /dev/null
+++ b/virtualizationservice/aidl/android/system/virtualizationcommon/ErrorCode.aidl
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.system.virtualizationcommon;
+
+/**
+ * Errors reported from within a VM.
+ */
+@Backing(type="int")
+enum ErrorCode {
+ /**
+ * Error code for all other errors not listed below.
+ */
+ UNKNOWN = 0,
+
+ /**
+ * Error code indicating that the payload can't be verified due to various reasons (e.g invalid
+ * merkle tree, invalid formats, etc).
+ */
+ PAYLOAD_VERIFICATION_FAILED = 1,
+
+ /**
+ * Error code indicating that the payload is verified, but has changed since the last boot.
+ */
+ PAYLOAD_CHANGED = 2,
+
+ /**
+ * Error code indicating that the payload config is invalid.
+ */
+ PAYLOAD_CONFIG_INVALID = 3,
+}
diff --git a/virtualizationservice/aidl/android/system/virtualizationservice/IVirtualMachineCallback.aidl b/virtualizationservice/aidl/android/system/virtualizationservice/IVirtualMachineCallback.aidl
index 6c8eb4a..8d6ed08 100644
--- a/virtualizationservice/aidl/android/system/virtualizationservice/IVirtualMachineCallback.aidl
+++ b/virtualizationservice/aidl/android/system/virtualizationservice/IVirtualMachineCallback.aidl
@@ -15,6 +15,7 @@
*/
package android.system.virtualizationservice;
+import android.system.virtualizationcommon.ErrorCode;
import android.system.virtualizationservice.DeathReason;
/**
@@ -44,7 +45,7 @@
/**
* Called when an error occurs in the VM.
*/
- void onError(int cid, int errorCode, in String message);
+ void onError(int cid, ErrorCode errorCode, in String message);
/**
* Called when the VM dies.
diff --git a/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineAppConfig.aidl b/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineAppConfig.aidl
index 8eb5497..d86f2bf 100644
--- a/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineAppConfig.aidl
+++ b/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineAppConfig.aidl
@@ -48,7 +48,7 @@
}
/** Debug level of the VM */
- DebugLevel debugLevel;
+ DebugLevel debugLevel = DebugLevel.NONE;
/** Whether the VM should be a protected VM. */
boolean protectedVm;
diff --git a/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineDebugInfo.aidl b/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineDebugInfo.aidl
index 672c41a..bed4097 100644
--- a/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineDebugInfo.aidl
+++ b/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineDebugInfo.aidl
@@ -38,5 +38,5 @@
int requesterPid;
/** The current lifecycle state of the VM. */
- VirtualMachineState state;
+ VirtualMachineState state = VirtualMachineState.NOT_STARTED;
}
diff --git a/virtualizationservice/aidl/android/system/virtualmachineservice/IVirtualMachineService.aidl b/virtualizationservice/aidl/android/system/virtualmachineservice/IVirtualMachineService.aidl
index dff5d46..e8c1724 100644
--- a/virtualizationservice/aidl/android/system/virtualmachineservice/IVirtualMachineService.aidl
+++ b/virtualizationservice/aidl/android/system/virtualmachineservice/IVirtualMachineService.aidl
@@ -15,6 +15,8 @@
*/
package android.system.virtualmachineservice;
+import android.system.virtualizationcommon.ErrorCode;
+
/** {@hide} */
interface IVirtualMachineService {
/**
@@ -51,28 +53,7 @@
void notifyPayloadFinished(int exitCode);
/**
- * Notifies that an error has occurred. See the ERROR_* constants.
+ * Notifies that an error has occurred inside the VM..
*/
- void notifyError(int errorCode, in String message);
-
- /**
- * Error code for all other errors not listed below.
- */
- const int ERROR_UNKNOWN = 0;
-
- /**
- * Error code indicating that the payload can't be verified due to various reasons (e.g invalid
- * merkle tree, invalid formats, etc).
- */
- const int ERROR_PAYLOAD_VERIFICATION_FAILED = 1;
-
- /**
- * Error code indicating that the payload is verified, but has changed since the last boot.
- */
- const int ERROR_PAYLOAD_CHANGED = 2;
-
- /**
- * Error code indicating that the payload config is invalid.
- */
- const int ERROR_PAYLOAD_INVALID_CONFIG = 3;
+ void notifyError(ErrorCode errorCode, in String message);
}
diff --git a/virtualizationservice/src/aidl.rs b/virtualizationservice/src/aidl.rs
index 6a4cc93..352b4f1 100644
--- a/virtualizationservice/src/aidl.rs
+++ b/virtualizationservice/src/aidl.rs
@@ -39,12 +39,11 @@
self, BinderFeatures, ExceptionCode, Interface, LazyServiceGuard, ParcelFileDescriptor,
SpIBinder, Status, StatusCode, Strong, ThreadState,
};
-use android_system_virtualmachineservice::aidl::android::system::virtualmachineservice::{
- IVirtualMachineService::{
+use android_system_virtualmachineservice::aidl::android::system::virtualmachineservice::IVirtualMachineService::{
BnVirtualMachineService, IVirtualMachineService, VM_BINDER_SERVICE_PORT,
VM_STREAM_SERVICE_PORT, VM_TOMBSTONES_SERVICE_PORT,
- },
};
+use android_system_virtualizationcommon::aidl::android::system::virtualizationcommon::ErrorCode::ErrorCode;
use anyhow::{anyhow, bail, Context, Result};
use rpcbinder::run_rpc_server_with_factory;
use disk::QcowFile;
@@ -878,7 +877,7 @@
}
/// Call all registered callbacks to say that the VM encountered an error.
- pub fn notify_error(&self, cid: Cid, error_code: i32, message: &str) {
+ pub fn notify_error(&self, cid: Cid, error_code: ErrorCode, message: &str) {
let callbacks = &*self.0.lock().unwrap();
for callback in callbacks {
if let Err(e) = callback.onError(cid as i32, error_code, message) {
@@ -1116,7 +1115,7 @@
}
}
- fn notifyError(&self, error_code: i32, message: &str) -> binder::Result<()> {
+ fn notifyError(&self, error_code: ErrorCode, message: &str) -> binder::Result<()> {
let cid = self.cid;
if let Some(vm) = self.state.lock().unwrap().get_vm(cid) {
info!("VM having CID {} encountered an error", cid);