OSDN Git Service

btm_get_dev_class: Create empty record if not found
authorHansong Zhang <hsz@google.com>
Mon, 9 Nov 2020 19:38:02 +0000 (11:38 -0800)
committerHansong Zhang <hsz@google.com>
Mon, 9 Nov 2020 19:39:38 +0000 (11:39 -0800)
We may not have a device record at that time, so create one if needed.
This fixes the diff introduces in https://android-review.googlesource.com/c/platform/system/bt/+/1480894/9/stack/acl/btm_acl.cc#b2183

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Test: pair to a speaker
Change-Id: I0149ecb7a11ed33f6cb6344f74c08746d948c513

stack/btm/btm_sec.cc
stack/btm/btm_sec.h

index 0a4c58a..9e37a0f 100644 (file)
@@ -4827,9 +4827,8 @@ void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported,
   }
 }
 
-// Return DEV_CLASS (uint8_t[3]) of bda
+// Return DEV_CLASS (uint8_t[3]) of bda. If record doesn't exist, create one.
 const uint8_t* btm_get_dev_class(const RawAddress& bda) {
-  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda);
-  if (p_dev_rec == nullptr) return nullptr;
+  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_or_alloc_dev(bda);
   return p_dev_rec->dev_class;
 }
index 5ad5621..857c2c8 100644 (file)
@@ -779,5 +779,5 @@ void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported,
                                bool sc_supported,
                                bool hci_role_switch_supported);
 
-// Return DEV_CLASS (uint8_t[3]) of bda
+// Return DEV_CLASS (uint8_t[3]) of bda. If record doesn't exist, create one.
 const uint8_t* btm_get_dev_class(const RawAddress& bda);