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