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

Commit ea7029ee authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Remove flag com.android.server.power.optimization.streamlined_misc_battery_stats

Bug: 409605114
Test: presubmit
Flag: EXEMPT removing com.android.server.power.optimization.streamlined_misc_battery_stats
Change-Id: Ia4da87410ee9df54817bf97d281f526ac81d7d57
parent 3449acf9
Loading
Loading
Loading
Loading
+30 −62
Original line number Original line Diff line number Diff line
@@ -393,13 +393,12 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                com.android.internal.R.integer.config_radioScanningTimeout) * 1000L);
                com.android.internal.R.integer.config_radioScanningTimeout) * 1000L);
        mPowerStatsStore = new PowerStatsStore(systemDir, mHandler);
        mPowerStatsStore = new PowerStatsStore(systemDir, mHandler);
        mPowerAttributor = new MultiStatePowerAttributor(mContext, mPowerStatsStore, mPowerProfile,
        mPowerAttributor = new MultiStatePowerAttributor(mContext, mPowerStatsStore, mPowerProfile,
                mCpuScalingPolicies, () -> mStats.getBatteryCapacity());
                mCpuScalingPolicies, mStats::getBatteryCapacity);
        mPowerStatsScheduler = createPowerStatsScheduler(mContext);
        mPowerStatsScheduler = createPowerStatsScheduler(mContext);


        int accumulatedBatteryUsageStatsSpanSize = mContext.getResources().getInteger(
        int accumulatedBatteryUsageStatsSpanSize = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_accumulatedBatteryUsageStatsSpanSize);
                com.android.internal.R.integer.config_accumulatedBatteryUsageStatsSpanSize);
        mBatteryUsageStatsProvider = new BatteryUsageStatsProvider(context,
        mBatteryUsageStatsProvider = new BatteryUsageStatsProvider(mPowerAttributor,
                mPowerAttributor, mPowerProfile, mCpuScalingPolicies,
                mPowerStatsStore, accumulatedBatteryUsageStatsSpanSize, Clock.SYSTEM_CLOCK,
                mPowerStatsStore, accumulatedBatteryUsageStatsSpanSize, Clock.SYSTEM_CLOCK,
                mMonotonicClock);
                mMonotonicClock);
        mDumpHelper = new BatteryStatsDumpHelperImpl(mBatteryUsageStatsProvider);
        mDumpHelper = new BatteryStatsDumpHelperImpl(mBatteryUsageStatsProvider);
@@ -480,23 +479,15 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_CPU, true);
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_CPU, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_CPU, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_CPU, true);


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


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


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


        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO, true);
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO, true);
@@ -508,52 +499,30 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_BLUETOOTH, true);
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_BLUETOOTH, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_BLUETOOTH, true);
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_BLUETOOTH, true);


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

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


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

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


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

        attributor.setPowerComponentSupported(
        mStats.setPowerStatsCollectorEnabled(BatteryConsumer.POWER_COMPONENT_CAMERA, true);
                BatteryConsumer.POWER_COMPONENT_FLASHLIGHT,
        attributor.setPowerComponentSupported(BatteryConsumer.POWER_COMPONENT_CAMERA, true);
                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());


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


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


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


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


    /**
    /**
+0 −93
Original line number Original line 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 Original line 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 Original line 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);
    }
}
+1 −135

File changed.

Preview size limit exceeded, changes collapsed.

Loading