jackqdyulei | a224b01 | 2017-01-27 16:11:13 -0800 | [diff] [blame] | 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 | |
jackqdyulei | 238c1c0 | 2017-02-23 17:31:00 -0800 | [diff] [blame] | 19 | import android.content.Context; |
jackqdyulei | a224b01 | 2017-01-27 16:11:13 -0800 | [diff] [blame] | 20 | import android.content.Intent; |
jackqdyulei | 238c1c0 | 2017-02-23 17:31:00 -0800 | [diff] [blame] | 21 | import android.content.pm.PackageManager; |
Salvador Martinez | 126c032 | 2017-05-03 18:58:27 -0700 | [diff] [blame] | 22 | import android.database.Cursor; |
| 23 | import android.net.Uri; |
jackqdyulei | 238c1c0 | 2017-02-23 17:31:00 -0800 | [diff] [blame] | 24 | import android.os.Process; |
| 25 | import com.android.internal.os.BatterySipper; |
| 26 | import com.android.internal.util.ArrayUtils; |
jackqdyulei | 0dce3c0 | 2017-05-03 15:15:41 -0700 | [diff] [blame] | 27 | import com.android.settings.fuelgauge.anomaly.Anomaly; |
jackqdyulei | a224b01 | 2017-01-27 16:11:13 -0800 | [diff] [blame] | 28 | |
| 29 | public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider { |
jackqdyulei | 238c1c0 | 2017-02-23 17:31:00 -0800 | [diff] [blame] | 30 | |
| 31 | private static final String PACKAGE_CALENDAR_PROVIDER = "com.android.providers.calendar"; |
jackqdyulei | 44e8968 | 2017-02-28 13:51:24 -0800 | [diff] [blame] | 32 | private static final String PACKAGE_MEDIA_PROVIDER = "com.android.providers.media"; |
jackqdyulei | 1e95b74 | 2017-03-27 16:38:47 -0700 | [diff] [blame] | 33 | private static final String PACKAGE_SYSTEMUI = "com.android.systemui"; |
jackqdyulei | 44e8968 | 2017-02-28 13:51:24 -0800 | [diff] [blame] | 34 | private static final String[] PACKAGES_SYSTEM = {PACKAGE_MEDIA_PROVIDER, |
jackqdyulei | 1e95b74 | 2017-03-27 16:38:47 -0700 | [diff] [blame] | 35 | PACKAGE_CALENDAR_PROVIDER, PACKAGE_SYSTEMUI}; |
jackqdyulei | 238c1c0 | 2017-02-23 17:31:00 -0800 | [diff] [blame] | 36 | |
| 37 | protected PackageManager mPackageManager; |
| 38 | |
| 39 | public PowerUsageFeatureProviderImpl(Context context) { |
| 40 | mPackageManager = context.getPackageManager(); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public boolean isTypeService(BatterySipper sipper) { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public boolean isTypeSystem(BatterySipper sipper) { |
| 50 | final int uid = sipper.uidObj == null ? -1 : sipper.getUid(); |
| 51 | sipper.mPackages = mPackageManager.getPackagesForUid(uid); |
| 52 | // Classify all the sippers to type system if the range of uid is 0...FIRST_APPLICATION_UID |
| 53 | if (uid >= Process.ROOT_UID && uid < Process.FIRST_APPLICATION_UID) { |
| 54 | return true; |
jackqdyulei | 44e8968 | 2017-02-28 13:51:24 -0800 | [diff] [blame] | 55 | } else if (sipper.mPackages != null) { |
| 56 | for (final String packageName : sipper.mPackages) { |
| 57 | if (ArrayUtils.contains(PACKAGES_SYSTEM, packageName)) { |
| 58 | return true; |
| 59 | } |
| 60 | } |
jackqdyulei | 238c1c0 | 2017-02-23 17:31:00 -0800 | [diff] [blame] | 61 | } |
jackqdyulei | 44e8968 | 2017-02-28 13:51:24 -0800 | [diff] [blame] | 62 | |
| 63 | return false; |
jackqdyulei | 238c1c0 | 2017-02-23 17:31:00 -0800 | [diff] [blame] | 64 | } |
| 65 | |
jackqdyulei | a224b01 | 2017-01-27 16:11:13 -0800 | [diff] [blame] | 66 | @Override |
| 67 | public boolean isLocationSettingEnabled(String[] packages) { |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public boolean isAdditionalBatteryInfoEnabled() { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public Intent getAdditionalBatteryInfoIntent() { |
| 78 | return null; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public boolean isAdvancedUiEnabled() { |
jackqdyulei | 1d51b3c | 2017-05-23 15:35:54 -0700 | [diff] [blame] | 83 | return true; |
jackqdyulei | a224b01 | 2017-01-27 16:11:13 -0800 | [diff] [blame] | 84 | } |
jackqdyulei | acc195f | 2017-02-13 15:14:51 -0800 | [diff] [blame] | 85 | |
| 86 | @Override |
jackqdyulei | 5115265 | 2017-02-15 16:27:03 -0800 | [diff] [blame] | 87 | public boolean isPowerAccountingToggleEnabled() { |
jackqdyulei | 1d51b3c | 2017-05-23 15:35:54 -0700 | [diff] [blame] | 88 | return true; |
jackqdyulei | 5115265 | 2017-02-15 16:27:03 -0800 | [diff] [blame] | 89 | } |
jackqdyulei | d1a1fed | 2017-04-26 10:48:05 -0700 | [diff] [blame] | 90 | |
| 91 | @Override |
| 92 | public boolean isAnomalyDetectionEnabled() { |
| 93 | return false; |
| 94 | } |
Salvador Martinez | 126c032 | 2017-05-03 18:58:27 -0700 | [diff] [blame] | 95 | |
| 96 | @Override |
| 97 | public long getEnhancedBatteryPrediction(Context context) { |
| 98 | return -1; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public boolean isEnhancedBatteryPredictionEnabled(Context context) { |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public Uri getEnhancedBatteryPredictionUri() { |
| 108 | return null; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public long getTimeRemainingEstimate(Cursor cursor) { |
| 113 | return 0; |
| 114 | } |
jackqdyulei | 0dce3c0 | 2017-05-03 15:15:41 -0700 | [diff] [blame] | 115 | |
| 116 | @Override |
| 117 | public boolean isAnomalyDetectorEnabled(@Anomaly.AnomalyType int type) { |
| 118 | return false; |
| 119 | } |
Salvador Martinez | f4727ea | 2017-05-22 17:26:39 -0700 | [diff] [blame] | 120 | |
| 121 | @Override |
| 122 | public String getEnhancedEstimateDebugString(String timeRemaining) { |
| 123 | return null; |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public boolean isEstimateDebugEnabled() { |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public String getOldEstimateDebugString(String timeRemaining) { |
| 133 | return null; |
| 134 | } |
Salvador Martinez | cbefbc2 | 2017-06-19 10:33:41 -0700 | [diff] [blame^] | 135 | |
| 136 | @Override |
| 137 | public String getAdvancedUsageScreenInfoString() { |
| 138 | return null; |
| 139 | } |
jackqdyulei | a224b01 | 2017-01-27 16:11:13 -0800 | [diff] [blame] | 140 | } |