Mobile Development 11 min read

Deep Dive into Android M Doze Mode: Concepts, Debugging, and Code Analysis

An extensive exploration of Android M’s Doze feature covers its evolution, activation conditions, restricted app behaviors, whitelist management, debugging commands, internal state machine, source code breakdown, network restrictions, GCM handling, and techniques for programmatically exiting Doze, offering developers practical insights for power‑saving optimization.

WeChat Client Technology Team
WeChat Client Technology Team
WeChat Client Technology Team
Deep Dive into Android M Doze Mode: Concepts, Debugging, and Code Analysis

Android M Doze Feature Research

On May 29, 2015, Google I/O introduced the Android M preview (API "MNC"), adding the Doze and App Standby power‑saving features. This article focuses on Doze, analyzing the Release 1 code and noting changes in Release 2. Documentation: https://developer.android.com/preview/behavior-changes.html#behavior-power

Doze Concept

Doze first appeared in Android 4.4 Wear (API 20) to describe a low‑power static display state. In Android M, Doze means an "IDLE" state allowing only limited background activity, effectively a pseudo‑background mode to improve battery life.

Conditions to Enter Doze

Screen off

No USB charging

Device stationary for a period

Restricted Functions in Doze

Network access is blocked, except high‑priority GCM messages

Wake locks are ignored

Alarms are blocked unless using setAlarmClock() or setAndAllowWhileIdle()

Wi‑Fi hotspot scanning stops

Sync and JobScheduler tasks are suspended

Whitelist

System services such as Google Play and GMS are whitelisted by default. Users can add or remove apps via Settings → Apps → Advanced → Ignore optimization.

Debugging

Use adb commands to force the device into Doze (IDLE) for testing. First disable charging mode, then run the battery service’s unplug command.

The "deviceidle" service implements Doze logic. Its state machine has five states: ACTIVE, INACTIVE, IDLE_PENDING, IDLE, and IDLE_MAINTENANCE (Release 2 adds SENSING between IDLE_PENDING and IDLE).

State Machine

The DeviceIdleController uses a BroadcastReceiver and listeners to drive state transitions based on alarms and external events such as charging or motion.

When the ACTION_STEP_IDLE_STATE alarm fires, the controller calls stepIdleStateLocked() to move between states.

External events (e.g., USB charging) trigger transitions back to ACTIVE via updateChargingLocked().

External Calls

DeviceIdleController does not expose a public API. It communicates with PowerManager, NetworkPolicyManager, BatteryStats, etc., via internal handlers.

Interface

The system provides the IDeviceIdleController AIDL interface; DeviceIdleController’s BinderService registers it under the name "deviceidle".

It defines seven methods for whitelist management and debugging.

Whitelist data is stored at "/data/system/deviceidle.xml".

Network Connectivity

In Doze, network connections are blocked for non‑whitelisted apps. A test thread shows openConnection hangs, and isAvailable() returns true while isConnected() is false.

ConnectivityService blocks network access based on per‑UID policies synchronized from NetworkPolicyManagerService.

NetworkPolicyManagerService returns RULE_REJECT_METERED for background traffic in Doze.

GCM

Google Cloud Messaging (GCM) is the recommended way for apps to receive messages during Doze. However, even after receiving a GCM push, subsequent network requests are still blocked, indicating a current limitation.

Exiting Doze Actively

Apps can exit Doze by triggering allowed events such as turning the screen on or vibrating.

1. Screen on – with WAKE_LOCK permission, call the appropriate API to wake the device.

2. Vibration – with VIBRATE permission, trigger a vibration to wake the device.

Conclusion

Doze imposes many restrictions but significantly improves battery life, especially during overnight standby. Developers must adapt their apps to this power‑saving mode while preserving functionality and user experience.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DebuggingAndroidpower managementDozeDeviceIdleController
WeChat Client Technology Team
Written by

WeChat Client Technology Team

Official account of the WeChat mobile client development team, sharing development experience, cutting‑edge tech, and little‑known stories across Android, iOS, macOS, Windows Phone, and Windows.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.