1 /*
2  * Copyright (C) 2017 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.content.Context;
20 import android.content.Intent;
21 import android.content.pm.PackageManager;
22 import android.net.Uri;
23 import android.os.Process;
24 import android.util.SparseIntArray;
25 
26 import com.android.internal.os.BatterySipper;
27 import com.android.internal.util.ArrayUtils;
28 import com.android.settingslib.fuelgauge.Estimate;
29 
30 import java.util.HashSet;
31 import java.util.Map;
32 import java.util.Set;
33 
34 public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider {
35 
36     private static final String PACKAGE_CALENDAR_PROVIDER = "com.android.providers.calendar";
37     private static final String PACKAGE_MEDIA_PROVIDER = "com.android.providers.media";
38     private static final String PACKAGE_SYSTEMUI = "com.android.systemui";
39     private static final String[] PACKAGES_SYSTEM = {PACKAGE_MEDIA_PROVIDER,
40             PACKAGE_CALENDAR_PROVIDER, PACKAGE_SYSTEMUI};
41 
42     protected PackageManager mPackageManager;
43     protected Context mContext;
44 
PowerUsageFeatureProviderImpl(Context context)45     public PowerUsageFeatureProviderImpl(Context context) {
46         mPackageManager = context.getPackageManager();
47         mContext = context.getApplicationContext();
48     }
49 
50     @Override
isTypeService(BatterySipper sipper)51     public boolean isTypeService(BatterySipper sipper) {
52         return false;
53     }
54 
55     @Override
isTypeSystem(BatterySipper sipper)56     public boolean isTypeSystem(BatterySipper sipper) {
57         final int uid = sipper.uidObj == null ? -1 : sipper.getUid();
58         sipper.mPackages = mPackageManager.getPackagesForUid(uid);
59         // Classify all the sippers to type system if the range of uid is 0...FIRST_APPLICATION_UID
60         if (uid >= Process.ROOT_UID && uid < Process.FIRST_APPLICATION_UID) {
61             return true;
62         } else if (sipper.mPackages != null) {
63             for (final String packageName : sipper.mPackages) {
64                 if (ArrayUtils.contains(PACKAGES_SYSTEM, packageName)) {
65                     return true;
66                 }
67             }
68         }
69 
70         return false;
71     }
72 
73     @Override
isTypeSystem(int uid, String[] packages)74     public boolean isTypeSystem(int uid, String[] packages) {
75         // Classify all the sippers to type system if the range of uid is 0...FIRST_APPLICATION_UID
76         if (uid >= Process.ROOT_UID && uid < Process.FIRST_APPLICATION_UID) {
77             return true;
78         } else if (packages != null) {
79             for (final String packageName : packages) {
80                 if (ArrayUtils.contains(PACKAGES_SYSTEM, packageName)) {
81                     return true;
82                 }
83             }
84         }
85         return false;
86     }
87 
88     @Override
isLocationSettingEnabled(String[] packages)89     public boolean isLocationSettingEnabled(String[] packages) {
90         return false;
91     }
92 
93     @Override
isAdditionalBatteryInfoEnabled()94     public boolean isAdditionalBatteryInfoEnabled() {
95         return false;
96     }
97 
98     @Override
getAdditionalBatteryInfoIntent()99     public Intent getAdditionalBatteryInfoIntent() {
100         return null;
101     }
102 
103     @Override
isAdvancedUiEnabled()104     public boolean isAdvancedUiEnabled() {
105         return true;
106     }
107 
108     @Override
isPowerAccountingToggleEnabled()109     public boolean isPowerAccountingToggleEnabled() {
110         return true;
111     }
112 
113     @Override
getEnhancedBatteryPrediction(Context context)114     public Estimate getEnhancedBatteryPrediction(Context context) {
115         return null;
116     }
117 
118     @Override
getEnhancedBatteryPredictionCurve(Context context, long zeroTime)119     public SparseIntArray getEnhancedBatteryPredictionCurve(Context context, long zeroTime) {
120         return null;
121     }
122 
123     @Override
isEnhancedBatteryPredictionEnabled(Context context)124     public boolean isEnhancedBatteryPredictionEnabled(Context context) {
125         return false;
126     }
127 
128     @Override
getEnhancedEstimateDebugString(String timeRemaining)129     public String getEnhancedEstimateDebugString(String timeRemaining) {
130         return null;
131     }
132 
133     @Override
isEstimateDebugEnabled()134     public boolean isEstimateDebugEnabled() {
135         return false;
136     }
137 
138     @Override
getOldEstimateDebugString(String timeRemaining)139     public String getOldEstimateDebugString(String timeRemaining) {
140         return null;
141     }
142 
143     @Override
getAdvancedUsageScreenInfoString()144     public String getAdvancedUsageScreenInfoString() {
145         return null;
146     }
147 
148     @Override
getEarlyWarningSignal(Context context, String id)149     public boolean getEarlyWarningSignal(Context context, String id) {
150         return false;
151     }
152 
153     @Override
isSmartBatterySupported()154     public boolean isSmartBatterySupported() {
155         return mContext.getResources().getBoolean(
156                 com.android.internal.R.bool.config_smart_battery_available);
157     }
158 
159     @Override
isChartGraphEnabled(Context context)160     public boolean isChartGraphEnabled(Context context) {
161         return false;
162     }
163 
164     @Override
isChartGraphSlotsEnabled(Context context)165     public boolean isChartGraphSlotsEnabled(Context context) {
166         return false;
167     }
168 
169     @Override
isAdaptiveChargingSupported()170     public boolean isAdaptiveChargingSupported() {
171         return false;
172     }
173 
174     @Override
getResumeChargeIntent()175     public Intent getResumeChargeIntent() {
176         return null;
177     }
178 
179     @Override
getBatteryHistory(Context context)180     public Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context) {
181         return null;
182     }
183 
184     @Override
getBatteryHistoryUri()185     public Uri getBatteryHistoryUri() {
186         return null;
187     }
188 
189     @Override
getHideBackgroundUsageTimeSet(Context context)190     public Set<CharSequence> getHideBackgroundUsageTimeSet(Context context) {
191         return new HashSet<>();
192     }
193 
194     @Override
getHideApplicationEntries(Context context)195     public CharSequence[] getHideApplicationEntries(Context context) {
196         return new CharSequence[0];
197     }
198 
199     @Override
getHideApplicationSummary(Context context)200     public CharSequence[] getHideApplicationSummary(Context context) {
201         return new CharSequence[0];
202     }
203 }
204