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

Commit 20d14569 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Close BTA HID host connection only if it was connected

BTIF HID host tries to close the BTA HID host connection if it
determined that the connection should be closed. However it makes
determination without considering if BTA HID host was connected or not.

Test: mmm packages/modules/Bluetooth
Test: Manual | Pair with an earbud supporting both DSA 1.0 and DSA 2.0,
frequently switch between classic audio and LE audio
Flag: com.android.bluetooth.flags.close_hid_only_if_connected
Bug: 357707854
Bug: 358241286

Change-Id: I86baf524844335fb324e80115e50669bfeb8f8b7
parent 05629789
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -464,12 +464,14 @@ static bthh_connection_state_t hh_get_state_on_disconnect(tAclLinkSpec& link_spe
  }
}

static void hh_connect_complete(uint8_t handle, tAclLinkSpec& link_spec,
                                bthh_connection_state_t state) {
static void hh_connect_complete(tBTA_HH_CONN& conn, bthh_connection_state_t state) {
  if (state != BTHH_CONN_STATE_CONNECTED) {
    BTA_HhClose(handle);
    if (!com::android::bluetooth::flags::close_hid_only_if_connected() ||
        conn.status == BTA_HH_OK) {
      BTA_HhClose(conn.handle);
    }
  }
  BTHH_STATE_UPDATE(link_spec, state);
  BTHH_STATE_UPDATE(conn.link_spec, state);
}

/*******************************************************************************
@@ -585,7 +587,7 @@ static void hh_open_handler(tBTA_HH_CONN& conn) {
      }

      if (!com::android::bluetooth::flags::suppress_hid_rejection_broadcast()) {
        hh_connect_complete(conn.handle, conn.link_spec, BTHH_CONN_STATE_DISCONNECTED);
        hh_connect_complete(conn, BTHH_CONN_STATE_DISCONNECTED);
        return;
      }
      BTA_HhClose(conn.handle);
@@ -607,14 +609,14 @@ static void hh_open_handler(tBTA_HH_CONN& conn) {

      p_dev->dev_status = hh_get_state_on_disconnect(p_dev->link_spec);
    }
    hh_connect_complete(conn.handle, conn.link_spec, BTHH_CONN_STATE_DISCONNECTED);
    hh_connect_complete(conn, BTHH_CONN_STATE_DISCONNECTED);
    return;
  }

  /* Initialize device driver */
  if (!bta_hh_co_open(conn.handle, conn.sub_class, conn.attr_mask, conn.app_id, conn.link_spec)) {
    log::warn("Failed to find the uhid driver");
    hh_connect_complete(conn.handle, conn.link_spec, BTHH_CONN_STATE_DISCONNECTED);
    hh_connect_complete(conn, BTHH_CONN_STATE_DISCONNECTED);
    return;
  }

@@ -623,7 +625,7 @@ static void hh_open_handler(tBTA_HH_CONN& conn) {
    /* The connect request must have come from device side and exceeded the
     * connected HID device number. */
    log::warn("Cannot find device with handle {}", conn.handle);
    hh_connect_complete(conn.handle, conn.link_spec, BTHH_CONN_STATE_DISCONNECTED);
    hh_connect_complete(conn, BTHH_CONN_STATE_DISCONNECTED);
    return;
  }

@@ -634,7 +636,7 @@ static void hh_open_handler(tBTA_HH_CONN& conn) {
    p_dev->link_spec = conn.link_spec;
    p_dev->dev_status = BTHH_CONN_STATE_CONNECTED;
  }
  hh_connect_complete(conn.handle, conn.link_spec, BTHH_CONN_STATE_CONNECTED);
  hh_connect_complete(conn, BTHH_CONN_STATE_CONNECTED);
  // Send set_idle if the peer_device is a keyboard
  if (check_cod_hid_major(conn.link_spec.addrt.bda, COD_HID_KEYBOARD) ||
      check_cod_hid_major(conn.link_spec.addrt.bda, COD_HID_COMBO)) {