Home | History | Annotate | Download | only in applications
      1 /*
      2  * Copyright (C) 2015 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 package com.android.settings.applications;
     17 
     18 import com.android.settings.fuelgauge.PowerWhitelistBackend;
     19 import com.android.settingslib.applications.ApplicationsState;
     20 import com.android.settingslib.applications.ApplicationsState.AppEntry;
     21 import com.android.settingslib.applications.ApplicationsState.AppFilter;
     22 import com.android.settingslib.applications.ApplicationsState.CompoundFilter;
     23 
     24 import java.util.ArrayList;
     25 
     26 /**
     27  * Connects data from the PowerWhitelistBackend to ApplicationsState.
     28  */
     29 public class AppStatePowerBridge extends AppStateBaseBridge {
     30 
     31     private final PowerWhitelistBackend mBackend = PowerWhitelistBackend.getInstance();
     32 
     33     public AppStatePowerBridge(ApplicationsState appState, Callback callback) {
     34         super(appState, callback);
     35     }
     36 
     37     @Override
     38     protected void loadAllExtraInfo() {
     39         ArrayList<AppEntry> apps = mAppSession.getAllApps();
     40         final int N = apps.size();
     41         for (int i = 0; i < N; i++) {
     42             AppEntry app = apps.get(i);
     43             app.extraInfo = mBackend.isWhitelisted(app.info.packageName)
     44                     ? Boolean.TRUE : Boolean.FALSE;
     45         }
     46     }
     47 
     48     @Override
     49     protected void updateExtraInfo(AppEntry app, String pkg, int uid) {
     50         app.extraInfo = mBackend.isWhitelisted(pkg) ? Boolean.TRUE : Boolean.FALSE;
     51     }
     52 
     53     public static class HighPowerState {
     54         public boolean isHighPower;
     55         public boolean isSystemHighPower;
     56     }
     57 
     58     public static final AppFilter FILTER_POWER_WHITELISTED = new CompoundFilter(
     59             ApplicationsState.FILTER_WITHOUT_DISABLED_UNTIL_USED, new AppFilter() {
     60         @Override
     61         public void init() {
     62         }
     63 
     64         @Override
     65         public boolean filterApp(AppEntry info) {
     66             return info.extraInfo == Boolean.TRUE;
     67         }
     68     });
     69 }
     70