FileDocCategorySizeDatePackage
PowerProfile.javaAPI DocAndroid 5.1 API9973Thu Mar 12 22:22:10 GMT 2015com.android.internal.os

PowerProfile

public class PowerProfile extends Object
Reports power consumption values for various device activities. Reads values from an XML file. Customize the XML file for different devices. [hidden]

Fields Summary
public static final String
POWER_NONE
No power consumption, or accounted for elsewhere.
public static final String
POWER_CPU_IDLE
Power consumption when CPU is in power collapse mode.
public static final String
POWER_CPU_AWAKE
Power consumption when CPU is awake (when a wake lock is held). This should be 0 on devices that can go into full CPU power collapse even when a wake lock is held. Otherwise, this is the power consumption in addition to POWERR_CPU_IDLE due to a wake lock being held but with no CPU activity.
public static final String
POWER_CPU_ACTIVE
Power consumption when CPU is in power collapse mode.
public static final String
POWER_WIFI_SCAN
Power consumption when WiFi driver is scanning for networks.
public static final String
POWER_WIFI_ON
Power consumption when WiFi driver is on.
public static final String
POWER_WIFI_ACTIVE
Power consumption when WiFi driver is transmitting/receiving.
public static final String
POWER_GPS_ON
Power consumption when GPS is on.
public static final String
POWER_BLUETOOTH_ON
Power consumption when Bluetooth driver is on.
public static final String
POWER_BLUETOOTH_ACTIVE
Power consumption when Bluetooth driver is transmitting/receiving.
public static final String
POWER_BLUETOOTH_AT_CMD
Power consumption when Bluetooth driver gets an AT command.
public static final String
POWER_SCREEN_ON
Power consumption when screen is on, not including the backlight power.
public static final String
POWER_RADIO_ON
Power consumption when cell radio is on but not on a call.
public static final String
POWER_RADIO_SCANNING
Power consumption when cell radio is hunting for a signal.
public static final String
POWER_RADIO_ACTIVE
Power consumption when talking on the phone.
public static final String
POWER_SCREEN_FULL
Power consumption at full backlight brightness. If the backlight is at 50% brightness, then this should be multiplied by 0.5
public static final String
POWER_AUDIO
Power consumed by the audio hardware when playing back audio content. This is in addition to the CPU power, probably due to a DSP and / or amplifier.
public static final String
POWER_VIDEO
Power consumed by any media hardware when playing back video content. This is in addition to the CPU power, probably due to a DSP.
public static final String
POWER_FLASHLIGHT
Power consumption when camera flashlight is on.
public static final String
POWER_CPU_SPEEDS
public static final String
POWER_WIFI_BATCHED_SCAN
Power consumed by wif batched scaning. Broken down into bins by Channels Scanned per Hour. May do 1-720 scans per hour of 1-100 channels for a range of 1-72,000. Going logrithmic (1-8, 9-64, 65-512, 513-4096, 4097-)!
public static final String
POWER_BATTERY_CAPACITY
Battery capacity in milliAmpHour (mAh).
static final HashMap
sPowerMap
private static final String
TAG_DEVICE
private static final String
TAG_ITEM
private static final String
TAG_ARRAY
private static final String
TAG_ARRAYITEM
private static final String
ATTR_NAME
Constructors Summary
public PowerProfile(android.content.Context context)


       
        // Read the XML file for the given profile (normally only one per
        // device)
        if (sPowerMap.size() == 0) {
            readPowerValuesFromXml(context);
        }
    
Methods Summary
public doublegetAveragePower(java.lang.String type)
Returns the average current in mA consumed by the subsystem

param
type the subsystem type
return
the average current in milliAmps.

        if (sPowerMap.containsKey(type)) {
            Object data = sPowerMap.get(type);
            if (data instanceof Double[]) {
                return ((Double[])data)[0];
            } else {
                return (Double) sPowerMap.get(type);
            }
        } else {
            return 0;
        }
    
public doublegetAveragePower(java.lang.String type, int level)
Returns the average current in mA consumed by the subsystem for the given level.

param
type the subsystem type
param
level the level of power at which the subsystem is running. For instance, the signal strength of the cell network between 0 and 4 (if there are 4 bars max.) If there is no data for multiple levels, the level is ignored.
return
the average current in milliAmps.

        if (sPowerMap.containsKey(type)) {
            Object data = sPowerMap.get(type);
            if (data instanceof Double[]) {
                final Double[] values = (Double[]) data;
                if (values.length > level && level >= 0) {
                    return values[level];
                } else if (level < 0) {
                    return 0;
                } else {
                    return values[values.length - 1];
                }
            } else {
                return (Double) data;
            }
        } else {
            return 0;
        }
    
public doublegetBatteryCapacity()
Returns the battery capacity, if available, in milli Amp Hours. If not available, it returns zero.

return
the battery capacity in mAh

        return getAveragePower(POWER_BATTERY_CAPACITY);
    
public intgetNumSpeedSteps()
Returns the number of speeds that the CPU can be run at.

return

        Object value = sPowerMap.get(POWER_CPU_SPEEDS);
        if (value != null && value instanceof Double[]) {
            return ((Double[])value).length;
        }
        return 1; // Only one speed
    
private voidreadPowerValuesFromXml(android.content.Context context)

        int id = com.android.internal.R.xml.power_profile;
        XmlResourceParser parser = context.getResources().getXml(id);
        boolean parsingArray = false;
        ArrayList<Double> array = new ArrayList<Double>();
        String arrayName = null;

        try {
            XmlUtils.beginDocument(parser, TAG_DEVICE);

            while (true) {
                XmlUtils.nextElement(parser);

                String element = parser.getName();
                if (element == null) break;

                if (parsingArray && !element.equals(TAG_ARRAYITEM)) {
                    // Finish array
                    sPowerMap.put(arrayName, array.toArray(new Double[array.size()]));
                    parsingArray = false;
                }
                if (element.equals(TAG_ARRAY)) {
                    parsingArray = true;
                    array.clear();
                    arrayName = parser.getAttributeValue(null, ATTR_NAME);
                } else if (element.equals(TAG_ITEM) || element.equals(TAG_ARRAYITEM)) {
                    String name = null;
                    if (!parsingArray) name = parser.getAttributeValue(null, ATTR_NAME);
                    if (parser.next() == XmlPullParser.TEXT) {
                        String power = parser.getText();
                        double value = 0;
                        try {
                            value = Double.valueOf(power);
                        } catch (NumberFormatException nfe) {
                        }
                        if (element.equals(TAG_ITEM)) {
                            sPowerMap.put(name, value);
                        } else if (parsingArray) {
                            array.add(value);
                        }
                    }
                }
            }
            if (parsingArray) {
                sPowerMap.put(arrayName, array.toArray(new Double[array.size()]));
            }
        } catch (XmlPullParserException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            parser.close();
        }