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;
18 
19 import android.app.Activity;
20 import android.app.Application;
21 import android.app.settings.SettingsEnums;
22 import android.content.Context;
23 import android.provider.SearchIndexableResource;
24 
25 import androidx.fragment.app.Fragment;
26 
27 import com.android.settings.R;
28 import com.android.settings.search.BaseSearchIndexProvider;
29 import com.android.settings.search.Indexable;
30 import com.android.settingslib.core.AbstractPreferenceController;
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);
51     }
52 
buildPreferenceControllers(Context context, Application app, Fragment host)53     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
54             Application app, Fragment host) {
55         final List<AbstractPreferenceController> controllers = new ArrayList<>();
56         controllers.add(new ZenModeAllBypassingAppsPreferenceController(context, app, host));
57         return controllers;
58     }
59 
60     @Override
getPreferenceScreenResId()61     protected int getPreferenceScreenResId() {
62         return R.xml.zen_mode_bypassing_apps;
63     }
64 
65     @Override
getLogTag()66     protected String getLogTag() {
67         return TAG;
68     }
69 
70     @Override
getMetricsCategory()71     public int getMetricsCategory() {
72         return SettingsEnums.NOTIFICATION_ZEN_MODE_OVERRIDING_APPS;
73     }
74 
75     /**
76      * For Search.
77      */
78     public static final 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_bypassing_apps;
88                     result.add(sir);
89                     return result;
90                 }
91 
92                 @Override
93                 public List<AbstractPreferenceController> createPreferenceControllers(
94                         Context context) {
95                     return buildPreferenceControllers(context, null, null);
96                 }
97             };
98 }
99