[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Platform power management with Doze\n\nTo improve device battery life, Android can affect the device state by\nmonitoring device use and wakefulness. The platform can enter a state of\nsleep to pause activities from running while the device is unused.\n\nAbout Doze\n----------\n\nDoze extends battery life by deferring app background CPU and\nnetwork activity when a device is unused for long periods.\n\nIdle devices in Doze periodically enter a maintenance window, during which\napps can complete pending work (syncs, jobs, etc.). Doze then resumes\nsleep for a longer period of time, followed by another maintenance window. The\nplatform continues the Doze sleep/maintenance sequence, increasing the length of\nidle each time, until a maximum of a few hours of sleep time is reached. At all\ntimes, a device in Doze remains aware of motion and immediately leaves Doze\nif motion is detected.\n\nAndroid 7.0 and higher extends Doze to trigger a lighter set of optimizations\nevery time a user turns off the device screen, even when the user continues to\nmove around, enabling longer-lasting battery life.\n\nCritical system services are generally set up by device manufacturers to be\nexempt from Doze. Users can also exempt specific apps from Doze using the\nSettings menu. However, exempting apps may cause battery drain on the device.\nBy default, Doze is **disabled** in AOSP; for\ndetails on enabling Doze, see [Integrating Doze](#integrate-doze).\n\nDoze requirements\n-----------------\n\nDoze support requires that the device has a cloud messaging service, such as\n[Firebase\nCloud Messaging (FCM)](https://firebase.google.com/docs/cloud-messaging/). External trigger events, such as cloud messages,\ncan temporarily wake apps to do work while the device remains in Doze mode.\n\nFull Doze support also requires a\n[significant\nmotion detector (SMD)](/docs/core/interaction/sensors/sensor-types#significant_motion) on the device; however, the lightweight Doze mode in\nAndroid 7.0 and higher doesn't require an SMD. If Doze is enabled on a device\nthat:\n\n- Has an SMD, full Doze optimizations occur (includes lightweight optimizations).\n- Doesn't have an SMD, only the lightweight Doze optimizations occur.\n\nDoze lifecycle\n--------------\n\nDoze begins when the platform detects that the device is idle and\nends when one or more exit criteria activities occur.\n\nThe platform detects that a device is idle when:\n\n- Device is stationary (using SMD).\n- Device screen is off for some amount of time.\n\nDoze mode doesn't engage while a battery-powered device is plugged into a power charger.\n\nDuring Doze\n-----------\n\nThe platform attempts to keep the system in a sleep state, periodically\nresuming normal operations during a maintenance window then returning the device\nto sleep for longer repeating periods. During sleep, the following\nrestrictions are active:\n\n- Apps aren't allowed network access.\n- App wakelocks ignored.\n- 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.\n- Wi-Fi scans aren't performed.\n- `SyncAdapter` syncs and `JobScheduler` jobs deferred until the next maintenance window.\n- Apps receiving SMS and MMS messages are put on a temporary whitelist so that they can complete their processing.\n\n### Exit\n\nThe platform exits the device from Doze when it detects:\n\n- User interaction with device\n- Device movement\n- Device screen turns on\n- Imminent AlarmClock alarm\n\nNotifications don't cause the device to exit from Doze.\n\nAndroid 7.0 and higher extends Doze by enabling a lightweight sleep mode\nduring screen off, before the device is idle.\n\n**Figure 1.** Doze modes for nonstationary and stationary devices.\n\n| Action | Doze | Lightweight Doze |\n|--------------|---------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|\n| Trigger | Screen off, on battery, stationary | Screen off, on battery (unplugged) |\n| Timing | Successively increasing periods with maintenance | Repeated N-minute periods with maintenance windows |\n| 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 |\n| 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 |\n| Exit | Motion, screen on, or alarm clock alarm | Screen on |\n\nInteraction with App Standby\n----------------------------\n\n- Time spent in Doze doesn't count toward App Standby.\n- While the device is in Doze, idle apps are allowed to perform normal operations at least once a day.\n\nIntegrate Doze\n--------------\n\nWhen Doze is enabled, devices that support\n[`SENSOR_TYPE_SIGNIFICANT_MOTION`](/docs/core/interaction/sensors/sensor-types#significant_motion)\nperform full Doze optimizations (including lightweight optimizations);\ndevices without an SMD perform only lightweight Doze optimizations. Android\nautomatically selects the appropriate Doze optimizations and vendor\nconfiguration isn't necessary.\n\nTo enable Doze for a device:\n\n1. Confirm that the device has a cloud messaging service installed.\n2. In the device overlay config file `overlay/frameworks/base/core/res/res/values/config.xml`, set `config_enableAutoPowerModes` to `true`: \n\n ```\n \u003cbool name=\"config_enableAutoPowerModes\"\u003etrue\u003c/bool\u003e\n ```\n In AOSP, this parameter is set to `false` (Doze disabled) by default. \n3. Confirm that preloaded apps and services:\n - Use the [power-saving\n optimization guidelines](https://developer.android.com/training/monitoring-device-state/doze-standby.html). For details, see [Testing and\n optimizing apps](#test-apps).\n\n **OR**\n - Are exempted from Doze and App Standby. For details, see [Exempting apps](/docs/core/power/mgmt#exempt-apps).\n4. Confirm that the necessary services are exempted from Doze.\n\n### Tips\n\n- If possible, use FCM for [downstream\n messaging](https://firebase.google.com/docs/cloud-messaging/http-server-ref#send-downstream).\n- If your users must see a notification right away, use a [FCM\n high-priority message](https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message).\n- Provide sufficient information within the initial [message\n payload](https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages) (to avoid unnecessary subsequent network access).\n- Set critical alarms with [`setAndAllowWhileIdle()`](http://developer.android.com/reference/android/app/AlarmManager.html#setAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent)) and [`setExactAndAllowWhileIdle()`](http://developer.android.com/reference/android/app/AlarmManager.html#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent)).\n\n### Test and optimize apps\n\nTest all apps (especially preloaded apps) in Doze mode. For details, refer to\n[Testing\nwith Doze and App Standby](https://developer.android.com/training/monitoring-device-state/doze-standby.html#testing_doze_and_app_standby).\n| **Note:** MMS/SMS/telephony services function independently of Doze and always wake the client apps even while the device remains in Doze mode."]]