Assorted refactoring
Mostly removing duplication. Also added a comment as suggested by
Andrew.
Bug: 161471326
Test: composd_cmd async-odrefresh
Change-Id: I7da83cb825de7b4fd2267b1e496808a423544c16
diff --git a/compos/composd/src/composd_main.rs b/compos/composd/src/composd_main.rs
index 2915a58..6f1e951 100644
--- a/compos/composd/src/composd_main.rs
+++ b/compos/composd/src/composd_main.rs
@@ -26,7 +26,6 @@
mod odrefresh;
mod odrefresh_task;
mod service;
-mod util;
use crate::instance_manager::InstanceManager;
use android_system_composd::binder::{register_lazy_service, ProcessState};
diff --git a/compos/composd/src/internal_service.rs b/compos/composd/src/internal_service.rs
index ebebaae..3fad6d4 100644
--- a/compos/composd/src/internal_service.rs
+++ b/compos/composd/src/internal_service.rs
@@ -17,7 +17,7 @@
//! Implementation of ICompilationInternal, called from odrefresh during compilation.
use crate::instance_manager::InstanceManager;
-use crate::util::to_binder_result;
+use compos_common::binder::to_binder_result;
use android_system_composd_internal::aidl::android::system::composd::internal::ICompilationInternal::{
BnCompilationInternal, ICompilationInternal,
};
diff --git a/compos/composd/src/odrefresh.rs b/compos/composd/src/odrefresh.rs
index f06a4b2..a6ca995 100644
--- a/compos/composd/src/odrefresh.rs
+++ b/compos/composd/src/odrefresh.rs
@@ -63,8 +63,8 @@
pub fn wait_for_exit(&self) -> Result<ExitCode> {
// No timeout here - but clients can kill the process, which will end the wait.
let status = self.child.wait()?;
- if let Some(exit_code) = status.code().and_then(ExitCode::from_i32) {
- Ok(exit_code)
+ if let Some(exit_code) = status.code() {
+ ExitCode::from_i32(exit_code)
} else {
bail!("odrefresh exited with {}", status)
}
diff --git a/compos/composd/src/odrefresh_task.rs b/compos/composd/src/odrefresh_task.rs
index b7de479..56b697e 100644
--- a/compos/composd/src/odrefresh_task.rs
+++ b/compos/composd/src/odrefresh_task.rs
@@ -22,7 +22,7 @@
ICompilationTask::ICompilationTask, ICompilationTaskCallback::ICompilationTaskCallback,
};
use android_system_composd::binder::{Interface, Result as BinderResult, Strong};
-use anyhow::{bail, Context, Result};
+use anyhow::{Context, Result};
use compos_aidl_interface::aidl::com::android::compos::ICompOsService::ICompOsService;
use compos_common::odrefresh::ExitCode;
use log::{error, warn};
@@ -140,11 +140,7 @@
)?;
drop(fd_server_raii);
- if let Some(exit_code) = ExitCode::from_i32(exit_code.into()) {
- Ok(exit_code)
- } else {
- bail!("odrefresh exited with {}", exit_code)
- }
+ ExitCode::from_i32(exit_code.into())
}
/// Returns an owned FD of the directory. It currently returns a `File` as a FD owner, but
diff --git a/compos/composd/src/service.rs b/compos/composd/src/service.rs
index 23c411b..69cf008 100644
--- a/compos/composd/src/service.rs
+++ b/compos/composd/src/service.rs
@@ -20,7 +20,6 @@
use crate::compilation_task::CompilationTask;
use crate::instance_manager::InstanceManager;
use crate::odrefresh_task::OdrefreshTask;
-use crate::util::to_binder_result;
use android_system_composd::aidl::android::system::composd::{
ICompilationTask::{BnCompilationTask, ICompilationTask},
ICompilationTaskCallback::ICompilationTaskCallback,
@@ -30,6 +29,7 @@
self, BinderFeatures, ExceptionCode, Interface, Status, Strong, ThreadState,
};
use anyhow::{Context, Result};
+use compos_common::binder::to_binder_result;
use rustutils::{users::AID_ROOT, users::AID_SYSTEM};
use std::sync::Arc;
diff --git a/compos/composd/src/util.rs b/compos/composd/src/util.rs
deleted file mode 100644
index 54d7751..0000000
--- a/compos/composd/src/util.rs
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 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 android_system_composd::binder::Result as BinderResult;
-use anyhow::Result;
-use binder_common::new_binder_service_specific_error;
-use log::error;
-use std::fmt::Debug;
-
-pub fn to_binder_result<T, E: Debug>(result: Result<T, E>) -> BinderResult<T> {
- result.map_err(|e| {
- let message = format!("{:?}", e);
- error!("Returning binder error: {}", &message);
- new_binder_service_specific_error(-1, message)
- })
-}