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