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