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

Commit 6224a321 authored by Adam Lesinski's avatar Adam Lesinski Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'learned_capacity'

* changes:
  BatteryStats: Report learned battery capacity as event
  Parcel/unparcel charge_full state from BatteryProperties
parents 607ed230 041d917b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ public class BatteryProperties implements Parcelable {
    public int batteryLevel;
    public int batteryVoltage;
    public int batteryTemperature;
    public int batteryFullCharge;
    public int batteryChargeCounter;
    public String batteryTechnology;

@@ -48,6 +49,7 @@ public class BatteryProperties implements Parcelable {
        batteryLevel = other.batteryLevel;
        batteryVoltage = other.batteryVoltage;
        batteryTemperature = other.batteryTemperature;
        batteryFullCharge = other.batteryFullCharge;
        batteryChargeCounter = other.batteryChargeCounter;
        batteryTechnology = other.batteryTechnology;
    }
@@ -69,6 +71,7 @@ public class BatteryProperties implements Parcelable {
        batteryLevel = p.readInt();
        batteryVoltage = p.readInt();
        batteryTemperature = p.readInt();
        batteryFullCharge = p.readInt();
        batteryChargeCounter = p.readInt();
        batteryTechnology = p.readString();
    }
@@ -85,6 +88,7 @@ public class BatteryProperties implements Parcelable {
        p.writeInt(batteryLevel);
        p.writeInt(batteryVoltage);
        p.writeInt(batteryTemperature);
        p.writeInt(batteryFullCharge);
        p.writeInt(batteryChargeCounter);
        p.writeString(batteryTechnology);
    }
+23 −4
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import java.util.Formatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;

import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -1342,9 +1343,11 @@ public abstract class BatteryStats implements Parcelable {
        public static final int EVENT_WAKEUP_AP = 0x0013;
        // 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;
        // 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.
        public static final int EVENT_COUNT = 0x0015;
        public static final int EVENT_COUNT = 0x0016;
        // Mask to extract out only the type part of the event.
        public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);

@@ -2040,13 +2043,28 @@ public abstract class BatteryStats implements Parcelable {
    public static final String[] HISTORY_EVENT_NAMES = new String[] {
            "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
            "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist",
            "screenwake", "wakeupap", "longwake"
            "screenwake", "wakeupap", "longwake", "est_capacity"
    };

    public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
            "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
            "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
            "Esw", "Ewa", "Elw"
            "Esw", "Ewa", "Elw", "Eec"
    };

    @FunctionalInterface
    public interface IntToString {
        String applyAsString(int val);
    }

    private static final IntToString sUidToString = UserHandle::formatUid;
    private static final IntToString sIntToString = Integer::toString;

    public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
            sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
            sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
            sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
            sUidToString, sUidToString, sUidToString, sIntToString
    };

    /**
@@ -4975,7 +4993,8 @@ public abstract class BatteryStats implements Parcelable {
                    if (checkin) {
                        pw.print(rec.eventTag.poolIdx);
                    } else {
                        UserHandle.formatUid(pw, rec.eventTag.uid);
                        pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
                                .applyAsString(rec.eventTag.uid));
                        pw.print(":\"");
                        pw.print(rec.eventTag.string);
                        pw.print("\"");
+1 −1
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ interface IBatteryStats {
    void noteNetworkStatsEnabled();
    void noteDeviceIdleMode(int mode, String activeReason, int activeUid);
    void setBatteryState(int status, int health, int plugType, int level, int temp, int volt,
            int chargeUAh);
            int chargeUAh, int chargeFullUAh);
    long getAwakeTimeBattery();
    long getAwakeTimePlugged();

+15 −1
Original line number Diff line number Diff line
@@ -559,6 +559,10 @@ public class BatteryStatsImpl extends BatteryStats {

    private int mEstimatedBatteryCapacity = -1;

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

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

    private PowerProfile mPowerProfile;
@@ -9818,7 +9822,7 @@ public class BatteryStatsImpl extends BatteryStats {
    public static final int BATTERY_PLUGGED_NONE = 0;

    public void setBatteryStateLocked(int status, int health, int plugType, int level,
            int temp, int volt, int chargeUAh) {
            int temp, int volt, int chargeUAh, int chargeFullUAh) {
        final boolean onBattery = plugType == BATTERY_PLUGGED_NONE;
        final long uptime = mClocks.uptimeMillis();
        final long elapsedRealtime = mClocks.elapsedRealtime();
@@ -9980,6 +9984,16 @@ public class BatteryStatsImpl extends BatteryStats {
            // The next time we are unplugged, history will be cleared.
            mRecordingHistory = DEBUG;
        }

        if (differsByMoreThan(chargeFullUAh, mLastChargeFullUAh, 100)) {
            mLastChargeFullUAh = chargeFullUAh;
            addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ESTIMATED_BATTERY_CAP,
                    "", chargeFullUAh / 1000);
        }
    }

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

    public long getAwakeTimeBattery() {
+4 −2
Original line number Diff line number Diff line
@@ -347,13 +347,14 @@ public final class BatteryService extends SystemService {
                    + ", chargerWirelessOnline=" + mBatteryProps.chargerWirelessOnline
                    + ", maxChargingCurrent" + mBatteryProps.maxChargingCurrent
                    + ", maxChargingVoltage" + mBatteryProps.maxChargingVoltage
                    + ", chargeCounter" + mBatteryProps.batteryChargeCounter
                    + ", batteryStatus=" + mBatteryProps.batteryStatus
                    + ", batteryHealth=" + mBatteryProps.batteryHealth
                    + ", batteryPresent=" + mBatteryProps.batteryPresent
                    + ", batteryLevel=" + mBatteryProps.batteryLevel
                    + ", batteryTechnology=" + mBatteryProps.batteryTechnology
                    + ", batteryVoltage=" + mBatteryProps.batteryVoltage
                    + ", batteryChargeCounter=" + mBatteryProps.batteryChargeCounter
                    + ", batteryFullCharge=" + mBatteryProps.batteryFullCharge
                    + ", batteryTemperature=" + mBatteryProps.batteryTemperature
                    + ", mBatteryLevelCritical=" + mBatteryLevelCritical
                    + ", mPlugType=" + mPlugType);
@@ -363,7 +364,8 @@ public final class BatteryService extends SystemService {
        try {
            mBatteryStats.setBatteryState(mBatteryProps.batteryStatus, mBatteryProps.batteryHealth,
                    mPlugType, mBatteryProps.batteryLevel, mBatteryProps.batteryTemperature,
                    mBatteryProps.batteryVoltage, mBatteryProps.batteryChargeCounter);
                    mBatteryProps.batteryVoltage, mBatteryProps.batteryChargeCounter,
                    mBatteryProps.batteryFullCharge);
        } catch (RemoteException e) {
            // Should never happen.
        }
Loading