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