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