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

Commit 4d9a352a authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Ignore attribution data for unsupported custom power components

Bug: 348978972
Test: atest PowerStatsTests
Flag: com.android.server.power.optimization.streamlined_misc_battery_stats


Change-Id: Ia723ebaf615d7656e3e3b475ceeb383b7b3a3818
parent 43ef074d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -869,6 +869,16 @@ public final class BatteryUsageStats implements Parcelable, Closeable {
            return mIncludesProcessStateData;
        }

        /**
         * Returns true if this Builder is configured to hold data for the specified
         * custom power component ID.
         */
        public boolean isSupportedCustomPowerComponent(int componentId) {
            return componentId >= BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID
                    && componentId < BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID
                    + mBatteryConsumerDataLayout.customPowerComponentCount;
        }

        /**
         * Constructs a read-only object using the Builder values.
         */
+5 −2
Original line number Diff line number Diff line
@@ -154,8 +154,11 @@ public class PowerStatsExporter {
                batteryUsageStatsBuilder.getAggregateBatteryConsumerBuilder(
                        BatteryUsageStats.AGGREGATE_BATTERY_CONSUMER_SCOPE_DEVICE);
        if (descriptor.powerComponentId >= BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID) {
            if (batteryUsageStatsBuilder.isSupportedCustomPowerComponent(
                    descriptor.powerComponentId)) {
                deviceScope.addConsumedPowerForCustomComponent(descriptor.powerComponentId,
                        totalPower[0]);
            }
        } else {
            deviceScope.addConsumedPower(descriptor.powerComponentId,
                    totalPower[0], BatteryConsumer.POWER_MODEL_UNDEFINED);