From 9f8931cf477f44591aa5f5bf01bed7943fbe3f4a Mon Sep 17 00:00:00 2001 From: Andre Eisenbach Date: Thu, 16 Mar 2017 22:19:19 -0700 Subject: [PATCH] Bluetooth: Do not die quietly on binder death Log if the Bluetooth service has died. Also check the return status for Bluetooth service binder callbacks to avoid DEAD_OBJECT exception when com.android.bluetooth crashes. Bug: 36026072 Test: unit tests; Bluetooth off/on/off; kill -6 com.android.bluetooth Change-Id: Ia28e6777ee7b78f06db8d5214324e696441d00f7 --- bluetooth/1.0/default/bluetooth_hci.cc | 41 ++++++++++++++++++++++---- bluetooth/1.0/default/bluetooth_hci.h | 11 +------ 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/bluetooth/1.0/default/bluetooth_hci.cc b/bluetooth/1.0/default/bluetooth_hci.cc index 5a282bf2a3..fec5b8155c 100644 --- a/bluetooth/1.0/default/bluetooth_hci.cc +++ b/bluetooth/1.0/default/bluetooth_hci.cc @@ -30,6 +30,19 @@ static const uint8_t HCI_DATA_TYPE_COMMAND = 1; static const uint8_t HCI_DATA_TYPE_ACL = 2; static const uint8_t HCI_DATA_TYPE_SCO = 3; +class BluetoothDeathRecipient : public hidl_death_recipient { + public: + BluetoothDeathRecipient(const sp hci) : mHci(hci) {} + + virtual void serviceDied( + uint64_t /*cookie*/, + const wp<::android::hidl::base::V1_0::IBase>& /*who*/) { + ALOGE("BluetoothDeathRecipient::serviceDied - Bluetooth service died"); + mHci->close(); + } + sp mHci; +}; + BluetoothHci::BluetoothHci() : deathRecipient(new BluetoothDeathRecipient(this)) {} @@ -41,19 +54,37 @@ Return BluetoothHci::initialize( bool rc = VendorInterface::Initialize( [this](bool status) { - event_cb_->initializationComplete( + auto hidl_status = event_cb_->initializationComplete( status ? Status::SUCCESS : Status::INITIALIZATION_ERROR); + if (!hidl_status.isOk()) { + ALOGE("VendorInterface -> Unable to call initializationComplete()"); + } }, [this](const hidl_vec& packet) { - event_cb_->hciEventReceived(packet); + auto hidl_status = event_cb_->hciEventReceived(packet); + if (!hidl_status.isOk()) { + ALOGE("VendorInterface -> Unable to call hciEventReceived()"); + } }, [this](const hidl_vec& packet) { - event_cb_->aclDataReceived(packet); + auto hidl_status = event_cb_->aclDataReceived(packet); + if (!hidl_status.isOk()) { + ALOGE("VendorInterface -> Unable to call aclDataReceived()"); + } }, [this](const hidl_vec& packet) { - event_cb_->scoDataReceived(packet); + auto hidl_status = event_cb_->scoDataReceived(packet); + if (!hidl_status.isOk()) { + ALOGE("VendorInterface -> Unable to call scoDataReceived()"); + } }); - if (!rc) event_cb_->initializationComplete(Status::INITIALIZATION_ERROR); + if (!rc) { + auto hidl_status = + event_cb_->initializationComplete(Status::INITIALIZATION_ERROR); + if (!hidl_status.isOk()) { + ALOGE("VendorInterface -> Unable to call initializationComplete(ERR)"); + } + } return Void(); } diff --git a/bluetooth/1.0/default/bluetooth_hci.h b/bluetooth/1.0/default/bluetooth_hci.h index 67d6c37975..4f9223150e 100644 --- a/bluetooth/1.0/default/bluetooth_hci.h +++ b/bluetooth/1.0/default/bluetooth_hci.h @@ -30,16 +30,7 @@ namespace implementation { 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 BluetoothDeathRecipient; class BluetoothHci : public IBluetoothHci { public: