Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit df8241b2 authored by Ugo Yu's avatar Ugo Yu Committed by android-build-merger
Browse files

Merge "Handle Bluetooth HAL service died"

am: 09e16759

Change-Id: I105aad49177d7987fd0ad97fdad9d22359fd32d6
parents b13b967b 09e16759
Loading
Loading
Loading
Loading
+27 −6
Original line number Original line Diff line number Diff line
@@ -37,14 +37,15 @@
#define LOG_PATH "/data/misc/bluetooth/logs/firmware_events.log"
#define LOG_PATH "/data/misc/bluetooth/logs/firmware_events.log"
#define LAST_LOG_PATH "/data/misc/bluetooth/logs/firmware_events.log.last"
#define LAST_LOG_PATH "/data/misc/bluetooth/logs/firmware_events.log.last"


using android::hardware::bluetooth::V1_0::IBluetoothHci;
using ::android::hardware::hidl_death_recipient;
using android::hardware::bluetooth::V1_0::IBluetoothHciCallbacks;
using ::android::hardware::hidl_vec;
using android::hardware::bluetooth::V1_0::HciPacket;
using ::android::hardware::ProcessState;
using android::hardware::bluetooth::V1_0::Status;
using android::hardware::ProcessState;
using ::android::hardware::Return;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;
using ::android::hardware::bluetooth::V1_0::HciPacket;
using ::android::hardware::bluetooth::V1_0::IBluetoothHci;
using ::android::hardware::bluetooth::V1_0::IBluetoothHciCallbacks;
using ::android::hardware::bluetooth::V1_0::Status;


extern void initialization_complete();
extern void initialization_complete();
extern void hci_event_received(const base::Location& from_here, BT_HDR* packet);
extern void hci_event_received(const base::Location& from_here, BT_HDR* packet);
@@ -53,6 +54,15 @@ extern void sco_data_received(BT_HDR* packet);


android::sp<IBluetoothHci> btHci;
android::sp<IBluetoothHci> btHci;


class BluetoothHciDeathRecipient : public hidl_death_recipient {
 public:
  virtual void serviceDied(uint64_t /*cookie*/, const android::wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
    LOG_ERROR(LOG_TAG, "Bluetooth HAL service died!");
    abort();
  }
};
android::sp<BluetoothHciDeathRecipient> bluetoothHciDeathRecipient = new BluetoothHciDeathRecipient();

class BluetoothHciCallbacks : public IBluetoothHciCallbacks {
class BluetoothHciCallbacks : public IBluetoothHciCallbacks {
 public:
 public:
  BluetoothHciCallbacks() {
  BluetoothHciCallbacks() {
@@ -106,6 +116,11 @@ void hci_initialize() {
  btHci = IBluetoothHci::getService();
  btHci = IBluetoothHci::getService();
  // If android.hardware.bluetooth* is not found, Bluetooth can not continue.
  // If android.hardware.bluetooth* is not found, Bluetooth can not continue.
  CHECK(btHci != nullptr);
  CHECK(btHci != nullptr);
  auto death_link = btHci->linkToDeath(bluetoothHciDeathRecipient, 0);
  if (!death_link.isOk()) {
    LOG_ERROR(LOG_TAG, "%s: Unable to set the death recipient for the Bluetooth HAL", __func__);
    abort();
  }
  LOG_INFO(LOG_TAG, "%s: IBluetoothHci::getService() returned %p (%s)",
  LOG_INFO(LOG_TAG, "%s: IBluetoothHci::getService() returned %p (%s)",
           __func__, btHci.get(), (btHci->isRemote() ? "remote" : "local"));
           __func__, btHci.get(), (btHci->isRemote() ? "remote" : "local"));


@@ -117,6 +132,12 @@ void hci_initialize() {
}
}


void hci_close() {
void hci_close() {
  if (btHci != nullptr) {
    auto death_unlink = btHci->unlinkToDeath(bluetoothHciDeathRecipient);
    if (!death_unlink.isOk()) {
      LOG_ERROR(LOG_TAG, "%s: Error unlinking death recipient from the Bluetooth HAL", __func__);
    }
  }
  btHci->close();
  btHci->close();
  btHci = nullptr;
  btHci = nullptr;
}
}