1 /*
2  * Copyright (C) 2018 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.zen;
18 
19 import android.app.Activity;
20 import android.app.Application;
21 import android.app.settings.SettingsEnums;
22 import android.content.Context;
23 
24 import androidx.fragment.app.Fragment;
25 
26 import com.android.settings.R;
27 import com.android.settings.notification.NotificationBackend;
28 import com.android.settings.search.BaseSearchIndexProvider;
29 import com.android.settingslib.core.AbstractPreferenceController;
30 import com.android.settingslib.search.Indexable;
31 import com.android.settingslib.search.SearchIndexable;
32 
33 import java.util.ArrayList;
34 import java.util.List;
35 
36 @SearchIndexable
37 public class ZenModeBypassingAppsSettings extends ZenModeSettingsBase implements
38         Indexable {
39     private final String TAG = "ZenBypassingApps";
40 
41     @Override
createPreferenceControllers(Context context)42     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
43         final Activity activity = getActivity();
44         final Application app;
45         if (activity != null) {
46             app = activity.getApplication();
47         } else {
48             app = null;
49         }
50         return buildPreferenceControllers(context, app, this, new NotificationBackend());
51     }
52 
buildPreferenceControllers(Context context, Application app, Fragment host, NotificationBackend notificationBackend)53     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
54             Application app, Fragment host, NotificationBackend notificationBackend) {
55         final List<AbstractPreferenceController> controllers = new ArrayList<>();
56         controllers.add(new ZenModeAllBypassingAppsPreferenceController(context, app, host,
57                 notificationBackend));
58         controllers.add(new ZenModeAddBypassingAppsPreferenceController(context, app, host,
59                 notificationBackend));
60         return controllers;
61     }
62 
63     @Override
getPreferenceScreenResId()64     protected int getPreferenceScreenResId() {
65         return R.xml.zen_mode_bypassing_apps;
66     }
67 
68     @Override
getLogTag()69     protected String getLogTag() {
70         return TAG;
71     }
72 
73     @Override
getMetricsCategory()74     public int getMetricsCategory() {
75         return SettingsEnums.NOTIFICATION_ZEN_MODE_OVERRIDING_APPS;
76     }
77 
78     /**
79      * For Search.
80      */
81     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
82             new BaseSearchIndexProvider(R.xml.zen_mode_bypassing_apps) {
83 
84                 @Override
85                 public List<AbstractPreferenceController> createPreferenceControllers(
86                         Context context) {
87                     return buildPreferenceControllers(context, null, null, null);
88                 }
89             };
90 }
91