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; 18 19 import static android.service.notification.Adjustment.KEY_TYPE; 20 21 import android.app.Activity; 22 import android.app.Application; 23 import android.app.Flags; 24 import android.app.settings.SettingsEnums; 25 import android.content.Context; 26 27 import com.android.settings.R; 28 import com.android.settings.dashboard.DashboardFragment; 29 import com.android.settings.search.BaseSearchIndexProvider; 30 import com.android.settingslib.applications.ApplicationsState; 31 import com.android.settingslib.core.AbstractPreferenceController; 32 import com.android.settingslib.search.SearchIndexable; 33 34 import java.util.ArrayList; 35 import java.util.List; 36 37 /** 38 * Fragment for bundled notifications. 39 */ 40 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) 41 public class BundlePreferenceFragment extends DashboardFragment { 42 43 private static final String BUNDLE_CATEGORY_KEY = "enabled_settings"; 44 45 @Override getMetricsCategory()46 public int getMetricsCategory() { 47 return SettingsEnums.BUNDLED_NOTIFICATIONS; 48 } 49 50 @Override getPreferenceScreenResId()51 protected int getPreferenceScreenResId() { 52 return R.xml.bundle_notifications_settings; 53 } 54 55 @Override createPreferenceControllers(Context context)56 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 57 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 58 controllers.add(new BundleCombinedPreferenceController(context, BUNDLE_CATEGORY_KEY, 59 new NotificationBackend())); 60 return controllers; 61 } 62 63 @Override getLogTag()64 protected String getLogTag() { 65 return "BundlePreferenceFragment"; 66 } 67 68 @Override onAttach(Context context)69 public void onAttach(Context context) { 70 super.onAttach(context); 71 if (use(AdjustmentExcludedAppsPreferenceController.class) != null) { 72 final Activity activity = getActivity(); 73 Application app = null; 74 ApplicationsState appState = null; 75 if (activity != null) { 76 app = activity.getApplication(); 77 } else { 78 app = null; 79 } 80 if (app != null) { 81 appState = ApplicationsState.getInstance(app); 82 } 83 use(AdjustmentExcludedAppsPreferenceController.class).onAttach( 84 appState, this, new NotificationBackend(), KEY_TYPE); 85 } 86 } 87 88 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 89 new BaseSearchIndexProvider(R.xml.bundle_notifications_settings) { 90 91 @Override 92 protected boolean isPageSearchEnabled(Context context) { 93 return Flags.notificationClassificationUi(); 94 } 95 }; 96 } 97