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

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

Factor BTA_SYS_PLCY_CLR into its own function

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: Ic8a86d7a49e9a49a64f547f38ae9a2d481ac4011
parent 53fb7bed
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -836,6 +836,21 @@ void BTA_dm_set_policy(uint8_t policy, const RawAddress& peer_addr) {
  BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy));
}

void BTA_dm_clear_policy(uint8_t policy, const RawAddress& peer_addr) {
  auto p_dev = bta_dm_find_peer_device(peer_addr);
  if (!p_dev) {
    return;
  }
  /* clear the policy from the default link policy */
  p_dev->link_policy &= (~policy);
  BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy));

  if (policy & (HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_PARK_MODE)) {
    /* if clearing sniff/park, wake the link */
    bta_dm_pm_active(p_dev->peer_bdaddr);
  }
}

/*******************************************************************************
 *
 * Function         bta_dm_policy_cback
@@ -857,18 +872,6 @@ void BTA_dm_update_policy(tBTA_SYS_CONN_STATUS status, uint8_t id,

  APPL_TRACE_DEBUG(" cmd:%d, policy:0x%x", status, policy);
  switch (status) {
    case BTA_SYS_PLCY_CLR:
      if (!p_dev) return;
      /* clear the policy from the default link policy */
      p_dev->link_policy &= (~policy);
      BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy));

      if (policy & (HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_PARK_MODE)) {
        /* if clearing sniff/park, wake the link */
        bta_dm_pm_active(p_dev->peer_bdaddr);
      }
      break;

    case BTA_SYS_PLCY_DEF_SET:
      /* want to restore/set the role switch policy */
      bta_dm_cb.role_policy_mask &= ~mask;
@@ -2575,8 +2578,7 @@ static void handle_role_change(const RawAddress& bd_addr, uint8_t new_role,
    }

    if (need_policy_change) {
      BTA_dm_update_policy(BTA_SYS_PLCY_CLR, 0, HCI_ENABLE_MASTER_SLAVE_SWITCH,
                           p_dev->peer_bdaddr);
      BTA_dm_clear_policy(HCI_ENABLE_MASTER_SLAVE_SWITCH, p_dev->peer_bdaddr);
    }
  } else {
    /* there's AV no activity on this link and role switch happened
@@ -2805,9 +2807,7 @@ static bool bta_dm_check_av(uint16_t event) {
          switching = true;
        }
        /* else either already master or can not switch for some reasons */
        BTA_dm_update_policy(BTA_SYS_PLCY_CLR, 0,
                             HCI_ENABLE_MASTER_SLAVE_SWITCH,
                             p_dev->peer_bdaddr);
        BTA_dm_clear_policy(HCI_ENABLE_MASTER_SLAVE_SWITCH, p_dev->peer_bdaddr);
        break;
      }
    }
+0 −1
Original line number Diff line number Diff line
@@ -111,7 +111,6 @@ typedef uint8_t tBTA_SYS_ID;
#define BTA_SYS_CONN_BUSY 0x07

/* for link policy */
#define BTA_SYS_PLCY_CLR 0x11     /* clear the link policy to the given addr */
#define BTA_SYS_PLCY_DEF_SET 0x12 /* set the default link policy */
#define BTA_SYS_PLCY_DEF_CLR 0x13 /* clear the default link policy */
#define BTA_SYS_ROLE_CHANGE 0x14  /* role change */
+2 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
void BTA_dm_update_policy(tBTA_SYS_CONN_STATUS status, uint8_t id,
                          uint8_t app_id, const RawAddress& peer_addr);
void BTA_dm_set_policy(uint8_t policy, const RawAddress& peer_addr);
void BTA_dm_clear_policy(uint8_t policy, const RawAddress& peer_addr);

/*******************************************************************************
 *
@@ -377,7 +378,7 @@ void bta_sys_clear_policy(uint8_t id, uint8_t policy,
                          const RawAddress& peer_addr) {
  APPL_TRACE_DEBUG("%s: peer %s id:%d policy:0x%x", __func__,
                   peer_addr.ToString().c_str(), id, policy);
  BTA_dm_update_policy(BTA_SYS_PLCY_CLR, id, policy, peer_addr);
  BTA_dm_clear_policy(policy, peer_addr);
}

/*******************************************************************************