Loading core/java/com/android/internal/os/BatterySipper.java +20 −12 Original line number Original line Diff line number Diff line Loading @@ -73,14 +73,16 @@ public class BatterySipper implements Comparable<BatterySipper> { public double usagePowerMah; public double usagePowerMah; // Subsystem usage times. // Subsystem usage times. public long audioTimeMs; public long bluetoothRunningTimeMs; public long cameraTimeMs; public long cpuFgTimeMs; public long cpuTimeMs; public long cpuTimeMs; public long flashlightTimeMs; public long gpsTimeMs; public long gpsTimeMs; public long wifiRunningTimeMs; public long videoTimeMs; public long cpuFgTimeMs; public long wakeLockTimeMs; public long wakeLockTimeMs; public long cameraTimeMs; public long wifiRunningTimeMs; public long flashlightTimeMs; public long bluetoothRunningTimeMs; public long mobileRxPackets; public long mobileRxPackets; public long mobileTxPackets; public long mobileTxPackets; Loading @@ -102,15 +104,17 @@ public class BatterySipper implements Comparable<BatterySipper> { // Measured in mAh (milli-ampere per hour). // Measured in mAh (milli-ampere per hour). // These are included when summed. // These are included when summed. public double wifiPowerMah; public double audioPowerMah; public double bluetoothPowerMah; public double cameraPowerMah; public double cpuPowerMah; public double cpuPowerMah; public double wakeLockPowerMah; public double flashlightPowerMah; public double mobileRadioPowerMah; public double gpsPowerMah; public double gpsPowerMah; public double mobileRadioPowerMah; public double sensorPowerMah; public double sensorPowerMah; public double cameraPowerMah; public double videoPowerMah; public double flashlightPowerMah; public double wakeLockPowerMah; public double bluetoothPowerMah; public double wifiPowerMah; public enum DrainType { public enum DrainType { AMBIENT_DISPLAY, AMBIENT_DISPLAY, Loading Loading @@ -177,10 +181,12 @@ public class BatterySipper implements Comparable<BatterySipper> { totalPowerMah += other.totalPowerMah; totalPowerMah += other.totalPowerMah; usageTimeMs += other.usageTimeMs; usageTimeMs += other.usageTimeMs; usagePowerMah += other.usagePowerMah; usagePowerMah += other.usagePowerMah; audioTimeMs += other.audioTimeMs; cpuTimeMs += other.cpuTimeMs; cpuTimeMs += other.cpuTimeMs; gpsTimeMs += other.gpsTimeMs; gpsTimeMs += other.gpsTimeMs; wifiRunningTimeMs += other.wifiRunningTimeMs; wifiRunningTimeMs += other.wifiRunningTimeMs; cpuFgTimeMs += other.cpuFgTimeMs; cpuFgTimeMs += other.cpuFgTimeMs; videoTimeMs += other.videoTimeMs; wakeLockTimeMs += other.wakeLockTimeMs; wakeLockTimeMs += other.wakeLockTimeMs; cameraTimeMs += other.cameraTimeMs; cameraTimeMs += other.cameraTimeMs; flashlightTimeMs += other.flashlightTimeMs; flashlightTimeMs += other.flashlightTimeMs; Loading @@ -197,6 +203,7 @@ public class BatterySipper implements Comparable<BatterySipper> { wifiTxBytes += other.wifiTxBytes; wifiTxBytes += other.wifiTxBytes; btRxBytes += other.btRxBytes; btRxBytes += other.btRxBytes; btTxBytes += other.btTxBytes; btTxBytes += other.btTxBytes; audioPowerMah += other.audioPowerMah; wifiPowerMah += other.wifiPowerMah; wifiPowerMah += other.wifiPowerMah; gpsPowerMah += other.gpsPowerMah; gpsPowerMah += other.gpsPowerMah; cpuPowerMah += other.cpuPowerMah; cpuPowerMah += other.cpuPowerMah; Loading @@ -207,6 +214,7 @@ public class BatterySipper implements Comparable<BatterySipper> { flashlightPowerMah += other.flashlightPowerMah; flashlightPowerMah += other.flashlightPowerMah; bluetoothPowerMah += other.bluetoothPowerMah; bluetoothPowerMah += other.bluetoothPowerMah; screenPowerMah += other.screenPowerMah; screenPowerMah += other.screenPowerMah; videoPowerMah += other.videoPowerMah; proportionalSmearMah += other.proportionalSmearMah; proportionalSmearMah += other.proportionalSmearMah; totalSmearedPowerMah += other.totalSmearedPowerMah; totalSmearedPowerMah += other.totalSmearedPowerMah; } } Loading @@ -220,7 +228,7 @@ public class BatterySipper implements Comparable<BatterySipper> { public double sumPower() { public double sumPower() { totalPowerMah = usagePowerMah + wifiPowerMah + gpsPowerMah + cpuPowerMah + totalPowerMah = usagePowerMah + wifiPowerMah + gpsPowerMah + cpuPowerMah + sensorPowerMah + mobileRadioPowerMah + wakeLockPowerMah + cameraPowerMah + sensorPowerMah + mobileRadioPowerMah + wakeLockPowerMah + cameraPowerMah + flashlightPowerMah + bluetoothPowerMah; flashlightPowerMah + bluetoothPowerMah + audioPowerMah + videoPowerMah; totalSmearedPowerMah = totalPowerMah + screenPowerMah + proportionalSmearMah; totalSmearedPowerMah = totalPowerMah + screenPowerMah + proportionalSmearMah; return totalPowerMah; return totalPowerMah; Loading core/java/com/android/internal/os/BatteryStatsHelper.java +7 −0 Original line number Original line Diff line number Diff line Loading @@ -136,6 +136,7 @@ public class BatteryStatsHelper { PowerCalculator mCameraPowerCalculator; PowerCalculator mCameraPowerCalculator; PowerCalculator mFlashlightPowerCalculator; PowerCalculator mFlashlightPowerCalculator; PowerCalculator mMemoryPowerCalculator; PowerCalculator mMemoryPowerCalculator; PowerCalculator mMediaPowerCalculator; boolean mHasWifiPowerReporting = false; boolean mHasWifiPowerReporting = false; boolean mHasBluetoothPowerReporting = false; boolean mHasBluetoothPowerReporting = false; Loading Loading @@ -424,6 +425,11 @@ public class BatteryStatsHelper { } } mFlashlightPowerCalculator.reset(); mFlashlightPowerCalculator.reset(); if (mMediaPowerCalculator == null) { mMediaPowerCalculator = new MediaPowerCalculator(mPowerProfile); } mMediaPowerCalculator.reset(); mStatsType = statsType; mStatsType = statsType; mRawUptimeUs = rawUptimeUs; mRawUptimeUs = rawUptimeUs; mRawRealtimeUs = rawRealtimeUs; mRawRealtimeUs = rawRealtimeUs; Loading Loading @@ -560,6 +566,7 @@ public class BatteryStatsHelper { mCameraPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType); mCameraPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType); mFlashlightPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mFlashlightPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType); mStatsType); mMediaPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType); final double totalPower = app.sumPower(); final double totalPower = app.sumPower(); if (DEBUG && totalPower != 0) { if (DEBUG && totalPower != 0) { Loading core/java/com/android/internal/os/MediaPowerCalculator.java 0 → 100644 +61 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.os; import android.os.BatteryStats; /** * A {@link PowerCalculator} to calculate power consumed by audio and video hardware. * * Also see {@link PowerProfile#POWER_AUDIO} and {@link PowerProfile#POWER_VIDEO}. */ public class MediaPowerCalculator extends PowerCalculator { private static final int MS_IN_HR = 1000 * 60 * 60; private final double mAudioAveragePowerMa; private final double mVideoAveragePowerMa; public MediaPowerCalculator(PowerProfile profile) { mAudioAveragePowerMa = profile.getAveragePower(PowerProfile.POWER_AUDIO); mVideoAveragePowerMa = profile.getAveragePower(PowerProfile.POWER_VIDEO); } @Override public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs, long rawUptimeUs, int statsType) { // Calculate audio power usage, an estimate based on the average power routed to different // components like speaker, bluetooth, usb-c, earphone, etc. final BatteryStats.Timer audioTimer = u.getAudioTurnedOnTimer(); if (audioTimer == null) { app.audioTimeMs = 0; app.audioPowerMah = 0; } else { final long totalTime = audioTimer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000; app.audioTimeMs = totalTime; app.audioPowerMah = (totalTime * mAudioAveragePowerMa) / MS_IN_HR; } // Calculate video power usage. final BatteryStats.Timer videoTimer = u.getVideoTurnedOnTimer(); if (videoTimer == null) { app.videoTimeMs = 0; app.videoPowerMah = 0; } else { final long totalTime = videoTimer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000; app.videoTimeMs = totalTime; app.videoPowerMah = (totalTime * mVideoAveragePowerMa) / MS_IN_HR; } } } core/java/com/android/internal/os/PowerProfile.java +17 −10 Original line number Original line Diff line number Diff line Loading @@ -43,7 +43,7 @@ public class PowerProfile { */ */ public static final String POWER_NONE = "none"; public static final String POWER_NONE = "none"; /** /* * POWER_CPU_SUSPEND: Power consumption when CPU is in power collapse mode. * POWER_CPU_SUSPEND: Power consumption when CPU is in power collapse mode. * POWER_CPU_IDLE: Power consumption when CPU is awake (when a wake lock is held). This should * POWER_CPU_IDLE: Power consumption when CPU is awake (when a wake lock is held). This should * be zero on devices that can go into full CPU power collapse even when a wake * be zero on devices that can go into full CPU power collapse even when a wake Loading Loading @@ -84,7 +84,6 @@ public class PowerProfile { // Updated power constants. These are not estimated, they are real world // Updated power constants. These are not estimated, they are real world // currents and voltages for the underlying bluetooth and wifi controllers. // currents and voltages for the underlying bluetooth and wifi controllers. // // public static final String POWER_WIFI_CONTROLLER_IDLE = "wifi.controller.idle"; public static final String POWER_WIFI_CONTROLLER_IDLE = "wifi.controller.idle"; public static final String POWER_WIFI_CONTROLLER_RX = "wifi.controller.rx"; public static final String POWER_WIFI_CONTROLLER_RX = "wifi.controller.rx"; public static final String POWER_WIFI_CONTROLLER_TX = "wifi.controller.tx"; public static final String POWER_WIFI_CONTROLLER_TX = "wifi.controller.tx"; Loading Loading @@ -117,6 +116,7 @@ public class PowerProfile { /** /** * Power consumption when Bluetooth driver is on. * Power consumption when Bluetooth driver is on. * * @deprecated * @deprecated */ */ @Deprecated @Deprecated Loading @@ -124,6 +124,7 @@ public class PowerProfile { /** /** * Power consumption when Bluetooth driver is transmitting/receiving. * Power consumption when Bluetooth driver is transmitting/receiving. * * @deprecated * @deprecated */ */ @Deprecated @Deprecated Loading @@ -131,6 +132,7 @@ public class PowerProfile { /** /** * Power consumption when Bluetooth driver gets an AT command. * Power consumption when Bluetooth driver gets an AT command. * * @deprecated * @deprecated */ */ @Deprecated @Deprecated Loading Loading @@ -171,13 +173,13 @@ public class PowerProfile { * Power consumed by the audio hardware when playing back audio content. This is in addition * 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. * to the CPU power, probably due to a DSP and / or amplifier. */ */ public static final String POWER_AUDIO = "dsp.audio"; public static final String POWER_AUDIO = "audio"; /** /** * Power consumed by any media hardware when playing back video content. This is in addition * Power consumed by any media hardware when playing back video content. This is in addition * to the CPU power, probably due to a DSP. * to the CPU power, probably due to a DSP. */ */ public static final String POWER_VIDEO = "dsp.video"; public static final String POWER_VIDEO = "video"; /** /** * Average power consumption when camera flashlight is on. * Average power consumption when camera flashlight is on. Loading Loading @@ -409,6 +411,7 @@ public class PowerProfile { /** /** * Returns the number of memory bandwidth buckets defined in power_profile.xml, or a * Returns the number of memory bandwidth buckets defined in power_profile.xml, or a * default value if the subsystem has no recorded value. * default value if the subsystem has no recorded value. * * @return the number of memory bandwidth buckets. * @return the number of memory bandwidth buckets. */ */ public int getNumElements(String key) { public int getNumElements(String key) { Loading @@ -423,6 +426,7 @@ public class PowerProfile { /** /** * Returns the average current in mA consumed by the subsystem, or the given * Returns the average current in mA consumed by the subsystem, or the given * default value if the subsystem has no recorded value. * default value if the subsystem has no recorded value. * * @param type the subsystem type * @param type the subsystem type * @param defaultValue the value to return if the subsystem has no recorded value. * @param defaultValue the value to return if the subsystem has no recorded value. * @return the average current in milliAmps. * @return the average current in milliAmps. Loading @@ -439,6 +443,7 @@ public class PowerProfile { /** /** * Returns the average current in mA consumed by the subsystem * Returns the average current in mA consumed by the subsystem * * @param type the subsystem type * @param type the subsystem type * @return the average current in milliAmps. * @return the average current in milliAmps. */ */ Loading @@ -448,6 +453,7 @@ public class PowerProfile { /** /** * Returns the average current in mA consumed by the subsystem for the given level. * Returns the average current in mA consumed by the subsystem for the given level. * * @param type the subsystem type * @param type the subsystem type * @param level the level of power at which the subsystem is running. For instance, the * @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.) * signal strength of the cell network between 0 and 4 (if there are 4 bars max.) Loading @@ -474,6 +480,7 @@ public class PowerProfile { /** /** * Returns the battery capacity, if available, in milli Amp Hours. If not available, * Returns the battery capacity, if available, in milli Amp Hours. If not available, * it returns zero. * it returns zero. * * @return the battery capacity in mAh * @return the battery capacity in mAh */ */ public double getBatteryCapacity() { public double getBatteryCapacity() { Loading core/res/res/xml/power_profile.xml +2 −2 Original line number Original line Diff line number Diff line Loading @@ -36,8 +36,8 @@ <item name="wifi.on">0.1</item> <!-- ~3mA --> <item name="wifi.on">0.1</item> <!-- ~3mA --> <item name="wifi.active">0.1</item> <!-- WIFI data transfer, ~200mA --> <item name="wifi.active">0.1</item> <!-- WIFI data transfer, ~200mA --> <item name="wifi.scan">0.1</item> <!-- WIFI network scanning, ~100mA --> <item name="wifi.scan">0.1</item> <!-- WIFI network scanning, ~100mA --> <item name="dsp.audio">0.1</item> <!-- ~10mA --> <item name="audio">0.1</item> <!-- ~10mA --> <item name="dsp.video">0.1</item> <!-- ~50mA --> <item name="video">0.1</item> <!-- ~50mA --> <item name="camera.flashlight">0.1</item> <!-- Avg. power for camera flash, ~160mA --> <item name="camera.flashlight">0.1</item> <!-- Avg. power for camera flash, ~160mA --> <item name="camera.avg">0.1</item> <!-- Avg. power use of camera in standard usecases, ~550mA --> <item name="camera.avg">0.1</item> <!-- Avg. power use of camera in standard usecases, ~550mA --> <item name="gps.on">0.1</item> <!-- ~50mA --> <item name="gps.on">0.1</item> <!-- ~50mA --> Loading Loading
core/java/com/android/internal/os/BatterySipper.java +20 −12 Original line number Original line Diff line number Diff line Loading @@ -73,14 +73,16 @@ public class BatterySipper implements Comparable<BatterySipper> { public double usagePowerMah; public double usagePowerMah; // Subsystem usage times. // Subsystem usage times. public long audioTimeMs; public long bluetoothRunningTimeMs; public long cameraTimeMs; public long cpuFgTimeMs; public long cpuTimeMs; public long cpuTimeMs; public long flashlightTimeMs; public long gpsTimeMs; public long gpsTimeMs; public long wifiRunningTimeMs; public long videoTimeMs; public long cpuFgTimeMs; public long wakeLockTimeMs; public long wakeLockTimeMs; public long cameraTimeMs; public long wifiRunningTimeMs; public long flashlightTimeMs; public long bluetoothRunningTimeMs; public long mobileRxPackets; public long mobileRxPackets; public long mobileTxPackets; public long mobileTxPackets; Loading @@ -102,15 +104,17 @@ public class BatterySipper implements Comparable<BatterySipper> { // Measured in mAh (milli-ampere per hour). // Measured in mAh (milli-ampere per hour). // These are included when summed. // These are included when summed. public double wifiPowerMah; public double audioPowerMah; public double bluetoothPowerMah; public double cameraPowerMah; public double cpuPowerMah; public double cpuPowerMah; public double wakeLockPowerMah; public double flashlightPowerMah; public double mobileRadioPowerMah; public double gpsPowerMah; public double gpsPowerMah; public double mobileRadioPowerMah; public double sensorPowerMah; public double sensorPowerMah; public double cameraPowerMah; public double videoPowerMah; public double flashlightPowerMah; public double wakeLockPowerMah; public double bluetoothPowerMah; public double wifiPowerMah; public enum DrainType { public enum DrainType { AMBIENT_DISPLAY, AMBIENT_DISPLAY, Loading Loading @@ -177,10 +181,12 @@ public class BatterySipper implements Comparable<BatterySipper> { totalPowerMah += other.totalPowerMah; totalPowerMah += other.totalPowerMah; usageTimeMs += other.usageTimeMs; usageTimeMs += other.usageTimeMs; usagePowerMah += other.usagePowerMah; usagePowerMah += other.usagePowerMah; audioTimeMs += other.audioTimeMs; cpuTimeMs += other.cpuTimeMs; cpuTimeMs += other.cpuTimeMs; gpsTimeMs += other.gpsTimeMs; gpsTimeMs += other.gpsTimeMs; wifiRunningTimeMs += other.wifiRunningTimeMs; wifiRunningTimeMs += other.wifiRunningTimeMs; cpuFgTimeMs += other.cpuFgTimeMs; cpuFgTimeMs += other.cpuFgTimeMs; videoTimeMs += other.videoTimeMs; wakeLockTimeMs += other.wakeLockTimeMs; wakeLockTimeMs += other.wakeLockTimeMs; cameraTimeMs += other.cameraTimeMs; cameraTimeMs += other.cameraTimeMs; flashlightTimeMs += other.flashlightTimeMs; flashlightTimeMs += other.flashlightTimeMs; Loading @@ -197,6 +203,7 @@ public class BatterySipper implements Comparable<BatterySipper> { wifiTxBytes += other.wifiTxBytes; wifiTxBytes += other.wifiTxBytes; btRxBytes += other.btRxBytes; btRxBytes += other.btRxBytes; btTxBytes += other.btTxBytes; btTxBytes += other.btTxBytes; audioPowerMah += other.audioPowerMah; wifiPowerMah += other.wifiPowerMah; wifiPowerMah += other.wifiPowerMah; gpsPowerMah += other.gpsPowerMah; gpsPowerMah += other.gpsPowerMah; cpuPowerMah += other.cpuPowerMah; cpuPowerMah += other.cpuPowerMah; Loading @@ -207,6 +214,7 @@ public class BatterySipper implements Comparable<BatterySipper> { flashlightPowerMah += other.flashlightPowerMah; flashlightPowerMah += other.flashlightPowerMah; bluetoothPowerMah += other.bluetoothPowerMah; bluetoothPowerMah += other.bluetoothPowerMah; screenPowerMah += other.screenPowerMah; screenPowerMah += other.screenPowerMah; videoPowerMah += other.videoPowerMah; proportionalSmearMah += other.proportionalSmearMah; proportionalSmearMah += other.proportionalSmearMah; totalSmearedPowerMah += other.totalSmearedPowerMah; totalSmearedPowerMah += other.totalSmearedPowerMah; } } Loading @@ -220,7 +228,7 @@ public class BatterySipper implements Comparable<BatterySipper> { public double sumPower() { public double sumPower() { totalPowerMah = usagePowerMah + wifiPowerMah + gpsPowerMah + cpuPowerMah + totalPowerMah = usagePowerMah + wifiPowerMah + gpsPowerMah + cpuPowerMah + sensorPowerMah + mobileRadioPowerMah + wakeLockPowerMah + cameraPowerMah + sensorPowerMah + mobileRadioPowerMah + wakeLockPowerMah + cameraPowerMah + flashlightPowerMah + bluetoothPowerMah; flashlightPowerMah + bluetoothPowerMah + audioPowerMah + videoPowerMah; totalSmearedPowerMah = totalPowerMah + screenPowerMah + proportionalSmearMah; totalSmearedPowerMah = totalPowerMah + screenPowerMah + proportionalSmearMah; return totalPowerMah; return totalPowerMah; Loading
core/java/com/android/internal/os/BatteryStatsHelper.java +7 −0 Original line number Original line Diff line number Diff line Loading @@ -136,6 +136,7 @@ public class BatteryStatsHelper { PowerCalculator mCameraPowerCalculator; PowerCalculator mCameraPowerCalculator; PowerCalculator mFlashlightPowerCalculator; PowerCalculator mFlashlightPowerCalculator; PowerCalculator mMemoryPowerCalculator; PowerCalculator mMemoryPowerCalculator; PowerCalculator mMediaPowerCalculator; boolean mHasWifiPowerReporting = false; boolean mHasWifiPowerReporting = false; boolean mHasBluetoothPowerReporting = false; boolean mHasBluetoothPowerReporting = false; Loading Loading @@ -424,6 +425,11 @@ public class BatteryStatsHelper { } } mFlashlightPowerCalculator.reset(); mFlashlightPowerCalculator.reset(); if (mMediaPowerCalculator == null) { mMediaPowerCalculator = new MediaPowerCalculator(mPowerProfile); } mMediaPowerCalculator.reset(); mStatsType = statsType; mStatsType = statsType; mRawUptimeUs = rawUptimeUs; mRawUptimeUs = rawUptimeUs; mRawRealtimeUs = rawRealtimeUs; mRawRealtimeUs = rawRealtimeUs; Loading Loading @@ -560,6 +566,7 @@ public class BatteryStatsHelper { mCameraPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType); mCameraPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType); mFlashlightPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mFlashlightPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType); mStatsType); mMediaPowerCalculator.calculateApp(app, u, mRawRealtimeUs, mRawUptimeUs, mStatsType); final double totalPower = app.sumPower(); final double totalPower = app.sumPower(); if (DEBUG && totalPower != 0) { if (DEBUG && totalPower != 0) { Loading
core/java/com/android/internal/os/MediaPowerCalculator.java 0 → 100644 +61 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.os; import android.os.BatteryStats; /** * A {@link PowerCalculator} to calculate power consumed by audio and video hardware. * * Also see {@link PowerProfile#POWER_AUDIO} and {@link PowerProfile#POWER_VIDEO}. */ public class MediaPowerCalculator extends PowerCalculator { private static final int MS_IN_HR = 1000 * 60 * 60; private final double mAudioAveragePowerMa; private final double mVideoAveragePowerMa; public MediaPowerCalculator(PowerProfile profile) { mAudioAveragePowerMa = profile.getAveragePower(PowerProfile.POWER_AUDIO); mVideoAveragePowerMa = profile.getAveragePower(PowerProfile.POWER_VIDEO); } @Override public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs, long rawUptimeUs, int statsType) { // Calculate audio power usage, an estimate based on the average power routed to different // components like speaker, bluetooth, usb-c, earphone, etc. final BatteryStats.Timer audioTimer = u.getAudioTurnedOnTimer(); if (audioTimer == null) { app.audioTimeMs = 0; app.audioPowerMah = 0; } else { final long totalTime = audioTimer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000; app.audioTimeMs = totalTime; app.audioPowerMah = (totalTime * mAudioAveragePowerMa) / MS_IN_HR; } // Calculate video power usage. final BatteryStats.Timer videoTimer = u.getVideoTurnedOnTimer(); if (videoTimer == null) { app.videoTimeMs = 0; app.videoPowerMah = 0; } else { final long totalTime = videoTimer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000; app.videoTimeMs = totalTime; app.videoPowerMah = (totalTime * mVideoAveragePowerMa) / MS_IN_HR; } } }
core/java/com/android/internal/os/PowerProfile.java +17 −10 Original line number Original line Diff line number Diff line Loading @@ -43,7 +43,7 @@ public class PowerProfile { */ */ public static final String POWER_NONE = "none"; public static final String POWER_NONE = "none"; /** /* * POWER_CPU_SUSPEND: Power consumption when CPU is in power collapse mode. * POWER_CPU_SUSPEND: Power consumption when CPU is in power collapse mode. * POWER_CPU_IDLE: Power consumption when CPU is awake (when a wake lock is held). This should * POWER_CPU_IDLE: Power consumption when CPU is awake (when a wake lock is held). This should * be zero on devices that can go into full CPU power collapse even when a wake * be zero on devices that can go into full CPU power collapse even when a wake Loading Loading @@ -84,7 +84,6 @@ public class PowerProfile { // Updated power constants. These are not estimated, they are real world // Updated power constants. These are not estimated, they are real world // currents and voltages for the underlying bluetooth and wifi controllers. // currents and voltages for the underlying bluetooth and wifi controllers. // // public static final String POWER_WIFI_CONTROLLER_IDLE = "wifi.controller.idle"; public static final String POWER_WIFI_CONTROLLER_IDLE = "wifi.controller.idle"; public static final String POWER_WIFI_CONTROLLER_RX = "wifi.controller.rx"; public static final String POWER_WIFI_CONTROLLER_RX = "wifi.controller.rx"; public static final String POWER_WIFI_CONTROLLER_TX = "wifi.controller.tx"; public static final String POWER_WIFI_CONTROLLER_TX = "wifi.controller.tx"; Loading Loading @@ -117,6 +116,7 @@ public class PowerProfile { /** /** * Power consumption when Bluetooth driver is on. * Power consumption when Bluetooth driver is on. * * @deprecated * @deprecated */ */ @Deprecated @Deprecated Loading @@ -124,6 +124,7 @@ public class PowerProfile { /** /** * Power consumption when Bluetooth driver is transmitting/receiving. * Power consumption when Bluetooth driver is transmitting/receiving. * * @deprecated * @deprecated */ */ @Deprecated @Deprecated Loading @@ -131,6 +132,7 @@ public class PowerProfile { /** /** * Power consumption when Bluetooth driver gets an AT command. * Power consumption when Bluetooth driver gets an AT command. * * @deprecated * @deprecated */ */ @Deprecated @Deprecated Loading Loading @@ -171,13 +173,13 @@ public class PowerProfile { * Power consumed by the audio hardware when playing back audio content. This is in addition * 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. * to the CPU power, probably due to a DSP and / or amplifier. */ */ public static final String POWER_AUDIO = "dsp.audio"; public static final String POWER_AUDIO = "audio"; /** /** * Power consumed by any media hardware when playing back video content. This is in addition * Power consumed by any media hardware when playing back video content. This is in addition * to the CPU power, probably due to a DSP. * to the CPU power, probably due to a DSP. */ */ public static final String POWER_VIDEO = "dsp.video"; public static final String POWER_VIDEO = "video"; /** /** * Average power consumption when camera flashlight is on. * Average power consumption when camera flashlight is on. Loading Loading @@ -409,6 +411,7 @@ public class PowerProfile { /** /** * Returns the number of memory bandwidth buckets defined in power_profile.xml, or a * Returns the number of memory bandwidth buckets defined in power_profile.xml, or a * default value if the subsystem has no recorded value. * default value if the subsystem has no recorded value. * * @return the number of memory bandwidth buckets. * @return the number of memory bandwidth buckets. */ */ public int getNumElements(String key) { public int getNumElements(String key) { Loading @@ -423,6 +426,7 @@ public class PowerProfile { /** /** * Returns the average current in mA consumed by the subsystem, or the given * Returns the average current in mA consumed by the subsystem, or the given * default value if the subsystem has no recorded value. * default value if the subsystem has no recorded value. * * @param type the subsystem type * @param type the subsystem type * @param defaultValue the value to return if the subsystem has no recorded value. * @param defaultValue the value to return if the subsystem has no recorded value. * @return the average current in milliAmps. * @return the average current in milliAmps. Loading @@ -439,6 +443,7 @@ public class PowerProfile { /** /** * Returns the average current in mA consumed by the subsystem * Returns the average current in mA consumed by the subsystem * * @param type the subsystem type * @param type the subsystem type * @return the average current in milliAmps. * @return the average current in milliAmps. */ */ Loading @@ -448,6 +453,7 @@ public class PowerProfile { /** /** * Returns the average current in mA consumed by the subsystem for the given level. * Returns the average current in mA consumed by the subsystem for the given level. * * @param type the subsystem type * @param type the subsystem type * @param level the level of power at which the subsystem is running. For instance, the * @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.) * signal strength of the cell network between 0 and 4 (if there are 4 bars max.) Loading @@ -474,6 +480,7 @@ public class PowerProfile { /** /** * Returns the battery capacity, if available, in milli Amp Hours. If not available, * Returns the battery capacity, if available, in milli Amp Hours. If not available, * it returns zero. * it returns zero. * * @return the battery capacity in mAh * @return the battery capacity in mAh */ */ public double getBatteryCapacity() { public double getBatteryCapacity() { Loading
core/res/res/xml/power_profile.xml +2 −2 Original line number Original line Diff line number Diff line Loading @@ -36,8 +36,8 @@ <item name="wifi.on">0.1</item> <!-- ~3mA --> <item name="wifi.on">0.1</item> <!-- ~3mA --> <item name="wifi.active">0.1</item> <!-- WIFI data transfer, ~200mA --> <item name="wifi.active">0.1</item> <!-- WIFI data transfer, ~200mA --> <item name="wifi.scan">0.1</item> <!-- WIFI network scanning, ~100mA --> <item name="wifi.scan">0.1</item> <!-- WIFI network scanning, ~100mA --> <item name="dsp.audio">0.1</item> <!-- ~10mA --> <item name="audio">0.1</item> <!-- ~10mA --> <item name="dsp.video">0.1</item> <!-- ~50mA --> <item name="video">0.1</item> <!-- ~50mA --> <item name="camera.flashlight">0.1</item> <!-- Avg. power for camera flash, ~160mA --> <item name="camera.flashlight">0.1</item> <!-- Avg. power for camera flash, ~160mA --> <item name="camera.avg">0.1</item> <!-- Avg. power use of camera in standard usecases, ~550mA --> <item name="camera.avg">0.1</item> <!-- Avg. power use of camera in standard usecases, ~550mA --> <item name="gps.on">0.1</item> <!-- ~50mA --> <item name="gps.on">0.1</item> <!-- ~50mA --> Loading