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