To improve device battery life, Android can affect the device state by monitoring device use and wakefulness. The platform can enter a state of sleep to pause activities from running while the device is unused.
About 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.). Doze then resumes sleep for a longer period of time, followed by another maintenance window. The platform continues the Doze sleep/maintenance sequence, increasing the length of idle each time, until a maximum of a few hours of sleep time is reached. At all times, a device in Doze remains aware of motion and immediately leaves Doze if motion is detected.
Android 7.0 and higher extends Doze to trigger a lighter set of optimizations every time a user turns off the device screen, even when the user continues to move around, enabling longer-lasting battery life.
Critical system services are generally set up by device manufacturers to be exempt from Doze. Users can also exempt specific apps from Doze using the Settings menu. However, exempting apps may cause battery drain on the device. By default, Doze is disabled in AOSP; for details on enabling Doze, see Integrating Doze.
Doze requirements
Doze support requires that the device has a cloud messaging service, such as Firebase Cloud Messaging (FCM). External trigger events, such as cloud messages, can temporarily wake apps to do work while the device remains in Doze mode.
Full Doze support also requires a significant motion detector (SMD) on the device; however, the lightweight Doze mode in Android 7.0 and higher doesn't require an SMD. If Doze is enabled on a device that:
- Has an SMD, full Doze optimizations occur (includes lightweight optimizations).
- Doesn't have an SMD, only the lightweight Doze optimizations occur.
Doze lifecycle
Doze begins when the platform detects that the device is idle and ends when one or more exit criteria activities occur.
The platform detects that a device is idle when:
- Device is stationary (using SMD).
- Device screen is off for some amount of time.
Doze mode doesn't engage while a battery-powered device is plugged into a power charger.
During Doze
The platform attempts to keep the system in a sleep state, periodically resuming normal operations during a maintenance window then returning the device to sleep for longer repeating periods. During sleep, the following restrictions are active:
- Apps aren't allowed network access.
- App wakelocks ignored.
- Alarms are deferred. Excludes alarm clock alarms and alarms set using
setAndAllowWhileIdle()
(limited to 1 per 15 minutes per app while in Doze). This exemption is intended for apps (such as Calendar) that must show event reminder notifications. - Wi-Fi scans aren't performed.
SyncAdapter
syncs andJobScheduler
jobs deferred until the next maintenance window.- Apps receiving SMS and MMS messages are put on a temporary whitelist so that they can complete their processing.
Exit
The platform exits the device from Doze when it detects:
- User interaction with device
- Device movement
- Device screen turns on
- Imminent AlarmClock alarm
Notifications don't cause the device to exit from Doze.
Android 7.0 and higher extends Doze by enabling a lightweight sleep mode during screen off, before the device is idle.
Figure 1. Doze modes for nonstationary and stationary devices.
Action | Doze | Lightweight Doze |
---|---|---|
Trigger | Screen off, on battery, stationary | Screen off, on battery (unplugged) |
Timing | Successively increasing periods with maintenance | Repeated N-minute periods with maintenance windows |
Restrictions | No network access, wake lock, or GPS/Wi-Fi scan; alarms and jobs/syncs deferred | No network access; jobs/syncs deferred except during maintenance windows |
Behavior | Only high-priority push notification messages received | All real-time messages (instant messages, calls, etc.) received; high-priority push notification message enables temporary network access |
Exit | Motion, screen on, or alarm clock alarm | Screen on |
Interaction with App Standby
- Time spent in Doze doesn't count toward App Standby.
- While the device is in Doze, idle apps are allowed to perform normal operations at least once a day.
Integrate Doze
When Doze is enabled, devices that support
SENSOR_TYPE_SIGNIFICANT_MOTION
perform full Doze optimizations (including lightweight optimizations);
devices without an SMD perform only lightweight Doze optimizations. Android
automatically selects the appropriate Doze optimizations and vendor
configuration isn't necessary.
To enable Doze for a device:
- Confirm that the device has a cloud messaging service installed.
- In the device overlay config file
overlay/frameworks/base/core/res/res/values/config.xml
, setconfig_enableAutoPowerModes
totrue
:<bool name="config_enableAutoPowerModes">true</bool>
In AOSP, this parameter is set tofalse
(Doze disabled) by default.
- Confirm that preloaded apps and services:
- Use the
power-saving
optimization guidelines. For details, see Testing and
optimizing apps.
OR
- Are exempted from Doze and App Standby. For details, see Exempting apps.
- Use the
power-saving
optimization guidelines. For details, see Testing and
optimizing apps.
- Confirm that the necessary services are exempted from Doze.
Tips
- If possible, use FCM for downstream messaging.
- If your users must see a notification right away, use a FCM high-priority message.
- Provide sufficient information within the initial message payload (to avoid unnecessary subsequent network access).
- Set critical alarms with
setAndAllowWhileIdle()
andsetExactAndAllowWhileIdle()
.
Test and optimize apps
Test all apps (especially preloaded apps) in Doze mode. For details, refer to Testing with Doze and App Standby.