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

Commit 004451be authored by Dmitri Plotnikov's avatar Dmitri Plotnikov Committed by Android (Google) Code Review
Browse files

Merge changes Ia4da8741,Ifbfea9e1,Ice606f9b,I6b4a8e0c into main

* changes:
  Remove flag com.android.server.power.optimization.streamlined_misc_battery_stats
  Ensure tests pass when streamlined_misc_battery_stats flag is enabled
  Remove functional uses of flag com.android.server.power.optimization.streamlined_connectivity_battery_stats
  Remove flag com.android.server.power.optimization.streamlined_battery_stats
parents 947520ab ea7029ee
Loading
Loading
Loading
Loading
+56 −112
Original line number Diff line number Diff line
@@ -393,13 +393,12 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                com.android.internal.R.integer.config_radioScanningTimeout) * 1000L);
        mPowerStatsStore = new PowerStatsStore(systemDir, mHandler);
        mPowerAttributor = new MultiStatePowerAttributor(mContext, mPowerStatsStore, mPowerProfile,
                mCpuScalingPolicies, () -> mStats.getBatteryCapacity());
                mCpuScalingPolicies, mStats::getBatteryCapacity);
        mPowerStatsScheduler = createPowerStatsScheduler(mContext);

        int accumulatedBatteryUsageStatsSpanSize = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_accumulatedBatteryUsageStatsSpanSize);
        mBatteryUsageStatsProvider = new BatteryUsageStatsProvider(context,
                mPowerAttributor, mPowerProfile, mCpuScalingPolicies,
        mBatteryUsageStatsProvider = new BatteryUsageStatsProvider(mPowerAttributor,
                mPowerStatsStore, accumulatedBatteryUsageStatsSpanSize, Clock.SYSTEM_CLOCK,
                mMonotonicClock);
        mDumpHelper = new BatteryStatsDumpHelperImpl(mBatteryUsageStatsProvider);
@@ -476,97 +475,54 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                !Flags.extendedBatteryHistoryContinuousCollectionEnabled());

        MultiStatePowerAttributor attributor = (MultiStatePowerAttributor) mPowerAttributor;
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_CPU,
                Flags.streamlinedBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_CPU,
                Flags.streamlinedBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_WAKELOCK,
                Flags.streamlinedMiscBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_WAKELOCK,
                Flags.streamlinedMiscBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_SCREEN,
                Flags.streamlinedMiscBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_SCREEN,
                Flags.streamlinedMiscBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY,
                Flags.streamlinedMiscBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY,
                Flags.streamlinedMiscBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO,
                Flags.streamlinedConnectivityBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO,
                Flags.streamlinedConnectivityBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_PHONE,
                Flags.streamlinedConnectivityBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_WIFI,
                Flags.streamlinedConnectivityBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_WIFI,
                Flags.streamlinedConnectivityBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_BLUETOOTH,
                Flags.streamlinedConnectivityBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_BLUETOOTH,
                Flags.streamlinedConnectivityBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_AUDIO,
                Flags.streamlinedMiscBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_AUDIO,
                Flags.streamlinedMiscBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_VIDEO,
                Flags.streamlinedMiscBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_VIDEO,
                Flags.streamlinedMiscBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_FLASHLIGHT,
                Flags.streamlinedMiscBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_FLASHLIGHT,
                Flags.streamlinedMiscBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_GNSS,
                Flags.streamlinedMiscBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_GNSS,
                Flags.streamlinedMiscBatteryStats());

        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_SENSORS,
                Flags.streamlinedMiscBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_CAMERA,
                Flags.streamlinedMiscBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_CAMERA,
                Flags.streamlinedMiscBatteryStats());

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_CPU, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_CPU, true);

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_WAKELOCK, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_WAKELOCK, true);

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_SCREEN, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_SCREEN, true);

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY,
                true);

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_PHONE, true);

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_WIFI, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_WIFI, true);

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_BLUETOOTH, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_BLUETOOTH, true);

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_AUDIO, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_AUDIO, true);

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_VIDEO, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_VIDEO, true);

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_FLASHLIGHT, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_FLASHLIGHT, true);

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_GNSS, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_GNSS, true);

        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_SENSORS, true);

        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_CAMERA, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_CAMERA, true);

        // Currently unimplemented.
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_MEMORY,
                Flags.streamlinedMiscBatteryStats());
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_MEMORY,
                Flags.streamlinedMiscBatteryStats());
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_MEMORY, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_MEMORY, true);

        // By convention POWER_COMPONENT_ANY represents custom Energy Consumers
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_ANY,
                Flags.streamlinedMiscBatteryStats());
        attributor.setPowerComponentSupported(
                BatteryConsumer.POWER_COMPONENT_ANY,
                Flags.streamlinedMiscBatteryStats());
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_ANY, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_ANY, true);

        mStats.setMoveWscLoggingToNotifierEnabled(
                mPowerManagerFlags.isMoveWscLoggingToNotifierEnabled());
@@ -609,10 +565,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
    }

    private static boolean isBatteryUsageStatsAccumulationSupported() {
        return Flags.accumulateBatteryUsageStats()
                && Flags.streamlinedBatteryStats()
                && Flags.streamlinedConnectivityBatteryStats()
                && Flags.streamlinedMiscBatteryStats();
        return Flags.accumulateBatteryUsageStats();
    }

    /**
@@ -620,7 +573,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
     */
    public void onSystemReady() {
        mStats.onSystemReady(mContext);
        mPowerStatsScheduler.start(Flags.streamlinedBatteryStats());
        mPowerStatsScheduler.start();
    }

    private final class LocalService extends BatteryStatsInternal {
@@ -988,10 +941,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                SystemClock.elapsedRealtime(),
                mWorker.getLastCollectionTimeStamp())) {
            syncStats("get-stats", BatteryExternalStatsWorker.UPDATE_ALL);
            if (Flags.streamlinedBatteryStats()) {
            mStats.collectPowerStatsSamples();
        }
        }

        return mBatteryUsageStatsProvider.getBatteryUsageStats(mStats, queries);
    }
@@ -3011,9 +2962,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        if (isBatteryUsageStatsAccumulationSupported()) {
            pw.println("     --accumulated: continuously accumulated since setup or reset-all");
        }
        if (Flags.streamlinedBatteryStats()) {
        pw.println("  --sample: collect and dump a sample of stats for debugging purpose");
        }
        pw.println("  --sync: wait for delayed processing to finish (for use in tests)");
        pw.println("  <package.name>: optional name of package to filter output by.");
        pw.println("  -h: print this help text.");
@@ -3035,10 +2984,6 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        awaitCompletion();
        synchronized (mStats) {
            mStats.dumpConstantsLocked(pw);

            pw.println("Flags:");
            pw.println("    " + Flags.FLAG_STREAMLINED_BATTERY_STATS
                    + ": " + Flags.streamlinedBatteryStats());
        }
    }

@@ -3100,11 +3045,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        synchronized (mStats) {
            mStats.prepareForDumpLocked();
        }
        if (Flags.streamlinedBatteryStats()) {

        // Important: perform this operation outside the mStats lock, because it will
        // need to access BatteryStats from a handler thread
        mStats.collectPowerStatsSamples();
        }

        try (BatteryUsageStats batteryUsageStats =
                     mBatteryUsageStatsProvider.getBatteryUsageStats(mStats, query)) {
@@ -3305,10 +3249,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                    mCpuWakeupStats.dump(new IndentingPrintWriter(pw, "  "),
                            SystemClock.elapsedRealtime());
                    return;
                } else if (Flags.streamlinedBatteryStats() && "--sample".equals(arg)) {
                } else if ("--sample".equals(arg)) {
                    dumpStatsSample(pw);
                    return;
                } else if (Flags.streamlinedBatteryStats() && "--aggregated".equals(arg)) {
                } else if ("--aggregated".equals(arg)) {
                    dumpAggregatedStats(pw);
                    return;
                } else if ("--store".equals(arg)) {
+0 −93
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.power.stats;

import static com.android.internal.os.PowerProfile.POWER_GROUP_DISPLAY_AMBIENT;

import android.os.BatteryConsumer;
import android.os.BatteryStats;
import android.os.BatteryUsageStats;
import android.os.BatteryUsageStatsQuery;

import com.android.internal.os.PowerProfile;

/**
 * Estimates power consumed by the ambient display
 */
public class AmbientDisplayPowerCalculator extends PowerCalculator {
    private final UsageBasedPowerEstimator[] mPowerEstimators;

    @Override
    public boolean isPowerComponentSupported(@BatteryConsumer.PowerComponent int powerComponent) {
        return powerComponent == BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY;
    }

    public AmbientDisplayPowerCalculator(PowerProfile powerProfile) {
        final int numDisplays = powerProfile.getNumDisplays();
        mPowerEstimators = new UsageBasedPowerEstimator[numDisplays];
        for (int display = 0; display < numDisplays; display++) {
            mPowerEstimators[display] = new UsageBasedPowerEstimator(
                    powerProfile.getAveragePowerForOrdinal(POWER_GROUP_DISPLAY_AMBIENT, display));
        }
    }

    /**
     * Ambient display power is the additional power the screen takes while in ambient display/
     * screen doze/always-on display (interchangeable terms) mode.
     */
    @Override
    public void calculate(BatteryUsageStats.Builder builder, BatteryStats batteryStats,
            long rawRealtimeUs, long rawUptimeUs, BatteryUsageStatsQuery query) {
        final long energyConsumerUC = batteryStats.getScreenDozeEnergyConsumptionUC();
        final int powerModel = getPowerModel(energyConsumerUC, query);
        final long durationMs = calculateDuration(batteryStats, rawRealtimeUs,
                BatteryStats.STATS_SINCE_CHARGED);
        final double powerMah = calculateTotalPower(powerModel, batteryStats, rawRealtimeUs,
                energyConsumerUC);
        builder.getAggregateBatteryConsumerBuilder(
                BatteryUsageStats.AGGREGATE_BATTERY_CONSUMER_SCOPE_DEVICE)
                .setUsageDurationMillis(BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY, durationMs)
                .setConsumedPower(BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY,
                        powerMah, powerModel);
    }

    private long calculateDuration(BatteryStats batteryStats, long rawRealtimeUs, int statsType) {
        return batteryStats.getScreenDozeTime(rawRealtimeUs, statsType) / 1000;
    }

    private double calculateTotalPower(@BatteryConsumer.PowerModel int powerModel,
            BatteryStats batteryStats, long rawRealtimeUs, long consumptionUC) {
        switch (powerModel) {
            case BatteryConsumer.POWER_MODEL_ENERGY_CONSUMPTION:
                return uCtoMah(consumptionUC);
            case BatteryConsumer.POWER_MODEL_POWER_PROFILE:
            default:
                return calculateEstimatedPower(batteryStats, rawRealtimeUs);
        }
    }

    private double calculateEstimatedPower(BatteryStats batteryStats, long rawRealtimeUs) {
        final int numDisplays = mPowerEstimators.length;
        double power = 0;
        for (int display = 0; display < numDisplays; display++) {
            final long dozeTime = batteryStats.getDisplayScreenDozeTime(display, rawRealtimeUs)
                    / 1000;
            power += mPowerEstimators[display].calculatePower(dozeTime);
        }
        return power;
    }
}
+0 −88
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.server.power.stats;

import android.os.BatteryConsumer;
import android.os.BatteryStats;
import android.os.BatteryUsageStats;
import android.os.BatteryUsageStatsQuery;
import android.os.UidBatteryConsumer;
import android.util.SparseArray;

import com.android.internal.os.PowerProfile;

/**
 * A {@link PowerCalculator} to calculate power consumed by audio hardware.
 *
 * Also see {@link PowerProfile#POWER_AUDIO}.
 */
public class AudioPowerCalculator extends PowerCalculator {
    // Calculate audio power usage, an estimate based on the average power routed to different
    // components like speaker, bluetooth, usb-c, earphone, etc.
    // TODO(b/175344313): improve the model by taking into account different audio routes
    private final UsageBasedPowerEstimator mPowerEstimator;

    private static class PowerAndDuration {
        public long durationMs;
        public double powerMah;
    }

    public AudioPowerCalculator(PowerProfile powerProfile) {
        mPowerEstimator = new UsageBasedPowerEstimator(
                powerProfile.getAveragePower(PowerProfile.POWER_AUDIO));
    }

    @Override
    public boolean isPowerComponentSupported(@BatteryConsumer.PowerComponent int powerComponent) {
        return powerComponent == BatteryConsumer.POWER_COMPONENT_AUDIO;
    }

    @Override
    public void calculate(BatteryUsageStats.Builder builder, BatteryStats batteryStats,
            long rawRealtimeUs, long rawUptimeUs, BatteryUsageStatsQuery query) {
        final PowerAndDuration total = new PowerAndDuration();

        final SparseArray<UidBatteryConsumer.Builder> uidBatteryConsumerBuilders =
                builder.getUidBatteryConsumerBuilders();
        for (int i = uidBatteryConsumerBuilders.size() - 1; i >= 0; i--) {
            final UidBatteryConsumer.Builder app = uidBatteryConsumerBuilders.valueAt(i);
            calculateApp(app, total, app.getBatteryStatsUid(), rawRealtimeUs);
        }

        builder.getAggregateBatteryConsumerBuilder(
                BatteryUsageStats.AGGREGATE_BATTERY_CONSUMER_SCOPE_DEVICE)
                .setUsageDurationMillis(BatteryConsumer.POWER_COMPONENT_AUDIO, total.durationMs)
                .setConsumedPower(BatteryConsumer.POWER_COMPONENT_AUDIO, total.powerMah);

        builder.getAggregateBatteryConsumerBuilder(
                BatteryUsageStats.AGGREGATE_BATTERY_CONSUMER_SCOPE_ALL_APPS)
                .setUsageDurationMillis(BatteryConsumer.POWER_COMPONENT_AUDIO, total.durationMs)
                .setConsumedPower(BatteryConsumer.POWER_COMPONENT_AUDIO, total.powerMah);
    }

    private void calculateApp(UidBatteryConsumer.Builder app, PowerAndDuration total,
            BatteryStats.Uid u, long rawRealtimeUs) {
        final long durationMs = mPowerEstimator.calculateDuration(u.getAudioTurnedOnTimer(),
                rawRealtimeUs, BatteryStats.STATS_SINCE_CHARGED);
        final double powerMah = mPowerEstimator.calculatePower(durationMs);
        app.setUsageDurationMillis(BatteryConsumer.POWER_COMPONENT_AUDIO, durationMs)
                .setConsumedPower(BatteryConsumer.POWER_COMPONENT_AUDIO, powerMah);
        if (!app.isVirtualUid()) {
            total.durationMs += durationMs;
            total.powerMah += powerMah;
        }
    }
}
+0 −72
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.power.stats;

import android.os.BatteryConsumer;
import android.os.BatteryStats;
import android.os.BatteryUsageStats;
import android.os.BatteryUsageStatsQuery;

/**
 * Estimates the battery discharge amounts.
 */
public class BatteryChargeCalculator extends PowerCalculator {

    @Override
    public boolean isPowerComponentSupported(@BatteryConsumer.PowerComponent int powerComponent) {
        // Always apply this power calculator, no matter what power components were requested
        return true;
    }

    @Override
    public void calculate(BatteryUsageStats.Builder builder, BatteryStats batteryStats,
            long rawRealtimeUs, long rawUptimeUs, BatteryUsageStatsQuery query) {
        builder.addDischargePercentage(
                batteryStats.getDischargeAmount(BatteryStats.STATS_SINCE_CHARGED));

        int batteryCapacityMah = batteryStats.getBatteryCapacity();
        builder.setBatteryCapacity(batteryCapacityMah);

        final double dischargedPowerLowerBoundMah =
                batteryStats.getLowDischargeAmountSinceCharge() * batteryCapacityMah / 100.0;
        final double dischargedPowerUpperBoundMah =
                batteryStats.getHighDischargeAmountSinceCharge() * batteryCapacityMah / 100.0;
        builder
                .addDischargedPowerRange(dischargedPowerLowerBoundMah, dischargedPowerUpperBoundMah)
                .addDischargeDurationMs(batteryStats.getBatteryRealtime(rawRealtimeUs) / 1000);

        final long batteryTimeRemainingMs = batteryStats.computeBatteryTimeRemaining(rawRealtimeUs);
        if (batteryTimeRemainingMs != -1) {
            builder.setBatteryTimeRemainingMs(batteryTimeRemainingMs / 1000);
        }

        final long chargeTimeRemainingMs = batteryStats.computeChargeTimeRemaining(rawRealtimeUs);
        if (chargeTimeRemainingMs != -1) {
            builder.setChargeTimeRemainingMs(chargeTimeRemainingMs / 1000);
        }

        long dischargeMah = batteryStats.getUahDischarge(BatteryStats.STATS_SINCE_CHARGED) / 1000;
        if (dischargeMah == 0) {
            dischargeMah = (long) ((dischargedPowerLowerBoundMah + dischargedPowerUpperBoundMah) / 2
                    + 0.5);
        }

        builder.getAggregateBatteryConsumerBuilder(
                BatteryUsageStats.AGGREGATE_BATTERY_CONSUMER_SCOPE_DEVICE)
                .setConsumedPower(dischargeMah);
    }
}
+28 −535

File changed.

Preview size limit exceeded, changes collapsed.

Loading