Home | History | Annotate | Download | only in applications
      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.content.Context;
     20 import android.content.pm.PackageManager;
     21 import android.os.UserHandle;
     22 import android.service.notification.NotificationListenerService;
     23 
     24 import com.android.internal.widget.LockPatternUtils;
     25 import com.android.settings.notification.NotificationBackend;
     26 import com.android.settings.notification.NotificationBackend.AppRow;
     27 import com.android.settingslib.applications.ApplicationsState;
     28 import com.android.settingslib.applications.ApplicationsState.AppEntry;
     29 import com.android.settingslib.applications.ApplicationsState.AppFilter;
     30 
     31 import java.util.ArrayList;
     32 
     33 /**
     34  * Connects the info provided by ApplicationsState and the NotificationBackend.
     35  * Also provides app filters that can use the notification data.
     36  */
     37 public class AppStateNotificationBridge extends AppStateBaseBridge {
     38 
     39     private final NotificationBackend mNotifBackend;
     40     private final PackageManager mPm;
     41     private final Context mContext;
     42 
     43     public AppStateNotificationBridge(Context context, ApplicationsState appState,
     44             Callback callback, NotificationBackend notifBackend) {
     45         super(appState, callback);
     46         mContext = context;
     47         mPm = mContext.getPackageManager();
     48         mNotifBackend = notifBackend;
     49     }
     50 
     51     @Override
     52     protected void loadAllExtraInfo() {
     53         ArrayList<AppEntry> apps = mAppSession.getAllApps();
     54         final int N = apps.size();
     55         for (int i = 0; i < N; i++) {
     56             AppEntry app = apps.get(i);
     57             app.extraInfo = mNotifBackend.loadAppRow(mContext, mPm, app.info);
     58         }
     59     }
     60 
     61     @Override
     62     protected void updateExtraInfo(AppEntry app, String pkg, int uid) {
     63         app.extraInfo = mNotifBackend.loadAppRow(mContext, mPm, app.info);
     64     }
     65 
     66     public static final AppFilter FILTER_APP_NOTIFICATION_BLOCKED = new AppFilter() {
     67         @Override
     68         public void init() {
     69         }
     70 
     71         @Override
     72         public boolean filterApp(AppEntry info) {
     73             if (info == null || info.extraInfo == null) {
     74                 return false;
     75             }
     76             if (info.extraInfo instanceof AppRow) {
     77                 AppRow row = (AppRow) info.extraInfo;
     78                 return row.banned;
     79             }
     80             return false;
     81         }
     82     };
     83 
     84     public static final AppFilter FILTER_APP_NOTIFICATION_SILENCED = new AppFilter() {
     85         @Override
     86         public void init() {
     87         }
     88 
     89         @Override
     90         public boolean filterApp(AppEntry info) {
     91             if (info == null || info.extraInfo == null) {
     92                 return false;
     93             }
     94             AppRow row = (AppRow) info.extraInfo;
     95             return row.appImportance > NotificationListenerService.Ranking.IMPORTANCE_NONE
     96                     && row.appImportance < NotificationListenerService.Ranking.IMPORTANCE_DEFAULT;
     97         }
     98     };
     99 
    100     public static final AppFilter FILTER_APP_NOTIFICATION_PRIORITY = new AppFilter() {
    101         @Override
    102         public void init() {
    103         }
    104 
    105         @Override
    106         public boolean filterApp(AppEntry info) {
    107             if (info == null || info.extraInfo == null) {
    108                 return false;
    109             }
    110             return ((AppRow) info.extraInfo).appBypassDnd;
    111         }
    112     };
    113 
    114     public static final AppFilter FILTER_APP_NOTIFICATION_HIDE_SENSITIVE = new AppFilter() {
    115         @Override
    116         public void init() {
    117         }
    118 
    119         @Override
    120         public boolean filterApp(AppEntry info) {
    121             if (info == null || info.extraInfo == null) {
    122                 return false;
    123             }
    124             return ((AppRow) info.extraInfo).lockScreenSecure
    125                     && ((AppRow) info.extraInfo).appVisOverride == Notification.VISIBILITY_PRIVATE;
    126         }
    127     };
    128 
    129     public static final AppFilter FILTER_APP_NOTIFICATION_HIDE_ALL = new AppFilter() {
    130         @Override
    131         public void init() {
    132         }
    133 
    134         @Override
    135         public boolean filterApp(AppEntry info) {
    136             if (info == null || info.extraInfo == null) {
    137                 return false;
    138             }
    139             return ((AppRow) info.extraInfo).lockScreenSecure
    140                     && ((AppRow) info.extraInfo).appVisOverride == Notification.VISIBILITY_SECRET;
    141         }
    142     };
    143 }
    144