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

Commit 1091d59b authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Automerger Merge Worker
Browse files

GATT: Disable notifications when disconnecting am: f65b7a50

parents 072b33d6 f65b7a50
Loading
Loading
Loading
Loading
+28 −0
Original line number Original line 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;
    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 */
  /* a connected remote device */
  if (GATT_GetConnIdIfConnected(
  if (GATT_GetConnIdIfConnected(
          p_clcb->p_rcb->client_if, p_data->api_conn.remote_bda,
          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;
  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 */
  /* start database cache if needed */
  if (p_clcb->p_srcb->gatt_database.IsEmpty() ||
  if (p_clcb->p_srcb->gatt_database.IsEmpty() ||
      p_clcb->p_srcb->state != BTA_GATTC_SERV_IDLE) {
      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);
    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);
  bta_gattc_clcb_dealloc(p_clcb);


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


typedef struct {
typedef struct {
  bool in_use;
  bool in_use;
  bool app_disconnected;
  RawAddress remote_bda;
  RawAddress remote_bda;
  uint16_t handle;
  uint16_t handle;
} tBTA_GATTC_NOTIF_REG;
} tBTA_GATTC_NOTIF_REG;
+2 −1
Original line number Original line 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++) {
  for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i++) {
    if (p_clreg->notif_reg[i].in_use &&
    if (p_clreg->notif_reg[i].in_use &&
        p_clreg->notif_reg[i].remote_bda == p_srcb->server_bda &&
        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!";
      VLOG(1) << "Notification registered!";
      return true;
      return true;
    }
    }