Home | History | Annotate | Download | only in notification
      1 /*
      2  * Copyright (C) 2017 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.app.Fragment;
     20 import android.content.Context;
     21 import android.provider.SearchIndexableResource;
     22 import android.service.notification.ConditionProviderService;
     23 
     24 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     25 import com.android.settings.R;
     26 import com.android.settings.search.BaseSearchIndexProvider;
     27 import com.android.settings.search.Indexable;
     28 import com.android.settings.utils.ManagedServiceSettings;
     29 import com.android.settings.utils.ZenServiceListing;
     30 import com.android.settingslib.core.AbstractPreferenceController;
     31 import com.android.settingslib.core.lifecycle.Lifecycle;
     32 
     33 import java.util.ArrayList;
     34 import java.util.List;
     35 
     36 public class ZenModeAutomationSettings extends ZenModeSettingsBase {
     37     protected final ManagedServiceSettings.Config CONFIG = getConditionProviderConfig();
     38 
     39     @Override
     40     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
     41         ZenServiceListing serviceListing = new ZenServiceListing(getContext(), CONFIG);
     42         serviceListing.reloadApprovedServices();
     43         return buildPreferenceControllers(context, this, serviceListing, getLifecycle());
     44     }
     45 
     46     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
     47             Fragment parent, ZenServiceListing serviceListing, Lifecycle lifecycle) {
     48         List<AbstractPreferenceController> controllers = new ArrayList<>();
     49         controllers.add(new ZenModeAddAutomaticRulePreferenceController(context, parent,
     50                 serviceListing, lifecycle));
     51         controllers.add(new ZenModeAutomaticRulesPreferenceController(context, parent, lifecycle));
     52 
     53         return controllers;
     54     }
     55 
     56     @Override
     57     protected int getPreferenceScreenResId() {
     58         return R.xml.zen_mode_automation_settings;
     59     }
     60 
     61     @Override
     62     public int getMetricsCategory() {
     63         return MetricsEvent.NOTIFICATION_ZEN_MODE_AUTOMATION;
     64     }
     65 
     66     protected static ManagedServiceSettings.Config getConditionProviderConfig() {
     67         return new ManagedServiceSettings.Config.Builder()
     68                 .setTag(TAG)
     69                 .setIntentAction(ConditionProviderService.SERVICE_INTERFACE)
     70                 .setPermission(android.Manifest.permission.BIND_CONDITION_PROVIDER_SERVICE)
     71                 .setNoun("condition provider")
     72                 .build();
     73     }
     74 
     75     /**
     76      * For Search.
     77      */
     78     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
     79             new BaseSearchIndexProvider() {
     80 
     81                 @Override
     82                 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
     83                         boolean enabled) {
     84                     final ArrayList<SearchIndexableResource> result = new ArrayList<>();
     85 
     86                     final SearchIndexableResource sir = new SearchIndexableResource(context);
     87                     sir.xmlResId = R.xml.zen_mode_automation_settings;
     88                     result.add(sir);
     89                     return result;
     90                 }
     91 
     92                 @Override
     93                 public List<String> getNonIndexableKeys(Context context) {
     94                     final List<String> keys = super.getNonIndexableKeys(context);
     95                     keys.add(ZenModeAddAutomaticRulePreferenceController.KEY);
     96                     keys.add(ZenModeAutomaticRulesPreferenceController.KEY);
     97                     return keys;
     98                 }
     99 
    100                 @Override
    101                 public List<AbstractPreferenceController> createPreferenceControllers(
    102                         Context context) {
    103                     return buildPreferenceControllers(context, null, null, null);
    104                 }
    105             };
    106 }
    107