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

Commit 8859f372 authored by Qasim Javed's avatar Qasim Javed
Browse files

Store and report the union of SDP and BLE UUIDs.

We can discover UUIDs through SDP on classic or through GATT discovery
procedures in BLE. Currently, whichever finishes later ends up
overwriting the UUIDs discovered by the former. So if we first discover
some UUIDs using SDP and store them in the config file and then later
kick off a BLE discovery, when BLE reports discovered UUIDs we do not
check if there are any existing UUIDs discovered via SDP and happily
overwrite the config file with only the UUIDs discovered through BLE.

Bug: 235407715
Tag: #refactor
Test: Manual tests using JBL5 since we discover some UUIDs on it using
BLE and SDP. I made sure that the union of those is reported to Java.

Merged-In: I0c12296441e9c61ea766a969e6294ea192d9a1c4
Change-Id: I0c12296441e9c61ea766a969e6294ea192d9a1c4
parent d21ffe3a
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ typedef struct {
  bool is_le_nc; /* LE Numeric comparison */
  btif_dm_ble_cb_t ble;
  uint8_t fail_reason;
  std::set<Uuid::UUID128Bit> uuids;
} btif_dm_pairing_cb_t;

// TODO(jpawlowski): unify ?
@@ -1383,6 +1384,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
      bt_property_t prop;
      uint32_t i = 0;
      bt_status_t ret;
      std::vector<uint8_t> property_value;

      RawAddress& bd_addr = p_data->disc_res.bd_addr;

@@ -1404,12 +1406,18 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
      prop.len = 0;
      if ((p_data->disc_res.result == BTA_SUCCESS) &&
          (p_data->disc_res.num_uuids > 0)) {
        prop.val = p_data->disc_res.p_uuid_list;
        prop.len = p_data->disc_res.num_uuids * Uuid::kNumBytes128;
        LOG_INFO("New UUIDs:");
        for (i = 0; i < p_data->disc_res.num_uuids; i++) {
          std::string temp = ((p_data->disc_res.p_uuid_list + i))->ToString();
          LOG_INFO("index:%d uuid:%s", i, temp.c_str());
          auto uuid = p_data->disc_res.p_uuid_list + i;
          LOG_INFO("index:%d uuid:%s", i, uuid->ToString().c_str());
          auto valAsBe = uuid->To128BitBE();
          pairing_cb.uuids.insert(valAsBe);
        }
        for (auto uuid : pairing_cb.uuids) {
          property_value.insert(property_value.end(), uuid.begin(), uuid.end());
        }
        prop.val = (void*)property_value.data();
        prop.len = Uuid::kNumBytes128 * pairing_cb.uuids.size();
      }

      /* onUuidChanged requires getBondedDevices to be populated.
@@ -1470,15 +1478,18 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
      std::vector<uint8_t> property_value;
      int num_uuids = 0;

      LOG_INFO("New BLE UUIDs:");
      for (Uuid uuid : *p_data->disc_ble_res.services) {
        LOG_VERBOSE("service %s", uuid.ToString().c_str());
        LOG_INFO("index:%d uuid:%s", num_uuids, uuid.ToString().c_str());
        if (btif_is_interesting_le_service(uuid)) {
          num_uuids++;
          auto valAsBe = uuid.To128BitBE();
          property_value.insert(property_value.end(), valAsBe.begin(),
                                valAsBe.end());
          pairing_cb.uuids.insert(valAsBe);
        }
      }
      for (auto uuid : pairing_cb.uuids) {
        property_value.insert(property_value.end(), uuid.begin(), uuid.end());
      }

      if (num_uuids == 0) {
        LOG_INFO("No well known BLE services discovered");
@@ -1488,7 +1499,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
      RawAddress& bd_addr = p_data->disc_ble_res.bd_addr;
      prop[0].type = BT_PROPERTY_UUIDS;
      prop[0].val = (void*)property_value.data();
      prop[0].len = Uuid::kNumBytes128 * num_uuids;
      prop[0].len = Uuid::kNumBytes128 * pairing_cb.uuids.size();

      /* Also write this to the NVRAM */
      bt_status_t ret =
@@ -1584,7 +1595,7 @@ void BTIF_dm_enable() {
    }
  }
  /* clear control blocks */
  memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t));
  pairing_cb = {};
  pairing_cb.bond_type = tBTM_SEC_DEV_REC::BOND_TYPE_PERSISTENT;
  if (enable_address_consolidate) {
    LOG_INFO("enable address consolidate");