r/androiddev • u/9_hamden • 15d ago
Article Android silently downgrades long-running BLE scans after 5 minutes: measurements, logcat and AOSP links
I’ve been fighting background BLE beacon scanning on Android and wrote up what I measured on a Samsung (Android 14, One UI 6.1). Short version:
- A filtered
LOW_LATENCYscan gets silently downgraded toLOW_POWERafterscan_timeout_millis: 300 s on my device (AOSP default was 30 min, 10 min on Android 15+). Detections dropped from ~80/min to ~10/min. No callback, no error, justMoving filtered scan client to downgraded scanin logcat. - An empty
ScanFilteris treated as no filter: with the screen off the scan is suspended and you get ~0 results. - The quota of 5 starts per 30 s: the 6th
startScanwas rejected, andonScanFailedwas never called. - With a Foreground Service, turning the screen off didn’t kill the scan by itself. The timeout did.
- Restarting the scan every 4 min through a single start counter, plus a silence watchdog, kept it at ~90/min with the screen on and ~48/min with the screen off.
Full write-up with code and AOSP links (my article): https://medium.com/@9hamden/your-android-ble-scan-quietly-dies-after-5-minutes-and-you-dont-even-know-it-5e603c493177
Curious what you see on your devices: what does adb shell device_config get bluetooth scan_timeout_millis return? Especially Pixel, Xiaomi and OnePlus.
0
Upvotes
18
u/_5er_ 15d ago
Isn't this known / expected behavior of doze mode?
7
u/ComfortablyBalanced You will pry XML Views from my cold dead hands 15d ago
BLE is by far one of the shittiest technologies I worked on programmatically. I don't know about other platforms; maybe it's specific to Android. Undefined behaviour, unexpected and unknown errors, and questionable API design are some of its common problems, not to mention edge cases. I suggest checking Punch Through's ultimate guide about BLE if you haven't already.
5
u/iain_1986 15d ago
This has been known for a long time now hasn't it?
At least the "6ths scan in 30 seconds" being silently rejected but your app has no clue (it just looks like nothing is found). That's been there since android 12 or something hasn't it?
11
u/kosiarska 15d ago
The only thing you really need to do is to pay attention to release notes of each system. I know this fact for years.