From d801952d8ca9b97b2fef7af1c3c3bb5de62da925 Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Wed, 10 Jun 2026 15:24:34 +0800 Subject: [PATCH] fix(bt): Suppress gattc drop-notif warning for unregistered gatt_if GATT stack broadcasts notifications to every client app, so unregistered gatt_if instances were flooding logs even when another app had registered the handle. Only warn when no client app registered for the handle. (cherry picked from commit c18c8dc5e765c804954da4058ce70f0e7e01695e) Co-authored-by: zhanghaipeng --- .../host/bluedroid/bta/gatt/bta_gattc_act.c | 14 ++++++----- .../host/bluedroid/bta/gatt/bta_gattc_utils.c | 23 +++++++++++++++++++ .../bta/gatt/include/bta_gattc_int.h | 1 + 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c index fbc87a3c7b8..afc6c821588 100644 --- a/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c +++ b/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c @@ -2209,12 +2209,14 @@ void bta_gattc_process_indicate(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_CL_COMPL bta_gattc_proc_other_indication(p_clcb, op, p_data, ¬ify); } } else { - /* No app registered for this handle: drop the PDU, but log it - * so the common "registered a wrong handle" bug is visible - * instead of silently failing. */ - APPL_TRACE_WARNING("drop %s, handle 0x%04x not registered", - (op == GATTC_OPTYPE_INDICATION) ? "ind" : "notif", - handle); + /* GATT stack broadcasts notif/ind to every client app; drop here + * when this gatt_if did not register. Only warn if no app at all + * registered for the handle (likely wrong handle). */ + if (!bta_gattc_any_notif_registry(p_srcb, ¬ify)) { + APPL_TRACE_WARNING("drop %s, handle 0x%04x not registered", + (op == GATTC_OPTYPE_INDICATION) ? "ind" : "notif", + handle); + } if (op == GATTC_OPTYPE_INDICATION) { GATTC_SendHandleValueConfirm(conn_id, handle); } diff --git a/components/bt/host/bluedroid/bta/gatt/bta_gattc_utils.c b/components/bt/host/bluedroid/bta/gatt/bta_gattc_utils.c index 1786835e330..a0342514a3f 100644 --- a/components/bt/host/bluedroid/bta/gatt/bta_gattc_utils.c +++ b/components/bt/host/bluedroid/bta/gatt/bta_gattc_utils.c @@ -612,6 +612,29 @@ BOOLEAN bta_gattc_check_notif_registry(tBTA_GATTC_RCB *p_clreg, tBTA_GATTC_SERV return FALSE; } + +/******************************************************************************* +** +** Function bta_gattc_any_notif_registry +** +** Description check if any GATT client app registered for the notification. +** +** Returns TRUE if any app registered, FALSE otherwise. +** +*******************************************************************************/ +BOOLEAN bta_gattc_any_notif_registry(tBTA_GATTC_SERV *p_srcb, tBTA_GATTC_NOTIFY *p_notify) +{ + UINT8 i; + + for (i = 0; i < BTA_GATTC_CL_MAX; i++) { + if (bta_gattc_cb.cl_rcb[i].in_use && + bta_gattc_check_notif_registry(&bta_gattc_cb.cl_rcb[i], p_srcb, p_notify)) { + return TRUE; + } + } + return FALSE; +} + /******************************************************************************* ** ** Function bta_gattc_clear_notif_registration diff --git a/components/bt/host/bluedroid/bta/gatt/include/bta_gattc_int.h b/components/bt/host/bluedroid/bta/gatt/include/bta_gattc_int.h index e74b5759ee7..277d2b267cf 100644 --- a/components/bt/host/bluedroid/bta/gatt/include/bta_gattc_int.h +++ b/components/bt/host/bluedroid/bta/gatt/include/bta_gattc_int.h @@ -520,6 +520,7 @@ extern BOOLEAN bta_gattc_enqueue(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_dat extern BOOLEAN bta_gattc_uuid_compare (const tBT_UUID *p_src, const tBT_UUID *p_tar, BOOLEAN is_precise); extern BOOLEAN bta_gattc_check_notif_registry(tBTA_GATTC_RCB *p_clreg, tBTA_GATTC_SERV *p_srcb, tBTA_GATTC_NOTIFY *p_notify); +extern BOOLEAN bta_gattc_any_notif_registry(tBTA_GATTC_SERV *p_srcb, tBTA_GATTC_NOTIFY *p_notify); extern BOOLEAN bta_gattc_mark_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR_PTR remote_bda, BOOLEAN add, BOOLEAN is_listen); extern BOOLEAN bta_gattc_check_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, UINT8 role); extern UINT8 bta_gattc_num_reg_app(void);