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).