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.os.Process;
23 import android.util.SparseIntArray;
24 
25 import com.android.internal.os.BatterySipper;
26 import com.android.internal.util.ArrayUtils;
27 import com.android.settingslib.fuelgauge.Estimate;
28 
29 public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider {
30 
31     private static final String PACKAGE_CALENDAR_PROVIDER = "com.android.providers.calendar";
32     private static final String PACKAGE_MEDIA_PROVIDER = "com.android.providers.media";
33     private static final String PACKAGE_SYSTEMUI = "com.android.systemui";
34     private static final String[] PACKAGES_SYSTEM = {PACKAGE_MEDIA_PROVIDER,
35             PACKAGE_CALENDAR_PROVIDER, PACKAGE_SYSTEMUI};
36 
37     protected PackageManager mPackageManager;
38     protected Context mContext;
39 
PowerUsageFeatureProviderImpl(Context context)40     public PowerUsageFeatureProviderImpl(Context context) {
41         mPackageManager = context.getPackageManager();
42         mContext = context.getApplicationContext();
43     }
44 
45     @Override
isTypeService(BatterySipper sipper)46     public boolean isTypeService(BatterySipper sipper) {
47         return false;
48     }
49 
50     @Override
isTypeSystem(BatterySipper sipper)51     public boolean isTypeSystem(BatterySipper sipper) {
52         final int uid = sipper.uidObj == null ? -1 : sipper.getUid();
53         sipper.mPackages = mPackageManager.getPackagesForUid(uid);
54         // Classify all the sippers to type system if the range of uid is 0...FIRST_APPLICATION_UID
55         if (uid >= Process.ROOT_UID && uid < Process.FIRST_APPLICATION_UID) {
56             return true;
57         } else if (sipper.mPackages != null) {
58             for (final String packageName : sipper.mPackages) {
59                 if (ArrayUtils.contains(PACKAGES_SYSTEM, packageName)) {
60                     return true;
61                 }
62             }
63         }
64 
65         return false;
66     }
67 
68     @Override
isLocationSettingEnabled(String[] packages)69     public boolean isLocationSettingEnabled(String[] packages) {
70         return false;
71     }
72 
73     @Override
isAdditionalBatteryInfoEnabled()74     public boolean isAdditionalBatteryInfoEnabled() {
75         return false;
76     }
77 
78     @Override
getAdditionalBatteryInfoIntent()79     public Intent getAdditionalBatteryInfoIntent() {
80         return null;
81     }
82 
83     @Override
isAdvancedUiEnabled()84     public boolean isAdvancedUiEnabled() {
85         return true;
86     }
87 
88     @Override
isPowerAccountingToggleEnabled()89     public boolean isPowerAccountingToggleEnabled() {
90         return true;
91     }
92 
93     @Override
getEnhancedBatteryPrediction(Context context)94     public Estimate getEnhancedBatteryPrediction(Context context) {
95         return null;
96     }
97 
98     @Override
getEnhancedBatteryPredictionCurve(Context context, long zeroTime)99     public SparseIntArray getEnhancedBatteryPredictionCurve(Context context, long zeroTime) {
100         return null;
101     }
102 
103     @Override
isEnhancedBatteryPredictionEnabled(Context context)104     public boolean isEnhancedBatteryPredictionEnabled(Context context) {
105         return false;
106     }
107 
108     @Override
getEnhancedEstimateDebugString(String timeRemaining)109     public String getEnhancedEstimateDebugString(String timeRemaining) {
110         return null;
111     }
112 
113     @Override
isEstimateDebugEnabled()114     public boolean isEstimateDebugEnabled() {
115         return false;
116     }
117 
118     @Override
getOldEstimateDebugString(String timeRemaining)119     public String getOldEstimateDebugString(String timeRemaining) {
120         return null;
121     }
122 
123     @Override
getAdvancedUsageScreenInfoString()124     public String getAdvancedUsageScreenInfoString() {
125         return null;
126     }
127 
128     @Override
getEarlyWarningSignal(Context context, String id)129     public boolean getEarlyWarningSignal(Context context, String id) {
130         return false;
131     }
132 
133     @Override
isSmartBatterySupported()134     public boolean isSmartBatterySupported() {
135         return mContext.getResources().getBoolean(
136                 com.android.internal.R.bool.config_smart_battery_available);
137     }
138 }
139