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.
*/
public abstract LevelStepTracker getDischargeLevelStepTracker();
whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
totalRealtime / 1000, totalUptime / 1000,
getStartClockTime(),
- whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
+ whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
+ getEstimatedBatteryCapacity());
// Calculate wakelock times across all uids.
final SparseArray<? extends Uid> uidStats = getUidStats();
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.append(prefix);
sb.append(" Time on battery: ");
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
// 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.
private static final int MAX_HISTORY_ITEMS = 2000;
private int mLoadedNumConnectivityChange;
private int mUnpluggedNumConnectivityChange;
+ private int mEstimatedBatteryCapacity = -1;
+
private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry();
private PowerProfile mPowerProfile;
return mDischargeCounter;
}
+ @Override
+ public int getEstimatedBatteryCapacity() {
+ return mEstimatedBatteryCapacity;
+ }
+
public BatteryStatsImpl() {
this(new SystemClocks());
}
numSpeedSteps);
firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i);
}
+
+ if (mEstimatedBatteryCapacity == -1) {
+ // Initialize the estimated battery capacity to a known preset one.
+ mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity();
+ }
}
}
for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
mScreenBrightnessTimer[i].reset(false);
}
+ mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity();
mInteractiveTimer.reset(false);
mPowerSaveModeEnabledTimer.reset(false);
mLastIdleTimeStart = elapsedRealtimeMillis;
}
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;
Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE);
m.arg1 = onBattery ? 1 : 0;
}
doWrite = true;
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;
reset = true;
mDischargeStepTracker.init();
mDischargeScreenOffCounter.addCountLocked(chargeDiff);
}
mHistoryCur.batteryChargeUAh = chargeUAh;
- setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level);
+ setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level, chargeUAh);
} else {
boolean changed = false;
if (mHistoryCur.batteryLevel != level) {
mDischargePlugLevel = in.readInt();
mDischargeCurrentLevel = in.readInt();
mCurrentBatteryLevel = in.readInt();
+ mEstimatedBatteryCapacity = in.readInt();
mLowDischargeAmountSinceCharge = in.readInt();
mHighDischargeAmountSinceCharge = in.readInt();
mDischargeAmountScreenOnSinceCharge = in.readInt();
out.writeInt(mDischargePlugLevel);
out.writeInt(mDischargeCurrentLevel);
out.writeInt(mCurrentBatteryLevel);
+ out.writeInt(mEstimatedBatteryCapacity);
out.writeInt(getLowDischargeAmountSinceCharge());
out.writeInt(getHighDischargeAmountSinceCharge());
out.writeInt(getDischargeAmountScreenOnSinceCharge());
mRealtime = in.readLong();
mRealtimeStart = in.readLong();
mOnBattery = in.readInt() != 0;
+ mEstimatedBatteryCapacity = in.readInt();
mOnBatteryInternal = false; // we are no longer really running.
mOnBatteryTimeBase.readFromParcel(in);
mOnBatteryScreenOffTimeBase.readFromParcel(in);
out.writeLong(mRealtime);
out.writeLong(mRealtimeStart);
out.writeInt(mOnBattery ? 1 : 0);
+ out.writeInt(mEstimatedBatteryCapacity);
mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime);
mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime);