Overview

Android系统通过跟踪设备组件状态变化来收集电池使用统计信息,如Wi-Fi、蜂窝网络、蓝牙、GPS、显示屏和CPU等。电池使用统计数据记录在电池状态服务中,并在重启时保留。设备制造商需提供组件功率配置文件,定义组件电流消耗和长期电池损耗。功率配置文件用于估算不同组件的电池消耗,例如显示屏亮度和CPU运行速度对电池的影响。这些数据用于评估应用程序的电池消耗并进行排名。

Power Profiles for Android

Battery use information is derived from battery use statistics and power profile values.

Battery use statistics

The framework automatically determines battery use statistics by tracking how long device components spend in different states. As components (Wi-Fi chipset, cellular radio, Bluetooth, GPS, display, CPU) change states (OFF/ON, idle/full power, low/high brightness, etc.), the controlling service reports to the framework BatteryStats service. BatteryStats collects information over time and stores it for use across reboots. The service doesn’t track battery current draw directly, but instead collects timing information that can be used to approximate battery consumption by different components.

The framework gathers statistics using the following methods:

  • Push. Services aware of component changes push state changes to the BatteryStats service.
  • 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.

Resource consumption is associated with the application using the resource. When multiple applications simultaneously use a resource (such as wakelocks that prevent the system from suspending), the framework spreads consumption across those applications, although not necessarily equally.

To avoid losing use statistics for a shutdown event, which may indicate battery power consumption problems (i.e. shutdown occurs because the battery reached zero remaining capacity), the framework flashes statistics approximately every 30 minutes.

Battery use statistics are handled entirely by the framework and do not require OEM modifications.

Power profile values

Caution: Device manufacturers must provide a component power profile that defines the current consumption value for the component and the approximate battery drain caused by the component over time. This profile is defined in platform/frameworks/base/core/res/res/xml/power_profile.xml. For guidance on these settings, see Power Values.

Within a power profile, power consumption is specified in milliamps (mA) of current draw at a nominal voltage and can be a fractional value specified in microamps (uA). The value should be the mA consumed at the battery and not a value applicable to a power rail that does not correspond to current consumed from the battery.

For example, a display power profile specifies the mA of current required to keep the display on at minimum brightness and at maximum brightness. To determine the power cost (i.e the battery drained by the display component) of keeping the display on, the framework tracks the time spent at each brightness level, then multiplies those time intervals by an interpolated display brightness cost.

The framework also multiplies the CPU time for each application by the mA required to run the CPU at a specific speed. This calculation establishes a comparative ranking of how much battery an application consumes by executing CPU code (time as the foreground app and total time including background activity are reported separately).

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值