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

Commit 55df34e5 authored by Hemant Gupta's avatar Hemant Gupta Committed by Jakub Pawlowski
Browse files

HID: Update state to disconnected in virtual unplug

Usecase:
1.Pair and connect DUT with Remote device
2.Disconnect Remote device from DUT (Settings menu)
3.Connect to Remote device from settings menu when Remote will not be
  advertising.
4.With in 30 secs of connect command, delete the stored link key and then pair
  and connect again to Remote device from settings menu
  (when RD is advertising).

Expected Result:
Remote device should connect successfully.

Observed Result:
Remote device is shown in paired devices(settings menu)but not connected.

Root cause:
When virtual unplug happens device state is not cleared properly. So next
time when we are trying to connect its going to connected state.

Fix:
Update the current device state to BTHH_CONN_STATE_CONNECTING to
BTIF_HH_DEV_DISCONNECTED when virtual unplug happens.

Test: Issue is not seen after above steps

Fixes: 74082929
Change-Id: I8a325987ff5eb0a8e4f8708fc7c76b8a9ade6ccf
(cherry picked from commit e8e24bcf)
parent 6a6ac6da
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ typedef struct {
  btif_hh_added_device_t added_devices[BTIF_HH_MAX_ADDED_DEV];
  btif_hh_device_t* p_curr_dev;
  bool service_dereg_active;
  RawAddress pending_conn_address;
} btif_hh_cb_t;

/*******************************************************************************
+11 −10
Original line number Diff line number Diff line
@@ -534,10 +534,6 @@ bool btif_hh_copy_hid_info(tBTA_HH_DEV_DSCP_INFO* dest,
bt_status_t btif_hh_virtual_unplug(const RawAddress* bd_addr) {
  BTIF_TRACE_DEBUG("%s", __func__);
  btif_hh_device_t* p_dev;
  char bd_str[18];
  snprintf(bd_str, sizeof(bd_str), "%02X:%02X:%02X:%02X:%02X:%02X",
           bd_addr->address[0], bd_addr->address[1], bd_addr->address[2],
           bd_addr->address[3], bd_addr->address[4], bd_addr->address[5]);
  p_dev = btif_hh_find_dev_by_bda(*bd_addr);
  if ((p_dev != NULL) && (p_dev->dev_status == BTHH_CONN_STATE_CONNECTED) &&
      (p_dev->attr_mask & HID_VIRTUAL_CABLE)) {
@@ -548,7 +544,13 @@ bt_status_t btif_hh_virtual_unplug(const RawAddress* bd_addr) {
    BTA_HhSendCtrl(p_dev->dev_handle, BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG);
    return BT_STATUS_SUCCESS;
  } else {
    BTIF_TRACE_ERROR("%s: Error, device %s not opened.", __func__, bd_str);
    BTIF_TRACE_ERROR("%s: Error, device %s not opened, status = %d", __func__,
                     bd_addr->ToString().c_str(), btif_hh_cb.status);
    if ((btif_hh_cb.pending_conn_address == *bd_addr) &&
       (btif_hh_cb.status == BTIF_HH_DEV_CONNECTING)) {
          btif_hh_cb.status = (BTIF_HH_STATUS)BTIF_HH_DEV_DISCONNECTED;
          btif_hh_cb.pending_conn_address = RawAddress::kEmpty;
    }
    return BT_STATUS_FAIL;
  }
}
@@ -603,6 +605,7 @@ bt_status_t btif_hh_connect(const RawAddress* bd_addr) {
   pagescan mode, we will do 2 retries to connect before giving up */
  tBTA_SEC sec_mask = BTUI_HH_SECURITY;
  btif_hh_cb.status = BTIF_HH_DEV_CONNECTING;
  btif_hh_cb.pending_conn_address = *bd_addr;
  BTA_HhOpen(*bd_addr, BTA_HH_PROTO_RPT_MODE, sec_mask);

  // TODO(jpawlowski); make cback accept const and remove tmp!
@@ -750,6 +753,7 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
    case BTA_HH_OPEN_EVT:
      BTIF_TRACE_WARNING("%s: BTA_HH_OPN_EVT: handle=%d, status =%d", __func__,
                         p_data->conn.handle, p_data->conn.status);
      btif_hh_cb.pending_conn_address = RawAddress::kEmpty;
      if (p_data->conn.status == BTA_HH_OK) {
        p_dev = btif_hh_find_connected_dev_by_handle(p_data->conn.handle);
        if (p_dev == NULL) {
@@ -1265,17 +1269,14 @@ static bt_status_t virtual_unplug(RawAddress* bd_addr) {
  CHECK_BTHH_INIT();
  BTIF_TRACE_EVENT("BTHH: %s", __func__);
  btif_hh_device_t* p_dev;
  char bd_str[18];
  snprintf(bd_str, sizeof(bd_str), "%02X:%02X:%02X:%02X:%02X:%02X",
           bd_addr->address[0], bd_addr->address[1], bd_addr->address[2],
           bd_addr->address[3], bd_addr->address[4], bd_addr->address[5]);
  if (btif_hh_cb.status == BTIF_HH_DISABLED) {
    BTIF_TRACE_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
    return BT_STATUS_FAIL;
  }
  p_dev = btif_hh_find_dev_by_bda(*bd_addr);
  if (!p_dev) {
    BTIF_TRACE_ERROR("%s: Error, device %s not opened.", __func__, bd_str);
    BTIF_TRACE_ERROR("%s: Error, device %s not opened.", __func__,
                     bd_addr->ToString().c_str());
    return BT_STATUS_FAIL;
  }
  btif_transfer_context(btif_hh_handle_evt, BTIF_HH_VUP_REQ_EVT, (char*)bd_addr,