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

Commit 0f2fa146 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Search end event to callback

Bug: 330675788
Flag: exempt, no logic changes
Test: mma -j32
Change-Id: I6f4ee6c01a7334d33b542c8982e0b4ee0c7e7b12
parent aa570669
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -949,9 +949,12 @@ static void bta_dm_disc_result(tBTA_DM_MSG* p_data) {
  /* if any BR/EDR service discovery has been done, report the event */
  if (!is_gatt_over_ble && (bta_dm_search_cb.services &
                            ((BTA_ALL_SERVICE_MASK | BTA_USER_SERVICE_MASK) &
                             ~BTA_BLE_SERVICE_MASK)))
    bta_dm_search_cb.service_search_cbacks.legacy(BTA_DM_DISC_RES_EVT,
                                                  &p_data->disc_result.result);
                             ~BTA_BLE_SERVICE_MASK))) {
    auto& r = p_data->disc_result.result.disc_res;
    bta_dm_search_cb.service_search_cbacks.on_service_discovery_results(
        r.bd_addr, r.bd_name, r.services, r.device_type, r.num_uuids,
        r.p_uuid_list, r.result, r.hci_status);
  }

  get_gatt_interface().BTA_GATTC_CancelOpen(0, bta_dm_search_cb.peer_bdaddr,
                                            true);
@@ -977,9 +980,11 @@ static void bta_dm_search_result(tBTA_DM_MSG* p_data) {
  if ((!bta_dm_search_cb.services) ||
      ((bta_dm_search_cb.services) &&
       (p_data->disc_result.result.disc_res.services))) {
    if (bta_dm_search_cb.service_search_cbacks.legacy) {
      bta_dm_search_cb.service_search_cbacks.legacy(
          BTA_DM_DISC_RES_EVT, &p_data->disc_result.result);
    if (bta_dm_search_cb.service_search_cbacks.on_service_discovery_results) {
      auto& r = p_data->disc_result.result.disc_res;
      bta_dm_search_cb.service_search_cbacks.on_service_discovery_results(
          r.bd_addr, r.bd_name, r.services, r.device_type, r.num_uuids,
          r.p_uuid_list, r.result, r.hci_status);
    } else {
      log::warn("Received search result without valid callback");
    }
+6 −1
Original line number Diff line number Diff line
@@ -302,12 +302,17 @@ typedef void(tBTA_DM_DID_RES_CBACK)(RawAddress bd_addr, uint8_t vendor_id_src,
typedef void(tBTA_DM_NAME_READ_CBACK)(RawAddress bd_addr,
                                      tHCI_ERROR_CODE hci_status,
                                      const BD_NAME bd_name);
typedef void(tBTA_DM_DISC_CBACK)(RawAddress bd_addr, BD_NAME bd_name,
                                 tBTA_SERVICE_MASK services,
                                 tBT_DEVICE_TYPE device_type, size_t num_uuids,
                                 bluetooth::Uuid* p_uuid_list,
                                 tBTA_STATUS result, tHCI_STATUS hci_status);
struct service_discovery_callbacks {
  /* legacy callback I'll tear apart and get rid of */
  tBTA_DM_SEARCH_CBACK* legacy;
  tBTA_DM_GATT_DISC_CBACK* on_gatt_results;
  tBTA_DM_DID_RES_CBACK* on_did_received;
  tBTA_DM_NAME_READ_CBACK* on_name_read;
  tBTA_DM_DISC_CBACK* on_service_discovery_results;
};

/* Execute call back */
+9 −6
Original line number Diff line number Diff line
@@ -238,24 +238,27 @@ TEST_F(BtaInitializedTest, bta_dm_disc_stop_device_discovery) {
TEST_F(BtaInitializedTest,
       bta_dm_disc_start_service_discovery__BT_TRANSPORT_AUTO) {
  bta_dm_disc_start_service_discovery(
      {[](tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) {}, nullptr,
       nullptr, nullptr},
      {nullptr, nullptr, nullptr,
       [](RawAddress, BD_NAME, tBTA_SERVICE_MASK, tBT_DEVICE_TYPE, size_t,
          bluetooth::Uuid*, tBTA_STATUS, tHCI_STATUS) {}},
      kRawAddress, BT_TRANSPORT_AUTO);
}

TEST_F(BtaInitializedTest,
       bta_dm_disc_start_service_discovery__BT_TRANSPORT_BR_EDR) {
  bta_dm_disc_start_service_discovery(
      {[](tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) {}, nullptr,
       nullptr, nullptr},
      {nullptr, nullptr, nullptr,
       [](RawAddress, BD_NAME, tBTA_SERVICE_MASK, tBT_DEVICE_TYPE, size_t,
          bluetooth::Uuid*, tBTA_STATUS, tHCI_STATUS) {}},
      kRawAddress, BT_TRANSPORT_BR_EDR);
}

TEST_F(BtaInitializedTest,
       bta_dm_disc_start_service_discovery__BT_TRANSPORT_LE) {
  bta_dm_disc_start_service_discovery(
      {[](tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) {}, nullptr,
       nullptr, nullptr},
      {nullptr, nullptr, nullptr,
       [](RawAddress, BD_NAME, tBTA_SERVICE_MASK, tBT_DEVICE_TYPE, size_t,
          bluetooth::Uuid*, tBTA_STATUS, tHCI_STATUS) {}},
      kRawAddress, BT_TRANSPORT_LE);
}

+0 −1
Original line number Diff line number Diff line
@@ -531,7 +531,6 @@ TEST_F(BtaDmTest, bta_dm_search_evt_text) {
  std::vector<std::pair<tBTA_DM_SEARCH_EVT, std::string>> events = {
      std::make_pair(BTA_DM_INQ_RES_EVT, "BTA_DM_INQ_RES_EVT"),
      std::make_pair(BTA_DM_INQ_CMPL_EVT, "BTA_DM_INQ_CMPL_EVT"),
      std::make_pair(BTA_DM_DISC_RES_EVT, "BTA_DM_DISC_RES_EVT"),
      std::make_pair(BTA_DM_DISC_CMPL_EVT, "BTA_DM_DISC_CMPL_EVT"),
      std::make_pair(BTA_DM_SEARCH_CANCEL_CMPL_EVT,
                     "BTA_DM_SEARCH_CANCEL_CMPL_EVT"),
+145 −176
Original line number Diff line number Diff line
@@ -1740,31 +1740,17 @@ static bool btif_is_gatt_service_discovery_post_pairing(const RawAddress bd_addr
          btif_dm_pairing_cb_t::ServiceDiscoveryState::SCHEDULED));
}

/*******************************************************************************
 *
 * Function         btif_dm_search_services_evt
 *
 * Description      Executes search services event in btif context
 *
 * Returns          void
 *
 ******************************************************************************/
static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
                                        tBTA_DM_SEARCH* p_data) {
  switch (event) {
    case BTA_DM_DISC_RES_EVT: {
static void btif_on_service_discovery_results(
    RawAddress bd_addr, BD_NAME bd_name, tBTA_SERVICE_MASK services,
    tBT_DEVICE_TYPE device_type, size_t num_uuids, bluetooth::Uuid* p_uuid_list,
    tBTA_STATUS result, tHCI_STATUS hci_status) {
  bt_property_t prop;
      uint32_t i = 0;
  std::vector<uint8_t> property_value;
  std::set<Uuid> uuids;
  bool a2dp_sink_capable = false;

      RawAddress& bd_addr = p_data->disc_res.bd_addr;

      log::verbose("result=0x{:x}, services 0x{:x}", p_data->disc_res.result,
                   p_data->disc_res.services);
      if (p_data->disc_res.result != BTA_SUCCESS &&
          pairing_cb.state == BT_BOND_STATE_BONDED &&
  log::verbose("result=0x{:x}, services 0x{:x}", result, services);
  if (result != BTA_SUCCESS && pairing_cb.state == BT_BOND_STATE_BONDED &&
      pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING) {
    if (pairing_cb.sdp_attempts) {
      log::warn("SDP failed after bonding re-attempting for {}",
@@ -1781,8 +1767,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
    return;
  }

      if ((bd_addr == pairing_cb.bd_addr ||
           bd_addr == pairing_cb.static_bdaddr)) {
  if ((bd_addr == pairing_cb.bd_addr || bd_addr == pairing_cb.static_bdaddr)) {
    log::info("SDP finished for {}:", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    pairing_cb.sdp_over_classic =
        btif_dm_pairing_cb_t::ServiceDiscoveryState::FINISHED;
@@ -1790,11 +1775,10 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,

  prop.type = BT_PROPERTY_UUIDS;
  prop.len = 0;
      if ((p_data->disc_res.result == BTA_SUCCESS) &&
          (p_data->disc_res.num_uuids > 0)) {
  if ((result == BTA_SUCCESS) && (num_uuids > 0)) {
    log::info("New UUIDs for {}:", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
        for (i = 0; i < p_data->disc_res.num_uuids; i++) {
          auto uuid = p_data->disc_res.p_uuid_list + i;
    for (size_t i = 0; i < num_uuids; i++) {
      auto uuid = p_uuid_list + i;
      if (btif_should_ignore_uuid(*uuid)) {
        continue;
      }
@@ -1845,14 +1829,13 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
  size_t num_eir_uuids = 0U;
  Uuid uuid = {};
  if (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts &&
          (p_data->disc_res.bd_addr == pairing_cb.bd_addr ||
           p_data->disc_res.bd_addr == pairing_cb.static_bdaddr)) {
      (bd_addr == pairing_cb.bd_addr || bd_addr == pairing_cb.static_bdaddr)) {
    log::info("SDP search done for {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    pairing_cb.sdp_attempts = 0;

    // Send UUIDs discovered through EIR to Java to unblock pairing intent
    // when SDP failed
        if (p_data->disc_res.result != BTA_SUCCESS) {
    if (result != BTA_SUCCESS) {
      auto uuids_iter = eir_uuids_cache.find(bd_addr);
      if (uuids_iter != eir_uuids_cache.end()) {
        num_eir_uuids = uuids_iter->second.size();
@@ -1883,19 +1866,17 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
    }
  }

      const tBTA_STATUS bta_status = p_data->disc_res.result;
      BTM_LogHistory(
          kBtmLogTagSdp, bd_addr, "Discovered services",
  const tBTA_STATUS bta_status = result;
  BTM_LogHistory(kBtmLogTagSdp, bd_addr, "Discovered services",
                 base::StringPrintf("bta_status:%s sdp_uuids:%zu eir_uuids:%zu",
                                    bta_status_text(bta_status).c_str(),
                             p_data->disc_res.num_uuids, num_eir_uuids));
                                    num_uuids, num_eir_uuids));

      if (p_data->disc_res.num_uuids != 0 || num_eir_uuids != 0) {
  if (num_uuids != 0 || num_eir_uuids != 0) {
    /* Also write this to the NVRAM */
    const bt_status_t ret =
        btif_storage_set_remote_device_property(&bd_addr, &prop);
        ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed",
                ret);
    ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);

    if (skip_reporting_wait_for_le) {
      log::info(
@@ -1913,12 +1894,6 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
    GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb(
        BT_STATUS_SUCCESS, bd_addr, 1, &prop);
  }
    } break;

    default: {
      ASSERTC(0, "unhandled search services event", event);
    } break;
  }
}

void btif_on_gatt_results(RawAddress bd_addr, BD_NAME bd_name,
@@ -1985,7 +1960,8 @@ void btif_on_gatt_results(RawAddress bd_addr, BD_NAME bd_name,
    log::info("No well known GATT services discovered");

    /* If services were returned as part of SDP discovery, we will
     * immediately send them with rest of SDP results in BTA_DM_DISC_RES_EVT
     * immediately send them with rest of SDP results in
     * on_service_discovery_results
     */
    if (!transport_le) {
      return;
@@ -2074,7 +2050,7 @@ void btif_on_gatt_results(RawAddress bd_addr, BD_NAME bd_name,
  }

  /* If services were returned as part of SDP discovery, we will immediately
   * send them with rest of SDP results in BTA_DM_DISC_RES_EVT */
   * send them with rest of SDP results in on_service_discovery_results */
  if (!transport_le) {
    return;
  }
@@ -3141,11 +3117,8 @@ void btif_dm_get_remote_services(RawAddress remote_addr, const int transport) {

  BTA_DmDiscover(remote_addr,
                 service_discovery_callbacks{
                     btif_dm_search_services_evt,
                     btif_on_gatt_results,
                     btif_on_did_received,
                     btif_on_name_read,
                 },
                     btif_on_gatt_results, btif_on_did_received,
                     btif_on_name_read, btif_on_service_discovery_results},
                 transport);
}

@@ -4277,15 +4250,11 @@ void bta_energy_info_cb(tBTM_BLE_TX_TIME_MS tx_time,
                       status);
}

void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
                                 tBTA_DM_SEARCH* p_data) {
  ::btif_dm_search_services_evt(event, p_data);
}

void btif_on_name_read(RawAddress bd_addr, tHCI_ERROR_CODE hci_status,
                       const BD_NAME bd_name) {
  ::btif_on_name_read(bd_addr, hci_status, bd_name);
}

}  // namespace testing
}  // namespace legacy
}  // namespace bluetooth
Loading