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

Commit 2794baa5 authored by Jack He's avatar Jack He Committed by Automerger Merge Worker
Browse files

Merge "Add btm_cb.notify_when_complete_cb when inquiry is cancelled" into...

Merge "Add btm_cb.notify_when_complete_cb when inquiry is cancelled" into tm-dev am: 6a9d7ece am: 32d1a964

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/18441059



Change-Id: Ifdef2c01b4810b730f6dce03c7884ffc466c2d1a
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 22d429e3 32d1a964
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -873,9 +873,11 @@ void bta_dm_search_start(tBTA_DM_MSG* p_data) {
 ******************************************************************************/
void bta_dm_search_cancel() {
  if (BTM_IsInquiryActive()) {
    BTM_CancelInquiry();
    LOG_DEBUG("Cancelling search with inquiry active");
    BTM_CancelInquiryNotifyWhenComplete([]() {
      bta_dm_search_cancel_notify();
      bta_dm_search_cmpl();
    });
  }
  /* If no Service Search going on then issue cancel remote name in case it is
     active */
+33 −1
Original line number Diff line number Diff line
@@ -461,6 +461,18 @@ void BTM_CancelInquiry(void) {
  }
}

void BTM_CancelInquiryNotifyWhenComplete(
    std::function<void()> notify_when_complete_cb) {
  if (btm_cb.notify_when_complete_cb) {
    LOG_ERROR(
        "Please do not overwrite a previous cancel inquiry notification "
        "callback");
    return;
  }
  btm_cb.notify_when_complete_cb = notify_when_complete_cb;
  BTM_CancelInquiry();
}

/*******************************************************************************
 *
 * Function         BTM_StartInquiry
@@ -1263,7 +1275,26 @@ void btm_sort_inq_result(void) {
 *
 ******************************************************************************/
void btm_process_inq_complete(tHCI_STATUS status, uint8_t mode) {
  tBTM_CMPL_CB* p_inq_cb = btm_cb.btm_inq_vars.p_inq_cmpl_cb;
  if (mode == 0) {
    LOG_WARN("Inquiry completed but no modes were specified");
    return;
  }

  // The mode parameters may be a bitmask with only 2 valid bits indicating
  // completion
  if (mode & ~(BTM_INQUIRY_ACTIVE_MASK)) {
    LOG_WARN("Calling with illegal mode:0x%02x", mode);
  }

  if (mode == BTM_GENERAL_INQUIRY && btm_cb.notify_when_complete_cb) {
    LOG_DEBUG(
        "Cleaning up previous inquiry cancel with proper completion callback "
        "inq_active:0x%02x inqparms.mode:0x%02x",
        btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.inqparms.mode);
    btm_cb.notify_when_complete_cb();
    btm_cb.notify_when_complete_cb = {};
    return;
  }
  tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars;

  p_inq->inqparms.mode &= ~(mode);
@@ -1297,6 +1328,7 @@ void btm_process_inq_complete(tHCI_STATUS status, uint8_t mode) {
      /* Clear the results callback if set */
      p_inq->p_inq_results_cb = NULL;
      p_inq->inq_active = BTM_INQUIRY_INACTIVE;
      tBTM_CMPL_CB* p_inq_cb = btm_cb.btm_inq_vars.p_inq_cmpl_cb;
      p_inq->p_inq_cmpl_cb = NULL;

      /* If we have a callback registered for inquiry complete, call it */
+2 −0
Original line number Diff line number Diff line
@@ -309,6 +309,7 @@ typedef struct tBTM_CB {
  tACL_CB acl_cb_;

  std::shared_ptr<TimestampedStringCircularBuffer> history_{nullptr};
  std::function<void()> notify_when_complete_cb;

  void Init(uint8_t initial_security_mode) {
    memset(&cfg, 0, sizeof(cfg));
@@ -353,6 +354,7 @@ typedef struct tBTM_CB {
        kBtmLogHistoryBufferSize);
    CHECK(history_ != nullptr);
    history_->Push(std::string("Initialized btm history"));
    notify_when_complete_cb = {};
  }

  void Free() {
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#define BTM_API_H

#include <cstdint>
#include <functional>

#include "device/include/esco_parameters.h"
#include "stack/btm/neighbor_inquiry.h"
@@ -316,6 +317,7 @@ uint16_t BTM_IsInquiryActive(void);
 *
 ******************************************************************************/
void BTM_CancelInquiry(void);
void BTM_CancelInquiryNotifyWhenComplete(std::function<void()>);

/*******************************************************************************
 *
+1 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ struct btm_client_interface_t {
  // Neighbor
  struct {
    void (*BTM_CancelInquiry)();
    void (*BTM_CancelInquiryNotifyWhenComplete)();
    tBTM_INQ_INFO* (*BTM_InqDbNext)(tBTM_INQ_INFO* p_cur);
    tBTM_STATUS (*BTM_ClearInqDb)(const RawAddress* p_bda);
    tBTM_STATUS (*BTM_SetDiscoverability)(uint16_t inq_mode);
Loading