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

Commit dfd5a2a2 authored by Yun-Hao Chung's avatar Yun-Hao Chung
Browse files

Floss: Separate out open failure case from BTA_HH close act

Currently we use disconnect reason in bta_hh_close_act to tell if HID is
connected or not. One case that could make this approach fail is
HID_ERR_AUTH_FAILED, which can be reported before HID open (ex.
encyption mode not acceptable) or after HID open (ex. key refresh caused
by role switch).

This patch separates out the open failure case from the close act and
use BTA_HH_STATE to decide whether the HID is opened or not.

Bug: 312091718
Test: run sr_reconnect_multiple_classic_hid on sarien
Test: mma -j
Tag: #floss

Change-Id: I928ac08d3f923c7abc8844dc1bcac1473396e5eb
parent 25552a3e
Loading
Loading
Loading
Loading
+12 −37
Original line number Diff line number Diff line
@@ -899,7 +899,6 @@ void bta_hh_open_failure(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
 *
 ******************************************************************************/
void bta_hh_close_act(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
  tBTA_HH_CONN conn_dat;
  tBTA_HH_CBDATA disc_dat = {BTA_HH_OK, 0};

  uint32_t reason = p_data->hid_cback.data; /* Reason for closing (32-bit) */
@@ -924,29 +923,6 @@ void bta_hh_close_act(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
                                    hid_status_text(hid_status).c_str(),
                                    overlay_fail.c_str()));

  /* Check reason for closing */
  if ((reason & (HID_L2CAP_CONN_FAIL |
                 HID_L2CAP_REQ_FAIL)) || /* Failure to initialize connection
                                            (page timeout or l2cap error) */
      (reason ==
       HID_ERR_AUTH_FAILED) || /* Authenication error (while initiating) */
      (reason == HID_ERR_L2CAP_FAILED)) /* Failure creating l2cap connection */
  {
    /* Failure in opening connection */
    conn_dat.handle = p_cb->hid_handle;
    conn_dat.status =
        (reason == HID_ERR_AUTH_FAILED) ? BTA_HH_ERR_AUTH_FAILED : BTA_HH_ERR;
    conn_dat.bda = p_cb->addr;
    HID_HostCloseDev(p_cb->hid_handle);

    /* Report OPEN fail event */
    (*bta_hh_cb.p_cback)(BTA_HH_OPEN_EVT, (tBTA_HH*)&conn_dat);

    bta_hh_trace_dev_db();
    return;
  }
  /* otherwise report CLOSE/VC_UNPLUG event */
  else {
  /* inform role manager */
  bta_sys_conn_close(BTA_ID_HH, p_cb->app_id, p_cb->addr);
  /* update total conn number */
@@ -963,7 +939,6 @@ void bta_hh_close_act(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
  }

  bta_hh_trace_dev_db();
  }

  /* clean up control block, but retain SDP info and device handle */
  p_cb->vp = false;
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ static void bta_hh_better_state_machine(tBTA_HH_DEV_CB* p_cb, uint16_t event,
          bta_hh_open_act(p_cb, p_data);
          break;
        case BTA_HH_INT_CLOSE_EVT:
          bta_hh_close_act(p_cb, p_data);
          bta_hh_open_failure(p_cb, p_data);
          break;
        case BTA_HH_API_MAINT_DEV_EVT:
          bta_hh_maint_dev_act(p_cb, p_data);