Merge "BatteryStats: record best estimated battery capacity" into nyc-dev

This commit is contained in:
TreeHugger Robot
2016-06-20 19:49:44 +00:00
committed by Android (Google) Code Review
2 changed files with 43 additions and 4 deletions

View File

@@ -2384,6 +2384,13 @@ public abstract class BatteryStats implements Parcelable {
*/ */
public abstract LongCounter getDischargeCoulombCounter(); public abstract LongCounter getDischargeCoulombCounter();
/**
* Returns the estimated real battery capacity, which may be less than the capacity
* declared by the PowerProfile.
* @return The estimated battery capacity in mAh.
*/
public abstract int getEstimatedBatteryCapacity();
/** /**
* Return the array of discharge step durations. * Return the array of discharge step durations.
*/ */
@@ -2836,7 +2843,8 @@ public abstract class BatteryStats implements Parcelable {
whichBatteryRealtime / 1000, whichBatteryUptime / 1000, whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
totalRealtime / 1000, totalUptime / 1000, totalRealtime / 1000, totalUptime / 1000,
getStartClockTime(), getStartClockTime(),
whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000); whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
getEstimatedBatteryCapacity());
// Calculate wakelock times across all uids. // Calculate wakelock times across all uids.
@@ -3348,6 +3356,16 @@ public abstract class BatteryStats implements Parcelable {
final SparseArray<? extends Uid> uidStats = getUidStats(); final SparseArray<? extends Uid> uidStats = getUidStats();
final int NU = uidStats.size(); final int NU = uidStats.size();
final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
if (estimatedBatteryCapacity > 0) {
sb.setLength(0);
sb.append(prefix);
sb.append(" Estimated battery capacity: ");
sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
sb.append(" mAh");
pw.println(sb.toString());
}
sb.setLength(0); sb.setLength(0);
sb.append(prefix); sb.append(prefix);
sb.append(" Time on battery: "); sb.append(" Time on battery: ");

View File

@@ -108,7 +108,7 @@ public class BatteryStatsImpl extends BatteryStats {
private static final int MAGIC = 0xBA757475; // 'BATSTATS' private static final int MAGIC = 0xBA757475; // 'BATSTATS'
// Current on-disk Parcel version // Current on-disk Parcel version
private static final int VERSION = 146 + (USE_OLD_HISTORY ? 1000 : 0); private static final int VERSION = 147 + (USE_OLD_HISTORY ? 1000 : 0);
// Maximum number of items we will record in the history. // Maximum number of items we will record in the history.
private static final int MAX_HISTORY_ITEMS = 2000; private static final int MAX_HISTORY_ITEMS = 2000;
@@ -547,6 +547,8 @@ public class BatteryStatsImpl extends BatteryStats {
private int mLoadedNumConnectivityChange; private int mLoadedNumConnectivityChange;
private int mUnpluggedNumConnectivityChange; private int mUnpluggedNumConnectivityChange;
private int mEstimatedBatteryCapacity = -1;
private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry();
private PowerProfile mPowerProfile; private PowerProfile mPowerProfile;
@@ -578,6 +580,11 @@ public class BatteryStatsImpl extends BatteryStats {
return mDischargeCounter; return mDischargeCounter;
} }
@Override
public int getEstimatedBatteryCapacity() {
return mEstimatedBatteryCapacity;
}
public BatteryStatsImpl() { public BatteryStatsImpl() {
this(new SystemClocks()); this(new SystemClocks());
} }
@@ -7625,6 +7632,11 @@ public class BatteryStatsImpl extends BatteryStats {
numSpeedSteps); numSpeedSteps);
firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i);
} }
if (mEstimatedBatteryCapacity == -1) {
// Initialize the estimated battery capacity to a known preset one.
mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity();
}
} }
} }
@@ -8174,6 +8186,7 @@ public class BatteryStatsImpl extends BatteryStats {
for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
mScreenBrightnessTimer[i].reset(false); mScreenBrightnessTimer[i].reset(false);
} }
mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity();
mInteractiveTimer.reset(false); mInteractiveTimer.reset(false);
mPowerSaveModeEnabledTimer.reset(false); mPowerSaveModeEnabledTimer.reset(false);
mLastIdleTimeStart = elapsedRealtimeMillis; mLastIdleTimeStart = elapsedRealtimeMillis;
@@ -9158,7 +9171,7 @@ public class BatteryStatsImpl extends BatteryStats {
} }
void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery,
final int oldStatus, final int level) { final int oldStatus, final int level, final int chargeUAh) {
boolean doWrite = false; boolean doWrite = false;
Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE);
m.arg1 = onBattery ? 1 : 0; m.arg1 = onBattery ? 1 : 0;
@@ -9212,6 +9225,10 @@ public class BatteryStatsImpl extends BatteryStats {
} }
doWrite = true; doWrite = true;
resetAllStatsLocked(); resetAllStatsLocked();
if (chargeUAh > 0) {
// Only use the reported coulomb charge value if it is supported and reported.
mEstimatedBatteryCapacity = (int) ((level / 100.0) * (chargeUAh / 1000));
}
mDischargeStartLevel = level; mDischargeStartLevel = level;
reset = true; reset = true;
mDischargeStepTracker.init(); mDischargeStepTracker.init();
@@ -9379,7 +9396,7 @@ public class BatteryStatsImpl extends BatteryStats {
mDischargeScreenOffCounter.addCountLocked(chargeDiff); mDischargeScreenOffCounter.addCountLocked(chargeDiff);
} }
mHistoryCur.batteryChargeUAh = chargeUAh; mHistoryCur.batteryChargeUAh = chargeUAh;
setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level); setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level, chargeUAh);
} else { } else {
boolean changed = false; boolean changed = false;
if (mHistoryCur.batteryLevel != level) { if (mHistoryCur.batteryLevel != level) {
@@ -10093,6 +10110,7 @@ public class BatteryStatsImpl extends BatteryStats {
mDischargePlugLevel = in.readInt(); mDischargePlugLevel = in.readInt();
mDischargeCurrentLevel = in.readInt(); mDischargeCurrentLevel = in.readInt();
mCurrentBatteryLevel = in.readInt(); mCurrentBatteryLevel = in.readInt();
mEstimatedBatteryCapacity = in.readInt();
mLowDischargeAmountSinceCharge = in.readInt(); mLowDischargeAmountSinceCharge = in.readInt();
mHighDischargeAmountSinceCharge = in.readInt(); mHighDischargeAmountSinceCharge = in.readInt();
mDischargeAmountScreenOnSinceCharge = in.readInt(); mDischargeAmountScreenOnSinceCharge = in.readInt();
@@ -10445,6 +10463,7 @@ public class BatteryStatsImpl extends BatteryStats {
out.writeInt(mDischargePlugLevel); out.writeInt(mDischargePlugLevel);
out.writeInt(mDischargeCurrentLevel); out.writeInt(mDischargeCurrentLevel);
out.writeInt(mCurrentBatteryLevel); out.writeInt(mCurrentBatteryLevel);
out.writeInt(mEstimatedBatteryCapacity);
out.writeInt(getLowDischargeAmountSinceCharge()); out.writeInt(getLowDischargeAmountSinceCharge());
out.writeInt(getHighDischargeAmountSinceCharge()); out.writeInt(getHighDischargeAmountSinceCharge());
out.writeInt(getDischargeAmountScreenOnSinceCharge()); out.writeInt(getDischargeAmountScreenOnSinceCharge());
@@ -10809,6 +10828,7 @@ public class BatteryStatsImpl extends BatteryStats {
mRealtime = in.readLong(); mRealtime = in.readLong();
mRealtimeStart = in.readLong(); mRealtimeStart = in.readLong();
mOnBattery = in.readInt() != 0; mOnBattery = in.readInt() != 0;
mEstimatedBatteryCapacity = in.readInt();
mOnBatteryInternal = false; // we are no longer really running. mOnBatteryInternal = false; // we are no longer really running.
mOnBatteryTimeBase.readFromParcel(in); mOnBatteryTimeBase.readFromParcel(in);
mOnBatteryScreenOffTimeBase.readFromParcel(in); mOnBatteryScreenOffTimeBase.readFromParcel(in);
@@ -10992,6 +11012,7 @@ public class BatteryStatsImpl extends BatteryStats {
out.writeLong(mRealtime); out.writeLong(mRealtime);
out.writeLong(mRealtimeStart); out.writeLong(mRealtimeStart);
out.writeInt(mOnBattery ? 1 : 0); out.writeInt(mOnBattery ? 1 : 0);
out.writeInt(mEstimatedBatteryCapacity);
mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime);
mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime);