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

Commit bfa78dac authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Cancelling pending connections to already added HID device

Initiated connection to the already added HID device puts it in the pending connections list. If application requests disconnection before connection is completed, the device control block state is updated but the device is not removed from the pending connections list.
This allows the remote device to be able to reconnect even when the connection policy forbids it.

Change-Id: I093bd17fce02989048bfec99e5986dc91e5acb04
Test: atest BumbleBluetoothTest:HidHostTest
Flag: com.android.bluetooth.flags.pending_hid_connection_cancellation
Bug: 380477704
Bug: 381135214
parent 27913d4f
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -1120,11 +1120,16 @@ bt_status_t btif_hh_connect(const tAclLinkSpec& link_spec) {
    p_dev->dev_status = BTHH_CONN_STATE_CONNECTING;
  }

  // Add the new connection to the pending list
  if (!com::android::bluetooth::flags::pending_hid_connection_cancellation() ||
      added_dev == nullptr) {
    btif_hh_cb.pending_connections.push_back(link_spec);
  }

  /* Not checking the NORMALLY_Connectible flags from sdp record, and anyways
   sending this request from host, for subsequent user initiated connection.
   If the remote is not in pagescan mode, we will do 2 retries to connect before
   giving up */
  btif_hh_cb.pending_connections.push_back(link_spec);
  BTA_HhOpen(link_spec);

  do_in_jni_thread(base::Bind(
@@ -1645,6 +1650,10 @@ static bt_status_t disconnect(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type,
        log::warn("Device {} already not connected, state: {}", p_dev->link_spec,
                  bthh_connection_state_text(p_dev->dev_status));
        p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED;

        if (com::android::bluetooth::flags::pending_hid_connection_cancellation()) {
          btif_hh_cb.pending_connections.remove(link_spec);
        }
        return BT_STATUS_DONE;
      } else if (com::android::bluetooth::flags::initiate_multiple_hid_connections() &&
                 std::find(btif_hh_cb.pending_connections.begin(),