Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 655653f4 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Android Build Coastguard Worker
Browse files

GATT: Disable notifications when disconnecting

Currently, if we receive notification after disconnection, but before
closing the client, stack would notify upper layers that connection is
avaliable, and sned notifications to Java.

This can be troublesome i.e. for Heart Rate Monitors, that send
notifications very often, and can prevent apps from closing properly.

Bug: 231818024
Test: connect to HRM with more than one application, close/disconnect multiple times
Merged-In: I1e9ca7ba6379322f7321b77a2ea92c96c799a452
Change-Id: I1e9ca7ba6379322f7321b77a2ea92c96c799a452
(cherry picked from commit 666f247f)
(cherry picked from commit f65b7a50)
Merged-In: I1e9ca7ba6379322f7321b77a2ea92c96c799a452
parent 67952a5b
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -385,6 +385,16 @@ void bta_gattc_open(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) {
    return;
  }

  tBTA_GATTC_RCB* p_clreg = p_clcb->p_rcb;
  /* Re-enable notification registration for closed connection */
  for (int i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i++) {
    if (p_clreg->notif_reg[i].in_use &&
        p_clreg->notif_reg[i].remote_bda == p_clcb->bda &&
        p_clreg->notif_reg[i].app_disconnected) {
      p_clreg->notif_reg[i].app_disconnected = false;
    }
  }

  /* a connected remote device */
  if (GATT_GetConnIdIfConnected(
          p_clcb->p_rcb->client_if, p_data->api_conn.remote_bda,
@@ -511,6 +521,16 @@ void bta_gattc_conn(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) {

  if (p_clcb->p_srcb->mtu == 0) p_clcb->p_srcb->mtu = GATT_DEF_BLE_MTU_SIZE;

  tBTA_GATTC_RCB* p_clreg = p_clcb->p_rcb;
  /* Re-enable notification registration for closed connection */
  for (int i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i++) {
    if (p_clreg->notif_reg[i].in_use &&
        p_clreg->notif_reg[i].remote_bda == p_clcb->bda &&
        p_clreg->notif_reg[i].app_disconnected) {
      p_clreg->notif_reg[i].app_disconnected = false;
    }
  }

  /* start database cache if needed */
  if (p_clcb->p_srcb->gatt_database.IsEmpty() ||
      p_clcb->p_srcb->state != BTA_GATTC_SERV_IDLE) {
@@ -604,6 +624,14 @@ void bta_gattc_close(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) {
    bta_sys_conn_close(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
  }

  /* Disable notification registration for closed connection */
  for (int i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i++) {
    if (p_clreg->notif_reg[i].in_use &&
        p_clreg->notif_reg[i].remote_bda == p_clcb->bda) {
      p_clreg->notif_reg[i].app_disconnected = true;
    }
  }

  bta_gattc_clcb_dealloc(p_clcb);

  if (p_data->hdr.event == BTA_GATTC_API_CLOSE_EVT) {
+1 −0
Original line number Diff line number Diff line
@@ -230,6 +230,7 @@ typedef struct {

typedef struct {
  bool in_use;
  bool app_disconnected;
  RawAddress remote_bda;
  uint16_t handle;
} tBTA_GATTC_NOTIF_REG;
+2 −1
Original line number Diff line number Diff line
@@ -352,7 +352,8 @@ bool bta_gattc_check_notif_registry(tBTA_GATTC_RCB* p_clreg,
  for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i++) {
    if (p_clreg->notif_reg[i].in_use &&
        p_clreg->notif_reg[i].remote_bda == p_srcb->server_bda &&
        p_clreg->notif_reg[i].handle == p_notify->handle) {
        p_clreg->notif_reg[i].handle == p_notify->handle &&
        !p_clreg->notif_reg[i].app_disconnected) {
      VLOG(1) << "Notification registered!";
      return true;
    }