AppStateNotificationBridge.java revision ed5c50a9cb5b67c8eed9661221f8825b69dd4da8
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 android.content.pm.PackageManager; 19 20import com.android.settings.notification.NotificationBackend; 21import com.android.settings.notification.NotificationBackend.AppRow; 22import com.android.settingslib.applications.ApplicationsState; 23import com.android.settingslib.applications.ApplicationsState.AppEntry; 24import com.android.settingslib.applications.ApplicationsState.AppFilter; 25 26import java.util.ArrayList; 27 28/** 29 * Connects the info provided by ApplicationsState and the NotificationBackend. 30 * Also provides app filters that can use the notification data. 31 */ 32public class AppStateNotificationBridge extends AppStateBaseBridge { 33 34 private final NotificationBackend mNotifBackend; 35 private final PackageManager mPm; 36 37 public AppStateNotificationBridge(PackageManager pm, ApplicationsState appState, 38 Callback callback, NotificationBackend notifBackend) { 39 super(appState, callback); 40 mPm = pm; 41 mNotifBackend = notifBackend; 42 } 43 44 @Override 45 protected void loadAllExtraInfo() { 46 ArrayList<AppEntry> apps = mAppSession.getAllApps(); 47 final int N = apps.size(); 48 for (int i = 0; i < N; i++) { 49 AppEntry app = apps.get(i); 50 app.extraInfo = mNotifBackend.loadAppRow(mPm, app.info); 51 } 52 } 53 54 @Override 55 protected void updateExtraInfo(AppEntry app, String pkg, int uid) { 56 app.extraInfo = mNotifBackend.loadAppRow(mPm, app.info); 57 } 58 59 public static final AppFilter FILTER_APP_NOTIFICATION_BLOCKED = new AppFilter() { 60 @Override 61 public void init() { 62 } 63 64 @Override 65 public boolean filterApp(AppEntry info) { 66 if (info == null) { 67 return false; 68 } 69 AppRow row = (AppRow) info.extraInfo; 70 return row.banned; 71 } 72 }; 73} 74