Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 13 disconnects on first connect attempt to paired device after app restart #956

Open
xalepo4 opened this issue Mar 10, 2023 · 9 comments

Comments

@xalepo4
Copy link

xalepo4 commented Mar 10, 2023

Hello,

I'm using the plugin with ionic for connect to an EV charger application. On Android devices < 13 all is fine. On Android 13, I can pair with the device but when I close the app and open it again, always get Peripheral disconnected and I cannot get data from the device.

Any ideas?

Thanks

@peitschie
Copy link
Collaborator

Hi @xalepo4

How long are you leaving the app between closing and opening again? Are you able to confirm from the peripheral side that the phone is actually disconnecting?

There's been a few reports across both this plugin and others now of peripheral disconnect errors surfacing on Android 13, so clearly something has changed there in the OS.

As a fallback, are you able to retry the connection within the app by calling ble.connect again? In most of the applications I write this is my standard way of dealing with connections, which I find are often unreliable at best.

@peitschie
Copy link
Collaborator

Oh, if possible, grabbing a copy of the adb logs (e.g., adb logcat > debug.logs) may give us some extra information to work with.

@xalepo4
Copy link
Author

xalepo4 commented Mar 16, 2023

Ok, I collect logs today and I attach it here.

@xalepo4
Copy link
Author

xalepo4 commented Mar 16, 2023

Here I attach de logcat output when I try to connect with BLE device.

debug.txt

@xalepo4
Copy link
Author

xalepo4 commented Apr 13, 2023

Hello @peitschie , any new about the problem?

@peitschie
Copy link
Collaborator

@xalepo4 I'm away on a vacation at the moment. It'll be about 1.5 weeks before I have a chance to dig into this further.

@peitschie
Copy link
Collaborator

peitschie commented Apr 20, 2023

@xalepo4 Is it possible to grab an equivalent debug.txt log from the working version?

Just to confirm, when you say "close the app", are you meaning when you swipe it up to kill the app in the background, or merely pushing the app into the background, but leaving it running?

Looking through the logs, there seems to be this reason coming up a lot:

03-16 15:19:45.478 17834 18243 I bt_stack: [INFO:gatt_attr.cc(348)] gatt_connect_cback: remove untrusted client status, bda=80:1f:12:b2:7f:ea
03-16 15:19:45.481 17834 18243 I bluetooth: packages/modules/Bluetooth/system/stack/gap/gap_ble.cc:303 client_connect_cback: No active GAP service found for peer:xx:xx:xx:xx:7f:ea callback:Disconnected
03-16 15:19:45.481 17834 18243 I bt_bta_gattc: packages/modules/Bluetooth/system/bta/gatt/bta_gattc_act.cc:1249 bta_gattc_conn_cback: Disconnected att_id:3 addr:xx:xx:xx:xx:7f:ea, transport:BT_TRANSPORT_LE reason:GATT_CONN_TIMEOUT
03-16 15:19:45.481 17834 18243 I bt_bta_gattc: packages/modules/Bluetooth/system/bta/gatt/bta_gattc_act.cc:1249 bta_gattc_conn_cback: Disconnected att_id:4 addr:xx:xx:xx:xx:7f:ea, transport:BT_TRANSPORT_LE reason:GATT_CONN_TIMEOUT
03-16 15:19:45.481 17834 18243 I bt_bta_gattc: packages/modules/Bluetooth/system/bta/gatt/bta_gattc_act.cc:1249 bta_gattc_conn_cback: Disconnected att_id:5 addr:xx:xx:xx:xx:7f:ea, transport:BT_TRANSPORT_LE reason:GATT_CONN_TIMEOUT
03-16 15:19:45.481 17834 18243 I bt_bta_gattc: packages/modules/Bluetooth/system/bta/gatt/bta_gattc_act.cc:1249 bta_gattc_conn_cback: Disconnected att_id:6 addr:xx:xx:xx:xx:7f:ea, transport:BT_TRANSPORT_LE reason:GATT_CONN_TIMEOUT
03-16 15:19:45.481 17834 18243 I bt_bta_gattc: packages/modules/Bluetooth/system/bta/gatt/bta_gattc_act.cc:1249 bta_gattc_conn_cback: Disconnected att_id:7 addr:xx:xx:xx:xx:7f:ea, transport:BT_TRANSPORT_LE reason:GATT_CONN_TIMEOUT

There is no calls made by the plugin here as far as I can tell to cause the disconnect... it's Android itself deciding the GATT connection has dropped, and I don't really see how the plugin can change this.

I wonder if there's perhaps some difference in the default connection intervals between Android versions. E.g., on connection with this version, we find:

03-16 15:19:55.915 16036 16050 D BluetoothGatt: onConnectionUpdated() - Device=80:1F:12:B2:7F:EA interval=6 latency=0 timeout=500 status=0

These connection parameters control how long a drop-out in packets can be handled before the connection is judged as disconnected.

@xalepo4
Copy link
Author

xalepo4 commented May 9, 2023

After testing my application a lot, I discover that the problem occurs by some misterious behaviour in Android 13 when I try to connect with my device and the phone has an smartband paired. It seems that Android use the same handle for the smartband and my device. If no smartband paired, the connection works fine.

@peitschie
Copy link
Collaborator

That's extremely surprising! Impressive investigating skills 🙂 ... thanks for sharing the discovery.

@peitschie peitschie changed the title Android 13 disconnections Android 13 disconnects on first connect attempt to paired device after app restart Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants