OSDN Git Service

Fix for BluetoothGattCallback.onConnectionStateChange being called more than once
authorJakub Pawlowski <jpawlowski@google.com>
Thu, 13 Jun 2019 14:31:53 +0000 (16:31 +0200)
committerJakub Pawlowski <jpawlowski@google.com>
Thu, 13 Jun 2019 19:35:03 +0000 (21:35 +0200)
This patch fixes the issue, where the onConenctionStateCallback is being
called twice when device is connected. This happens only if device was
connected before, and the physical connection was kept alive.

This issue was introduced during white list refactor.

Test: GattConnectTest:test_gatt_connect_in_quick_succession
Bug: 117182283
Merged-In: Id94db9429e31224ef35eb2c99c0f9a65e7c27d32
Change-Id: Id94db9429e31224ef35eb2c99c0f9a65e7c27d32

stack/gatt/gatt_main.cc

index ecdb6f2..87f9c87 100644 (file)
@@ -205,25 +205,9 @@ bool gatt_connect(const RawAddress& rem_bda, tGATT_TCB* p_tcb,
     return p_tcb->att_lcid != 0;
   }
 
-  // Already connected, send the callback, mark the link as used
+  // Already connected, mark the link as used
   if (gatt_get_ch_state(p_tcb) == GATT_CH_OPEN) {
-    /*  very similar to gatt_send_conn_cback, but no good way to reuse the code
-     */
-
-    /* notifying application about the connection up event */
-    for (int i = 0; i < GATT_MAX_APPS; i++) {
-      tGATT_REG* p_reg = &gatt_cb.cl_rcb[i];
-
-      if (!p_reg->in_use || p_reg->gatt_if != gatt_if) continue;
-
-      gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);
-      if (p_reg->app_cb.p_conn_cb) {
-        uint16_t conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if);
-        (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, p_tcb->peer_bda, conn_id,
-                                   true, 0, p_tcb->transport);
-      }
-    }
-
+    gatt_update_app_use_link_flag(gatt_if, p_tcb, true, true);
     return true;
   }