Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android M (preview) Doze mode and AlarmManager

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?

like image 518
Francesco Mameli Avatar asked Oct 02 '15 09:10

Francesco Mameli


People also ask

Does Work Manager work in doze mode?

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.

What is Android doze tool?

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.).

How do I put my device in doze mode?

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.


1 Answers

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.

like image 91
Victor Gomes Avatar answered Oct 12 '22 21:10

Victor Gomes