1 /* 2 * Copyright (C) 2018 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.privacy; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.os.Bundle; 22 import android.os.UserHandle; 23 import android.os.UserManager; 24 import android.provider.SearchIndexableResource; 25 26 import com.android.settings.R; 27 import com.android.settings.Utils; 28 import com.android.settings.dashboard.DashboardFragment; 29 import com.android.settings.safetycenter.SafetyCenterManagerWrapper; 30 import com.android.settings.safetycenter.SafetyCenterUtils; 31 import com.android.settings.search.BaseSearchIndexProvider; 32 import com.android.settingslib.core.AbstractPreferenceController; 33 import com.android.settingslib.core.lifecycle.Lifecycle; 34 import com.android.settingslib.search.SearchIndexable; 35 36 import java.util.List; 37 38 @SearchIndexable 39 public class PrivacyDashboardFragment extends DashboardFragment { 40 private static final String TAG = "PrivacyDashboardFrag"; 41 private static final String KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS = 42 "privacy_lock_screen_work_profile_notifications"; 43 44 @Override getMetricsCategory()45 public int getMetricsCategory() { 46 return SettingsEnums.TOP_LEVEL_PRIVACY; 47 } 48 49 @Override getLogTag()50 protected String getLogTag() { 51 return TAG; 52 } 53 54 @Override onCreate(Bundle icicle)55 public void onCreate(Bundle icicle) { 56 super.onCreate(icicle); 57 SafetyCenterUtils.replaceEnterpriseStringsForPrivacyEntries(this); 58 } 59 60 @Override getHelpResource()61 public int getHelpResource() { 62 return R.string.help_url_privacy_dashboard; 63 } 64 65 @Override createPreferenceControllers(Context context)66 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 67 return buildPreferenceControllers(context, getSettingsLifecycle()); 68 } 69 70 @Override getPreferenceScreenResId()71 protected int getPreferenceScreenResId() { 72 return R.xml.privacy_dashboard_settings; 73 } 74 buildPreferenceControllers( Context context, Lifecycle lifecycle)75 private static List<AbstractPreferenceController> buildPreferenceControllers( 76 Context context, Lifecycle lifecycle) { 77 return SafetyCenterUtils.getControllersForAdvancedPrivacy(context, lifecycle); 78 } 79 80 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 81 new BaseSearchIndexProvider(R.xml.privacy_dashboard_settings) { 82 /** 83 * If SafetyCenter is enabled, all of these entries will be in the More Settings 84 * page, and we don't want to index these entries. 85 */ 86 @Override 87 public List<SearchIndexableResource> getXmlResourcesToIndex( 88 Context context, boolean enabled) { 89 // NOTE: This check likely should be moved to the super method. This is done 90 // here to avoid potentially undesired side effects for existing implementors. 91 if (!isPageSearchEnabled(context)) { 92 return null; 93 } 94 return super.getXmlResourcesToIndex(context, enabled); 95 } 96 97 @Override 98 public List<AbstractPreferenceController> createPreferenceControllers( 99 Context context) { 100 return buildPreferenceControllers(context, null); 101 } 102 103 @Override 104 public List<String> getNonIndexableKeys(Context context) { 105 final List<String> keys = super.getNonIndexableKeys(context); 106 final int profileUserId = 107 Utils.getManagedProfileId( 108 UserManager.get(context), UserHandle.myUserId()); 109 // If work profile is supported, we should keep the search result. 110 if (profileUserId != UserHandle.USER_NULL) { 111 return keys; 112 } 113 114 // Otherwise, we should hide the search result. 115 keys.add(KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS); 116 return keys; 117 } 118 119 @Override 120 protected boolean isPageSearchEnabled(Context context) { 121 return !SafetyCenterManagerWrapper.get().isEnabled(context); 122 } 123 }; 124 } 125