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

Commit d5ca5dd4 authored by Zach Johnson's avatar Zach Johnson
Browse files

bta_dm_check_av is only called with 0

it's never BTA_DM_API_SEARCH_EVT, clean up unused
code path & vars.

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I8ecb755bcf168273b7540956354a29b40df37c55
parent 3bf9cda4
Loading
Loading
Loading
Loading
+7 −43
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ static uint8_t bta_dm_authentication_complete_cback(const RawAddress& bd_addr,
                                                    BD_NAME bd_name,
                                                    int result);
static void bta_dm_local_name_cback(void* p_name);
static bool bta_dm_check_av(uint16_t event);
static void bta_dm_check_av();

void BTA_dm_update_policy(tBTA_SYS_CONN_STATUS status, uint8_t id,
                          uint8_t app_id, const RawAddress& peer_addr);
@@ -2517,7 +2517,7 @@ static void handle_role_change(const RawAddress& bd_addr, uint8_t new_role,
    /* there's AV no activity on this link and role switch happened
     * check if AV is active
     * if so, make sure the AV link is master */
    bta_dm_check_av(0);
    bta_dm_check_av();
  }
  bta_sys_notify_role_chg(bd_addr, new_role, hci_status);
}
@@ -2679,25 +2679,6 @@ void BTA_dm_acl_down(const RawAddress bd_addr, tBT_TRANSPORT transport) {
  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_acl_down, bd_addr, transport));
}

/*******************************************************************************
 *
 * Function         bta_dm_rs_cback
 *
 * Description      Receives the role switch complete event
 *
 * Returns
 *
 ******************************************************************************/
static void bta_dm_rs_cback(UNUSED_ATTR void* p1) {
  APPL_TRACE_WARNING("bta_dm_rs_cback:%d", bta_dm_cb.rs_event);
  if (bta_dm_cb.rs_event == BTA_DM_API_SEARCH_EVT) {
    bta_dm_cb.search_msg.rs_res =
        BTA_DM_RS_OK; /* do not care about the result for now */
    bta_dm_cb.rs_event = 0;
    bta_dm_search_start((tBTA_DM_MSG*)&bta_dm_cb.search_msg);
  }
}

/*******************************************************************************
 *
 * Function         bta_dm_check_av
@@ -2705,44 +2686,27 @@ static void bta_dm_rs_cback(UNUSED_ATTR void* p1) {
 * Description      This function checks if AV is active
 *                  if yes, make sure the AV link is master
 *
 * Returns          bool - true, if switch is in progress
 *
 ******************************************************************************/
static bool bta_dm_check_av(uint16_t event) {
  bool avoid_roleswitch = false;
  bool switching = false;
static void bta_dm_check_av() {
  uint8_t i;
  tBTA_DM_PEER_DEVICE* p_dev;

  /* avoid role switch upon inquiry if a2dp is actively streaming as it
     introduces an audioglitch due to FW scheduling delays (unavoidable) */
  if (event == BTA_DM_API_SEARCH_EVT) {
    avoid_roleswitch = true;
  }

  APPL_TRACE_WARNING("bta_dm_check_av:%d", bta_dm_cb.cur_av_count);
  if (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];
      APPL_TRACE_WARNING("[%d]: state:%d, info:x%x, avoid_rs %d", i,
                         p_dev->conn_state, p_dev->info, avoid_roleswitch);
      APPL_TRACE_WARNING("[%d]: state:%d, info:x%x", i, p_dev->conn_state,
                         p_dev->info);
      if ((p_dev->conn_state == BTA_DM_CONNECTED) &&
          (p_dev->info & BTA_DM_DI_AV_ACTIVE) && (!avoid_roleswitch)) {
          (p_dev->info & BTA_DM_DI_AV_ACTIVE)) {
        /* make master and take away the role switch policy */
        if (BTM_CMD_STARTED == BTM_SwitchRole(p_dev->peer_bdaddr,
                                              HCI_ROLE_MASTER,
                                              bta_dm_rs_cback)) {
          /* the role switch command is actually sent */
          bta_dm_cb.rs_event = event;
          switching = true;
        }
        BTM_SwitchRole(p_dev->peer_bdaddr, HCI_ROLE_MASTER, nullptr);
        /* else either already master or can not switch for some reasons */
        BTA_dm_block_role_switch_for(p_dev->peer_bdaddr);
        break;
      }
    }
  }
  return switching;
}

/*******************************************************************************
+0 −1
Original line number Diff line number Diff line
@@ -296,7 +296,6 @@ typedef struct {
  uint8_t num_master_only;
  uint8_t pm_id;
  tBTA_PM_TIMER pm_timer[BTA_DM_NUM_PM_TIMER];
  uint16_t rs_event;      /* the event waiting for role switch */
  uint8_t cur_av_count;   /* current AV connecions */
  bool disable_pair_mode; /* disable pair mode or not */
  bool conn_paired_only;  /* allow connectable to paired device only or not */