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/compos/Android.bp b/compos/Android.bp
index 2cc5131..b1e5f89 100644
--- a/compos/Android.bp
+++ b/compos/Android.bp
@@ -40,6 +40,7 @@
"compos_aidl_interface-rust",
"libandroid_logger",
"libanyhow",
+ "libbinder_common",
"libbinder_rpc_unstable_bindgen",
"libbinder_rs",
"libclap",
diff --git a/compos/composd/Android.bp b/compos/composd/Android.bp
index 0a25f05..9887483 100644
--- a/compos/composd/Android.bp
+++ b/compos/composd/Android.bp
@@ -13,6 +13,7 @@
"compos_aidl_interface-rust",
"libandroid_logger",
"libanyhow",
+ "libbinder_common",
"libbinder_rs",
"libcompos_common",
"libcomposd_native_rust",
diff --git a/compos/composd/src/service.rs b/compos/composd/src/service.rs
index fadca6c..2a67a27 100644
--- a/compos/composd/src/service.rs
+++ b/compos/composd/src/service.rs
@@ -22,13 +22,13 @@
use android_system_composd::aidl::android::system::composd::IIsolatedCompilationService::{
BnIsolatedCompilationService, IIsolatedCompilationService,
};
-use android_system_composd::binder::{self, BinderFeatures, Interface, Status, Strong};
+use android_system_composd::binder::{self, BinderFeatures, Interface, Strong};
use anyhow::{bail, Context, Result};
+use binder_common::new_binder_service_specific_error;
use compos_aidl_interface::aidl::com::android::compos::{
CompilationResult::CompilationResult, FdAnnotation::FdAnnotation,
};
use log::{error, info};
-use std::ffi::CString;
pub struct IsolatedCompilationService {
instance_manager: InstanceManager,
@@ -59,8 +59,9 @@
fn to_binder_result<T>(result: Result<T>) -> binder::Result<T> {
result.map_err(|e| {
- error!("Returning binder error: {:#}", e);
- Status::new_service_specific_error(-1, CString::new(format!("{:#}", e)).ok().as_deref())
+ let message = format!("{:?}", e);
+ error!("Returning binder error: {}", &message);
+ new_binder_service_specific_error(-1, message)
})
}
diff --git a/compos/src/compsvc.rs b/compos/src/compsvc.rs
index 55d9d64..954adf5 100644
--- a/compos/src/compsvc.rs
+++ b/compos/src/compsvc.rs
@@ -19,9 +19,9 @@
//! actual compiler.
use anyhow::Result;
+use binder_common::new_binder_exception;
use log::warn;
use std::default::Default;
-use std::ffi::CString;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
@@ -36,7 +36,7 @@
ICompOsService::{BnCompOsService, ICompOsService},
};
use compos_aidl_interface::binder::{
- BinderFeatures, ExceptionCode, Interface, Result as BinderResult, Status, Strong,
+ BinderFeatures, ExceptionCode, Interface, Result as BinderResult, Strong,
};
const AUTHFS_SERVICE_NAME: &str = "authfs_service";
@@ -154,7 +154,3 @@
fn get_authfs_service() -> BinderResult<Strong<dyn IAuthFsService>> {
Ok(authfs_aidl_interface::binder::get_interface(AUTHFS_SERVICE_NAME)?)
}
-
-fn new_binder_exception<T: AsRef<str>>(exception: ExceptionCode, message: T) -> Status {
- Status::new_exception(exception, CString::new(message.as_ref()).as_deref().ok())
-}