1 /* 2 * Copyright (C) 2021 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.settings.SettingsEnums; 20 import android.content.Context; 21 import android.provider.SearchIndexableResource; 22 23 import com.android.settings.R; 24 import com.android.settings.dashboard.DashboardFragment; 25 import com.android.settings.search.BaseSearchIndexProvider; 26 import com.android.settingslib.core.AbstractPreferenceController; 27 import com.android.settingslib.search.SearchIndexable; 28 29 import java.util.ArrayList; 30 import java.util.Arrays; 31 import java.util.List; 32 33 /** Settings page for apps. */ 34 @SearchIndexable 35 public class AppDashboardFragment extends DashboardFragment { 36 37 private static final String TAG = "AppDashboardFragment"; 38 private AppsPreferenceController mAppsPreferenceController; 39 buildPreferenceControllers(Context context)40 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) { 41 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 42 controllers.add(new AppsPreferenceController(context)); 43 return controllers; 44 } 45 46 @Override getMetricsCategory()47 public int getMetricsCategory() { 48 return SettingsEnums.MANAGE_APPLICATIONS; 49 } 50 51 @Override getLogTag()52 protected String getLogTag() { 53 return TAG; 54 } 55 56 @Override getHelpResource()57 public int getHelpResource() { 58 return R.string.help_url_apps_and_notifications; 59 } 60 61 @Override getPreferenceScreenResId()62 protected int getPreferenceScreenResId() { 63 return R.xml.apps; 64 } 65 66 @Override onAttach(Context context)67 public void onAttach(Context context) { 68 super.onAttach(context); 69 use(SpecialAppAccessPreferenceController.class).setSession(getSettingsLifecycle()); 70 mAppsPreferenceController = use(AppsPreferenceController.class); 71 mAppsPreferenceController.setFragment(this /* fragment */); 72 getSettingsLifecycle().addObserver(mAppsPreferenceController); 73 74 final HibernatedAppsPreferenceController hibernatedAppsPreferenceController = 75 use(HibernatedAppsPreferenceController.class); 76 getSettingsLifecycle().addObserver(hibernatedAppsPreferenceController); 77 } 78 79 @Override createPreferenceControllers(Context context)80 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 81 return buildPreferenceControllers(context); 82 } 83 84 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 85 new BaseSearchIndexProvider() { 86 @Override 87 public List<SearchIndexableResource> getXmlResourcesToIndex( 88 Context context, boolean enabled) { 89 final SearchIndexableResource sir = new SearchIndexableResource(context); 90 sir.xmlResId = R.xml.apps; 91 return Arrays.asList(sir); 92 } 93 94 @Override 95 public List<AbstractPreferenceController> createPreferenceControllers( 96 Context context) { 97 return buildPreferenceControllers(context); 98 } 99 }; 100 } 101