1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 *      http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14package com.android.settings.datausage;
15
16import com.android.settings.applications.AppStateBaseBridge;
17import com.android.settingslib.applications.ApplicationsState;
18import com.android.settingslib.applications.ApplicationsState.AppEntry;
19
20import java.util.ArrayList;
21
22public class AppStateDataUsageBridge extends AppStateBaseBridge {
23
24    private static final String TAG = "AppStateDataUsageBridge";
25
26    private final DataSaverBackend mDataSaverBackend;
27
28    public AppStateDataUsageBridge(ApplicationsState appState, Callback callback,
29            DataSaverBackend backend) {
30        super(appState, callback);
31        mDataSaverBackend = backend;
32    }
33
34    @Override
35    protected void loadAllExtraInfo() {
36        ArrayList<AppEntry> apps = mAppSession.getAllApps();
37        final int N = apps.size();
38        for (int i = 0; i < N; i++) {
39            AppEntry app = apps.get(i);
40            app.extraInfo = new DataUsageState(mDataSaverBackend.isWhitelisted(app.info.uid),
41                    mDataSaverBackend.isBlacklisted(app.info.uid));
42        }
43    }
44
45    @Override
46    protected void updateExtraInfo(AppEntry app, String pkg, int uid) {
47        app.extraInfo = new DataUsageState(mDataSaverBackend.isWhitelisted(uid),
48                mDataSaverBackend.isBlacklisted(uid));
49    }
50
51    public static class DataUsageState {
52        public boolean isDataSaverWhitelisted;
53        public boolean isDataSaverBlacklisted;
54
55        public DataUsageState(boolean isDataSaverWhitelisted, boolean isDataSaverBlacklisted) {
56            this.isDataSaverWhitelisted = isDataSaverWhitelisted;
57            this.isDataSaverBlacklisted = isDataSaverBlacklisted;
58        }
59    }
60}
61