1 /* 2 * Copyright (C) 2022 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.settings.fuelgauge; 18 19 import android.annotation.Nullable; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.util.ArrayMap; 24 import android.util.SparseIntArray; 25 26 import androidx.annotation.NonNull; 27 28 import com.android.settings.fuelgauge.batteryusage.BatteryDiffData; 29 import com.android.settings.fuelgauge.batteryusage.BatteryEvent; 30 import com.android.settings.fuelgauge.batteryusage.DetectRequestSourceType; 31 import com.android.settings.fuelgauge.batteryusage.PowerAnomalyEventList; 32 import com.android.settingslib.fuelgauge.Estimate; 33 34 import java.util.List; 35 import java.util.Map; 36 import java.util.Set; 37 38 /** Feature Provider used in power usage */ 39 public interface PowerUsageFeatureProvider { 40 41 /** Check whether the battery usage button is enabled in the battery page */ isBatteryUsageEnabled()42 boolean isBatteryUsageEnabled(); 43 44 /** Check whether the battery tips card is enabled in the battery usage page */ isBatteryTipsEnabled()45 boolean isBatteryTipsEnabled(); 46 47 /** Check whether overwrite the app optimization mode to restricted mode is enabled */ isRestrictedModeOverwriteEnabled()48 boolean isRestrictedModeOverwriteEnabled(); 49 50 /** Check whether force expire the app optimization mode. */ isForceExpireAppOptimizationModeEnabled()51 boolean isForceExpireAppOptimizationModeEnabled(); 52 53 /** Check whether to log the optimization mode of app entry in period job */ isAppOptimizationModeLogged()54 boolean isAppOptimizationModeLogged(); 55 56 /** 57 * Returns a threshold (in milliseconds) for the minimal screen on time in battery usage list 58 */ getBatteryUsageListScreenOnTimeThresholdInMs()59 double getBatteryUsageListScreenOnTimeThresholdInMs(); 60 61 /** Returns a threshold (mA) for the minimal comsume power in battery usage list */ getBatteryUsageListConsumePowerThreshold()62 double getBatteryUsageListConsumePowerThreshold(); 63 64 /** Returns an allowlist of app names combined into the system-apps item */ getSystemAppsAllowlist()65 List<String> getSystemAppsAllowlist(); 66 67 /** Returns the data retention days in the database */ getDataRetentionDays()68 int getDataRetentionDays(); 69 70 /** Check whether location setting is enabled */ isLocationSettingEnabled(String[] packages)71 boolean isLocationSettingEnabled(String[] packages); 72 73 /** Gets an {@link Intent} to show additional battery info */ getAdditionalBatteryInfoIntent()74 Intent getAdditionalBatteryInfoIntent(); 75 76 /** Check whether it is type service */ isTypeService(int uid)77 boolean isTypeService(int uid); 78 79 /** Check whether it is type system */ isTypeSystem(int uid, String[] packages)80 boolean isTypeSystem(int uid, String[] packages); 81 82 /** Returns an improved prediction for battery time remaining */ getEnhancedBatteryPrediction(Context context)83 Estimate getEnhancedBatteryPrediction(Context context); 84 85 /** 86 * Returns an improved projection curve for future battery level 87 * 88 * @param zeroTime timestamps (array keys) are shifted by this amount 89 */ getEnhancedBatteryPredictionCurve(Context context, long zeroTime)90 SparseIntArray getEnhancedBatteryPredictionCurve(Context context, long zeroTime); 91 92 /** Checks whether the toggle for enhanced battery predictions is enabled */ isEnhancedBatteryPredictionEnabled(Context context)93 boolean isEnhancedBatteryPredictionEnabled(Context context); 94 95 /** Checks whether debugging should be enabled for battery estimates */ isEstimateDebugEnabled()96 boolean isEstimateDebugEnabled(); 97 98 /** 99 * Converts the provided string containing the remaining time into a debug string for enhanced 100 * estimates 101 * 102 * @return A string containing the estimate and a label indicating it is an enhanced estimate 103 */ getEnhancedEstimateDebugString(String timeRemaining)104 String getEnhancedEstimateDebugString(String timeRemaining); 105 106 /** 107 * Converts the provided string containing the remaining time into a debug string 108 * 109 * @return A string containing the estimate and a label indicating it is a normal estimate 110 */ getOldEstimateDebugString(String timeRemaining)111 String getOldEstimateDebugString(String timeRemaining); 112 113 /** Checks whether smart battery feature is supported in this device */ isSmartBatterySupported()114 boolean isSmartBatterySupported(); 115 116 /** Checks whether we should show usage information by slots or not */ isChartGraphSlotsEnabled(Context context)117 boolean isChartGraphSlotsEnabled(Context context); 118 119 /** Checks whether adaptive charging feature is supported in this device */ isAdaptiveChargingSupported()120 boolean isAdaptiveChargingSupported(); 121 122 /** Checks whether battery manager feature is supported in this device */ isBatteryManagerSupported()123 boolean isBatteryManagerSupported(); 124 125 /** Returns {@code true} if current defender mode is extra defend */ isExtraDefend()126 boolean isExtraDefend(); 127 128 /** Returns {@code true} if delay the hourly job when device is booting */ delayHourlyJobWhenBooting()129 boolean delayHourlyJobWhenBooting(); 130 131 /** Returns {@link Bundle} for power anomaly detection result */ 132 @Nullable detectPowerAnomaly( Context context, double displayDrain, DetectRequestSourceType detectRequestSourceType)133 PowerAnomalyEventList detectPowerAnomaly( 134 Context context, double displayDrain, DetectRequestSourceType detectRequestSourceType); 135 136 /** Gets an intent for one time bypass charge limited to resume charging. */ getResumeChargeIntent(boolean isDockDefender)137 Intent getResumeChargeIntent(boolean isDockDefender); 138 139 /** Returns the intent action used to mark as the full charge start event. */ getFullChargeIntentAction()140 String getFullChargeIntentAction(); 141 142 /** Returns {@link Set} for the system component ids which are combined into others */ getOthersSystemComponentSet()143 Set<Integer> getOthersSystemComponentSet(); 144 145 /** Returns {@link Set} for the custom system component names which are combined into others */ getOthersCustomComponentNameSet()146 Set<String> getOthersCustomComponentNameSet(); 147 148 /** Returns {@link Set} for hiding system component ids in the usage screen */ getHideSystemComponentSet()149 Set<Integer> getHideSystemComponentSet(); 150 151 /** Returns {@link Set} for hiding application package names in the usage screen */ getHideApplicationSet()152 Set<String> getHideApplicationSet(); 153 154 /** Returns {@link Set} for hiding applications background usage time */ getHideBackgroundUsageTimeSet()155 Set<String> getHideBackgroundUsageTimeSet(); 156 157 /** Returns {@link Set} for ignoring task root class names for screen on time */ getIgnoreScreenOnTimeTaskRootSet()158 Set<String> getIgnoreScreenOnTimeTaskRootSet(); 159 160 /** Returns the customized device build information for data backup */ getBuildMetadata1(Context context)161 String getBuildMetadata1(Context context); 162 163 /** Returns the customized device build information for data backup */ getBuildMetadata2(Context context)164 String getBuildMetadata2(Context context); 165 166 /** Whether the app optimization mode is valid to restore */ isValidToRestoreOptimizationMode(ArrayMap<String, String> deviceInfoMap)167 boolean isValidToRestoreOptimizationMode(ArrayMap<String, String> deviceInfoMap); 168 169 /** Whether the device is under the battery defender mode */ isBatteryDefend(BatteryInfo info)170 boolean isBatteryDefend(BatteryInfo info); 171 172 /** Whether the battery usage reattribute is eabled or not. */ isBatteryUsageReattributeEnabled()173 boolean isBatteryUsageReattributeEnabled(); 174 175 /** Collect and process battery reattribute data if needed. */ processBatteryReattributeData( @onNull Context context, @NonNull Map<Long, BatteryDiffData> batteryDiffDataMap, @NonNull List<BatteryEvent> batteryEventList, final boolean isFromPeriodJob)176 boolean processBatteryReattributeData( 177 @NonNull Context context, 178 @NonNull Map<Long, BatteryDiffData> batteryDiffDataMap, 179 @NonNull List<BatteryEvent> batteryEventList, 180 final boolean isFromPeriodJob); 181 } 182