OSDN Git Service

HID: Remove bond for device in case Virtual unplug is ongoing
authorHemant Gupta <hemantg@codeaurora.org>
Fri, 11 Dec 2015 10:17:45 +0000 (15:47 +0530)
committerAndre Eisenbach <eisenbach@google.com>
Fri, 4 Mar 2016 17:25:55 +0000 (09:25 -0800)
Remove bond for remote device in case virtual unplug was initiated from
local device, and ACL got disconnected while processing the VUP request.
this can happen when aaplication is sending disconnect and remove bond
in quick succession. Without this fix it was observed that device was
getting disconnected, but was not getting unpaired even when user
tried to unpair from UI.

Change-Id: Ife1fc99ed59b13daf0bcf0dce3e0a59c7d9e87d7

btif/src/btif_hh.c
stack/hid/hidh_api.c

index 22cea66..30bc8fe 100644 (file)
@@ -794,14 +794,24 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param)
             p_data->dev_status.status, p_data->dev_status.handle);
             p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle);
             if (p_dev != NULL) {
-                BTIF_TRACE_DEBUG("%s: uhid fd = %d", __FUNCTION__, p_dev->fd);
+                BTIF_TRACE_DEBUG("%s: uhid fd=%d local_vup=%d", __func__, p_dev->fd, p_dev->local_vup);
                 btif_hh_stop_vup_timer(&(p_dev->bd_addr));
+                /* If this is a locally initiated VUP, remove the bond as ACL got
+                 *  disconnected while VUP being processed.
+                 */
+                if (p_dev->local_vup)
+                {
+                    p_dev->local_vup = FALSE;
+                    BTA_DmRemoveDevice((UINT8 *)p_dev->bd_addr.address);
+                }
+
+                btif_hh_cb.status = BTIF_HH_DEV_DISCONNECTED;
+                p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED;
+
                 if (p_dev->fd >= 0) {
                     bta_hh_co_destroy(p_dev->fd);
                     p_dev->fd = -1;
                 }
-                btif_hh_cb.status = BTIF_HH_DEV_DISCONNECTED;
-                p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED;
                 HAL_CBACK(bt_hh_callbacks, connection_state_cb,&(p_dev->bd_addr), p_dev->dev_status);
             }
             else {
index b737783..db173f1 100644 (file)
@@ -491,12 +491,10 @@ tHID_STATUS HID_HostCloseDev( UINT8 dev_handle )
     if( (dev_handle >= HID_HOST_MAX_DEVICES) || (!hh_cb.devices[dev_handle].in_use) )
         return HID_ERR_INVALID_PARAM;
 
-    hh_cb.devices[dev_handle].conn_tries = HID_HOST_MAX_CONN_RETRY+1;
-    alarm_cancel(hh_cb.devices[dev_handle].conn.process_repage_timer);
-
     if( hh_cb.devices[dev_handle].state != HID_DEV_CONNECTED )
         return HID_ERR_NO_CONNECTION;
 
+    alarm_cancel(hh_cb.devices[dev_handle].conn.process_repage_timer);
     hh_cb.devices[dev_handle].conn_tries = HID_HOST_MAX_CONN_RETRY+1;
     return hidh_conn_disconnect( dev_handle );
 }