AppStatePowerBridge.java revision bf2516009068f4f686b34b316bb16c74ad4b57b3
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 */
16package com.android.settings.applications;
17
18import com.android.settingslib.applications.ApplicationsState;
19import com.android.settingslib.applications.ApplicationsState.AppEntry;
20import com.android.settingslib.applications.ApplicationsState.AppFilter;
21import com.android.settingslib.applications.ApplicationsState.CompoundFilter;
22import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
23
24import java.util.ArrayList;
25
26/**
27 * Connects data from the PowerWhitelistBackend to ApplicationsState.
28 */
29public 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