Thanks to visit codestin.com
Credit goes to github.com

Skip to content

android / p4android: BleakClient connect() broken when service characteristics have descriptors #1803

@jgruen

Description

@jgruen

See pull request #1804.

BleakClient.connect() fails in the p4android backend with the following Exception (when await client.connect() is run under try/except -- more complete log below):

08-07 12:53:37.375  7336  7490 I python  : Traceback (most recent call last):
...
08-07 12:53:37.375  7336  7490 I python  :   File "/PROJECT/arm64-v8a/bleak/__init__.py", line 566, in connect
08-07 12:53:37.375  7336  7490 I python  :   File "/PROJECT/arm64-v8a/bleak/backends/p4android/client.py", line 120, in connect
08-07 12:53:37.375  7336  7490 I python  :   File "/PROJECT/arm64-v8a/bleak/backends/p4android/client.py", line 292, in _get_services
08-07 12:53:37.375  7336  7490 I python  : AttributeError: 'BleakClientP4Android' object has no attribute 'obj'

This appears to have originated in Pull Request #1763.

With os.environ["BLEAK_LOGGING"] = "1", the above error is preceded with:

08-07 12:53:37.355  7336  7490 I python  : 2025-08-07 12:53:37,355 bleak.backends.p4android.client MainThread DEBUG: Got exception 'BleakClientP4Android' object has no attribute 'obj'; trying to disconnect
08-07 12:53:37.355  7336  7490 I python  : [DEBUG  ] Got exception 'BleakClientP4Android' object has no attribute 'obj'; trying to disconnect
08-07 12:53:37.355  7336  7490 I python  : 2025-08-07 12:53:37,355 bleak.backends.p4android.client MainThread DEBUG: Disconnecting from BLE device...
08-07 12:53:37.355  7336  7490 I python  : [DEBUG  ] Disconnecting from BLE device...
08-07 12:53:37.355  7336  7490 I python  : 2025-08-07 12:53:37,355 bleak.backends.p4android.utils MainThread DEBUG: Waiting for android api onConnectionStateChange
08-07 12:53:37.356  7336  7490 I python  : [DEBUG  ] Waiting for android api onConnectionStateChange
08-07 12:53:37.356  7336  7490 D BluetoothGatt: cancelOpen() - device: xx:xx:xx:xx:10:36
08-07 12:53:37.359  3164  3559 I bt_btif_gattc: system/btif/src/btif_gatt_client.cc:392 btif_gattc_close_impl: client_if=78, conn_id=590, address=xx:xx:xx:xx:10:36
08-07 12:53:37.359  3164  3511 I gatt_api: system/stack/gatt/gatt_api.cc:1567 GATT_Disconnect: conn_id=590
08-07 12:53:37.359  3164  3511 I bluetooth: system/stack/gatt/gatt_main.cc:336 gatt_update_app_hold_link_status: removed gatt_if=78
08-07 12:53:37.359  3164  3511 I bluetooth: system/stack/eatt/eatt_impl.h:879 disconnect: Device: xx:xx:xx:xx:10:36, cid: 0xffff
08-07 12:53:37.359  3164  3511 W bluetooth: system/stack/eatt/eatt_impl.h:883 disconnect: no eatt device found
08-07 12:53:37.359  3164  3511 I bluetooth: system/stack/gatt/gatt_main.cc:399 gatt_update_app_use_link_flag: GATT fixed channel is no longer useful, start link idle timer for 1 seconds
08-07 12:53:37.360  3164  3511 I gatt_api: system/stack/gatt/gatt_api.cc:1210 GATT_SetIdleTimeout: idle_timeout=1, is_active=false, status=true (1-OK 0-not performed)
08-07 12:53:37.360  3164  3511 E bt_bta_gattc: system/bta/gatt/bta_gattc_utils.cc:583 bta_gattc_mark_bg_conn: unable to find the bg connection mask for bd_addr=xx:xx:xx:xx:10:36
08-07 12:53:37.363  7336  7488 D BluetoothGatt: onClientConnectionState() - status=0 clientIf=78 connected=false device=XX:XX:XX:XX:10:36
08-07 12:53:37.363  7336  7488 D BluetoothGatt: unregisterApp() - mClientIf=78
08-07 12:53:37.367  3164  3511 I gatt_api: system/stack/gatt/gatt_api.cc:1295 GATT_Deregister: gatt_if=78
08-07 12:53:37.367  3164  3511 W bluetooth: system/stack/gatt/gatt_main.cc:332 gatt_update_app_hold_link_status: attempt to remove non-existing gatt_if=78
08-07 12:53:37.367  3164  3511 I bluetooth: system/stack/gatt/gatt_main.cc:369 gatt_update_app_use_link_flag: App status is not updated for gatt_if=78
08-07 12:53:37.367  3164  3511 W bluetooth: system/stack/gatt/gatt_main.cc:332 gatt_update_app_hold_link_status: attempt to remove non-existing gatt_if=78
08-07 12:53:37.367  3164  3511 I bluetooth: system/stack/gatt/gatt_main.cc:369 gatt_update_app_use_link_flag: App status is not updated for gatt_if=78
08-07 12:53:37.367  3164  3511 W bluetooth: system/stack/gatt/gatt_main.cc:332 gatt_update_app_hold_link_status: attempt to remove non-existing gatt_if=78
08-07 12:53:37.367  3164  3511 I bluetooth: system/stack/gatt/gatt_main.cc:369 gatt_update_app_use_link_flag: App status is not updated for gatt_if=78
08-07 12:53:37.369  7336  7490 I python  : 2025-08-07 12:53:37,369 bleak.backends.p4android.utils MainThread DEBUG: Java state transfer onConnectionStateChange error=None data=(0,)
08-07 12:53:37.370  7336  7490 I python  : [DEBUG  ] Java state transfer onConnectionStateChange error=None data=(0,)
08-07 12:53:37.370  7336  7490 I python  : 2025-08-07 12:53:37,370 bleak.backends.p4android.utils MainThread DEBUG: onConnectionStateChange succeeded ()
08-07 12:53:37.371  7336  7490 I python  : [DEBUG  ] onConnectionStateChange succeeded ()
08-07 12:53:37.371  7336  7490 D BluetoothGatt: close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions