Extract a library for common binder-related things
Initially this just unifies the various copies of we have of
new_binder_exception(), and adds a variation for service-specific
errors. (I thought this would help me solve my problem with missing
error info, but it turns out I was wrong.) I'm intending to move more
things here though to facilitate reuse.
Bug: 186126194
Test: atest -p
Change-Id: I82187903b55c4cd64307065761e1e03c4e6012f4
diff --git a/virtualizationservice/Android.bp b/virtualizationservice/Android.bp
index 54b32ec..443436d 100644
--- a/virtualizationservice/Android.bp
+++ b/virtualizationservice/Android.bp
@@ -25,6 +25,7 @@
"android.os.permissions_aidl-rust",
"libandroid_logger",
"libanyhow",
+ "libbinder_common",
"libbinder_rpc_unstable_bindgen",
"libbinder_rs",
"libcommand_fds",
diff --git a/virtualizationservice/src/aidl.rs b/virtualizationservice/src/aidl.rs
index 6679da6..76c3a16 100644
--- a/virtualizationservice/src/aidl.rs
+++ b/virtualizationservice/src/aidl.rs
@@ -19,6 +19,7 @@
use crate::payload::add_microdroid_images;
use crate::{Cid, FIRST_GUEST_CID, SYSPROP_LAST_CID};
+use binder_common::new_binder_exception;
use android_os_permissions_aidl::aidl::android::os::IPermissionController;
use android_system_virtualizationservice::aidl::android::system::virtualizationservice::IVirtualMachine::{
BnVirtualMachine, IVirtualMachine,
@@ -48,7 +49,6 @@
use microdroid_payload_config::VmPayloadConfig;
use rustutils::system_properties;
use std::convert::TryInto;
-use std::ffi::CString;
use std::fs::{File, OpenOptions, create_dir};
use std::io::{Error, ErrorKind, Write};
use std::num::NonZeroU32;
@@ -795,11 +795,6 @@
ParcelFileDescriptor::new(f)
}
-/// Constructs a new Binder error `Status` with the given `ExceptionCode` and message.
-fn new_binder_exception<T: AsRef<str>>(exception: ExceptionCode, message: T) -> Status {
- Status::new_exception(exception, CString::new(message.as_ref()).ok().as_deref())
-}
-
/// Simple utility for referencing Borrowed or Owned. Similar to std::borrow::Cow, but
/// it doesn't require that T implements Clone.
enum BorrowedOrOwned<'a, T> {