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; |
Alex Kulesza | 82dbcd9 | 2017-06-29 12:26:59 -0400 | [diff] [blame] | 25 | import android.util.SparseIntArray; |
| 26 | |
jackqdyulei | 238c1c0 | 2017-02-23 17:31:00 -0800 | [diff] [blame] | 27 | import com.android.internal.os.BatterySipper; |
| 28 | import com.android.internal.util.ArrayUtils; |
jackqdyulei | a224b01 | 2017-01-27 16:11:13 -0800 | [diff] [blame] | 29 | |
| 30 | public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider { |
jackqdyulei | 238c1c0 | 2017-02-23 17:31:00 -0800 | [diff] [blame] | 31 | |
| 32 | private static final String PACKAGE_CALENDAR_PROVIDER = "com.android.providers.calendar"; |
jackqdyulei | 44e8968 | 2017-02-28 13:51:24 -0800 | [diff] [blame] | 33 | private static final String PACKAGE_MEDIA_PROVIDER = "com.android.providers.media"; |
jackqdyulei | 1e95b74 | 2017-03-27 16:38:47 -0700 | [diff] [blame] | 34 | private static final String PACKAGE_SYSTEMUI = "com.android.systemui"; |
jackqdyulei | 44e8968 | 2017-02-28 13:51:24 -0800 | [diff] [blame] | 35 | private static final String[] PACKAGES_SYSTEM = {PACKAGE_MEDIA_PROVIDER, |
jackqdyulei | 1e95b74 | 2017-03-27 16:38:47 -0700 | [diff] [blame] | 36 | PACKAGE_CALENDAR_PROVIDER, PACKAGE_SYSTEMUI}; |
jackqdyulei | 238c1c0 | 2017-02-23 17:31:00 -0800 | [diff] [blame] | 37 | |
| 38 | protected PackageManager mPackageManager; |
| 39 | |
| 40 | public PowerUsageFeatureProviderImpl(Context context) { |
| 41 | mPackageManager = context.getPackageManager(); |
| 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; |
jackqdyulei | 44e8968 | 2017-02-28 13:51:24 -0800 | [diff] [blame] | 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 | } |
jackqdyulei | 238c1c0 | 2017-02-23 17:31:00 -0800 | [diff] [blame] | 62 | } |
jackqdyulei | 44e8968 | 2017-02-28 13:51:24 -0800 | [diff] [blame] | 63 | |
| 64 | return false; |
jackqdyulei | 238c1c0 | 2017-02-23 17:31:00 -0800 | [diff] [blame] | 65 | } |
| 66 | |
jackqdyulei | a224b01 | 2017-01-27 16:11:13 -0800 | [diff] [blame] | 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() { |
jackqdyulei | 1d51b3c | 2017-05-23 15:35:54 -0700 | [diff] [blame] | 84 | return true; |
jackqdyulei | a224b01 | 2017-01-27 16:11:13 -0800 | [diff] [blame] | 85 | } |
jackqdyulei | acc195f | 2017-02-13 15:14:51 -0800 | [diff] [blame] | 86 | |
| 87 | @Override |
jackqdyulei | 5115265 | 2017-02-15 16:27:03 -0800 | [diff] [blame] | 88 | public boolean isPowerAccountingToggleEnabled() { |
jackqdyulei | 1d51b3c | 2017-05-23 15:35:54 -0700 | [diff] [blame] | 89 | return true; |
jackqdyulei | 5115265 | 2017-02-15 16:27:03 -0800 | [diff] [blame] | 90 | } |
jackqdyulei | d1a1fed | 2017-04-26 10:48:05 -0700 | [diff] [blame] | 91 | |
| 92 | @Override |
Salvador Martinez | 126c032 | 2017-05-03 18:58:27 -0700 | [diff] [blame] | 93 | public long getEnhancedBatteryPrediction(Context context) { |
| 94 | return -1; |
| 95 | } |
| 96 | |
| 97 | @Override |
Alex Kulesza | 82dbcd9 | 2017-06-29 12:26:59 -0400 | [diff] [blame] | 98 | public SparseIntArray getEnhancedBatteryPredictionCurve(Context context, long zeroTime) { |
| 99 | return null; |
| 100 | } |
| 101 | |
| 102 | @Override |
Salvador Martinez | 126c032 | 2017-05-03 18:58:27 -0700 | [diff] [blame] | 103 | public boolean isEnhancedBatteryPredictionEnabled(Context context) { |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public Uri getEnhancedBatteryPredictionUri() { |
| 109 | return null; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public long getTimeRemainingEstimate(Cursor cursor) { |
| 114 | return 0; |
| 115 | } |
jackqdyulei | 0dce3c0 | 2017-05-03 15:15:41 -0700 | [diff] [blame] | 116 | |
| 117 | @Override |
Salvador Martinez | f4727ea | 2017-05-22 17:26:39 -0700 | [diff] [blame] | 118 | public String getEnhancedEstimateDebugString(String timeRemaining) { |
| 119 | return null; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public boolean isEstimateDebugEnabled() { |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public String getOldEstimateDebugString(String timeRemaining) { |
| 129 | return null; |
| 130 | } |
Salvador Martinez | cbefbc2 | 2017-06-19 10:33:41 -0700 | [diff] [blame] | 131 | |
| 132 | @Override |
| 133 | public String getAdvancedUsageScreenInfoString() { |
| 134 | return null; |
| 135 | } |
jackqdyulei | a224b01 | 2017-01-27 16:11:13 -0800 | [diff] [blame] | 136 | } |