diff options
Diffstat (limited to 'offload')
-rw-r--r-- | offload/hal/Android.bp | 2 | ||||
-rw-r--r-- | offload/hal/ffi.rs | 15 | ||||
-rw-r--r-- | offload/hal/include/hal/ffi.h | 1 | ||||
-rw-r--r-- | offload/hal/service.rs | 10 | ||||
-rw-r--r-- | offload/leaudio/hci/Android.bp | 1 |
5 files changed, 22 insertions, 7 deletions
diff --git a/offload/hal/Android.bp b/offload/hal/Android.bp index 91324d0d94..87058f085f 100644 --- a/offload/hal/Android.bp +++ b/offload/hal/Android.bp @@ -32,6 +32,7 @@ rust_library { visibility: [ "//hardware/interfaces/bluetooth:__subpackages__", "//packages/modules/Bluetooth/offload:__subpackages__", + "//vendor:__subpackages__", ], } @@ -44,5 +45,6 @@ cc_library_headers { ], visibility: [ "//hardware/interfaces/bluetooth:__subpackages__", + "//vendor:__subpackages__", ], } 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; }) }; diff --git a/offload/leaudio/hci/Android.bp b/offload/leaudio/hci/Android.bp index 0c7839bf91..f79d98a26e 100644 --- a/offload/leaudio/hci/Android.bp +++ b/offload/leaudio/hci/Android.bp @@ -37,6 +37,7 @@ rust_library { visibility: [ "//hardware/interfaces/bluetooth:__subpackages__", "//packages/modules/Bluetooth/offload:__subpackages__", + "//vendor:__subpackages__", ], } |