From fd0e9f1915dab624282c9d11ac6a1c7228c18c75 Mon Sep 17 00:00:00 2001 From: Anubhav Gupta Date: Wed, 4 Sep 2013 15:50:39 +0530 Subject: [PATCH] Properly handle outgoing connection requests in opening/opened state This happens in race conditions when we try to connect to a remote A2DP device from Bluetooth Settings UI and simultaneously there is incoming connection request from previously connected remote. This fix addresses the scenario where because of first A2DP connection btif moves to opening/ opened state and then the second connect request is received. This scenario is handled by gracefully rejecting the second connect request from btif layer if it is already connected or about to be connected by the first connect request. Bug: 22028876 Change-Id: I53be400d1d7c9a84ca9d9a75b6b6f010975cf0cf --- btif/src/btif_av.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/btif/src/btif_av.c b/btif/src/btif_av.c index b3f8615f9..27e174b49 100644 --- a/btif/src/btif_av.c +++ b/btif/src/btif_av.c @@ -453,6 +453,38 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data } } break; + case BTIF_AV_CONNECT_REQ_EVT: + // Check for device, if same device which moved to opening then ignore callback + if (memcmp ((bt_bdaddr_t*)p_data, &(btif_av_cb.peer_bda), + sizeof(btif_av_cb.peer_bda)) == 0) + { + BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Connect Req", __func__); + btif_queue_advance(); + break; + } + else + { + BTIF_TRACE_DEBUG("%s: Moved from idle by Incoming Connection request", __func__); + btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, (bt_bdaddr_t*)p_data); + btif_queue_advance(); + break; + } + + case BTA_AV_PENDING_EVT: + // Check for device, if same device which moved to opening then ignore callback + if (memcmp (((tBTA_AV*)p_data)->pend.bd_addr, &(btif_av_cb.peer_bda), + sizeof(btif_av_cb.peer_bda)) == 0) + { + BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Pending Req", __func__); + break; + } + else + { + BTIF_TRACE_DEBUG("%s: Moved from idle by outgoing Connection request", __func__); + BTA_AvDisconnect(((tBTA_AV*)p_data)->pend.bd_addr); + break; + } + CHECK_RC_EVENT(event, p_data); default: @@ -668,6 +700,21 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data) } break; + case BTIF_AV_CONNECT_REQ_EVT: + if (memcmp ((bt_bdaddr_t*)p_data, &(btif_av_cb.peer_bda), + sizeof(btif_av_cb.peer_bda)) == 0) + { + BTIF_TRACE_DEBUG("%s: Ignore BTIF_AV_CONNECT_REQ_EVT for same device", __func__); + } + else + { + BTIF_TRACE_DEBUG("%s: Moved to opened by Other Incoming Conn req", __func__); + btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, + (bt_bdaddr_t*)p_data); + } + btif_queue_advance(); + break; + CHECK_RC_EVENT(event, p_data); default: -- 2.11.0