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

Commit 464036f8 authored by Zach Johnson's avatar Zach Johnson Committed by Automerger Merge Worker
Browse files

Skip the message passing and call BTA_dm_report_role_change directly am:...

Skip the message passing and call BTA_dm_report_role_change directly am: df0d30a1 am: ebff2867 am: 82634244

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1393948

Change-Id: If408caf4722c35f44fa60c120f532e2f0be63520
parents bf94db84 82634244
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -2678,6 +2678,12 @@ static void handle_role_change(const RawAddress& bd_addr, uint8_t new_role,
  bta_sys_notify_role_chg(bd_addr, new_role, hci_status);
}

void BTA_dm_report_role_change(const RawAddress bd_addr, uint8_t new_role,
                               uint8_t hci_status) {
  do_in_main_thread(
      FROM_HERE, base::Bind(handle_role_change, bd_addr, new_role, hci_status));
}

static tBTA_DM_PEER_DEVICE* allocate_device_for(const RawAddress& bd_addr,
                                                tBT_TRANSPORT transport,
                                                uint16_t handle) {
@@ -2832,13 +2838,6 @@ void BTA_dm_acl_down(const RawAddress bd_addr, tBT_TRANSPORT transport) {
/** Callback from btm when acl connection goes up or down */
static void bta_dm_bl_change_cback(tBTM_BL_EVENT_DATA* p_data) {
  switch (p_data->event) {
    case BTM_BL_ROLE_CHG_EVT: {
      const auto& tmp = p_data->role_chg;
      do_in_main_thread(FROM_HERE, base::Bind(handle_role_change, *tmp.p_bda,
                                              tmp.new_role, tmp.hci_status));
      return;
    }

    case BTM_BL_COLLISION_EVT:
      /* Collision report from Stack: Notify profiles */
      do_in_main_thread(
+11 −30
Original line number Diff line number Diff line
@@ -80,6 +80,8 @@ void BTIF_dm_report_inquiry_status_change(uint8_t busy_level_flags);
void BTA_dm_acl_up(const RawAddress bd_addr, tBT_TRANSPORT transport,
                   uint16_t handle);
void BTA_dm_acl_down(const RawAddress bd_addr, tBT_TRANSPORT transport);
void BTA_dm_report_role_change(const RawAddress bd_addr, uint8_t new_role,
                               uint8_t hci_status);
/* 3 seconds timeout waiting for responses */
#define BTM_DEV_REPLY_TIMEOUT_MS (3 * 1000)

@@ -627,24 +629,15 @@ void btm_acl_encrypt_change(uint16_t handle, uint8_t status,
  else if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON) {
    p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
    p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
    btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status,
                               &p->remote_addr);

    /* if role change event is registered, report it now */
    if (btm_cb.acl_cb_.p_bl_changed_cb) {
      tBTM_BL_ROLE_CHG_DATA evt;
      evt.event = BTM_BL_ROLE_CHG_EVT;
      evt.new_role = btm_cb.devcb.switch_role_ref_data.role;
      evt.p_bda = &btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
      evt.hci_status = btm_cb.devcb.switch_role_ref_data.hci_status;
      tBTM_BL_EVENT_DATA btm_bl_event_data;
      btm_bl_event_data.role_chg = evt;
      (*btm_cb.acl_cb_.p_bl_changed_cb)(&btm_bl_event_data);
    auto new_role = btm_cb.devcb.switch_role_ref_data.role;
    auto hci_status = btm_cb.devcb.switch_role_ref_data.hci_status;
    btm_acl_report_role_change(hci_status, &p->remote_addr);
    BTA_dm_report_role_change(btm_cb.devcb.switch_role_ref_data.remote_bd_addr,
                              new_role, hci_status);

    BTM_TRACE_DEBUG(
        "%s: Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d",
          __func__, evt.new_role, evt.hci_status, p->switch_role_state);
    }
        __func__, new_role, hci_status, p->switch_role_state);

#if (BTM_DISC_DURING_RS == TRUE)
    /* If a disconnect is pending, issue it now that role switch has completed
@@ -1384,7 +1377,6 @@ void btm_acl_role_changed(uint8_t hci_status, const RawAddress* bd_addr,
      BTM_SetLinkSuperTout(p->remote_addr, p->link_super_tout);
    }
  } else {
    /* so the BTM_BL_ROLE_CHG_EVT uses the old role */
    new_role = p->link_role;
  }

@@ -1409,18 +1401,7 @@ void btm_acl_role_changed(uint8_t hci_status, const RawAddress* bd_addr,

  /* if role switch complete is needed, report it now */
  btm_acl_report_role_change(hci_status, bd_addr);

  /* if role change event is registered, report it now */
  if (btm_cb.acl_cb_.p_bl_changed_cb) {
    tBTM_BL_ROLE_CHG_DATA evt;
    evt.event = BTM_BL_ROLE_CHG_EVT;
    evt.new_role = new_role;
    evt.p_bda = p_bda;
    evt.hci_status = hci_status;
    tBTM_BL_EVENT_DATA btm_bl_event_data;
    btm_bl_event_data.role_chg = evt;
    (*btm_cb.acl_cb_.p_bl_changed_cb)(&btm_bl_event_data);
  }
  BTA_dm_report_role_change(*p_bda, new_role, hci_status);

  BTM_TRACE_DEBUG(
      "%s: peer %s Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, "
+0 −10
Original line number Diff line number Diff line
@@ -129,7 +129,6 @@ typedef struct {
} tBTM_INQ_TXPWR_RESULT;

enum {
  BTM_BL_ROLE_CHG_EVT,
  BTM_BL_COLLISION_EVT
};
typedef uint8_t tBTM_BL_EVENT;
@@ -153,19 +152,10 @@ typedef struct {
#define BTM_INQUIRY_STARTED 1
#define BTM_INQUIRY_CANCELLED 2
#define BTM_INQUIRY_COMPLETE 3
/* the data type associated with BTM_BL_ROLE_CHG_EVT */
typedef struct {
  tBTM_BL_EVENT event;     /* The event reported. */
  const RawAddress* p_bda; /* The address of the peer connected device */
  uint8_t new_role;
  uint8_t hci_status; /* HCI status returned with the event */
} tBTM_BL_ROLE_CHG_DATA;

typedef union {
  tBTM_BL_EVENT event;        /* The event reported. */
  tBTM_BL_CONN_DATA conn;     /* The data associated with BTM_BL_CONN_EVT */
  tBTM_BL_ROLE_CHG_DATA
      role_chg; /*The data associated with BTM_BL_ROLE_CHG_EVT */
} tBTM_BL_EVENT_DATA;

/* Callback function for notifications when the BTM busy level