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 */ 14 package com.android.settings.datausage; 15 16 import com.android.settings.applications.AppStateBaseBridge; 17 import com.android.settingslib.applications.ApplicationsState; 18 import com.android.settingslib.applications.ApplicationsState.AppEntry; 19 20 import java.util.ArrayList; 21 22 public class AppStateDataUsageBridge extends AppStateBaseBridge { 23 24 private static final String TAG = "AppStateDataUsageBridge"; 25 26 private final DataSaverBackend mDataSaverBackend; 27 AppStateDataUsageBridge(ApplicationsState appState, Callback callback, DataSaverBackend backend)28 public AppStateDataUsageBridge(ApplicationsState appState, Callback callback, 29 DataSaverBackend backend) { 30 super(appState, callback); 31 mDataSaverBackend = backend; 32 } 33 34 @Override loadAllExtraInfo()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 updateExtraInfo(AppEntry app, String pkg, int uid)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 DataUsageState(boolean isDataSaverWhitelisted, boolean isDataSaverBlacklisted)55 public DataUsageState(boolean isDataSaverWhitelisted, boolean isDataSaverBlacklisted) { 56 this.isDataSaverWhitelisted = isDataSaverWhitelisted; 57 this.isDataSaverBlacklisted = isDataSaverBlacklisted; 58 } 59 } 60 } 61