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

Commit 621e6f32 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

HidHost: Reject incoming connections based on connection policy

Connection policy for first time incoming connections should be
retrieved from the added devices list.
Connection policy should be stored using resolved transport type.

Test: mmm packages/modules/Bluetooth
Test: Manual | Pair HID device, restart BT, turn off input toggle, HID
device should not be able to reconnect
Bug: 331564000
Bug: 320762367

Change-Id: Iddcffe7a65ac9b8ca69147671571f6a923563815
parent 994d7fce
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -493,15 +493,26 @@ static void hh_open_handler(tBTA_HH_CONN& conn) {
             conn.link_spec.ToRedactedStringForLogging(), conn.status,
             conn.handle);

  if (IS_FLAG_ENABLED(allow_switching_hid_and_hogp) &&
      conn.link_spec.transport != BT_TRANSPORT_AUTO) {
  if (IS_FLAG_ENABLED(allow_switching_hid_and_hogp)) {
    // Initialize with disconnected/accepting state based on reconnection policy
    bthh_connection_state_t dev_status =
        hh_get_state_on_disconnect(conn.link_spec);

    // Use current state if the device instance already exists
    btif_hh_device_t* p_dev = btif_hh_find_dev_by_link_spec(conn.link_spec);
    if ((p_dev != NULL) && (p_dev->dev_status != BTHH_CONN_STATE_ACCEPTING &&
                            p_dev->dev_status != BTHH_CONN_STATE_CONNECTING)) {
    if (p_dev != nullptr) {
      dev_status = p_dev->dev_status;
    }

    if (dev_status != BTHH_CONN_STATE_ACCEPTING &&
        dev_status != BTHH_CONN_STATE_CONNECTING) {
      log::warn("Reject Incoming HID Connection, device: {}, state: {}",
                p_dev->link_spec.ToRedactedStringForLogging(),
                p_dev->dev_status);
                conn.link_spec.ToRedactedStringForLogging(), dev_status);

      if (p_dev != nullptr) {
        p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED;
      }

      hh_connect_complete(conn.handle, conn.link_spec,
                          BTIF_HH_DEV_DISCONNECTED);
      return;
@@ -1619,7 +1630,8 @@ static bt_status_t disconnect(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type,
    btif_hh_added_device_t* added_dev = btif_hh_find_added_dev(link_spec);
    if (added_dev != nullptr) {
      added_dev->reconnect_allowed = reconnect_allowed;
      btif_storage_set_hid_connection_policy(link_spec, reconnect_allowed);
      btif_storage_set_hid_connection_policy(added_dev->link_spec,
                                             reconnect_allowed);
    }
  }