Search code examples
androiddoze

Behaviour in Android Doze when using different Scheduler


I'm trying to optimize our app for Doze and AppStandBy and have implemented a test application to understand the behaviour of the system when using different background schedulers.

However I'm very confused about the behaviour when using AlarmManager and Observable.intervall().

AlarmManager

I have registered an alarm through an Activity and then brought the device via adb in Doze. The system behaves as expected, the alarm is not fired.

Rx-Observable.intervall

I have started a Service through an Activity and then brought the device via adb in Doze. The Service is NOT a foreground service. The system does not behave as expected in my eyes and the ticks are continuous delivered to the app.

To veryfy that the device was really in Doze I also reviewed the battery statistics with adb bugreport, and the historian tells me that the device was in Doze in that timespan.

Is there any documentation how the different schedulers work in Doze or AppStandBy?

Thanks for any advice.


Solution

  • The problem seems to be that adb keeps the CPU running (if the device is connected via usb) even if the device brought to doze by adb with the commands

    $ adb shell dumpsys battery unplug

    $ adb shell input keyevent KEYCODE_POWER

    adb shell dumpsys deviceidle step

    The interval timer scheduled by ScheduledThreadPoolExecutor (used by rxjava) seems not to be restricted in doze mode but alarms via AlarmManager do.