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

Commit 1146e346 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Close BTA HID host connection only if it was connected" into main am:...

Merge "Close BTA HID host connection only if it was connected" into main am: 551dc422 am: f0aa117a

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/3211162



Change-Id: I8dcff48a5e01d441cfc9b59c5e1b8663d7d858b7
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 5d1a26cd f0aa117a
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)) {