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