• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 package com.android.settings.applications;
16 
17 import android.app.Activity;
18 import android.content.Context;
19 import android.content.pm.ApplicationInfo;
20 import android.content.pm.PackageManager;
21 
22 import com.android.settings.R;
23 import com.android.settings.dashboard.SummaryLoader;
24 import com.android.settings.notification.NotificationBackend;
25 
26 /**
27  * Extension of ManageApplications with no changes other than having its own
28  * SummaryProvider.
29  */
30 public class NotificationApps extends ManageApplications {
31 
32     private static class SummaryProvider implements SummaryLoader.SummaryProvider {
33 
34         private final Context mContext;
35         private final SummaryLoader mLoader;
36         private final NotificationBackend mNotificationBackend;
37 
SummaryProvider(Context context, SummaryLoader loader)38         private SummaryProvider(Context context, SummaryLoader loader) {
39             mContext = context;
40             mLoader = loader;
41             mNotificationBackend = new NotificationBackend();
42         }
43 
44         @Override
setListening(boolean listening)45         public void setListening(boolean listening) {
46             if (listening) {
47                 new AppCounter(mContext,
48                         new PackageManagerWrapperImpl(mContext.getPackageManager())) {
49                     @Override
50                     protected void onCountComplete(int num) {
51                         updateSummary(num);
52                     }
53 
54                     @Override
55                     protected boolean includeInCount(ApplicationInfo info) {
56                         return mNotificationBackend.getNotificationsBanned(info.packageName,
57                                 info.uid);
58                     }
59                 }.execute();
60             }
61         }
62 
updateSummary(int count)63         private void updateSummary(int count) {
64             if (count == 0) {
65                 mLoader.setSummary(this, mContext.getString(R.string.notification_summary_none));
66             } else {
67                 mLoader.setSummary(this, mContext.getResources().getQuantityString(
68                         R.plurals.notification_summary, count, count));
69             }
70         }
71     }
72 
73     public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
74             = new SummaryLoader.SummaryProviderFactory() {
75         @Override
76         public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
77                                                                    SummaryLoader summaryLoader) {
78             return new SummaryProvider(activity, summaryLoader);
79         }
80     };
81 }
82