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 void onAttach(Context context) { 52 super.onAttach(context); 53 mProgressiveDisclosureMixin.setTileLimit(4); 54 } 55 56 @Override 57 protected int getHelpResource() { 58 return R.string.help_url_apps_and_notifications; 59 } 60 61 @Override 62 protected int getPreferenceScreenResId() { 63 return R.xml.app_and_notification; 64 } 65 66 @Override 67 protected List<AbstractPreferenceController> getPreferenceControllers(Context context) { 68 final Activity activity = getActivity(); 69 final Application app; 70 if (activity != null) { 71 app = activity.getApplication(); 72 } else { 73 app = null; 74 } 75 return buildPreferenceControllers(context, app, this); 76 } 77 78 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, 79 Application app, Fragment host) { 80 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 81 controllers.add(new EmergencyBroadcastPreferenceController(context, 82 "app_and_notif_cell_broadcast_settings")); 83 controllers.add(new SpecialAppAccessPreferenceController(context)); 84 controllers.add(new AppPermissionsPreferenceController(context)); 85 controllers.add(new RecentAppsPreferenceController(context, app, host)); 86 return controllers; 87 } 88 89 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 90 new BaseSearchIndexProvider() { 91 @Override 92 public List<SearchIndexableResource> getXmlResourcesToIndex( 93 Context context, boolean enabled) { 94 final SearchIndexableResource sir = new SearchIndexableResource(context); 95 sir.xmlResId = R.xml.app_and_notification; 96 return Arrays.asList(sir); 97 } 98 99 @Override 100 public List<AbstractPreferenceController> getPreferenceControllers( 101 Context context) { 102 return buildPreferenceControllers(context, null, null /* host */); 103 } 104 105 @Override 106 public List<String> getNonIndexableKeys(Context context) { 107 List<String> keys = super.getNonIndexableKeys(context); 108 keys.add((new SpecialAppAccessPreferenceController(context)) 109 .getPreferenceKey()); 110 return keys; 111 } 112 }; 113 } 114