From 7cc9c40ec2bf4a4fad77a366ec5aad901121d745 Mon Sep 17 00:00:00 2001 From: Myles Watson Date: Fri, 3 Mar 2017 14:58:47 -0800 Subject: Bluetooth: Add death recipient Test: No crash when Bluetooth fails to start Change-Id: I07295b3ff285104c6ab942df472e249b665b9896 --- bluetooth/bluetooth_hci.cc | 6 ++++++ bluetooth/bluetooth_hci.h | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/bluetooth/bluetooth_hci.cc b/bluetooth/bluetooth_hci.cc index fa14b539..fe2b782b 100644 --- a/bluetooth/bluetooth_hci.cc +++ b/bluetooth/bluetooth_hci.cc @@ -32,6 +32,9 @@ namespace hikey { using android::hardware::hidl_vec; +BluetoothHci::BluetoothHci() + : deathRecipient(new BluetoothDeathRecipient(this)) {} + Return BluetoothHci::initialize( const ::android::sp& cb) { ALOGI("BluetoothHci::initialize()"); @@ -44,6 +47,7 @@ Return BluetoothHci::initialize( } event_cb_ = cb; + event_cb_->linkToDeath(deathRecipient, 0); hci_ = new hci::H4Protocol( hci_tty_fd_, @@ -88,6 +92,8 @@ Return BluetoothHci::close() { hci_tty_fd_ = -1; } + event_cb_->unlinkToDeath(deathRecipient); + if (hci_ != nullptr) { delete hci_; hci_ = nullptr; diff --git a/bluetooth/bluetooth_hci.h b/bluetooth/bluetooth_hci.h index 484a6ab4..2f1015a0 100644 --- a/bluetooth/bluetooth_hci.h +++ b/bluetooth/bluetooth_hci.h @@ -32,8 +32,20 @@ namespace hikey { using ::android::hardware::Return; using ::android::hardware::hidl_vec; +struct BluetoothDeathRecipient : hidl_death_recipient { + BluetoothDeathRecipient(const sp hci) : mHci(hci) {} + + virtual void serviceDied( + uint64_t /*cookie*/, + const wp<::android::hidl::base::V1_0::IBase>& /*who*/) { + mHci->close(); + } + sp mHci; +}; + class BluetoothHci : public IBluetoothHci { public: + BluetoothHci(); Return initialize( const ::android::sp& cb) override; Return sendHciCommand(const hidl_vec& packet) override; @@ -50,6 +62,8 @@ class BluetoothHci : public IBluetoothHci { async::AsyncFdWatcher fd_watcher_; hci::H4Protocol* hci_; + + ::android::sp deathRecipient; }; } // namespace hikey -- cgit v1.2.3