Reputation: 2070
I slightly modified this app :https://github.com/commonsguy/cw-omnibus/tree/master/JobScheduler
It set alarms using setExactAndAllowWhileIdle and schedules an alarm to go off every 1 minute and log it.
According to Doze documentation, if this app is running while the phone is in Doze mode, only one alarm should be going off per 15 minutes. I'm not seeing that behavior .
On a a nexus 5 running Android M. After starting the app and the whole alarm scheduling process, I put the phone into Doze using the provided abd commands...
adb shell dumpsys battery unplug adb shell dumpsys deviceidle step adb shell dumpsys deviceidle -h
...From the log, I have seen around 30 minutes of alarms going off once per minute, then finally they are 15 minutes apart for about an hour. Then back to once per minute, and then back to 15 minutes apart. The phone was completely undisturbed during the test.
Does anyone know why this is? I was under the impression that the phone would immediately be in Doze mode after those adb commands , and that the alarms would be going off 15 minutes apart from the start.
Thanks for your help.
Upvotes: 4
Views: 1747
Reputation: 1005
The rate limit for setExactAndAllowWhileIdle
is different when the device is in idle mode. I'm guessing it's taking you 30 minutes for your phone to enter idle mode via Doze, at which point you'll be limited to calling setExactAndAllowWhileIdle
once every 15 minutes.
In Doze mode, your phone will wake up periodically for an Idle Maintenance period of up to 10 minutes. During those 10 minutes it will wake up from idle mode and your rate limit will be adjusted to once every minute. After the maintenance window ends, you're seeing it go back to once every 15 minutes.
The Idle Maintenance windows are described in the docs: http://developer.android.com/training/monitoring-device-state/doze-standby.html#understand_doze
Upvotes: 1
Reputation: 13397
For one thing, the relevant adb command docs are incomplete, as you noted in the link to ISSUE 2930.
The following command merely prints usage info:
adb shell dumpsys deviceidle -h
The following command will display the current state including the prerequisites (enabled, not moving, not charging, screen off) for getting into IDLE:
adb shell dumpsys deviceidle
Settings:
...
Whitelist (except idle) system apps:
...
Whitelist (except idle) all app ids:
...
mEnabled=true
mForceIdle=false
mSigMotionSensor=null
mCurDisplay=...
mScreenOn=false
mCharging=false
mSigMotionActive=false
mState=INACTIVE
That shows whether you need to do more setup. E.g. it seems to take 2 or 3 taps on the emulator's power button to get mScreenOn=false
.
The following command steps towards IDLE mode, but ISSUE 2930 explains that you need to step multiple times to get to INACTIVE, IDLE_PENDING, SENSING, then IDLE:
adb shell dumpsys deviceidle step
The following command will force it into idle:
adb shell dumpsys deviceidle force-idle
BTW the developer docs on Doze and App Standby were improved recently.
Upvotes: 1