* commit '533514c9b5bf05bbba33e2499618fa3c47f31451': Add UI for camera + flashlight battery reporting.
This commit is contained in:
@@ -1940,6 +1940,15 @@ public abstract class BatteryStats implements Parcelable {
|
||||
*/
|
||||
public abstract long getFlashlightOnCount(int which);
|
||||
|
||||
/**
|
||||
* Returns the time in microseconds that the camera has been on while the device was
|
||||
* running on battery.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
|
||||
|
||||
|
||||
public static final int NETWORK_MOBILE_RX_DATA = 0;
|
||||
public static final int NETWORK_MOBILE_TX_DATA = 1;
|
||||
public static final int NETWORK_WIFI_RX_DATA = 2;
|
||||
@@ -2735,6 +2744,9 @@ public abstract class BatteryStats implements Parcelable {
|
||||
case OVERCOUNTED:
|
||||
label = "over";
|
||||
break;
|
||||
case CAMERA:
|
||||
label = "camera";
|
||||
break;
|
||||
default:
|
||||
label = "???";
|
||||
}
|
||||
@@ -3523,6 +3535,10 @@ public abstract class BatteryStats implements Parcelable {
|
||||
pw.print(prefix); pw.print(" Over-counted: "); printmAh(pw, bs.totalPowerMah);
|
||||
pw.println();
|
||||
break;
|
||||
case CAMERA:
|
||||
pw.print(prefix); pw.print(" Camera: "); printmAh(pw, bs.totalPowerMah);
|
||||
pw.println();
|
||||
break;
|
||||
}
|
||||
}
|
||||
pw.println();
|
||||
|
||||
@@ -42,6 +42,8 @@ public class BatterySipper implements Comparable<BatterySipper> {
|
||||
public long wifiRunningTimeMs;
|
||||
public long cpuFgTimeMs;
|
||||
public long wakeLockTimeMs;
|
||||
public long cameraTimeMs;
|
||||
public long flashlightTimeMs;
|
||||
|
||||
public long mobileRxPackets;
|
||||
public long mobileTxPackets;
|
||||
@@ -67,6 +69,8 @@ public class BatterySipper implements Comparable<BatterySipper> {
|
||||
public double mobileRadioPowerMah;
|
||||
public double gpsPowerMah;
|
||||
public double sensorPowerMah;
|
||||
public double cameraPowerMah;
|
||||
public double flashlightPowerMah;
|
||||
|
||||
public enum DrainType {
|
||||
IDLE,
|
||||
@@ -79,7 +83,8 @@ public class BatterySipper implements Comparable<BatterySipper> {
|
||||
APP,
|
||||
USER,
|
||||
UNACCOUNTED,
|
||||
OVERCOUNTED
|
||||
OVERCOUNTED,
|
||||
CAMERA
|
||||
}
|
||||
|
||||
public BatterySipper(DrainType drainType, Uid uid, double value) {
|
||||
@@ -135,6 +140,8 @@ public class BatterySipper implements Comparable<BatterySipper> {
|
||||
wifiRunningTimeMs += other.wifiRunningTimeMs;
|
||||
cpuFgTimeMs += other.cpuFgTimeMs;
|
||||
wakeLockTimeMs += other.wakeLockTimeMs;
|
||||
cameraTimeMs += other.cameraTimeMs;
|
||||
flashlightTimeMs += other.flashlightTimeMs;
|
||||
mobileRxPackets += other.mobileRxPackets;
|
||||
mobileTxPackets += other.mobileTxPackets;
|
||||
mobileActive += other.mobileActive;
|
||||
@@ -151,6 +158,8 @@ public class BatterySipper implements Comparable<BatterySipper> {
|
||||
sensorPowerMah += other.sensorPowerMah;
|
||||
mobileRadioPowerMah += other.mobileRadioPowerMah;
|
||||
wakeLockPowerMah += other.wakeLockPowerMah;
|
||||
cameraPowerMah += other.cameraPowerMah;
|
||||
flashlightPowerMah += other.flashlightPowerMah;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +167,8 @@ public class BatterySipper implements Comparable<BatterySipper> {
|
||||
* @return the sum of all the power in this BatterySipper.
|
||||
*/
|
||||
public double sumPower() {
|
||||
return totalPowerMah = usagePowerMah + wifiPowerMah + gpsPowerMah + cpuPowerMah + sensorPowerMah
|
||||
+ mobileRadioPowerMah + wakeLockPowerMah;
|
||||
return totalPowerMah = usagePowerMah + wifiPowerMah + gpsPowerMah + cpuPowerMah +
|
||||
sensorPowerMah + mobileRadioPowerMah + wakeLockPowerMah + cameraPowerMah +
|
||||
flashlightPowerMah;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +122,8 @@ public final class BatteryStatsHelper {
|
||||
PowerCalculator mWifiPowerCalculator;
|
||||
PowerCalculator mBluetoothPowerCalculator;
|
||||
PowerCalculator mSensorPowerCalculator;
|
||||
PowerCalculator mCameraPowerCalculator;
|
||||
PowerCalculator mFlashlightPowerCalculator;
|
||||
|
||||
public static boolean checkWifiOnly(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(
|
||||
@@ -365,6 +367,16 @@ public final class BatteryStatsHelper {
|
||||
}
|
||||
mSensorPowerCalculator.reset();
|
||||
|
||||
if (mCameraPowerCalculator == null) {
|
||||
mCameraPowerCalculator = new CameraPowerCalculator(mPowerProfile);
|
||||
}
|
||||
mCameraPowerCalculator.reset();
|
||||
|
||||
if (mFlashlightPowerCalculator == null) {
|
||||
mFlashlightPowerCalculator = new FlashlightPowerCalculator(mPowerProfile);
|
||||
}
|
||||
mFlashlightPowerCalculator.reset();
|
||||
|
||||
mStatsType = statsType;
|
||||
mRawUptime = rawUptimeUs;
|
||||
mRawRealtime = rawRealtimeUs;
|
||||
@@ -480,6 +492,8 @@ public final class BatteryStatsHelper {
|
||||
mWifiPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
||||
mBluetoothPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
||||
mSensorPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
||||
mCameraPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
||||
mFlashlightPowerCalculator.calculateApp(app, u, mRawRealtime, mRawUptime, mStatsType);
|
||||
|
||||
final double totalPower = app.sumPower();
|
||||
if (DEBUG && totalPower != 0) {
|
||||
@@ -619,15 +633,6 @@ public final class BatteryStatsHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private void addFlashlightUsage() {
|
||||
long flashlightOnTimeMs = mStats.getFlashlightOnTime(mRawRealtime, mStatsType) / 1000;
|
||||
double flashlightPower = flashlightOnTimeMs
|
||||
* mPowerProfile.getAveragePower(PowerProfile.POWER_FLASHLIGHT) / (60*60*1000);
|
||||
if (flashlightPower != 0) {
|
||||
addEntry(BatterySipper.DrainType.FLASHLIGHT, flashlightOnTimeMs, flashlightPower);
|
||||
}
|
||||
}
|
||||
|
||||
private void addUserUsage() {
|
||||
for (int i = 0; i < mUserSippers.size(); i++) {
|
||||
final int userId = mUserSippers.keyAt(i);
|
||||
@@ -643,7 +648,6 @@ public final class BatteryStatsHelper {
|
||||
addUserUsage();
|
||||
addPhoneUsage();
|
||||
addScreenUsage();
|
||||
addFlashlightUsage();
|
||||
addWiFiUsage();
|
||||
addBluetoothUsage();
|
||||
addIdleUsage(); // Not including cellular idle power
|
||||
|
||||
@@ -4338,14 +4338,21 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override public long getFlashlightOnTime(long elapsedRealtimeUs, int which) {
|
||||
@Override
|
||||
public long getFlashlightOnTime(long elapsedRealtimeUs, int which) {
|
||||
return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which);
|
||||
}
|
||||
|
||||
@Override public long getFlashlightOnCount(int which) {
|
||||
@Override
|
||||
public long getFlashlightOnCount(int which) {
|
||||
return mFlashlightOnTimer.getCountLocked(which);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCameraOnTime(long elapsedRealtimeUs, int which) {
|
||||
return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getNetworkActivityBytes(int type, int which) {
|
||||
if (type >= 0 && type < mNetworkByteActivityCounters.length) {
|
||||
|
||||
48
core/java/com/android/internal/os/CameraPowerCalculator.java
Normal file
48
core/java/com/android/internal/os/CameraPowerCalculator.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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;
|
||||
|
||||
/**
|
||||
* Power calculator for the camera subsystem, excluding the flashlight.
|
||||
*
|
||||
* Note: Power draw for the flash unit should be included in the FlashlightPowerCalculator.
|
||||
*/
|
||||
public class CameraPowerCalculator extends PowerCalculator {
|
||||
private final double mCameraPowerOnAvg;
|
||||
|
||||
public CameraPowerCalculator(PowerProfile profile) {
|
||||
mCameraPowerOnAvg = profile.getAveragePower(PowerProfile.POWER_CAMERA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs,
|
||||
long rawUptimeUs, int statsType) {
|
||||
|
||||
// Calculate camera power usage. Right now, this is a (very) rough estimate based on the
|
||||
// average power usage for a typical camera application.
|
||||
final BatteryStats.Timer timer = u.getCameraTurnedOnTimer();
|
||||
if (timer != null) {
|
||||
final long totalTime = timer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000;
|
||||
app.cameraTimeMs = totalTime;
|
||||
app.cameraPowerMah = (totalTime * mCameraPowerOnAvg) / (1000*60*60);
|
||||
} else {
|
||||
app.cameraTimeMs = 0;
|
||||
app.cameraPowerMah = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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;
|
||||
|
||||
/**
|
||||
* Power calculator for the flashlight.
|
||||
*/
|
||||
public class FlashlightPowerCalculator extends PowerCalculator {
|
||||
private final double mFlashlightPowerOnAvg;
|
||||
|
||||
public FlashlightPowerCalculator(PowerProfile profile) {
|
||||
mFlashlightPowerOnAvg = profile.getAveragePower(PowerProfile.POWER_FLASHLIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs,
|
||||
long rawUptimeUs, int statsType) {
|
||||
|
||||
// Calculate flashlight power usage. Right now, this is based on the average power draw
|
||||
// of the flash unit when kept on over a short period of time.
|
||||
final BatteryStats.Timer timer = u.getFlashlightTurnedOnTimer();
|
||||
if (timer != null) {
|
||||
final long totalTime = timer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000;
|
||||
app.flashlightTimeMs = totalTime;
|
||||
app.flashlightPowerMah = (totalTime * mFlashlightPowerOnAvg) / (1000*60*60);
|
||||
} else {
|
||||
app.flashlightTimeMs = 0;
|
||||
app.flashlightPowerMah = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,10 +152,17 @@ public class PowerProfile {
|
||||
public static final String POWER_VIDEO = "dsp.video";
|
||||
|
||||
/**
|
||||
* Power consumption when camera flashlight is on.
|
||||
* Average power consumption when camera flashlight is on.
|
||||
*/
|
||||
public static final String POWER_FLASHLIGHT = "camera.flashlight";
|
||||
|
||||
/**
|
||||
* Average power consumption when the camera is on over all standard use cases.
|
||||
*
|
||||
* TODO: Add more fine-grained camera power metrics.
|
||||
*/
|
||||
public static final String POWER_CAMERA = "camera.avg";
|
||||
|
||||
public static final String POWER_CPU_SPEEDS = "cpu.speeds";
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user