Loading core/java/android/os/BatteryStats.java +19 −1 Original line number Diff line number Diff line Loading @@ -2384,6 +2384,13 @@ public abstract class BatteryStats implements Parcelable { */ 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. */ Loading Loading @@ -2836,7 +2843,8 @@ public abstract class BatteryStats implements Parcelable { whichBatteryRealtime / 1000, whichBatteryUptime / 1000, totalRealtime / 1000, totalUptime / 1000, getStartClockTime(), whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000); whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, getEstimatedBatteryCapacity()); // Calculate wakelock times across all uids. Loading Loading @@ -3348,6 +3356,16 @@ public abstract class BatteryStats implements Parcelable { 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: "); Loading core/java/com/android/internal/os/BatteryStatsImpl.java +24 −3 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ public class BatteryStatsImpl extends BatteryStats { 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; Loading Loading @@ -547,6 +547,8 @@ public class BatteryStatsImpl extends BatteryStats { private int mLoadedNumConnectivityChange; private int mUnpluggedNumConnectivityChange; private int mEstimatedBatteryCapacity = -1; private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); private PowerProfile mPowerProfile; Loading Loading @@ -578,6 +580,11 @@ public class BatteryStatsImpl extends BatteryStats { return mDischargeCounter; } @Override public int getEstimatedBatteryCapacity() { return mEstimatedBatteryCapacity; } public BatteryStatsImpl() { this(new SystemClocks()); } Loading Loading @@ -7625,6 +7632,11 @@ public class BatteryStatsImpl extends BatteryStats { numSpeedSteps); firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); } if (mEstimatedBatteryCapacity == -1) { // Initialize the estimated battery capacity to a known preset one. mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); } } } Loading Loading @@ -8174,6 +8186,7 @@ public class BatteryStatsImpl extends BatteryStats { 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; Loading Loading @@ -9158,7 +9171,7 @@ public class BatteryStatsImpl extends BatteryStats { } 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; Loading Loading @@ -9212,6 +9225,10 @@ public class BatteryStatsImpl extends BatteryStats { } 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(); Loading Loading @@ -9379,7 +9396,7 @@ public class BatteryStatsImpl extends BatteryStats { 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) { Loading Loading @@ -10093,6 +10110,7 @@ public class BatteryStatsImpl extends BatteryStats { mDischargePlugLevel = in.readInt(); mDischargeCurrentLevel = in.readInt(); mCurrentBatteryLevel = in.readInt(); mEstimatedBatteryCapacity = in.readInt(); mLowDischargeAmountSinceCharge = in.readInt(); mHighDischargeAmountSinceCharge = in.readInt(); mDischargeAmountScreenOnSinceCharge = in.readInt(); Loading Loading @@ -10445,6 +10463,7 @@ public class BatteryStatsImpl extends BatteryStats { out.writeInt(mDischargePlugLevel); out.writeInt(mDischargeCurrentLevel); out.writeInt(mCurrentBatteryLevel); out.writeInt(mEstimatedBatteryCapacity); out.writeInt(getLowDischargeAmountSinceCharge()); out.writeInt(getHighDischargeAmountSinceCharge()); out.writeInt(getDischargeAmountScreenOnSinceCharge()); Loading Loading @@ -10809,6 +10828,7 @@ public class BatteryStatsImpl extends BatteryStats { 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); Loading Loading @@ -10992,6 +11012,7 @@ public class BatteryStatsImpl extends BatteryStats { out.writeLong(mRealtime); out.writeLong(mRealtimeStart); out.writeInt(mOnBattery ? 1 : 0); out.writeInt(mEstimatedBatteryCapacity); mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); Loading Loading
core/java/android/os/BatteryStats.java +19 −1 Original line number Diff line number Diff line Loading @@ -2384,6 +2384,13 @@ public abstract class BatteryStats implements Parcelable { */ 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. */ Loading Loading @@ -2836,7 +2843,8 @@ public abstract class BatteryStats implements Parcelable { whichBatteryRealtime / 1000, whichBatteryUptime / 1000, totalRealtime / 1000, totalUptime / 1000, getStartClockTime(), whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000); whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, getEstimatedBatteryCapacity()); // Calculate wakelock times across all uids. Loading Loading @@ -3348,6 +3356,16 @@ public abstract class BatteryStats implements Parcelable { 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: "); Loading
core/java/com/android/internal/os/BatteryStatsImpl.java +24 −3 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ public class BatteryStatsImpl extends BatteryStats { 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; Loading Loading @@ -547,6 +547,8 @@ public class BatteryStatsImpl extends BatteryStats { private int mLoadedNumConnectivityChange; private int mUnpluggedNumConnectivityChange; private int mEstimatedBatteryCapacity = -1; private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); private PowerProfile mPowerProfile; Loading Loading @@ -578,6 +580,11 @@ public class BatteryStatsImpl extends BatteryStats { return mDischargeCounter; } @Override public int getEstimatedBatteryCapacity() { return mEstimatedBatteryCapacity; } public BatteryStatsImpl() { this(new SystemClocks()); } Loading Loading @@ -7625,6 +7632,11 @@ public class BatteryStatsImpl extends BatteryStats { numSpeedSteps); firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); } if (mEstimatedBatteryCapacity == -1) { // Initialize the estimated battery capacity to a known preset one. mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); } } } Loading Loading @@ -8174,6 +8186,7 @@ public class BatteryStatsImpl extends BatteryStats { 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; Loading Loading @@ -9158,7 +9171,7 @@ public class BatteryStatsImpl extends BatteryStats { } 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; Loading Loading @@ -9212,6 +9225,10 @@ public class BatteryStatsImpl extends BatteryStats { } 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(); Loading Loading @@ -9379,7 +9396,7 @@ public class BatteryStatsImpl extends BatteryStats { 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) { Loading Loading @@ -10093,6 +10110,7 @@ public class BatteryStatsImpl extends BatteryStats { mDischargePlugLevel = in.readInt(); mDischargeCurrentLevel = in.readInt(); mCurrentBatteryLevel = in.readInt(); mEstimatedBatteryCapacity = in.readInt(); mLowDischargeAmountSinceCharge = in.readInt(); mHighDischargeAmountSinceCharge = in.readInt(); mDischargeAmountScreenOnSinceCharge = in.readInt(); Loading Loading @@ -10445,6 +10463,7 @@ public class BatteryStatsImpl extends BatteryStats { out.writeInt(mDischargePlugLevel); out.writeInt(mDischargeCurrentLevel); out.writeInt(mCurrentBatteryLevel); out.writeInt(mEstimatedBatteryCapacity); out.writeInt(getLowDischargeAmountSinceCharge()); out.writeInt(getHighDischargeAmountSinceCharge()); out.writeInt(getDischargeAmountScreenOnSinceCharge()); Loading Loading @@ -10809,6 +10828,7 @@ public class BatteryStatsImpl extends BatteryStats { 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); Loading Loading @@ -10992,6 +11012,7 @@ public class BatteryStatsImpl extends BatteryStats { out.writeLong(mRealtime); out.writeLong(mRealtimeStart); out.writeInt(mOnBattery ? 1 : 0); out.writeInt(mEstimatedBatteryCapacity); mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); Loading