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

Commit 530dea47 authored by Chris Manton's avatar Chris Manton Committed by Automerger Merge Worker
Browse files

Add empty defaults for bt name and device class am: 43baa985 am: ebf7e6ef am: dd10a216

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

Change-Id: If7b057f2149eb3c81b479af3d44dc4c10b9d9d2e
parents 20fdd382 dd10a216
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2259,13 +2259,13 @@ void btm_sec_rmt_name_request_complete(const RawAddress* p_bd_addr,
        "status:%s name:%s",
        btm_pair_state_descr(btm_cb.pairing_state),
        hci_status_code_text(status).c_str(), p_bd_name);
    DEV_CLASS dev_class = {0, 0, 0};

    /* Notify all clients waiting for name to be resolved even if not found so
     * clients can continue */
    for (i = 0; i < BTM_SEC_MAX_RMT_NAME_CALLBACKS; i++) {
      if (btm_cb.p_rmt_name_callback[i] && p_bd_addr)
        (*btm_cb.p_rmt_name_callback[i])(*p_bd_addr, dev_class, (uint8_t*)"");
        (*btm_cb.p_rmt_name_callback[i])(*p_bd_addr, (uint8_t*)kDevClassEmpty,
                                         (uint8_t*)kBtmBdNameEmpty);
    }

    return;
+4 −0
Original line number Diff line number Diff line
@@ -25,6 +25,10 @@
#define DEV_CLASS_LEN 3
typedef uint8_t DEV_CLASS[DEV_CLASS_LEN]; /* Device class */

#ifdef __cplusplus
inline constexpr DEV_CLASS kDevClassEmpty = {};
#endif  // __cplusplus

#define DEVCLASS_TO_STREAM(p, a)                      \
  {                                                   \
    int ijk;                                          \
+4 −0
Original line number Diff line number Diff line
@@ -42,3 +42,7 @@ typedef uint8_t BD_NAME[BD_NAME_LEN + 1]; /* Device name */
typedef uint8_t tBTM_BD_NAME[BTM_MAX_REM_BD_NAME_LEN + 1];

typedef uint8_t tBTM_LOC_BD_NAME[BTM_MAX_LOC_BD_NAME_LEN + 1];

#ifdef __cplusplus
inline constexpr tBTM_BD_NAME kBtmBdNameEmpty = {};
#endif
+47 −0
Original line number Diff line number Diff line
@@ -30,8 +30,10 @@
#include "internal_include/stack_config.h"
#include "osi/include/allocator.h"
#include "osi/include/osi.h"
#include "stack/btm/btm_dev.h"
#include "stack/btm/btm_int_types.h"
#include "stack/btm/btm_sco.h"
#include "stack/btm/btm_sec.h"
#include "stack/include/acl_api.h"
#include "stack/include/acl_hci_link_interface.h"
#include "stack/include/btm_client_interface.h"
@@ -40,6 +42,9 @@
#include "test/mock/mock_stack_hcic_hcicmds.h"
#include "types/raw_address.h"

using testing::Each;
using testing::Eq;

namespace mock = test::mock::stack_hcic_hcicmds;

extern tBTM_CB btm_cb;
@@ -206,3 +211,45 @@ TEST(ScoTest, make_sco_packet) {
}

}  // namespace

void btm_sec_rmt_name_request_complete(const RawAddress* p_bd_addr,
                                       const uint8_t* p_bd_name,
                                       tHCI_STATUS status);

struct {
  RawAddress bd_addr;
  DEV_CLASS dc;
  tBTM_BD_NAME bd_name;
} btm_test;

TEST(SecTest, btm_sec_rmt_name_request_complete) {
  bluetooth::common::InitFlags::SetAllForTesting();
  btm_cb.Init(0);

  ASSERT_TRUE(BTM_SecAddRmtNameNotifyCallback(
      [](const RawAddress& bd_addr, DEV_CLASS dc, tBTM_BD_NAME bd_name) {
        btm_test.bd_addr = bd_addr;
        memcpy(btm_test.dc, dc, DEV_CLASS_LEN);
        memcpy(btm_test.bd_name, bd_name, BTM_MAX_REM_BD_NAME_LEN);
      }));

  RawAddress bd_addr = RawAddress({0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6});
  const uint8_t* p_bd_name = (const uint8_t*)"MyTestName";

  btm_test = {};
  btm_sec_rmt_name_request_complete(&bd_addr, p_bd_name, HCI_SUCCESS);

  ASSERT_THAT(btm_test.bd_name, Each(Eq(0)));
  ASSERT_THAT(btm_test.dc, Each(Eq(0)));
  ASSERT_EQ(bd_addr, btm_test.bd_addr);

  btm_test = {};
  ASSERT_TRUE(btm_find_or_alloc_dev(bd_addr) != nullptr);
  btm_sec_rmt_name_request_complete(&bd_addr, p_bd_name, HCI_SUCCESS);

  ASSERT_STREQ((const char*)p_bd_name, (const char*)btm_test.bd_name);
  ASSERT_THAT(btm_test.dc, Each(Eq(0)));
  ASSERT_EQ(bd_addr, btm_test.bd_addr);

  btm_cb.Free();
}