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 static com.android.settings.Utils.SYSTEMUI_PACKAGE_NAME; 20 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.pm.PackageManager; 24 import android.os.Process; 25 import android.util.ArrayMap; 26 import android.util.ArraySet; 27 import android.util.SparseIntArray; 28 29 import androidx.annotation.NonNull; 30 import androidx.annotation.Nullable; 31 32 import com.android.internal.util.ArrayUtils; 33 import com.android.settings.fuelgauge.batteryusage.BatteryDiffData; 34 import com.android.settings.fuelgauge.batteryusage.BatteryEvent; 35 import com.android.settings.fuelgauge.batteryusage.DetectRequestSourceType; 36 import com.android.settings.fuelgauge.batteryusage.PowerAnomalyEventList; 37 import com.android.settingslib.fuelgauge.Estimate; 38 39 import java.util.ArrayList; 40 import java.util.List; 41 import java.util.Map; 42 import java.util.Set; 43 44 /** Implementation of {@code PowerUsageFeatureProvider} */ 45 public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider { 46 47 private static final String PACKAGE_CALENDAR_PROVIDER = "com.android.providers.calendar"; 48 private static final String PACKAGE_MEDIA_PROVIDER = "com.android.providers.media"; 49 private static final String[] PACKAGES_SYSTEM = { 50 PACKAGE_MEDIA_PROVIDER, PACKAGE_CALENDAR_PROVIDER, SYSTEMUI_PACKAGE_NAME 51 }; 52 53 protected PackageManager mPackageManager; 54 protected Context mContext; 55 PowerUsageFeatureProviderImpl(Context context)56 public PowerUsageFeatureProviderImpl(Context context) { 57 mPackageManager = context.getPackageManager(); 58 mContext = context.getApplicationContext(); 59 } 60 61 @Override isTypeService(int uid)62 public boolean isTypeService(int uid) { 63 return false; 64 } 65 66 @Override isTypeSystem(int uid, String[] packages)67 public boolean isTypeSystem(int uid, String[] packages) { 68 // Classify all the sippers to type system if the range of uid is 0...FIRST_APPLICATION_UID 69 if (uid >= Process.ROOT_UID && uid < Process.FIRST_APPLICATION_UID) { 70 return true; 71 } else if (packages != null) { 72 for (final String packageName : packages) { 73 if (ArrayUtils.contains(PACKAGES_SYSTEM, packageName)) { 74 return true; 75 } 76 } 77 } 78 return false; 79 } 80 81 @Override isBatteryUsageEnabled()82 public boolean isBatteryUsageEnabled() { 83 return true; 84 } 85 86 @Override isBatteryTipsEnabled()87 public boolean isBatteryTipsEnabled() { 88 return false; 89 } 90 91 @Override isAppOptimizationModeLogged()92 public boolean isAppOptimizationModeLogged() { 93 return false; 94 } 95 96 @Override getBatteryUsageListScreenOnTimeThresholdInMs()97 public double getBatteryUsageListScreenOnTimeThresholdInMs() { 98 return 0; 99 } 100 101 @Override getBatteryUsageListConsumePowerThreshold()102 public double getBatteryUsageListConsumePowerThreshold() { 103 return 0; 104 } 105 106 @Override getSystemAppsAllowlist()107 public List<String> getSystemAppsAllowlist() { 108 return new ArrayList<>(); 109 } 110 111 @Override isLocationSettingEnabled(String[] packages)112 public boolean isLocationSettingEnabled(String[] packages) { 113 return false; 114 } 115 116 @Override getAdditionalBatteryInfoIntent()117 public Intent getAdditionalBatteryInfoIntent() { 118 return null; 119 } 120 121 @Override getEnhancedBatteryPrediction(Context context)122 public Estimate getEnhancedBatteryPrediction(Context context) { 123 return null; 124 } 125 126 @Override getEnhancedBatteryPredictionCurve(Context context, long zeroTime)127 public SparseIntArray getEnhancedBatteryPredictionCurve(Context context, long zeroTime) { 128 return null; 129 } 130 131 @Override isEnhancedBatteryPredictionEnabled(Context context)132 public boolean isEnhancedBatteryPredictionEnabled(Context context) { 133 return false; 134 } 135 136 @Override getEnhancedEstimateDebugString(String timeRemaining)137 public String getEnhancedEstimateDebugString(String timeRemaining) { 138 return null; 139 } 140 141 @Override isEstimateDebugEnabled()142 public boolean isEstimateDebugEnabled() { 143 return false; 144 } 145 146 @Override getOldEstimateDebugString(String timeRemaining)147 public String getOldEstimateDebugString(String timeRemaining) { 148 return null; 149 } 150 151 @Override isSmartBatterySupported()152 public boolean isSmartBatterySupported() { 153 return mContext.getResources() 154 .getBoolean(com.android.internal.R.bool.config_smart_battery_available); 155 } 156 157 @Override isChartGraphSlotsEnabled(Context context)158 public boolean isChartGraphSlotsEnabled(Context context) { 159 return false; 160 } 161 162 @Override isAdaptiveChargingSupported()163 public boolean isAdaptiveChargingSupported() { 164 return false; 165 } 166 167 @Override isBatteryManagerSupported()168 public boolean isBatteryManagerSupported() { 169 return true; 170 } 171 172 @Override getResumeChargeIntent(boolean isDockDefender)173 public Intent getResumeChargeIntent(boolean isDockDefender) { 174 return null; 175 } 176 177 @Override getFullChargeIntentAction()178 public String getFullChargeIntentAction() { 179 return Intent.ACTION_BATTERY_LEVEL_CHANGED; 180 } 181 182 @Override isExtraDefend()183 public boolean isExtraDefend() { 184 return false; 185 } 186 187 @Override delayHourlyJobWhenBooting()188 public boolean delayHourlyJobWhenBooting() { 189 return true; 190 } 191 192 @Override 193 @Nullable detectPowerAnomaly( Context context, double displayDrain, DetectRequestSourceType detectRequestSourceType)194 public PowerAnomalyEventList detectPowerAnomaly( 195 Context context, double displayDrain, DetectRequestSourceType detectRequestSourceType) { 196 return null; 197 } 198 199 @Override getOthersSystemComponentSet()200 public Set<Integer> getOthersSystemComponentSet() { 201 return new ArraySet<>(); 202 } 203 204 @Override getOthersCustomComponentNameSet()205 public Set<String> getOthersCustomComponentNameSet() { 206 return new ArraySet<>(); 207 } 208 209 @Override getHideSystemComponentSet()210 public Set<Integer> getHideSystemComponentSet() { 211 return new ArraySet<>(); 212 } 213 214 @Override getHideApplicationSet()215 public Set<String> getHideApplicationSet() { 216 return new ArraySet<>(); 217 } 218 219 @Override getHideBackgroundUsageTimeSet()220 public Set<String> getHideBackgroundUsageTimeSet() { 221 return new ArraySet<>(); 222 } 223 224 @Override getIgnoreScreenOnTimeTaskRootSet()225 public Set<String> getIgnoreScreenOnTimeTaskRootSet() { 226 return new ArraySet<>(); 227 } 228 229 @Override getBuildMetadata1(Context context)230 public String getBuildMetadata1(Context context) { 231 return null; 232 } 233 234 @Override getBuildMetadata2(Context context)235 public String getBuildMetadata2(Context context) { 236 return null; 237 } 238 239 @Override isValidToRestoreOptimizationMode(ArrayMap<String, String> deviceInfoMap)240 public boolean isValidToRestoreOptimizationMode(ArrayMap<String, String> deviceInfoMap) { 241 return false; 242 } 243 244 @Override isBatteryDefend(BatteryInfo info)245 public boolean isBatteryDefend(BatteryInfo info) { 246 return info.isBatteryDefender && !isExtraDefend(); 247 } 248 249 @Override isBatteryUsageReattributeEnabled()250 public boolean isBatteryUsageReattributeEnabled() { 251 return false; 252 } 253 254 @Override processBatteryReattributeData( @onNull Context context, @NonNull Map<Long, BatteryDiffData> batteryDiffDataMap, @NonNull List<BatteryEvent> batteryEventList, final boolean isFromPeriodJob)255 public boolean processBatteryReattributeData( 256 @NonNull Context context, 257 @NonNull Map<Long, BatteryDiffData> batteryDiffDataMap, 258 @NonNull List<BatteryEvent> batteryEventList, 259 final boolean isFromPeriodJob) { 260 return false; 261 } 262 } 263