summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system/btif/src/btif_dm.cc70
-rw-r--r--system/types/bluetooth/uuid.cc2
-rw-r--r--system/types/bluetooth/uuid.h3
3 files changed, 46 insertions, 29 deletions
diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc
index 1a35830252..0d5a11b952 100644
--- a/system/btif/src/btif_dm.cc
+++ b/system/btif/src/btif_dm.cc
@@ -70,6 +70,7 @@
#include "common/metrics.h"
#include "device/include/controller.h"
#include "device/include/interop.h"
+#include "gd/common/lru_cache.h"
#include "internal_include/stack_config.h"
#include "main/shim/dumpsys.h"
#include "main/shim/shim.h"
@@ -156,9 +157,6 @@ typedef struct {
bool is_le_nc; /* LE Numeric comparison */
btif_dm_ble_cb_t ble;
uint8_t fail_reason;
- Uuid::UUID128Bit eir_uuids[32];
- uint8_t num_eir_uuids;
- std::set<Uuid::UUID128Bit> uuids;
} btif_dm_pairing_cb_t;
// TODO(jpawlowski): unify ?
@@ -206,6 +204,11 @@ typedef struct {
#define MAX_BTIF_BOND_EVENT_ENTRIES 15
+#define MAX_NUM_DEVICES_IN_EIR_UUID_CACHE 128
+
+static bluetooth::common::LruCache<RawAddress, std::set<Uuid>> eir_uuids_cache(
+ MAX_NUM_DEVICES_IN_EIR_UUID_CACHE);
+
static skip_sdp_entry_t sdp_rejectlist[] = {{76}}; // Apple Mouse and Keyboard
/* This flag will be true if HCI_Inquiry is in progress */
@@ -1298,13 +1301,16 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
/* Cache EIR queried services */
if (num_uuids > 0) {
uint16_t* p_uuid16 = (uint16_t*)uuid_list;
- pairing_cb.num_eir_uuids = 0;
- LOG_INFO("EIR UUIDS:");
+ auto uuid_iter = eir_uuids_cache.find(bdaddr);
+ if (uuid_iter == eir_uuids_cache.end()) {
+ auto triple = eir_uuids_cache.try_emplace(bdaddr, std::set<Uuid>{});
+ uuid_iter = std::get<0>(triple);
+ }
+ LOG_INFO("EIR UUIDs for %s:", bdaddr.ToString().c_str());
for (int i = 0; i < num_uuids; ++i) {
Uuid uuid = Uuid::From16Bit(p_uuid16[i]);
LOG_INFO(" %s", uuid.ToString().c_str());
- pairing_cb.eir_uuids[i] = uuid.To128BitBE();
- pairing_cb.num_eir_uuids++;
+ uuid_iter->second.insert(uuid);
}
#if TARGET_FLOSS
@@ -1372,6 +1378,10 @@ static void btif_get_existing_uuids(RawAddress* bd_addr, Uuid* existing_uuids) {
btif_storage_get_remote_device_property(bd_addr, &tmp_prop);
}
+static bool btif_should_ignore_uuid(const Uuid& uuid) {
+ return uuid.IsEmpty() || uuid.IsBase();
+}
+
/*******************************************************************************
*
* Function btif_dm_search_services_evt
@@ -1414,7 +1424,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
LOG_INFO("New UUIDs for %s:", bd_addr.ToString().c_str());
for (i = 0; i < p_data->disc_res.num_uuids; i++) {
auto uuid = p_data->disc_res.p_uuid_list + i;
- if (uuid->IsEmpty()) {
+ if (btif_should_ignore_uuid(*uuid)) {
continue;
}
LOG_INFO("index:%d uuid:%s", i, uuid->ToString().c_str());
@@ -1426,7 +1436,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
for (int i = 0; i < BT_MAX_NUM_UUIDS; i++) {
Uuid uuid = existing_uuids[i];
- if (uuid.IsEmpty()) {
+ if (btif_should_ignore_uuid(uuid)) {
continue;
}
if (btif_is_interesting_le_service(uuid)) {
@@ -1447,6 +1457,8 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
/* onUuidChanged requires getBondedDevices to be populated.
** bond_state_changed needs to be sent prior to remote_device_property
*/
+ auto num_eir_uuids = 0;
+ 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)) {
@@ -1457,33 +1469,33 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
// when SDP failed or no UUID is discovered
if (p_data->disc_res.result != BTA_SUCCESS ||
p_data->disc_res.num_uuids == 0) {
- LOG_INFO("SDP failed, send %d EIR UUIDs to unblock bonding %s",
- pairing_cb.num_eir_uuids, bd_addr.ToString().c_str());
- bt_property_t prop_uuids;
- Uuid uuid = {};
- prop_uuids.type = BT_PROPERTY_UUIDS;
- if (pairing_cb.num_eir_uuids > 0) {
- prop_uuids.val = pairing_cb.eir_uuids;
- prop_uuids.len = pairing_cb.num_eir_uuids * Uuid::kNumBytes128;
+ auto uuids_iter = eir_uuids_cache.find(bd_addr);
+ if (uuids_iter != eir_uuids_cache.end()) {
+ num_eir_uuids = static_cast<int>(uuids_iter->second.size());
+ LOG_INFO("SDP failed, send %d EIR UUIDs to unblock bonding %s",
+ num_eir_uuids, bd_addr.ToString().c_str());
+ for (auto eir_uuid : uuids_iter->second) {
+ auto uuid_128bit = eir_uuid.To128BitBE();
+ property_value.insert(property_value.end(), uuid_128bit.begin(),
+ uuid_128bit.end());
+ }
+ }
+ if (num_eir_uuids > 0) {
+ prop.val = (void*)property_value.data();
+ prop.len = num_eir_uuids * Uuid::kNumBytes128;
} else {
- prop_uuids.val = &uuid;
- prop_uuids.len = Uuid::kNumBytes128;
+ LOG_WARN("SDP failed and we have no EIR UUIDs to report either");
+ prop.val = &uuid;
+ prop.len = Uuid::kNumBytes128;
}
-
- /* Send the event to the BTIF
- * prop_uuids will be deep copied by this call
- */
- invoke_remote_device_properties_cb(BT_STATUS_SUCCESS, bd_addr, 1,
- &prop_uuids);
- pairing_cb = {};
- break;
+ eir_uuids_cache.erase(uuids_iter);
}
// Both SDP and bonding are done, clear pairing control block in case
// it is not already cleared
pairing_cb = {};
}
- if (p_data->disc_res.num_uuids != 0) {
+ if (p_data->disc_res.num_uuids != 0 || num_eir_uuids != 0) {
/* Also write this to the NVRAM */
ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed",
@@ -1512,7 +1524,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
LOG_INFO("New BLE UUIDs for %s:", bd_addr.ToString().c_str());
for (Uuid uuid : *p_data->disc_ble_res.services) {
if (btif_is_interesting_le_service(uuid)) {
- if (uuid.IsEmpty()) {
+ if (btif_should_ignore_uuid(uuid)) {
continue;
}
LOG_INFO("index:%d uuid:%s", static_cast<int>(uuids.size()),
diff --git a/system/types/bluetooth/uuid.cc b/system/types/bluetooth/uuid.cc
index d05f4370f0..40186ae5c4 100644
--- a/system/types/bluetooth/uuid.cc
+++ b/system/types/bluetooth/uuid.cc
@@ -155,6 +155,8 @@ Uuid Uuid::GetRandom() {
bool Uuid::IsEmpty() const { return *this == kEmpty; }
+bool Uuid::IsBase() const { return *this == kBase; }
+
void Uuid::UpdateUuid(const Uuid& uuid) {
uu = uuid.uu;
}
diff --git a/system/types/bluetooth/uuid.h b/system/types/bluetooth/uuid.h
index 893f5d2049..f3e6ec2f1f 100644
--- a/system/types/bluetooth/uuid.h
+++ b/system/types/bluetooth/uuid.h
@@ -106,6 +106,9 @@ class Uuid final {
// Returns true if this UUID is equal to kEmpty
bool IsEmpty() const;
+ // Returns true if this UUID is equal to kBase
+ bool IsBase() const;
+
// Update UUID with new value
void UpdateUuid(const Uuid& uuid);