From 1746ffd2e0b7549941d7e5aaa121674e0dc92b47 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Wed, 26 Sep 2018 22:02:38 -0700 Subject: [PATCH] Hearing Aid: Clean up GATT on disconnect When user requests Disconnect(), after disconnecting GATT, OnGattDisconnected() never cleans up GATT queue, because the corresponding device is already removed from HearingDevices. We need to clean up the queue before connecting the same device again. Without the fix, sometimes ACL is connected, but the host failed to read GATT characteristic to open COC. Also clean up connection update status during disconnect Bug: 116317072 Bug: 115365334 Test: connect to both devices -> disconnect -> connect, and repeat Change-Id: I158b19b3d1f2cb2123ec554eb1ffe8c842df998e --- bta/hearing_aid/hearing_aid.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bta/hearing_aid/hearing_aid.cc b/bta/hearing_aid/hearing_aid.cc index e49875e71..27780ef7e 100644 --- a/bta/hearing_aid/hearing_aid.cc +++ b/bta/hearing_aid/hearing_aid.cc @@ -1106,6 +1106,8 @@ class HearingAidImpl : public HearingAid { // cancel autoconnect BTA_GATTC_CancelOpen(gatt_if, address, false); + DoDisconnectCleanUp(hearingDevice); + hearingDevices.Remove(address); if (connected) @@ -1121,22 +1123,26 @@ class HearingAidImpl : public HearingAid { return; } + DoDisconnectCleanUp(hearingDevice); + + callbacks->OnConnectionState(ConnectionState::DISCONNECTED, remote_bda); + } + + void DoDisconnectCleanUp(HearingDevice* hearingDevice) { if (hearingDevice->connection_update_status != NONE) { LOG(INFO) << __func__ << ": connection update not completed. Current=" << hearingDevice->connection_update_status; if (hearingDevice->connection_update_status == STARTED) { - OnConnectionUpdateComplete(conn_id); + OnConnectionUpdateComplete(hearingDevice->conn_id); } hearingDevice->connection_update_status = NONE; } + BtaGattQueue::Clean(hearingDevice->conn_id); + hearingDevice->accepting_audio = false; hearingDevice->conn_id = 0; - - BtaGattQueue::Clean(conn_id); - - callbacks->OnConnectionState(ConnectionState::DISCONNECTED, remote_bda); } void SetVolume(int8_t volume) override { -- 2.11.0