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

Commit 71e68251 authored by Myles Watson's avatar Myles Watson
Browse files

Use Rand instead of local name to synchronize

Bug: 321273521
Test: mma -j32
Flag: EXEMPT, no logical change
Change-Id: I8eb160af051ea8b69cc988f065e87a4c01f6a72b
parent d9b3e7eb
Loading
Loading
Loading
Loading
+2 −27
Original line number Diff line number Diff line
@@ -74,7 +74,6 @@ void BTIF_dm_disable();
void BTIF_dm_enable();
void btm_ble_scanner_init(void);

static void bta_dm_local_name_cback(void* p_name);
static void bta_dm_check_av();

void BTA_dm_update_policy(tBTA_SYS_CONN_STATUS status, uint8_t id, uint8_t app_id,
@@ -271,20 +270,8 @@ void BTA_dm_on_hw_on() {

  btm_ble_scanner_init();

  /* Earlier, we used to invoke BTM_ReadLocalAddr which was just copying the
     bd_addr
     from the control block and invoking the callback which was sending the
     DM_ENABLE_EVT.
     But then we have a few HCI commands being invoked above which were still
     in progress
     when the ENABLE_EVT was sent. So modified this to fetch the local name
     which forces
     the DM_ENABLE_EVT to be sent only after all the init steps are complete
     */
  if (get_btm_client_interface().local.BTM_ReadLocalDeviceNameFromController(
              bta_dm_local_name_cback) != tBTM_STATUS::BTM_CMD_STARTED) {
    log::warn("Unable to read local device name from controller");
  }
  // Synchronize with the controller before continuing
  bta_dm_le_rand(get_main_thread()->BindOnce([](uint64_t /*value*/) { BTIF_dm_enable(); }));

  bta_sys_rm_register(bta_dm_rm_cback);

@@ -685,18 +672,6 @@ bool bta_dm_removal_pending(const RawAddress& bd_addr) {
  return false;
}

/*******************************************************************************
 *
 * Function         bta_dm_local_name_cback
 *
 * Description      Callback from btm after local name is read
 *
 *
 * Returns          void
 *
 ******************************************************************************/
static void bta_dm_local_name_cback(void* /* p_name */) { BTIF_dm_enable(); }

static void handle_role_change(const RawAddress& bd_addr, tHCI_ROLE new_role,
                               tHCI_STATUS hci_status) {
  tBTA_DM_PEER_DEVICE* p_dev = bta_dm_find_peer_device(bd_addr);
+9 −0
Original line number Diff line number Diff line
@@ -32,9 +32,12 @@
#include "bta/hf_client/bta_hf_client_int.h"
#include "bta/include/bta_api.h"
#include "bta/test/bta_test_fixtures.h"
#include "hci/controller_interface_mock.h"
#include "hci/le_rand_callback.h"
#include "stack/include/btm_status.h"
#include "test/common/main_handler.h"
#include "test/common/mock_functions.h"
#include "test/mock/mock_main_shim_entry.h"
#include "test/mock/mock_osi_alarm.h"
#include "test/mock/mock_osi_allocator.h"
#include "test/mock/mock_osi_properties.h"
@@ -68,6 +71,10 @@ class BtaDmTest : public BtaWithContextTest {
protected:
  void SetUp() override {
    BtaWithContextTest::SetUp();
    ON_CALL(controller_, LeRand).WillByDefault([](bluetooth::hci::LeRandCallback cb) {
      cb(0x1234);
    });
    bluetooth::hci::testing::mock_controller_ = &controller_;

    BTA_dm_init();
    bluetooth::legacy::testing::bta_dm_init_cb();
@@ -81,7 +88,9 @@ protected:
  void TearDown() override {
    bluetooth::legacy::testing::bta_dm_deinit_cb();
    BtaWithContextTest::TearDown();
    bluetooth::hci::testing::mock_controller_ = nullptr;
  }
  bluetooth::hci::testing::MockControllerInterface controller_;
};

class BtaDmCustomAlarmTest : public BtaDmTest {
+14 −2
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@

#include "bta/dm/bta_dm_disc_int.h"
#include "bta/test/bta_test_fixtures.h"
#include "hci/controller_interface_mock.h"
#include "test/mock/mock_main_shim_entry.h"

void BTA_dm_on_hw_on();
void BTA_dm_on_hw_off();
@@ -40,9 +42,19 @@ void bta_dm_sdp_result(tSDP_STATUS sdp_status, tBTA_DM_SDP_STATE* state);

class BtaSdpTest : public BtaWithHwOnTest {
protected:
  void SetUp() override { BtaWithHwOnTest::SetUp(); }
  void SetUp() override {
    BtaWithHwOnTest::SetUp();
    ON_CALL(controller_, LeRand).WillByDefault([](bluetooth::hci::LeRandCallback cb) {
      cb(0x1234);
    });
    bluetooth::hci::testing::mock_controller_ = &controller_;
  }

  void TearDown() override { BtaWithHwOnTest::TearDown(); }
  void TearDown() override {
    BtaWithHwOnTest::TearDown();
    bluetooth::hci::testing::mock_controller_ = nullptr;
  }
  bluetooth::hci::testing::MockControllerInterface controller_;
};

class BtaSdpRegisteredTest : public BtaSdpTest {
+3 −4
Original line number Diff line number Diff line
@@ -20,8 +20,10 @@
#include <gmock/gmock.h>

#include "bta/dm/bta_dm_int.h"
#include "btm_client_interface.h"
#include "bta/include/bta_api.h"
#include "bta/sys/bta_sys.h"
#include "osi/include/allocator.h"
#include "stack/include/btm_client_interface.h"
#include "stack/include/btm_status.h"
#include "stack/include/main_thread.h"
#include "test/common/main_handler.h"
@@ -74,8 +76,6 @@ protected:
      osi_free(p_buf);
      return tBTM_STATUS::BTM_SUCCESS;
    };
    mock_btm_client_interface.local.BTM_ReadLocalDeviceNameFromController =
            [](tBTM_CMPL_CB* cb) -> tBTM_STATUS { return tBTM_STATUS::BTM_CMD_STARTED; };
    mock_btm_client_interface.security.BTM_SecRegister =
            [](const tBTM_APPL_INFO* p_cb_info) -> bool { return true; };
  }
@@ -85,7 +85,6 @@ protected:

    mock_btm_client_interface.eir.BTM_GetEirSupportedServices = {};
    mock_btm_client_interface.eir.BTM_WriteEIR = {};
    mock_btm_client_interface.local.BTM_ReadLocalDeviceNameFromController = {};

    bluetooth::testing::stack::rnr::reset_interface();
    bluetooth::hci::testing::mock_controller_ = nullptr;
+1 −6
Original line number Diff line number Diff line
@@ -19,12 +19,7 @@
#include <vector>

#include "base/functional/callback.h"
#include "device/include/esco_parameters.h"
#include "hci/le_rand_callback.h"
#include "stack/btm/neighbor_inquiry.h"
#include "stack/include/btm_api_types.h"
#include "stack/include/btm_ble_api_types.h"
#include "types/hci_role.h"
#include "stack/include/btm_status.h"
#include "types/raw_address.h"

namespace bluetooth {
Loading