Home | History | Annotate | Download | only in notification
      1 /*
      2  * Copyright (C) 2010 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 
     17 package com.android.settings.notification;
     18 
     19 import android.content.Context;
     20 import android.content.pm.PackageManager;
     21 import android.provider.Settings;
     22 import android.service.notification.NotificationListenerService;
     23 
     24 import com.android.internal.logging.MetricsLogger;
     25 import com.android.settings.R;
     26 
     27 public class NotificationAccessSettings extends ManagedServiceSettings {
     28     private static final String TAG = NotificationAccessSettings.class.getSimpleName();
     29     private static final Config CONFIG = getNotificationListenerConfig();
     30 
     31     private static Config getNotificationListenerConfig() {
     32         final Config c = new Config();
     33         c.tag = TAG;
     34         c.setting = Settings.Secure.ENABLED_NOTIFICATION_LISTENERS;
     35         c.intentAction = NotificationListenerService.SERVICE_INTERFACE;
     36         c.permission = android.Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE;
     37         c.noun = "notification listener";
     38         c.warningDialogTitle = R.string.notification_listener_security_warning_title;
     39         c.warningDialogSummary = R.string.notification_listener_security_warning_summary;
     40         c.emptyText = R.string.no_notification_listeners;
     41         return c;
     42     }
     43 
     44     @Override
     45     protected int getMetricsCategory() {
     46         return MetricsLogger.NOTIFICATION_ACCESS;
     47     }
     48 
     49     @Override
     50     protected Config getConfig() {
     51         return CONFIG;
     52     }
     53 
     54     public static int getListenersCount(PackageManager pm) {
     55         return ServiceListing.getServicesCount(CONFIG, pm);
     56     }
     57 
     58     public static int getEnabledListenersCount(Context context) {
     59         return ServiceListing.getEnabledServicesCount(CONFIG, context);
     60     }
     61 }
     62