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/authfs/service/Android.bp b/authfs/service/Android.bp
index 943db35..6c32c67 100644
--- a/authfs/service/Android.bp
+++ b/authfs/service/Android.bp
@@ -12,6 +12,7 @@
"authfs_aidl_interface-rust",
"libandroid_logger",
"libanyhow",
+ "libbinder_common",
"libbinder_rs",
"liblibc",
"liblog_rust",
diff --git a/authfs/service/src/authfs.rs b/authfs/service/src/authfs.rs
index f41a3a6..5601738 100644
--- a/authfs/service/src/authfs.rs
+++ b/authfs/service/src/authfs.rs
@@ -26,7 +26,6 @@
use std::thread::sleep;
use std::time::{Duration, Instant};
-use crate::common::new_binder_exception;
use authfs_aidl_interface::aidl::com::android::virt::fs::IAuthFs::{BnAuthFs, IAuthFs};
use authfs_aidl_interface::aidl::com::android::virt::fs::{
AuthFsConfig::AuthFsConfig, InputFdAnnotation::InputFdAnnotation,
@@ -35,6 +34,7 @@
use authfs_aidl_interface::binder::{
self, BinderFeatures, ExceptionCode, Interface, ParcelFileDescriptor, Strong,
};
+use binder_common::new_binder_exception;
const AUTHFS_BIN: &str = "/system/bin/authfs";
const AUTHFS_SETUP_POLL_INTERVAL_MS: Duration = Duration::from_millis(50);
diff --git a/authfs/service/src/common.rs b/authfs/service/src/common.rs
deleted file mode 100644
index 00efe9e..0000000
--- a/authfs/service/src/common.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2021 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.
- */
-
-use std::ffi::CString;
-
-use authfs_aidl_interface::binder::{ExceptionCode, Status};
-
-/// Helper function to create a binder exception.
-pub fn new_binder_exception<T: AsRef<str>>(exception: ExceptionCode, message: T) -> Status {
- Status::new_exception(exception, CString::new(message.as_ref()).as_deref().ok())
-}
diff --git a/authfs/service/src/main.rs b/authfs/service/src/main.rs
index e426734..af8c7f9 100644
--- a/authfs/service/src/main.rs
+++ b/authfs/service/src/main.rs
@@ -21,7 +21,6 @@
//! is able to retrieve "remote file descriptors".
mod authfs;
-mod common;
use anyhow::{bail, Context, Result};
use log::*;
@@ -29,7 +28,6 @@
use std::fs::{create_dir, read_dir, remove_dir_all, remove_file};
use std::sync::atomic::{AtomicUsize, Ordering};
-use crate::common::new_binder_exception;
use authfs_aidl_interface::aidl::com::android::virt::fs::AuthFsConfig::AuthFsConfig;
use authfs_aidl_interface::aidl::com::android::virt::fs::IAuthFs::IAuthFs;
use authfs_aidl_interface::aidl::com::android::virt::fs::IAuthFsService::{
@@ -38,6 +36,7 @@
use authfs_aidl_interface::binder::{
self, add_service, BinderFeatures, ExceptionCode, Interface, ProcessState, Strong,
};
+use binder_common::new_binder_exception;
const SERVICE_NAME: &str = "authfs_service";
const SERVICE_ROOT: &str = "/data/misc/authfs";