Idle mode is a state where the phone has no network connectivity and apps are temporarily suspended. Idle mode gets triggered by one of two ways: an asleep, still, unplugged phone (Doze mode), and when an app has not been opened in a significant amount of time (App Standby Mode). During idle mode via Doze, the phone will wake up periodically for a short amount of time, allowing apps to run and use network connectivity. Using several different methods outlined below, it is possible to wake apps up during idle mode outside of these maintenance windows.
1 hour of being still after the screen turns off.
TBD
While the phone Dozes, it will wake up periodically to allow apps to do work and to update information with network connectivity. The longer the phone dozes, the longer the time between these maintenance windows.
- Each wakeup lasts for 5-10 minutes
- Wakeups send a
DEVICE_IDLE_MODE_CHANGED
broadcast so we can track when the app has entered or exited idle mode. (https://developer.android.com/reference/android/os/PowerManager.html#ACTION_DEVICE_IDLE_MODE_CHANGED) - First window is one hour after entering idle mode (see below)
Time between wakeups after entering idle mode:
- 1 hour
- 2 hours
- 4 hours
- 6 hours (continues at 6 hour intervals)
# App behavior during idle mode It seems as if any running processes are allowed to finish during idle mode. However, the OS does not provide network connectivity, ignores wakelocks, and doesn't allow the running of Alarms, JobScheduler jobs, and sync adapters.
Deceptively, trying to detect network connectivity through the ConnectivityManager
is unreliable. It may tell you that the appp has network connectivity when it in fact does not.
Related: https://code.google.com/p/android-developer-preview/issues/detail?id=3164
Detect when the app enters/exits idle mode due to Doze
The OS will send a DEVICE_IDLE_MODE_CHANGED
broadcast so we can track when the app has entered or exited idle mode.
Note: This broadcast will be sent when the device occasionally starts or ends the 10 minute idle maintenance window.
See: https://developer.android.com/reference/android/os/PowerManager.html#ACTION_DEVICE_IDLE_MODE_CHANGED)
Detect if the app is in idle mode
The isDeviceIdleMode()
method in the PowerManager allows you to check if the device is currently in idle mode due to Doze.
See: https://developer.android.com/reference/android/os/PowerManager.html#isDeviceIdleMode()
TBD
Note: apps in standby mode may return false
from isDeviceIdleMode()
# Methods to wake your app from idle ## set[Exact]AndAllowWhileIdle() Wakes up the _app_, providing 10 seconds of network connectivity. Idle mode does not change and other applications are not alerted to this wakeup.
- We can only call these a minimum of 15 minutes apart.
- It seems as if that restriction is lifted for when we just enter idle mode via Doze.
- Calling them closer than 15 minutes apart defaults to 15 minutes exactly.
When I tried to wake the app using this method, my wakelock was indefinite - the phone didn't go back into idle mode. It's worth noting that wakeups via this method will allow other apps to do work and use network access, at the expense of the current app's battery stats. Additionally, Android will wake up the phone a small period before the scheduled alarm—presumably to allow other apps to perform syncing and maintenance.
From where did you get the information about maintenance mode wakeup intervals: 1, 2, 4, 6 hours ..... ? I cannot find it anywhere in android documentation