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

Commit d74ea950 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Remove unnecessary BTA_DM_NOT_CONNECTED state

Test: mmm packages/modules/Bluetooth
Flag: EXEMPT mechanical refactor
Bug: 345299390

Change-Id: Ib43567257763f1e0341f25ec57d9ac89c082e369
parent c50cae9d
Loading
Loading
Loading
Loading
+5 −16
Original line number Diff line number Diff line
@@ -684,7 +684,6 @@ static void bta_dm_acl_up(const RawAddress& bd_addr, tBT_TRANSPORT transport, ui
  }
  log::info("Acl connected peer:{} transport:{} handle:{}", bd_addr, bt_transport_text(transport),
            acl_handle);
  device->conn_state = tBTA_DM_CONN_STATE::BTA_DM_CONNECTED;
  device->pref_role = BTA_ANY_ROLE;
  device->reset_device_info();
  device->transport = transport;
@@ -831,8 +830,8 @@ static void bta_dm_check_av() {
    log::info("av_count:{}", bta_dm_cb.cur_av_count);
    for (i = 0; i < bta_dm_cb.device_list.count; i++) {
      p_dev = &bta_dm_cb.device_list.peer_device[i];
      log::warn("[{}]: state:{}, info:{}", i, p_dev->conn_state, p_dev->info_text());
      if ((p_dev->conn_state == tBTA_DM_CONN_STATE::BTA_DM_CONNECTED) && p_dev->is_av_active()) {
      log::warn("[{}]: info:{}, pending removal:{}", i, p_dev->info_text(), p_dev->is_connected());
      if (p_dev->is_connected() && p_dev->is_av_active()) {
        /* make central and take away the role switch policy */
        const tBTM_STATUS status =
                get_btm_client_interface().link_policy.BTM_SwitchRoleToCentral(p_dev->peer_bdaddr);
@@ -896,16 +895,6 @@ static void bta_dm_rm_cback(tBTA_SYS_CONN_STATUS status, tBTA_SYS_ID id, uint8_t
  p_dev = bta_dm_find_peer_device(peer_addr);
  if (status == BTA_SYS_CONN_OPEN) {
    if (p_dev) {
      /* Do not set to connected if we are in the middle of unpairing. When AV
       * stream is
       * started it fakes out a SYS_CONN_OPEN to potentially trigger a role
       * switch command.
       * But this should not be done if we are in the middle of unpairing.
       */
      if (p_dev->conn_state != tBTA_DM_CONN_STATE::BTA_DM_UNPAIRING) {
        p_dev->conn_state = tBTA_DM_CONN_STATE::BTA_DM_CONNECTED;
      }

      for (j = 1; j <= p_bta_dm_rm_cfg[0].app_id; j++) {
        if (((p_bta_dm_rm_cfg[j].app_id == app_id) ||
             (p_bta_dm_rm_cfg[j].app_id == BTA_ALL_APP_ID)) &&
@@ -981,7 +970,7 @@ static void bta_dm_adjust_roles(bool delay_role_switch) {
  uint8_t link_count = bta_dm_cb.device_list.count;
  if (link_count) {
    for (i = 0; i < bta_dm_cb.device_list.count; i++) {
      if (bta_dm_cb.device_list.peer_device[i].conn_state == tBTA_DM_CONN_STATE::BTA_DM_CONNECTED &&
      if (bta_dm_cb.device_list.peer_device[i].is_connected() &&
          bta_dm_cb.device_list.peer_device[i].transport == BT_TRANSPORT_BR_EDR) {
        if ((bta_dm_cb.device_list.peer_device[i].pref_role == BTA_CENTRAL_ROLE_ONLY) ||
            (link_count > 1)) {
@@ -1378,7 +1367,7 @@ tBTA_DM_PEER_DEVICE* find_connected_device(const RawAddress& bd_addr,
                                           tBT_TRANSPORT /* transport */) {
  for (uint8_t i = 0; i < bta_dm_cb.device_list.count; i++) {
    if (bta_dm_cb.device_list.peer_device[i].peer_bdaddr == bd_addr &&
        bta_dm_cb.device_list.peer_device[i].conn_state == tBTA_DM_CONN_STATE::BTA_DM_CONNECTED) {
        bta_dm_cb.device_list.peer_device[i].is_connected()) {
      return &bta_dm_cb.device_list.peer_device[i];
    }
  }
@@ -1447,7 +1436,7 @@ static tBTM_CONTRL_STATE bta_dm_obtain_system_context() {

  for (int i = 0; i < bta_dm_cb.device_list.count; i++) {
    tBTA_DM_PEER_DEVICE* p_dev = &bta_dm_cb.device_list.peer_device[i];
    if (p_dev->conn_state == tBTA_DM_CONN_STATE::BTA_DM_CONNECTED && p_dev->is_av_active()) {
    if (p_dev->is_connected() && p_dev->is_av_active()) {
      is_av_active = true;
      break;
    }
+1 −1
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ void BTA_DmDiscover(const RawAddress& bd_addr, service_discovery_callbacks cback
 ******************************************************************************/
bool BTA_DmGetConnectionState(const RawAddress& bd_addr) {
  tBTA_DM_PEER_DEVICE* p_dev = bta_dm_find_peer_device(bd_addr);
  return p_dev && p_dev->conn_state == tBTA_DM_CONN_STATE::BTA_DM_CONNECTED;
  return p_dev && p_dev->is_connected();
}

/*******************************************************************************
+9 −5
Original line number Diff line number Diff line
@@ -45,15 +45,15 @@

#define BTA_DM_NUM_PEER_DEVICE 7

// TODO: Remove when flag wait_for_disconnect_before_unbond is shipped
enum class tBTA_DM_CONN_STATE : uint8_t {
  BTA_DM_NOT_CONNECTED = 0,
  BTA_DM_CONNECTED = 1,
  BTA_DM_UNPAIRING = 2,
  BTA_DM_CONNECTED = 0,
  BTA_DM_UNPAIRING = 1,
};

// TODO: Remove when flag wait_for_disconnect_before_unbond is shipped
inline std::string bta_conn_state_text(tBTA_DM_CONN_STATE state) {
  switch (state) {
    CASE_RETURN_STRING(tBTA_DM_CONN_STATE::BTA_DM_NOT_CONNECTED);
    CASE_RETURN_STRING(tBTA_DM_CONN_STATE::BTA_DM_CONNECTED);
    CASE_RETURN_STRING(tBTA_DM_CONN_STATE::BTA_DM_UNPAIRING);
  }
@@ -97,7 +97,7 @@ typedef uint8_t tBTA_DM_PM_REQ;

struct tBTA_DM_PEER_DEVICE {
  RawAddress peer_bdaddr;
  tBTA_DM_CONN_STATE conn_state{tBTA_DM_CONN_STATE::BTA_DM_NOT_CONNECTED};
  tBTA_DM_CONN_STATE conn_state{tBTA_DM_CONN_STATE::BTA_DM_CONNECTED};
  tBTA_PREF_ROLES pref_role;
  bool in_use;

@@ -134,6 +134,10 @@ public:
  void reset_ssr_active() { info &= ~BTA_DM_DI_USE_SSR; }
  bool is_ssr_active() const { return info & BTA_DM_DI_USE_SSR; }

  bool is_connected() const {
    return (conn_state == tBTA_DM_CONN_STATE::BTA_DM_CONNECTED);
  }

  tBTA_DM_ENCRYPT_CBACK* p_encrypt_cback;
  tBTM_PM_STATUS prev_low; /* previous low power mode used */
  tBTA_DM_PM_ACTION pm_mode_attempted;
+0 −2
Original line number Diff line number Diff line
@@ -214,7 +214,6 @@ TEST_F(BtaDmTest, bta_dm_set_encryption) {
  tBTA_DM_PEER_DEVICE* device =
          bluetooth::legacy::testing::allocate_device_for(kRawAddress, transport);
  ASSERT_TRUE(device != nullptr);
  device->conn_state = tBTA_DM_CONN_STATE::BTA_DM_CONNECTED;
  device->p_encrypt_cback = nullptr;

  // Setup a device that is busy with another encryption
@@ -267,7 +266,6 @@ TEST_F(BtaDmTest, bta_dm_encrypt_cback) {
  tBTA_DM_PEER_DEVICE* device =
          bluetooth::legacy::testing::allocate_device_for(kRawAddress, transport);
  ASSERT_TRUE(device != nullptr);
  device->conn_state = tBTA_DM_CONN_STATE::BTA_DM_CONNECTED;

  // Encryption with no callback set
  device->p_encrypt_cback = nullptr;