Home | History | Annotate | Download | only in fuelgauge
      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 
     19 import android.content.Context;
     20 import android.content.Intent;
     21 import android.content.pm.PackageManager;
     22 import android.os.Process;
     23 import com.android.internal.os.BatterySipper;
     24 import com.android.internal.util.ArrayUtils;
     25 
     26 public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider {
     27 
     28     private static final String PACKAGE_CALENDAR_PROVIDER = "com.android.providers.calendar";
     29     private static final String PACKAGE_MEDIA_PROVIDER = "com.android.providers.media";
     30     private static final String PACKAGE_SYSTEMUI = "com.android.systemui";
     31     private static final String[] PACKAGES_SYSTEM = {PACKAGE_MEDIA_PROVIDER,
     32             PACKAGE_CALENDAR_PROVIDER, PACKAGE_SYSTEMUI};
     33 
     34     protected PackageManager mPackageManager;
     35 
     36     public PowerUsageFeatureProviderImpl(Context context) {
     37         mPackageManager = context.getPackageManager();
     38     }
     39 
     40     @Override
     41     public boolean isTypeService(BatterySipper sipper) {
     42         return false;
     43     }
     44 
     45     @Override
     46     public boolean isTypeSystem(BatterySipper sipper) {
     47         final int uid = sipper.uidObj == null ? -1 : sipper.getUid();
     48         sipper.mPackages = mPackageManager.getPackagesForUid(uid);
     49         // Classify all the sippers to type system if the range of uid is 0...FIRST_APPLICATION_UID
     50         if (uid >= Process.ROOT_UID && uid < Process.FIRST_APPLICATION_UID) {
     51             return true;
     52         } else if (sipper.mPackages != null) {
     53             for (final String packageName : sipper.mPackages) {
     54                 if (ArrayUtils.contains(PACKAGES_SYSTEM, packageName)) {
     55                     return true;
     56                 }
     57             }
     58         }
     59 
     60         return false;
     61     }
     62 
     63     @Override
     64     public boolean isLocationSettingEnabled(String[] packages) {
     65         return false;
     66     }
     67 
     68     @Override
     69     public boolean isAdditionalBatteryInfoEnabled() {
     70         return false;
     71     }
     72 
     73     @Override
     74     public Intent getAdditionalBatteryInfoIntent() {
     75         return null;
     76     }
     77 
     78     @Override
     79     public boolean isAdvancedUiEnabled() {
     80         return true;
     81     }
     82 
     83     @Override
     84     public boolean isPowerAccountingToggleEnabled() {
     85         return true;
     86     }
     87 }
     88