From 126397bc6e8ff19bd37b0bc4b9b5db978eecb773 Mon Sep 17 00:00:00 2001 From: Hemant Gupta Date: Fri, 2 Mar 2018 10:29:25 +0530 Subject: [PATCH] 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 --- btif/include/btif_hh.h | 1 + btif/src/btif_hh.cc | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/btif/include/btif_hh.h b/btif/include/btif_hh.h index 4aeafca3c..236454482 100644 --- a/btif/include/btif_hh.h +++ b/btif/include/btif_hh.h @@ -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; /******************************************************************************* diff --git a/btif/src/btif_hh.cc b/btif/src/btif_hh.cc index ceb2366dc..c5a90218a 100644 --- a/btif/src/btif_hh.cc +++ b/btif/src/btif_hh.cc @@ -544,8 +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_addr->ToString().c_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; } } @@ -600,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! @@ -747,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) { -- 2.11.0