summaryrefslogtreecommitdiff
path: root/offload
diff options
context:
space:
mode:
author Antoine SOULIER <asoulier@google.com> 2025-02-21 18:55:07 +0000
committer Antoine SOULIER <asoulier@google.com> 2025-02-21 18:56:55 +0000
commitbf1ef45a2f0bc3a7268a883f09315b1726446ad8 (patch)
tree8ed95af0edb20229fe61f5f6ec972e705382235a /offload
parentc812231fdc0c4f92c485d06e14e5350ad9331ded (diff)
LE Audio Software offload: Add client death recipient
Bug: 375485876 Flag: EXEMPT, enabled by vendor Test: mmm . Change-Id: Id13bf2c62d6b3d056d72eb462c62e39fd4db2b94
Diffstat (limited to 'offload')
-rw-r--r--offload/hal/ffi.rs15
-rw-r--r--offload/hal/include/hal/ffi.h1
-rw-r--r--offload/hal/service.rs10
3 files changed, 19 insertions, 7 deletions
diff --git a/offload/hal/ffi.rs b/offload/hal/ffi.rs
index 762e3c9d6b..e8be51f7f5 100644
--- a/offload/hal/ffi.rs
+++ b/offload/hal/ffi.rs
@@ -12,7 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use core::{ffi::c_void, slice};
+use core::ffi::c_void;
+use core::slice;
use std::sync::{Mutex, RwLock};
/// Callbacks from C to Rust
@@ -45,6 +46,7 @@ pub struct CInterface {
send_acl: unsafe extern "C" fn(handle: *mut c_void, data: *const u8, len: usize),
send_sco: unsafe extern "C" fn(handle: *mut c_void, data: *const u8, len: usize),
send_iso: unsafe extern "C" fn(handle: *mut c_void, data: *const u8, len: usize),
+ client_died: unsafe extern "C" fn(handle: *mut c_void),
}
//SAFETY: CInterface is safe to send between threads because we require the C code
@@ -146,6 +148,17 @@ impl<T: Callbacks> Ffi<T> {
self.remove_client();
}
+ pub(crate) fn client_died(&self) {
+ let intf = self.intf.lock().unwrap();
+
+ // SAFETY: The C Code has initialized the `CInterface` with a valid
+ // function pointer and an initialized `handle`.
+ unsafe {
+ (intf.client_died)(intf.handle);
+ }
+ self.remove_client();
+ }
+
fn set_client(&self, client: T) {
*self.wrapper.write().unwrap() = Some(client);
}
diff --git a/offload/hal/include/hal/ffi.h b/offload/hal/include/hal/ffi.h
index e066c68a09..f4d9b5ff4d 100644
--- a/offload/hal/include/hal/ffi.h
+++ b/offload/hal/include/hal/ffi.h
@@ -58,5 +58,6 @@ struct hal_interface {
void (*send_acl)(void *handle, const uint8_t *data, size_t len);
void (*send_sco)(void *handle, const uint8_t *data, size_t len);
void (*send_iso)(void *handle, const uint8_t *data, size_t len);
+ void (*client_died)(void *handle);
};
}
diff --git a/offload/hal/service.rs b/offload/hal/service.rs
index eb8c679b09..a72eea9200 100644
--- a/offload/hal/service.rs
+++ b/offload/hal/service.rs
@@ -13,9 +13,9 @@
// limitations under the License.
use crate::ffi::{CInterface, CStatus, Callbacks, DataCallbacks, Ffi};
-use android_hardware_bluetooth::aidl::android::hardware::bluetooth::{
- IBluetoothHci::IBluetoothHci, IBluetoothHciCallbacks::IBluetoothHciCallbacks, Status::Status,
-};
+use android_hardware_bluetooth::aidl::android::hardware::bluetooth::IBluetoothHci::IBluetoothHci;
+use android_hardware_bluetooth::aidl::android::hardware::bluetooth::IBluetoothHciCallbacks::IBluetoothHciCallbacks;
+use android_hardware_bluetooth::aidl::android::hardware::bluetooth::Status::Status;
use binder::{DeathRecipient, ExceptionCode, IBinder, Interface, Result as BinderResult, Strong};
use bluetooth_offload_hci::{Module, ModuleBuilder};
use std::sync::{Arc, RwLock};
@@ -78,9 +78,7 @@ impl IBluetoothHci for HciHalProxy {
DeathRecipient::new(move || {
log::info!("Bluetooth stack has died");
let mut state = state.write().unwrap();
- if !matches!(*state, State::Closed) {
- ffi.close();
- }
+ ffi.client_died();
*state = State::Closed;
})
};