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

Services should be re-discovered once onServiceChanged is called #662

Closed
JonatanPlesko opened this issue Mar 28, 2024 · 2 comments · Fixed by #754
Closed

Services should be re-discovered once onServiceChanged is called #662

JonatanPlesko opened this issue Mar 28, 2024 · 2 comments · Fixed by #754
Milestone

Comments

@JonatanPlesko
Copy link

In API 31, onServiceChanged was added to BluetoothGattCallback, which Kable currently does not override and handle.

When this callback is called, Kable needs to rediscover services and turn on notifications/indications again. I am currently experiencing an issue where none of the previously set observers work as Android silently clears up all of the existing notification/indication registrations when this occurs - see L1141 in bta_gattc_act.cc.

I'm not sure if rediscovering services and re-enabling notifications/indications is sufficient in this scenario for everything to work properly, but I can confirm that manually calling BluetoothGatt#setCharacteristicNotification fixes my issue.

As for reproducing the issue, it should occur when the server changes one (or more) of its services while you're already connected to it and subscribed to some characteristics.

@twyatt
Copy link
Member

twyatt commented Mar 30, 2024

Thanks for reporting this! I'll try to find time soon to work on it.

The device you're experiencing this issue with, and testing with, does it happen to be a publicly available device? As I don't believe any of the devices I currently have perform a peripheral side service change that would trigger this.

If there isn't a publicly available device to test against, I'll probably end up just calling setCharacteristicNotification as you suggested.

@JonatanPlesko
Copy link
Author

Unfortunately, I am not using a publicly available device. It's probably possible to mock such behaviour on Android, but I haven't had the time to try.
BTW, I think calling BluetoothGatt#discoverServices also needs to happen; it's not relevant in my scenario since all of the services and characteristics I was subscribed to are still there, but I think that someone else could run into issues there.

@twyatt twyatt added this to the 0.35.0 milestone Sep 5, 2024
@twyatt twyatt linked a pull request Sep 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants