Search code examples
androidadbalarmmanageralarmandroid-6.0-marshmallow

Does the Android M Doze state have multiple states itself?


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.


Solution

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