With the release of Android 6.0 (Marshmallow, API Level 23), Google introduced a smart power-saving feature called Doze Mode.
This feature helps extend battery life by restricting app activity when the device is idle for a certain period.
Let’s dive deep into how Doze works, when it gets activated, and how developers can test or adapt their apps for it.
What Is Android Doze Mode?
Doze Mode is a system-level battery optimization mechanism that minimizes background activity when the device is not in active use.
When Doze is active:
- Apps cannot execute code in the background.
- Network access is paused.
- Background syncs, alarms, and jobs are delayed until the next maintenance window.
The goal is simple — to save battery by allowing only essential system functions to run.
When Does Doze Activate?
Doze mode activates when the device meets the following conditions:
- The screen is off.
- The device is unplugged (not charging).
- The device has been stationary and idle for a preset period.
Once these conditions are met, the system gradually enters Doze Mode, restricting most app and network activities.
Android Versions Supporting Doze
- Introduced in: Android 6.0 (Marshmallow)
- API Level: 23 and above
Doze Mode has continued to evolve in newer Android versions, with enhanced background restrictions in Android 7.0+ (Nougat) and later.
What Is a Maintenance Window?
A Maintenance Window is a short period during which the system temporarily exits Doze Mode.
During this interval, apps can:
- Perform pending network operations
- Execute background jobs or syncs
- Trigger scheduled alarms
After the window closes, the device returns to Doze, and restrictions are re-applied until the next cycle.
Restrictions During Doze Mode
While in Doze, Android imposes several restrictions to conserve energy. These include:
- No network access (apps cannot send/receive data)
- Wake locks are ignored (apps cannot keep the CPU awake)
- Standard alarms are deferred until the next maintenance window
- No Wi-Fi scans or background syncing
- SyncAdapters and JobScheduler tasks won’t execute
However, you can still use special alarms that bypass Doze, such as:
setAndAllowWhileIdle()
setExactAndAllowWhileIdle()
These APIs let your app schedule critical tasks that must run even during Doze.
How to Test Doze Mode (Using ADB)
Developers can simulate Doze Mode behavior using ADB (Android Debug Bridge) commands.
Step 1: Force Device to Idle State
adb shell dumpsys deviceidle force-idle
Your app should now be offline — it cannot make network calls or run background code.
Step 2: Simulate App Standby
adb shell dumpsys battery unplug
adb shell am set-inactive true
This simulates the battery being unplugged and makes the app inactive, blocking background network activity.
Step 3: Bring App Back to Active State
adb shell am set-inactive false
adb shell am get-inactive
Once reactivated, your app can resume network operations normally.
Whitelisting an App from Doze
If your app requires continuous background operation — for example, health monitors, messaging apps, or alarm services — users can whitelist it to bypass Doze restrictions.
To whitelist manually:
- Open Settings → Battery
- Tap Battery Optimization
- Select Your App and choose Don’t Optimize
This allows your app to continue working even during Doze Mode.
Summary
| Feature | Description |
|---|---|
| Introduced in | Android 6.0 (Marshmallow), API 23+ |
| Purpose | Extend battery life by limiting background processes |
| Triggered when | Device is idle, stationary, and unplugged |
| Restricted actions | Network access, wakelocks, Wi-Fi scans, syncs, alarms |
| Maintenance window | Short intervals allowing temporary background execution |
| Testing method | Use ADB commands to simulate idle and standby states |
Reference
Official Android Developer Documentation:
https://developer.android.com
