1

I have an active-monitoring healthcare application that needs to be synced with different BLE devices every 15min in order to collect vitals and essential data. For this, I am using a ForegroundService with a Notification, Additionally, I have taken the wake-locks, and unrestricted power plan for the app as well with 15 min Periodic WorkManager Job as a safety check which basically triggers the same ForegroundService if somehow service is killed while device goes to idle or doze mode.

Problem Most devices seem to be working fine, However, most Samsung, Huawei, and Xiaomi devices fail in doze mode. the sync window is increased by 30-120min.

Requirement I want devices to sync reliably even in doze mode. I want to know possible solutions which may achieve this goal. Since data is important for real-time monitoring and triage a Battery-Tradeoff is acceptable as opposed by DOZE mode. Is there any special permission or mechanism I can use to achieve this?

GeekWithGlasses
  • 572
  • 2
  • 12
  • 30
  • If your priority is to run on time, try working around Alarm Manager, not ideal, but works. – Goutham Jan 19 '23 at 16:53
  • @Goutham I tried, gets either gets deferred or canceled. – GeekWithGlasses Jan 19 '23 at 16:54
  • 1
    Are the devices consumer owned or corporate / business owned devices? If corporate / business owned then you may want to look at EMM solutions, Samsung Knox does have [a doze mode whitelist feature - `addPackageToBatteryOptimizationWhiteList`](https://docs.samsungknox.com/devref/knox-sdk/reference/com/samsung/android/knox/application/ApplicationPolicy.html) – Morrison Chang Jan 19 '23 at 17:29
  • I would rather always have an outstanding connection with autoConnect=true and let the remote device advertise every 15 minutes and create a connection, send its data, go back to idle for 15 minutes and repeat. Then the app will be woken up by the Bluetooth stack instead, and you don't have to rely on an Android timer. – Emil Jan 19 '23 at 17:38
  • @Emil can you elaborate last comment? Are you saying that autoConnect=true will wake up the app? I think the BLE scan frequency also gets paused on doze mode. – GeekWithGlasses Jan 19 '23 at 17:51
  • Sure. Any connection change event (connected/disconnected), GATT notification etc. will wake up the app and execute the corresponding callback immediately. You only need to make sure that the app process does not get killed, for example by having a Foreground Service running in the same app process as your Bluetooth callbacks. BLE scanning (listening to advertisements) works a bit differently though since the system then takes the foreground / background status etc. into account. You could however try to use the scan api that uses PendingIntents as well. – Emil Jan 20 '23 at 00:41

0 Answers0