Issue #15986092: Add power tracking of flashlight.
Not yet hooked up. Change-Id: Id95e44ecc365e9f38169c0a629b0a48ddb29aa06
This commit is contained in:
@@ -614,6 +614,7 @@ public abstract class BatteryStats implements Parcelable {
|
||||
public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
|
||||
public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
|
||||
public static final int STATE2_WIFI_ON_FLAG = 1<<28;
|
||||
public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
|
||||
|
||||
public static final int MOST_INTERESTING_STATES2 =
|
||||
STATE2_LOW_POWER_FLAG | STATE2_WIFI_ON_FLAG;
|
||||
@@ -1235,6 +1236,7 @@ public abstract class BatteryStats implements Parcelable {
|
||||
new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
|
||||
new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Wr"),
|
||||
new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
|
||||
new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
|
||||
new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
|
||||
HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
|
||||
new String[] { "0", "1", "2", "3", "4" },
|
||||
@@ -1370,6 +1372,22 @@ public abstract class BatteryStats implements Parcelable {
|
||||
*/
|
||||
public abstract int getBluetoothStateCount(int bluetoothState, int which);
|
||||
|
||||
/**
|
||||
* Returns the time in microseconds that the flashlight has been on while the device was
|
||||
* running on battery.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
|
||||
|
||||
/**
|
||||
* Returns the number of times that the flashlight has been turned on while the device was
|
||||
* running on battery.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public abstract long getFlashlightOnCount(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;
|
||||
@@ -1965,6 +1983,9 @@ public abstract class BatteryStats implements Parcelable {
|
||||
case SCREEN:
|
||||
label="scrn";
|
||||
break;
|
||||
case FLASHLIGHT:
|
||||
label="flashlight";
|
||||
break;
|
||||
case APP:
|
||||
uid = bs.uidObj.getUid();
|
||||
label = "uid";
|
||||
@@ -2637,6 +2658,10 @@ public abstract class BatteryStats implements Parcelable {
|
||||
pw.print(prefix); pw.print(" Screen: "); printmAh(pw, bs.value);
|
||||
pw.println();
|
||||
break;
|
||||
case FLASHLIGHT:
|
||||
pw.print(prefix); pw.print(" Flashlight: "); printmAh(pw, bs.value);
|
||||
pw.println();
|
||||
break;
|
||||
case APP:
|
||||
pw.print(prefix); pw.print(" Uid ");
|
||||
UserHandle.formatUid(pw, bs.uidObj.getUid());
|
||||
|
||||
@@ -58,6 +58,8 @@ interface IBatteryStats {
|
||||
|
||||
void noteVibratorOn(int uid, long durationMillis);
|
||||
void noteVibratorOff(int uid);
|
||||
void noteFlashlightOn();
|
||||
void noteFlashlightOff();
|
||||
void noteStartGps(int uid);
|
||||
void noteStopGps(int uid);
|
||||
void noteScreenState(int state);
|
||||
|
||||
@@ -54,6 +54,7 @@ public class BatterySipper implements Comparable<BatterySipper> {
|
||||
PHONE,
|
||||
WIFI,
|
||||
BLUETOOTH,
|
||||
FLASHLIGHT,
|
||||
SCREEN,
|
||||
APP,
|
||||
USER,
|
||||
|
||||
@@ -706,6 +706,15 @@ public 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);
|
||||
@@ -760,6 +769,7 @@ public class BatteryStatsHelper {
|
||||
addUserUsage();
|
||||
addPhoneUsage();
|
||||
addScreenUsage();
|
||||
addFlashlightUsage();
|
||||
addWiFiUsage();
|
||||
addBluetoothUsage();
|
||||
addIdleUsage(); // Not including cellular idle power
|
||||
|
||||
@@ -89,7 +89,7 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
|
||||
|
||||
// Current on-disk Parcel version
|
||||
private static final int VERSION = 107 + (USE_OLD_HISTORY ? 1000 : 0);
|
||||
private static final int VERSION = 108 + (USE_OLD_HISTORY ? 1000 : 0);
|
||||
|
||||
// Maximum number of items we will record in the history.
|
||||
private static final int MAX_HISTORY_ITEMS = 2000;
|
||||
@@ -260,6 +260,9 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
boolean mVideoOn;
|
||||
StopwatchTimer mVideoOnTimer;
|
||||
|
||||
boolean mFlashlightOn;
|
||||
StopwatchTimer mFlashlightOnTimer;
|
||||
|
||||
int mPhoneSignalStrengthBin = -1;
|
||||
int mPhoneSignalStrengthBinRaw = -1;
|
||||
final StopwatchTimer[] mPhoneSignalStrengthsTimer =
|
||||
@@ -3177,6 +3180,32 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
getUidStatsLocked(uid).noteVibratorOffLocked();
|
||||
}
|
||||
|
||||
public void noteFlashlightOnLocked() {
|
||||
if (!mFlashlightOn) {
|
||||
final long elapsedRealtime = SystemClock.elapsedRealtime();
|
||||
final long uptime = SystemClock.uptimeMillis();
|
||||
mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG;
|
||||
if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: "
|
||||
+ Integer.toHexString(mHistoryCur.states));
|
||||
addHistoryRecordLocked(elapsedRealtime, uptime);
|
||||
mFlashlightOn = true;
|
||||
mFlashlightOnTimer.startRunningLocked(elapsedRealtime);
|
||||
}
|
||||
}
|
||||
|
||||
public void noteFlashlightOffLocked() {
|
||||
final long elapsedRealtime = SystemClock.elapsedRealtime();
|
||||
final long uptime = SystemClock.uptimeMillis();
|
||||
if (mFlashlightOn) {
|
||||
mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG;
|
||||
if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: "
|
||||
+ Integer.toHexString(mHistoryCur.states));
|
||||
addHistoryRecordLocked(elapsedRealtime, uptime);
|
||||
mFlashlightOn = false;
|
||||
mFlashlightOnTimer.stopRunningLocked(elapsedRealtime);
|
||||
}
|
||||
}
|
||||
|
||||
public void noteWifiRunningLocked(WorkSource ws) {
|
||||
if (!mGlobalWifiRunning) {
|
||||
final long elapsedRealtime = SystemClock.elapsedRealtime();
|
||||
@@ -3682,6 +3711,14 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
return mBluetoothStateTimer[bluetoothState].getCountLocked(which);
|
||||
}
|
||||
|
||||
@Override public long getFlashlightOnTime(long elapsedRealtimeUs, int which) {
|
||||
return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which);
|
||||
}
|
||||
|
||||
@Override public long getFlashlightOnCount(int which) {
|
||||
return mFlashlightOnTimer.getCountLocked(which);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getNetworkActivityBytes(int type, int which) {
|
||||
if (type >= 0 && type < mNetworkByteActivityCounters.length) {
|
||||
@@ -5681,6 +5718,7 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
}
|
||||
mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase);
|
||||
mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase);
|
||||
mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase);
|
||||
mOnBattery = mOnBatteryInternal = false;
|
||||
long uptime = SystemClock.uptimeMillis() * 1000;
|
||||
long realtime = SystemClock.elapsedRealtime() * 1000;
|
||||
@@ -5930,6 +5968,7 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
mPhoneOnTimer.reset(false);
|
||||
mAudioOnTimer.reset(false);
|
||||
mVideoOnTimer.reset(false);
|
||||
mFlashlightOnTimer.reset(false);
|
||||
for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
|
||||
mPhoneSignalStrengthsTimer[i].reset(false);
|
||||
}
|
||||
@@ -7124,6 +7163,8 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
for (int i=0; i< NUM_BLUETOOTH_STATES; i++) {
|
||||
mBluetoothStateTimer[i].readSummaryFromParcelLocked(in);
|
||||
}
|
||||
mFlashlightOn = false;
|
||||
mFlashlightOnTimer.readSummaryFromParcelLocked(in);
|
||||
|
||||
int NKW = in.readInt();
|
||||
if (NKW > 10000) {
|
||||
@@ -7381,6 +7422,7 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
for (int i=0; i< NUM_BLUETOOTH_STATES; i++) {
|
||||
mBluetoothStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS);
|
||||
}
|
||||
mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS);
|
||||
|
||||
out.writeInt(mKernelWakelockStats.size());
|
||||
for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) {
|
||||
@@ -7667,6 +7709,8 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase);
|
||||
mVideoOn = false;
|
||||
mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase);
|
||||
mFlashlightOn = false;
|
||||
mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in);
|
||||
mDischargeUnplugLevel = in.readInt();
|
||||
mDischargePlugLevel = in.readInt();
|
||||
mDischargeCurrentLevel = in.readInt();
|
||||
@@ -7798,6 +7842,7 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
for (int i=0; i< NUM_BLUETOOTH_STATES; i++) {
|
||||
mBluetoothStateTimer[i].writeToParcel(out, uSecRealtime);
|
||||
}
|
||||
mFlashlightOnTimer.writeToParcel(out, uSecRealtime);
|
||||
out.writeInt(mDischargeUnplugLevel);
|
||||
out.writeInt(mDischargePlugLevel);
|
||||
out.writeInt(mDischargeCurrentLevel);
|
||||
@@ -7931,6 +7976,8 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
pr.println("*** Bluetooth active type #" + i + ":");
|
||||
mBluetoothStateTimer[i].logState(pr, " ");
|
||||
}
|
||||
pr.println("*** Flashlight timer:");
|
||||
mFlashlightOnTimer.logState(pr, " ");
|
||||
}
|
||||
super.dumpLocked(context, pw, flags, reqUid, histStart);
|
||||
}
|
||||
|
||||
@@ -133,6 +133,11 @@ public class PowerProfile {
|
||||
*/
|
||||
public static final String POWER_VIDEO = "dsp.video";
|
||||
|
||||
/**
|
||||
* Power consumption when camera flashlight is on.
|
||||
*/
|
||||
public static final String POWER_FLASHLIGHT = "camera.flashlight";
|
||||
|
||||
public static final String POWER_CPU_SPEEDS = "cpu.speeds";
|
||||
|
||||
/**
|
||||
|
||||
@@ -365,6 +365,20 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
||||
}
|
||||
}
|
||||
|
||||
public void noteFlashlightOn() {
|
||||
enforceCallingPermission();
|
||||
synchronized (mStats) {
|
||||
mStats.noteFlashlightOnLocked();
|
||||
}
|
||||
}
|
||||
|
||||
public void noteFlashlightOff() {
|
||||
enforceCallingPermission();
|
||||
synchronized (mStats) {
|
||||
mStats.noteFlashlightOffLocked();
|
||||
}
|
||||
}
|
||||
|
||||
public void noteWifiRunning(WorkSource ws) {
|
||||
enforceCallingPermission();
|
||||
synchronized (mStats) {
|
||||
|
||||
Reference in New Issue
Block a user