自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
电源管理
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
电池续航时间是用户长期以来一直关注的问题。为了延长电池续航时间,Android 不断添加新功能,帮助平台优化应用和设备在非充电状态下的行为。
Android 提供以下电池续航时间增强功能:
-
应用限制。平台可以提示哪些应用会对电池续航时间产生不利影响,以便用户可以对这些应用施加限制,防止它们消耗资源。默认情况下,应用不会在后台受到限制。
- 应用待机模式。平台会使未使用的应用进入应用待机模式,从而暂时限制此类应用访问网络,并延迟其同步和作业。
-
低电耗模式。如果用户长时间没有主动使用其设备(处于静止状态且屏幕已关闭),平台会使设备进入深度休眠状态(定期恢复正常操作)。此外,当用户关闭设备屏幕但仍处于移动状态时,Android 7.0 及更高版本还会启用低电耗模式,以触发一系列轻度优化。
- 限制 USB 备份和恢复期间的电力传输。执行 USB 备份或恢复时,请将
UsbPort
类的 enableLimitPowerTransfer
方法设置为 true
,以停用充电并限制电源。如需验证电源是否受限,请调用 UsbPortStatus
类的 isPowerTransferLimited
方法。当 isPowerTransferLimited
为 true
时,Android 设备会将耗电量减少为 0(或硬件允许的最低值),并将源电流限制为 0。仅当成对端口都支持 USB Power Delivery (PD) 规范时,才能强制执行来源电源限制。如需将耗电量恢复到默认状态,请将 enableLimitPowerTransfer
设置为 false
。当 USB 线断开连接时,系统也会返回默认状态。
-
豁免。默认情况下,预加载的系统应用和云消息传递服务通常能够获得豁免,不会进入应用待机模式和低电耗模式。应用开发者可以使用 intent 将这些设置应用于其应用。用户可以在“设置”菜单中豁免应用,使其无需进入应用待机模式和低电耗节电模式。
-
跟踪器。应用后台行为跟踪器会监控应用的前台和后台电池用量,以判断应用是否违反了某些政策。
豁免应用
您可以豁免应用,使其不受低电耗模式和应用待机模式的影响。豁免功能可能适用于下列使用情形:
警告:请勿为了规避测试和优化而豁免应用。不必要的豁免会削弱低电耗模式和应用待机模式的优势,且有损于用户体验,因此我们强烈建议尽可能不要进行此类豁免(因为这样做会让应用破坏平台对耗电量的有益控制)。如果用户开始对这些应用的耗电量感到不满,则会导致令人失望的糟糕体验(和针对该应用的负面评价)并引发客户支持问题。出于这些原因,我们强烈建议您不要豁免第三方应用,而仅豁免云消息传递服务或功能相似的应用。
默认情况下,被豁免的应用会在“设置”>“应用和通知”>“特殊应用权限”>“电池优化”中列出。该列表用于豁免应用,使其不会进入低电耗模式和应用待机模式。为使用户清楚知道哪些应用已被豁免,“设置”菜单必须显示所有被豁免的应用。
用户可以依次前往“设置”>“应用和通知”>“APP-NAME”>“电池”>“电池优化”,然后选择要关闭(或重新开启)优化的应用,以此来手动豁免应用。不过,对于系统映像中默认豁免的应用或服务,用户无法更改其豁免状态。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","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,["# Power management\n\nBattery life is a perennial user concern. To extend battery life, Android\ncontinually adds new features to help the platform optimize the off-charger\nbehavior of apps and devices.\n\nAndroid includes the following battery life enhancements:\n\n- [App restrictions](/docs/core/power/app_mgmt#app-restrictions). The platform can suggest apps that negatively affect battery life, so that users can choose to restrict those apps from consuming resources. Apps aren't background restricted by default.\n- [App standby](/docs/core/power/app_mgmt#app-standby). The platform can place unused apps in App standby mode, temporarily restricting network access and deferring syncs and jobs for those apps.\n- [Doze](/docs/core/power/platform_mgmt#doze). The platform can enter a state of deep sleep (periodically resuming normal operations) if users haven't actively used their device (screen off and stationary) for extended periods of time. Android 7.0 and higher also enables Doze to trigger a lighter set of optimizations when users turn off the device screen yet continue to move around.\n- Limiting power transfer during USB backup and restore. When performing a USB backup or restore, set the `UsbPort` class's `enableLimitPowerTransfer` method to `true` to disable charging and limit the sourcing power. To verify that power is limited, call `UsbPortStatus` class's `isPowerTransferLimited` method. When `isPowerTransferLimited` is `true`, the Android device reduces the power draw as a sink to 0 (or the lowest possible value allowed by hardware) and limits the source current to 0. Limiting source power can be enforced only when both port partners support USB power delivery (PD) specification. To return power usage to the defatult state, set `enableLimitPowerTransfer` to `false`. The default state is also returned when the USB cable is disconnected.\n- [Exemptions](#exempt-apps). Preloaded system apps and cloud messaging services are typically exempted from App standby and Doze by default. App developers can use intents to apply these settings to their apps. Users can exempt apps from App standby and Doze power-saving modes in the Settings menu.\n- [Trackers](/docs/core/power/trackers). App background behavior trackers monitor apps' foreground and background battery usage to determine if the apps violate some policy.\n\nExempt apps\n-----------\n\nYou can exempt apps from being subject to Doze or App standby.\nExemptions may be needed in the following use cases:\n\n- Device manufacturers using a cloud messaging platform other than [Firebase\n cloud messaging (FCM)](https://firebase.google.com/docs/cloud-messaging/)\n- Carrier using non-FCM cloud messaging platform\n- Third-party app using non-FCM cloud messaging platform\n\n**Warning:** Don't exempt apps to avoid testing\nand optimizing. Unnecessary exemptions undermine the benefits of Doze and App\nstandby and can compromise the user experience, so we strongly suggest\nminimizing such exemptions as they allow apps to defeat beneficial\ncontrols the platform has over power use. If users become unhappy about the\npower consumption of these apps, it can lead to frustration, bad experiences\n(and negative reviews for the app), and customer support questions. For these\nreasons, we strongly recommend that you don't exempt third-party apps\nand instead exempt only cloud messaging services or apps with similar\nfunctions.\n\nApps exempted by default are listed in **Settings \\\u003e App \\&\nNotifications \\\u003e Special app access \\\u003e Battery Optimization** . This list is\nused for exempting the app from both Doze and App standby modes. To provide\ntransparency to the user, the Settings menu **MUST** show all\nexempted apps.\n\nUsers can manually exempt apps using **Settings \\\u003e App \\& Notifications \\\u003e\n\u003cvar translate=\"no\"\u003eAPP-NAME\u003c/var\u003e \\\u003e Battery \\\u003e Battery Optimization** and then selecting the\napp to turn off (or back on) optimization. However, users can't change the except status of any\napp or service that is exempted by default in the system image."]]