自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
Android 电源配置文件
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
电池使用信息来自电池使用统计信息和电源配置文件中的值。
电池使用情况统计信息
框架可通过跟踪设备组件在不同状态下维持的时间来自动确定电池使用情况统计信息。当组件(WLAN 芯片组、手机无线装置、蓝牙、GPS、显示屏和 CPU)状态发生改变(开/关、空闲/全功耗、低/高亮度等)时,控制服务会向框架中的 BatteryStats 服务报告状态改变信息。BatteryStats 会不断地收集信息,并存储这些信息以供在设备重新启动后继续使用。该服务不会直接跟踪电池中消耗的电流,而是通过收集计时信息来估算不同组件所消耗的电量。
该框架使用以下方法收集统计信息:
- 推送:服务察觉到组件状态发生变化后,会将状态变化推送到 BatteryStats 服务中。
- 拉取:对于应用使用的 CPU 等组件,框架会在转换点(例如启动 Activity 或停止 Activity)自动拉取数据以截取快照。
资源的消耗会关联到使用资源的应用。当多个应用同时使用某项资源(例如防止系统挂起的唤醒锁)时,框架会将资源消耗量分摊到这些应用上,但不一定会均分。
为了避免由于关机事件而丢失电池使用情况统计信息(这些统计信息可能表明存在电池功耗问题,比如由于电池电量耗尽而关机),框架大约每 30 分钟会将统计信息写入存储设备一次。
电池使用情况统计信息完全由框架处理,不需要原始设备制造商 (OEM) 做任何修改。
电源配置文件中的值
注意:设备制造商必须提供组件的电源配置文件,该配置文件定义了组件的电流消耗值以及该组件在一段时间内大概消耗的电量。有关此配置文件的定义,请查看 platform/frameworks/base/core/res/res/xml/power_profile.xml。要获得与这些设置相关的指导,请参阅电源值。
在电源配置文件中,功耗表示额定电压下的电流消耗量,单位为毫安 (mA),也可用微安 (uA) 表示(分数值)。该值应代表电池上消耗的电流,而非与电池消耗的电流不对应的某个电源轨的值。
例如,显示屏电源配置文件列出了当显示屏开启状态下保持最低亮度和最高亮度时需消耗的电流量 (mA)。为了确定显示屏常亮时所需的电源成本(即由显示屏组件所消耗的电池量),框架会跟踪在各个亮度级别下维持的时间,然后将这些时间间隔乘以通过插值算法计算出的显示亮度成本。
该框架还会将每个应用的 CPU 时间乘以在特定速度运行 CPU 所需的毫安量。通过该计算方法,您可以创建一个应用电池消耗量(执行 CPU 代码的消耗)的相对排名(应用在前台运行的时间和包含应用后台活动时间的总时间将分开进行报告)。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","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-03-26。"],[],[],null,["# Power profiles for Android\n\nBattery use information is derived from battery use statistics and power profile values.\n\nBattery use statistics\n----------------------\n\nThe framework automatically determines battery use statistics by tracking how long device\ncomponents spend in different states. As components (Wi-Fi chipset, cellular radio, Bluetooth, GPS,\ndisplay, CPU) change states (OFF/ON, idle/full power, low/high brightness, etc.), the controlling\nservice reports to the framework BatteryStats service. BatteryStats collects information over time\nand stores it for use across reboots. The service doesn't track battery current draw directly,\nbut instead collects timing information that can be used to approximate battery\nconsumption by different components.\n\nThe framework gathers statistics using the following methods:\n\n- **Push**. Services aware of component changes push state changes to the BatteryStats service.\n- **Pull**. For components such as the CPU use by apps, the framework automatically pulls the data at transition points (such as starting or stopping an activity) to take a snapshot.\n\nResource consumption is associated with the application using the resource. When multiple\napplications simultaneously use a resource (such as wakelocks that prevent the system from\nsuspending), the framework spreads consumption across those applications, although not necessarily\nequally.\n\nTo avoid losing use statistics for a shutdown event, which may indicate battery power\nconsumption problems (i.e. shutdown occurs because the battery reached zero remaining capacity),\nthe framework flashes statistics approximately every 30 minutes.\n\nBattery use statistics are handled entirely by the framework and do not require OEM\nmodifications.\n\nPower profile values\n--------------------\n\n**Caution:** Device manufacturers must provide a component power\nprofile that defines the current consumption value for the component and the approximate battery\ndrain caused by the component over time. This profile is defined in\n[platform/frameworks/base/core/res/res/xml/power_profile.xml](https://android.googlesource.com/platform/frameworks/base/+/android16-release/core/res/res/xml/power_profile.xml).\nFor guidance on these settings, see [Power Values](/docs/core/power/values).\n\nWithin a power profile, power consumption is specified in milliamps (mA) of current draw at a\nnominal voltage and can be a fractional value specified in microamps (uA). The value should be the\nmA consumed at the battery and not a value applicable to a power rail that does not correspond to\ncurrent consumed from the battery.\n\nFor example, a display power profile specifies the mA of current required to keep the display on\nat minimum brightness and at maximum brightness. To determine the power cost (i.e the battery\ndrained by the display component) of keeping the display on, the framework tracks the time spent at\neach brightness level, then multiplies those time intervals by an interpolated display brightness\ncost.\n\nThe framework also multiplies the CPU time for each application by the mA required to run the\nCPU at a specific speed. This calculation establishes a comparative ranking of how much battery an\napplication consumes by executing CPU code (time as the foreground app and total time including\nbackground activity are reported separately)."]]