Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b2aa0ceb authored by Jocelyn Dang's avatar Jocelyn Dang Committed by Android (Google) Code Review
Browse files

Merge "Add min and max learned battery capacity to batterystats." into oc-dev

parents addfe673 c627d106
Loading
Loading
Loading
Loading
+32 −4
Original line number Original line Diff line number Diff line
@@ -1365,8 +1365,6 @@ public abstract class BatteryStats implements Parcelable {
        public static final int EVENT_WAKEUP_AP = 0x0013;
        public static final int EVENT_WAKEUP_AP = 0x0013;
        // Event for reporting that a specific partial wake lock has been held for a long duration.
        // Event for reporting that a specific partial wake lock has been held for a long duration.
        public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
        public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
        // Event reporting the new estimated (learned) capacity of the battery in mAh.
        public static final int EVENT_ESTIMATED_BATTERY_CAP = 0x0015;


        // Number of event types.
        // Number of event types.
        public static final int EVENT_COUNT = 0x0016;
        public static final int EVENT_COUNT = 0x0016;
@@ -2500,6 +2498,16 @@ public abstract class BatteryStats implements Parcelable {
     */
     */
    public abstract int getEstimatedBatteryCapacity();
    public abstract int getEstimatedBatteryCapacity();


    /**
     * @return The minimum learned battery capacity in uAh.
     */
    public abstract int getMinLearnedBatteryCapacity();

    /**
     * @return The maximum learned battery capacity in uAh.
     */
    public abstract int getMaxLearnedBatteryCapacity() ;

    /**
    /**
     * Return the array of discharge step durations.
     * Return the array of discharge step durations.
     */
     */
@@ -2996,7 +3004,8 @@ public abstract class BatteryStats implements Parcelable {
                totalRealtime / 1000, totalUptime / 1000,
                totalRealtime / 1000, totalUptime / 1000,
                getStartClockTime(),
                getStartClockTime(),
                whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
                whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
                getEstimatedBatteryCapacity());
                getEstimatedBatteryCapacity(),
                getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity());


        
        
        // Calculate wakelock times across all uids.
        // Calculate wakelock times across all uids.
@@ -3583,6 +3592,25 @@ public abstract class BatteryStats implements Parcelable {
            pw.println(sb.toString());
            pw.println(sb.toString());
        }
        }


        final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
        if (minLearnedBatteryCapacity > 0) {
            sb.setLength(0);
            sb.append(prefix);
                sb.append("  Min learned battery capacity: ");
                sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
                sb.append(" mAh");
            pw.println(sb.toString());
        }
        final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
        if (maxLearnedBatteryCapacity > 0) {
            sb.setLength(0);
            sb.append(prefix);
                sb.append("  Max learned battery capacity: ");
                sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
                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: ");
+28 −12
Original line number Original line Diff line number Diff line
@@ -114,7 +114,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 = 154 + (USE_OLD_HISTORY ? 1000 : 0);
    private static final int VERSION = 155 + (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;
@@ -565,9 +565,8 @@ public class BatteryStatsImpl extends BatteryStats {


    private int mEstimatedBatteryCapacity = -1;
    private int mEstimatedBatteryCapacity = -1;


    // Last learned capacity reported by BatteryService in
    private int mMinLearnedBatteryCapacity = -1;
    // setBatteryState().
    private int mMaxLearnedBatteryCapacity = -1;
    private int mLastChargeFullUAh = 0;


    private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry();
    private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry();


@@ -605,6 +604,16 @@ public class BatteryStatsImpl extends BatteryStats {
        return mEstimatedBatteryCapacity;
        return mEstimatedBatteryCapacity;
    }
    }


    @Override
    public int getMinLearnedBatteryCapacity() {
        return mMinLearnedBatteryCapacity;
    }

    @Override
    public int getMaxLearnedBatteryCapacity() {
        return mMaxLearnedBatteryCapacity;
    }

    public BatteryStatsImpl() {
    public BatteryStatsImpl() {
        this(new SystemClocks());
        this(new SystemClocks());
    }
    }
@@ -8832,6 +8841,8 @@ public class BatteryStatsImpl extends BatteryStats {
        } else {
        } else {
            mEstimatedBatteryCapacity = -1;
            mEstimatedBatteryCapacity = -1;
        }
        }
        mMinLearnedBatteryCapacity = -1;
        mMaxLearnedBatteryCapacity = -1;
        mInteractiveTimer.reset(false);
        mInteractiveTimer.reset(false);
        mPowerSaveModeEnabledTimer.reset(false);
        mPowerSaveModeEnabledTimer.reset(false);
        mLastIdleTimeStart = elapsedRealtimeMillis;
        mLastIdleTimeStart = elapsedRealtimeMillis;
@@ -10193,15 +10204,12 @@ public class BatteryStatsImpl extends BatteryStats {
            mRecordingHistory = DEBUG;
            mRecordingHistory = DEBUG;
        }
        }


        if (differsByMoreThan(chargeFullUAh, mLastChargeFullUAh, 100)) {
        if (mMinLearnedBatteryCapacity == -1) {
            mLastChargeFullUAh = chargeFullUAh;
            mMinLearnedBatteryCapacity = chargeFullUAh;
            addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ESTIMATED_BATTERY_CAP,
        } else {
                    "", chargeFullUAh / 1000);
            Math.min(mMinLearnedBatteryCapacity, chargeFullUAh);
        }
        }
        }

        mMaxLearnedBatteryCapacity = Math.max(mMaxLearnedBatteryCapacity, chargeFullUAh);
    private static boolean differsByMoreThan(int left, int right, int diff) {
        return Math.abs(left - right) > diff;
    }
    }


    public long getAwakeTimeBattery() {
    public long getAwakeTimeBattery() {
@@ -10814,6 +10822,8 @@ public class BatteryStatsImpl extends BatteryStats {
        mDischargeCurrentLevel = in.readInt();
        mDischargeCurrentLevel = in.readInt();
        mCurrentBatteryLevel = in.readInt();
        mCurrentBatteryLevel = in.readInt();
        mEstimatedBatteryCapacity = in.readInt();
        mEstimatedBatteryCapacity = in.readInt();
        mMinLearnedBatteryCapacity = in.readInt();
        mMaxLearnedBatteryCapacity = in.readInt();
        mLowDischargeAmountSinceCharge = in.readInt();
        mLowDischargeAmountSinceCharge = in.readInt();
        mHighDischargeAmountSinceCharge = in.readInt();
        mHighDischargeAmountSinceCharge = in.readInt();
        mDischargeAmountScreenOnSinceCharge = in.readInt();
        mDischargeAmountScreenOnSinceCharge = in.readInt();
@@ -11189,6 +11199,8 @@ public class BatteryStatsImpl extends BatteryStats {
        out.writeInt(mDischargeCurrentLevel);
        out.writeInt(mDischargeCurrentLevel);
        out.writeInt(mCurrentBatteryLevel);
        out.writeInt(mCurrentBatteryLevel);
        out.writeInt(mEstimatedBatteryCapacity);
        out.writeInt(mEstimatedBatteryCapacity);
        out.writeInt(mMinLearnedBatteryCapacity);
        out.writeInt(mMaxLearnedBatteryCapacity);
        out.writeInt(getLowDischargeAmountSinceCharge());
        out.writeInt(getLowDischargeAmountSinceCharge());
        out.writeInt(getHighDischargeAmountSinceCharge());
        out.writeInt(getHighDischargeAmountSinceCharge());
        out.writeInt(getDischargeAmountScreenOnSinceCharge());
        out.writeInt(getDischargeAmountScreenOnSinceCharge());
@@ -11581,6 +11593,8 @@ public class BatteryStatsImpl extends BatteryStats {
        mRealtimeStart = in.readLong();
        mRealtimeStart = in.readLong();
        mOnBattery = in.readInt() != 0;
        mOnBattery = in.readInt() != 0;
        mEstimatedBatteryCapacity = in.readInt();
        mEstimatedBatteryCapacity = in.readInt();
        mMinLearnedBatteryCapacity = in.readInt();
        mMaxLearnedBatteryCapacity = 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);
@@ -11775,6 +11789,8 @@ public class BatteryStatsImpl extends BatteryStats {
        out.writeLong(mRealtimeStart);
        out.writeLong(mRealtimeStart);
        out.writeInt(mOnBattery ? 1 : 0);
        out.writeInt(mOnBattery ? 1 : 0);
        out.writeInt(mEstimatedBatteryCapacity);
        out.writeInt(mEstimatedBatteryCapacity);
        out.writeInt(mMinLearnedBatteryCapacity);
        out.writeInt(mMaxLearnedBatteryCapacity);
        mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime);
        mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime);
        mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime);
        mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime);