1 /* 2 * Copyright (C) 2016 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.applications; 18 19 import android.app.Activity; 20 import android.app.Application; 21 import android.app.Fragment; 22 import android.content.Context; 23 import android.provider.SearchIndexableResource; 24 25 import com.android.internal.logging.nano.MetricsProto; 26 import com.android.settings.R; 27 import com.android.settings.dashboard.DashboardFragment; 28 import com.android.settings.notification.EmergencyBroadcastPreferenceController; 29 import com.android.settings.search.BaseSearchIndexProvider; 30 import com.android.settingslib.core.AbstractPreferenceController; 31 32 import java.util.ArrayList; 33 import java.util.Arrays; 34 import java.util.List; 35 36 public class AppAndNotificationDashboardFragment extends DashboardFragment { 37 38 private static final String TAG = "AppAndNotifDashboard"; 39 40 @Override 41 public int getMetricsCategory() { 42 return MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY; 43 } 44 45 @Override 46 protected String getLogTag() { 47 return TAG; 48 } 49 50 @Override 51 public int getHelpResource() { 52 return R.string.help_url_apps_and_notifications; 53 } 54 55 @Override 56 protected int getPreferenceScreenResId() { 57 return R.xml.app_and_notification; 58 } 59 60 @Override 61 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 62 final Activity activity = getActivity(); 63 final Application app; 64 if (activity != null) { 65 app = activity.getApplication(); 66 } else { 67 app = null; 68 } 69 return buildPreferenceControllers(context, app, this); 70 } 71 72 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, 73 Application app, Fragment host) { 74 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 75 controllers.add(new EmergencyBroadcastPreferenceController(context, 76 "app_and_notif_cell_broadcast_settings")); 77 controllers.add(new SpecialAppAccessPreferenceController(context)); 78 controllers.add(new RecentAppsPreferenceController(context, app, host)); 79 return controllers; 80 } 81 82 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 83 new BaseSearchIndexProvider() { 84 @Override 85 public List<SearchIndexableResource> getXmlResourcesToIndex( 86 Context context, boolean enabled) { 87 final SearchIndexableResource sir = new SearchIndexableResource(context); 88 sir.xmlResId = R.xml.app_and_notification; 89 return Arrays.asList(sir); 90 } 91 92 @Override 93 public List<AbstractPreferenceController> createPreferenceControllers( 94 Context context) { 95 return buildPreferenceControllers(context, null, null /* host */); 96 } 97 98 @Override 99 public List<String> getNonIndexableKeys(Context context) { 100 List<String> keys = super.getNonIndexableKeys(context); 101 keys.add((new SpecialAppAccessPreferenceController(context)) 102 .getPreferenceKey()); 103 return keys; 104 } 105 }; 106 } 107