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

Commit 678af7f5 authored by Martijn Coenen's avatar Martijn Coenen
Browse files

Bluetooth: deal with framework going away.

Bug: 35624326
Test: Bluetooth HAL stays alive and works after com.android.bluetooth
is killed.

Change-Id: Id5b5a5b88cd35202e5737a0c99d28db9bebb4250
parent 4b9692ae
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -30,9 +30,13 @@ 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;

BluetoothHci::BluetoothHci()
    : deathRecipient(new BluetoothDeathRecipient(this)) {}

Return<void> BluetoothHci::initialize(
    const ::android::sp<IBluetoothHciCallbacks>& cb) {
  ALOGW("BluetoothHci::initialize()");
  cb->linkToDeath(deathRecipient, 0);
  event_cb_ = cb;

  bool rc = VendorInterface::Initialize(
@@ -62,6 +66,7 @@ Return<void> BluetoothHci::initialize(

Return<void> BluetoothHci::close() {
  ALOGW("BluetoothHci::close()");
  event_cb_->unlinkToDeath(deathRecipient);
  VendorInterface::Shutdown();
  return Void();
}
+13 −0
Original line number Diff line number Diff line
@@ -30,8 +30,20 @@ namespace implementation {
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;
@@ -42,6 +54,7 @@ class BluetoothHci : public IBluetoothHci {
 private:
  void sendDataToController(const uint8_t type, const hidl_vec<uint8_t>& data);
  ::android::sp<IBluetoothHciCallbacks> event_cb_;
  ::android::sp<BluetoothDeathRecipient> deathRecipient;
};

extern "C" IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* name);