Reputation: 15069
In android version 6.0+ assuming user has left the android somewhere, unplugged, power button pressed to lock it etc..
How much time does android spend in each state such as inactive, idle pending etc before it finally gets into idle ?
Now once in idle mode how long does it take to get into idle_maintenance mode and for how long does it stay there in idle_maintenance mode ?
Are these values constant or configurable or dependent on android version/manufacturer..
Please advise this is important for me to make important decisions about how to adjust my app for android ver 6.0/api 23+
Upvotes: 16
Views: 3364
Reputation: 9587
You should not concern yourself with when the device enters doze mode, rather with how does my app behave when the phone is in doze mode. To test this, you simply need to force your phone into doze and observe your app's behavior:
$ adb version
Android Debug Bridge version 1.0.32
Revision eac51f2bb6a8-android
$ adb shell dumpsys deviceidle | grep mState
mState=ACTIVE
$ adb shell dumpsys deviceidle force-idle
Now forced in to idle mode
$ adb shell dumpsys deviceidle | grep mState
mState=IDLE
Even better, you should test your application under all the various pre-doze states:
$ adb shell dumpsys deviceidle step
Stepped to: ACTIVE
$ adb shell dumpsys battery unplug # emulate unplugging the charging cable
$ for i in {1..5}; do adb shell dumpsys deviceidle step; done
Stepped to: IDLE_PENDING
Stepped to: SENSING
Stepped to: LOCATING
Stepped to: IDLE
Stepped to: IDLE_MAINTENANCE
# repeats IDLE and IDLE_MAINTENANCE forever
$ adb shell dumpsys battery reset
$ adb shell dumpsys deviceidle step
Stepped to: ACTIVE
You should test your app in all of the above states to ensure proper operation. See also the official documentation.
Now, if you insist on knowing the parameters of doze and maintenance, you should consult the full output of adb shell dumpsys deviceidle
. When the device is IDLE
, near the end of the output you will see:
mNextAlarmTime=+59m35s863ms
which derives from:
idle_to=+60m0s0ms
Also, unless the phone is woken up by the user, the next idle timeout is going to be larger, influenced by this parameter:
mNextIdleDelay=+2h0m0s0ms
etc. I am unaware of any official documentation about this, so take my interpretation with a grain of salt.
Upvotes: 12