I'm trying to test the behavior of our Android app when the OS goes in Doze mode. I'm using an emulator running Android API 23 (Revision 1). The application launches a Service through the AlarmManager using the method setInexactRepeating with type ELAPSED_REALTIME_WAKEUP. I set the alarm to fire approximately every three minutes (only for testing purposes). After several attempts (the official guide is very unclear) I succeed to put the emulator in IDLE state by locking the screen of the emulator and running dumpsys suggested commands. When the device is IDLE I'm still able to see the Service being launched by the alarm. This should not be the expected behavior. I was expecting the Alarm be stopped. Is this a bug? Or am I missing something?
Another nice feature of WorkManager is that it respects power-management features so that if a job is scheduled to run at a defined time and the device is in Doze at that time, WorkManager will try to run the task during a maintenance window if the constraints are met or after Doze is lifted.
Doze. Doze extends battery life by deferring app background CPU and network activity when a device is unused for long periods. Idle devices in Doze periodically enter a maintenance window, during which apps can complete pending work (syncs, jobs, etc.).
If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. In Doze mode, the system attempts to conserve battery by restricting apps' access to network and CPU-intensive services.
For test use code below.
adb shell dumpsys deviceidle enable
adb shell dumpsys battery unplug
adb shell dumpsys deviceidle step
adb shell dumpsys deviceidle force-idle
Use setAndAllowWhileIdle
for force smartphone wakeup.
In my case I use this:
if (android.os.Build.VERSION.SDK_INT > 22) {
am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
} else {
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender);
}
I believe that the expected is the Alarm be stopped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With