OSDN Git Service

Hearing Aid: Clean up GATT on disconnect
authorHansong Zhang <hsz@google.com>
Thu, 27 Sep 2018 05:02:38 +0000 (22:02 -0700)
committerHansong Zhang <hsz@google.com>
Fri, 28 Sep 2018 01:38:03 +0000 (18:38 -0700)
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: 115365334
Test: connect to both devices -> disconnect -> connect, and repeat
Change-Id: I158b19b3d1f2cb2123ec554eb1ffe8c842df998e

bta/hearing_aid/hearing_aid.cc

index a557f76..63d3ac8 100644 (file)
@@ -1105,6 +1105,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 {