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

Commit ba5cb913 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "whichless"

* changes:
  BatteryStats remove which - log warnings
  LongSamplingCounter - remove update()
  Remove which from BatteryStats
parents 358c63f2 db6d624a
Loading
Loading
Loading
Loading
+45 −58
Original line number Diff line number Diff line
@@ -200,13 +200,21 @@ public abstract class BatteryStats implements Parcelable {

    /**
     * Include only the current run in the stats.
     *
     * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, only {@link #STATS_SINCE_CHARGED}
     * is supported.
     */
    @UnsupportedAppUsage
    @Deprecated
    public static final int STATS_CURRENT = 1;

    /**
     * Include only the run since the last time the device was unplugged in the stats.
     *
     * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, only {@link #STATS_SINCE_CHARGED}
     * is supported.
     */
    @Deprecated
    public static final int STATS_SINCE_UNPLUGGED = 2;

    // NOTE: Update this list if you add/change any stats above.
@@ -255,8 +263,10 @@ public abstract class BatteryStats implements Parcelable {
     *   - Ambient display properly output in data dump.
     * New in version 33:
     *   - Fixed bug in min learned capacity updating process.
     * New in version 34:
     *   - Deprecated STATS_SINCE_UNPLUGGED and STATS_CURRENT.
     */
    static final int CHECKIN_VERSION = 33;
    static final int CHECKIN_VERSION = 34;

    /**
     * Old version, we hit 9 and ran out of room, need to remove.
@@ -3651,6 +3661,14 @@ public abstract class BatteryStats implements Parcelable {
     */
    public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
            boolean wifiOnly) {

        if (which != BatteryStats.STATS_SINCE_CHARGED) {
            dumpLine(pw, 0, STAT_NAMES[which], "err",
                    "ERROR: BatteryStats.dumpCheckin called for which type " + which
                    + " but only STATS_SINCE_CHARGED is supported.");
            return;
        }

        final long rawUptime = SystemClock.uptimeMillis() * 1000;
        final long rawRealtimeMs = SystemClock.elapsedRealtime();
        final long rawRealtime = rawRealtimeMs * 1000;
@@ -3848,20 +3866,6 @@ public abstract class BatteryStats implements Parcelable {
                multicastWakeLockTimeTotalMicros / 1000,
                multicastWakeLockCountTotal);

        if (which == STATS_SINCE_UNPLUGGED) {
            dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
                    getDischargeCurrentLevel());
        }

        if (which == STATS_SINCE_UNPLUGGED) {
            dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
                    getDischargeStartLevel()-getDischargeCurrentLevel(),
                    getDischargeStartLevel()-getDischargeCurrentLevel(),
                    getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
                    dischargeCount / 1000, dischargeScreenOffCount / 1000,
                    getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000,
                    dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000);
        } else {
        dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
                getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
                getDischargeAmountScreenOnSinceCharge(),
@@ -3869,7 +3873,6 @@ public abstract class BatteryStats implements Parcelable {
                dischargeCount / 1000, dischargeScreenOffCount / 1000,
                getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000,
                dischargeLightDozeCount / 1000, dischargeDeepDozeCount / 1000);
        }

        if (reqUid < 0) {
            final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
@@ -4432,6 +4435,13 @@ public abstract class BatteryStats implements Parcelable {
    @SuppressWarnings("unused")
    public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
            int reqUid, boolean wifiOnly) {

        if (which != BatteryStats.STATS_SINCE_CHARGED) {
            pw.println("ERROR: BatteryStats.dump called for which type " + which
                    + " but only STATS_SINCE_CHARGED is supported");
            return;
        }

        final long rawUptime = SystemClock.uptimeMillis() * 1000;
        final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
        final long rawRealtimeMs = (rawRealtime + 500) / 1000;
@@ -5044,28 +5054,6 @@ public abstract class BatteryStats implements Parcelable {

        pw.println();

        if (which == STATS_SINCE_UNPLUGGED) {
            if (getIsOnBattery()) {
                pw.print(prefix); pw.println("  Device is currently unplugged");
                pw.print(prefix); pw.print("    Discharge cycle start level: ");
                        pw.println(getDischargeStartLevel());
                pw.print(prefix); pw.print("    Discharge cycle current level: ");
                        pw.println(getDischargeCurrentLevel());
            } else {
                pw.print(prefix); pw.println("  Device is currently plugged into power");
                pw.print(prefix); pw.print("    Last discharge cycle start level: ");
                        pw.println(getDischargeStartLevel());
                pw.print(prefix); pw.print("    Last discharge cycle end level: ");
                        pw.println(getDischargeCurrentLevel());
            }
            pw.print(prefix); pw.print("    Amount discharged while screen on: ");
            pw.println(getDischargeAmountScreenOn());
            pw.print(prefix); pw.print("    Amount discharged while screen off: ");
            pw.println(getDischargeAmountScreenOff());
            pw.print(prefix); pw.print("    Amount discharged while screen doze: ");
            pw.println(getDischargeAmountScreenDoze());
            pw.println(" ");
        } else {
        pw.print(prefix); pw.println("  Device battery use since last full charge");
        pw.print(prefix); pw.print("    Amount discharged (lower bound): ");
        pw.println(getLowDischargeAmountSinceCharge());
@@ -5078,7 +5066,6 @@ public abstract class BatteryStats implements Parcelable {
        pw.print(prefix); pw.print("    Amount discharged while screen doze: ");
        pw.println(getDischargeAmountScreenDozeSinceCharge());
        pw.println();
        }

        final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
        helper.create(this);
+7 −5
Original line number Diff line number Diff line
@@ -37,11 +37,13 @@ import com.android.internal.app.IBatteryStats;
 * by the logging itself.  It can be substantial.
 * <p>
 * <b>Battery Usage</b><br>
 * The statistics related to power (battery) usage are recorded since the device
 * was last unplugged. It is expected that applications schedule more work to do
 * while the device is plugged in (e.g. using {@link android.app.job.JobScheduler
 * JobScheduler}), and while that can affect charging rates, it is still preferable
 * to actually draining the battery.
 * Since Android version {@link android.os.Build.VERSION_CODES#Q}, the statistics related to power
 * (battery) usage are recorded since the device was last considered fully charged (for previous
 * versions, it is instead since the device was last unplugged).
 * It is expected that applications schedule more work to do while the device is
 * plugged in (e.g. using {@link android.app.job.JobScheduler JobScheduler}), and
 * while that can affect charging rates, it is still preferable to actually draining
 * the battery.
 */
@SystemService(Context.SYSTEM_HEALTH_SERVICE)
public class SystemHealthManager {
+5 −0
Original line number Diff line number Diff line
@@ -368,6 +368,11 @@ public class BatteryStatsHelper {

    public void refreshStats(int statsType, SparseArray<UserHandle> asUsers, long rawRealtimeUs,
            long rawUptimeUs) {
        if (statsType != BatteryStats.STATS_SINCE_CHARGED) {
            Log.w(TAG, "refreshStats called for statsType " + statsType + " but only "
                    + "STATS_SINCE_CHARGED is supported. Using STATS_SINCE_CHARGED instead.");
        }

        // Initialize mStats if necessary.
        getStats();

+72 −486

File changed.

Preview size limit exceeded, changes collapsed.

+8 −6
Original line number Diff line number Diff line
@@ -27,9 +27,10 @@ public abstract class PowerCalculator {
     * @param u The recorded stats for the app.
     * @param rawRealtimeUs The raw system realtime in microseconds.
     * @param rawUptimeUs The raw system uptime in microseconds.
     * @param statsType The type of stats. Can be {@link BatteryStats#STATS_CURRENT},
     *                  {@link BatteryStats#STATS_SINCE_CHARGED}, or
     *                  {@link BatteryStats#STATS_SINCE_UNPLUGGED}.
     * @param statsType The type of stats. As of {@link android.os.Build.VERSION_CODES#Q}, this can
     *                  only be {@link BatteryStats#STATS_SINCE_CHARGED}, since
     *                  {@link BatteryStats#STATS_CURRENT} and
     *                  {@link BatteryStats#STATS_SINCE_UNPLUGGED} are deprecated.
     */
    public abstract void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs,
                                      long rawUptimeUs, int statsType);
@@ -40,9 +41,10 @@ public abstract class PowerCalculator {
     * @param stats The BatteryStats object from which to retrieve data.
     * @param rawRealtimeUs The raw system realtime in microseconds.
     * @param rawUptimeUs The raw system uptime in microseconds.
     * @param statsType The type of stats. Can be {@link BatteryStats#STATS_CURRENT},
     *                  {@link BatteryStats#STATS_SINCE_CHARGED}, or
     *                  {@link BatteryStats#STATS_SINCE_UNPLUGGED}.
     * @param statsType The type of stats. As of {@link android.os.Build.VERSION_CODES#Q}, this can
     *                  only be {@link BatteryStats#STATS_SINCE_CHARGED}, since
     *                  {@link BatteryStats#STATS_CURRENT} and
     *                  {@link BatteryStats#STATS_SINCE_UNPLUGGED} are deprecated.
     */
    public void calculateRemaining(BatterySipper app, BatteryStats stats, long rawRealtimeUs,
                                   long rawUptimeUs, int statsType) {
Loading