Samsung SM-A546E Bluetooth in background odd behaviour

27 views Asked by At

This is not a coding issue. And this question might get downvoted for that reason.
A brief history
We have a BLe device that advertise every 20 milliseconds. The phone (iOS or android) connects to the device, discover services, read and write to selected characteristics.
Everything works very well for long time now. We even are able to scan, connect and read/write on background even if app is swiped off using background service on android or beacon monitor on iOS.
As part of our test, we bought couple of Samsung devices (*mentioned in the title*) to test latest SDK >= 33 changes and update the app accordingly;

What is the problem?
On the mentioned device, if user opens the app, make a BLe connection, read then write all good. Once user puts the app to background without even locking the screen, for let's say ~20-30 seconds then bring the app back to foreground write fails. Meaning, `writeCharacteristics` returns 0 but never response (*app expects response within 1 second*). and on the device side nothing received. We thought that might be missing permission or other changes on android 14, but No. Tested on other android 14 phones, it works very well. User puts the app to background, lock the screen for any period of time and come and always works.
What we have tried?
We are sure that the BLe connection is absolutely fine, the Ble device sees the phone and trigger certain actions depending on phone location (or RSSI)
To be able to figure out what is going on, and where is the problem is? We tried to force `disconnect`. If write fails or in our case "timeout", we disconnect calling `gatt.disconnect`. To our surprise, app receives both disconnect, and connect callbacks but `discoverServices` is not received even though app requests after connection. After 1 minute or 2 another disconnect and connect callback are received followed by `discoverServices` then everything is back to normal until the app is put again to background.

Questions:
  1. Does anyone encounter this behaviour? and if so do you know why or what is the trigger?
  2. If you have any info about this topic, please share documentations
  3. If you have seen this issue before, do you have any idea what might be the solution?


Thank you!

0

There are 0 answers