1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.power.stats; 18 19 import android.os.BatteryConsumer; 20 import android.os.BatteryUsageStats; 21 import android.util.IndentingPrintWriter; 22 23 import com.android.internal.os.BatteryStatsHistory; 24 25 public interface PowerAttributor { 26 27 /** 28 * Returns true if the specified power component can be handled by this PowerAttributor 29 */ isPowerComponentSupported(@atteryConsumer.PowerComponentId int powerComponentId)30 boolean isPowerComponentSupported(@BatteryConsumer.PowerComponentId int powerComponentId); 31 32 /** 33 * Performs the power attribution calculations and returns the results by populating the 34 * supplied BatteryUsageStats.Builder 35 */ estimatePowerConsumption(BatteryUsageStats.Builder batteryUsageStatsBuilder, BatteryStatsHistory batteryHistory, long monotonicStartTime, long monotonicEndTime)36 void estimatePowerConsumption(BatteryUsageStats.Builder batteryUsageStatsBuilder, 37 BatteryStatsHistory batteryHistory, long monotonicStartTime, long monotonicEndTime); 38 39 /** 40 * Computes estimated power consumption attribution for the specified time range and stores 41 * it in PowerStatsStore for potential accumulation. 42 * 43 * Returns the monotonic timestamp of the last processed history item. 44 */ storeEstimatedPowerConsumption(BatteryStatsHistory batteryStatsHistory, long startTime, long endTimeMs)45 long storeEstimatedPowerConsumption(BatteryStatsHistory batteryStatsHistory, long startTime, 46 long endTimeMs); 47 48 /** 49 * Returns the monotonic timestamp of the last processed history item, stored in 50 * PowerStatsStore. 51 */ getLastSavedEstimatesPowerConsumptionTimestamp()52 long getLastSavedEstimatesPowerConsumptionTimestamp(); 53 54 /** 55 * Performs the power attribution calculation and prints the results. 56 */ dumpEstimatedPowerConsumption(IndentingPrintWriter ipw, BatteryStatsHistory batteryStatsHistory, long startTime, long endTime)57 void dumpEstimatedPowerConsumption(IndentingPrintWriter ipw, 58 BatteryStatsHistory batteryStatsHistory, long startTime, long endTime); 59 } 60