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

Commit 01d19e52 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Bluetooth HAL: Use a lambda and hidl_callbacks_"

parents c117fdf4 0cf16043
Loading
Loading
Loading
Loading
+17 −25
Original line number Original line Diff line number Diff line
@@ -315,8 +315,8 @@ class HciHalHidl : public HciHal {
    if (aidl_callbacks_) {
    if (aidl_callbacks_) {
      aidl_callbacks_->SetCallback(callback);
      aidl_callbacks_->SetCallback(callback);
    }
    }
    if (callbacks_) {
    if (hidl_callbacks_) {
      callbacks_->SetCallback(callback);
      hidl_callbacks_->SetCallback(callback);
    }
    }
  }
  }


@@ -324,8 +324,8 @@ class HciHalHidl : public HciHal {
    if (aidl_callbacks_) {
    if (aidl_callbacks_) {
      aidl_callbacks_->ResetCallback();
      aidl_callbacks_->ResetCallback();
    }
    }
    if (callbacks_) {
    if (hidl_callbacks_) {
      callbacks_->ResetCallback();
      hidl_callbacks_->ResetCallback();
    }
    }
  }
  }


@@ -405,18 +405,22 @@ class HciHalHidl : public HciHal {
      aidl_callbacks_->GetInitPromise()->get_future().wait();
      aidl_callbacks_->GetInitPromise()->get_future().wait();
    } else {
    } else {
      start_hidl();
      start_hidl();
      callbacks_->GetInitPromise()->get_future().wait();
      hidl_callbacks_->GetInitPromise()->get_future().wait();
    }
    }
  }
  }


  void start_aidl() {
  void start_aidl() {
    common::StopWatch stop_watch(__func__);
    common::StopWatch stop_watch(__func__);
    ::ndk::SpAIBinder binder(AServiceManager_getService(kBluetoothAidlHalServiceName));
    ::ndk::SpAIBinder binder(AServiceManager_waitForService(kBluetoothAidlHalServiceName));
    aidl_hci_ = IBluetoothHci::fromBinder(binder);
    aidl_hci_ = IBluetoothHci::fromBinder(binder);
    if (aidl_hci_ != nullptr) {
    if (aidl_hci_ != nullptr) {
      LOG_INFO("Using the AIDL interface");
      LOG_INFO("Using the AIDL interface");
      aidl_death_recipient_ = ::ndk::ScopedAIBinder_DeathRecipient(
      aidl_death_recipient_ =
          AIBinder_DeathRecipient_new(HciHalHidl::hci_binder_died_static));
          ::ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new([](void* cookie) {
            LOG_ERROR("Bluetooth HAL service died!");
            common::StopWatch::DumpStopWatchLog();
            abort();
          }));


      auto death_link =
      auto death_link =
          AIBinder_linkToDeath(aidl_hci_->asBinder().get(), aidl_death_recipient_.get(), this);
          AIBinder_linkToDeath(aidl_hci_->asBinder().get(), aidl_death_recipient_.get(), this);
@@ -426,7 +430,6 @@ class HciHalHidl : public HciHal {


      aidl_callbacks_ = ::ndk::SharedRefBase::make<AidlHciCallbacks>(btaa_logger_, btsnoop_logger_);
      aidl_callbacks_ = ::ndk::SharedRefBase::make<AidlHciCallbacks>(btaa_logger_, btsnoop_logger_);
      aidl_hci_->initialize(aidl_callbacks_);
      aidl_hci_->initialize(aidl_callbacks_);
      return;
    }
    }
  }
  }


@@ -465,12 +468,12 @@ class HciHalHidl : public HciHal {
    ASSERT(bt_hci_ != nullptr);
    ASSERT(bt_hci_ != nullptr);
    auto death_link = bt_hci_->linkToDeath(hci_death_recipient_, 0);
    auto death_link = bt_hci_->linkToDeath(hci_death_recipient_, 0);
    ASSERT_LOG(death_link.isOk(), "Unable to set the death recipient for the Bluetooth HAL");
    ASSERT_LOG(death_link.isOk(), "Unable to set the death recipient for the Bluetooth HAL");
    callbacks_ = new InternalHciCallbacks(btaa_logger_, btsnoop_logger_);
    hidl_callbacks_ = new InternalHciCallbacks(btaa_logger_, btsnoop_logger_);


    if (bt_hci_1_1_ != nullptr) {
    if (bt_hci_1_1_ != nullptr) {
      bt_hci_1_1_->initialize_1_1(callbacks_);
      bt_hci_1_1_->initialize_1_1(hidl_callbacks_);
    } else {
    } else {
      bt_hci_->initialize(callbacks_);
      bt_hci_->initialize(hidl_callbacks_);
    }
    }
  }
  }


@@ -488,17 +491,6 @@ class HciHalHidl : public HciHal {
  }
  }


 private:
 private:
  static void hci_binder_died_static(void* cookie) {
    auto hal_ptr = static_cast<HciHalHidl*>(cookie);
    hal_ptr->hci_binder_died();
  }

  void hci_binder_died() {
    LOG_ERROR("Bluetooth HAL service died!");
    common::StopWatch::DumpStopWatchLog();
    abort();
  }

  void stop_hidl() {
  void stop_hidl() {
    ASSERT(bt_hci_ != nullptr);
    ASSERT(bt_hci_ != nullptr);
    auto death_unlink = bt_hci_->unlinkToDeath(hci_death_recipient_);
    auto death_unlink = bt_hci_->unlinkToDeath(hci_death_recipient_);
@@ -511,7 +503,7 @@ class HciHalHidl : public HciHal {
    }
    }
    bt_hci_ = nullptr;
    bt_hci_ = nullptr;
    bt_hci_1_1_ = nullptr;
    bt_hci_1_1_ = nullptr;
    callbacks_->ResetCallback();
    hidl_callbacks_->ResetCallback();
  }
  }


  void stop_aidl() {
  void stop_aidl() {
@@ -528,7 +520,7 @@ class HciHalHidl : public HciHal {
    aidl_hci_ = nullptr;
    aidl_hci_ = nullptr;
    aidl_callbacks_->ResetCallback();
    aidl_callbacks_->ResetCallback();
  }
  }
  android::sp<InternalHciCallbacks> callbacks_;
  android::sp<InternalHciCallbacks> hidl_callbacks_;
  android::sp<IBluetoothHci_1_0> bt_hci_;
  android::sp<IBluetoothHci_1_0> bt_hci_;
  android::sp<IBluetoothHci_1_1> bt_hci_1_1_;
  android::sp<IBluetoothHci_1_1> bt_hci_1_1_;
  std::shared_ptr<IBluetoothHci> aidl_hci_;
  std::shared_ptr<IBluetoothHci> aidl_hci_;