summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMyles Watson <mylesgw@google.com>2017-03-15 21:24:32 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-03-15 21:24:32 +0000
commit143cfc373f63cd378df5d0fbc3244140e1a13b9e (patch)
tree87486e5f5e2f43cd09279ca373a6336944a6b6ea
parent51d12ac7b81fe6ac281606015fe8afc0e9ebdef6 (diff)
parentdf56c1f3c6a2dc16b833c0f0faf40089c7b9c9da (diff)
downloadhikey-143cfc373f63cd378df5d0fbc3244140e1a13b9e.tar.gz
Merge "Bluetooth: Add death recipient" am: 5e2670e4bc
am: df56c1f3c6 Change-Id: I2d2208d108641bb7ad7f4a52326e4f1509a76d50
-rw-r--r--bluetooth/bluetooth_hci.cc6
-rw-r--r--bluetooth/bluetooth_hci.h14
2 files changed, 20 insertions, 0 deletions
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<void> BluetoothHci::initialize(
const ::android::sp<IBluetoothHciCallbacks>& cb) {
ALOGI("BluetoothHci::initialize()");
@@ -44,6 +47,7 @@ Return<void> BluetoothHci::initialize(
}
event_cb_ = cb;
+ event_cb_->linkToDeath(deathRecipient, 0);
hci_ = new hci::H4Protocol(
hci_tty_fd_,
@@ -88,6 +92,8 @@ Return<void> 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<IBluetoothHci> hci) : mHci(hci) {}
+
+ virtual void serviceDied(
+ uint64_t /*cookie*/,
+ const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
+ mHci->close();
+ }
+ sp<IBluetoothHci> mHci;
+};
+
class BluetoothHci : public IBluetoothHci {
public:
+ BluetoothHci();
Return<void> initialize(
const ::android::sp<IBluetoothHciCallbacks>& cb) override;
Return<void> sendHciCommand(const hidl_vec<uint8_t>& packet) override;
@@ -50,6 +62,8 @@ class BluetoothHci : public IBluetoothHci {
async::AsyncFdWatcher fd_watcher_;
hci::H4Protocol* hci_;
+
+ ::android::sp<BluetoothDeathRecipient> deathRecipient;
};
} // namespace hikey