1 /* 2 * Copyright (C) 2023 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.safetycenter; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.os.UserHandle; 24 import android.os.UserManager; 25 import android.provider.SearchIndexableResource; 26 27 import com.android.settings.R; 28 import com.android.settings.Utils; 29 import com.android.settings.dashboard.DashboardFragment; 30 import com.android.settings.safetycenter.SafetyCenterUtils.EnterpriseOverrideString; 31 import com.android.settings.search.BaseSearchIndexProvider; 32 import com.android.settings.security.LockUnificationPreferenceController; 33 import com.android.settings.security.trustagent.TrustAgentListPreferenceController; 34 import com.android.settingslib.core.AbstractPreferenceController; 35 import com.android.settingslib.core.lifecycle.Lifecycle; 36 import com.android.settingslib.drawer.CategoryKey; 37 import com.android.settingslib.search.SearchIndexable; 38 39 import java.util.ArrayList; 40 import java.util.List; 41 42 /** 43 * An overflow menu for {@code SecuritySettings} containing advanced security and privacy settings. 44 * 45 * <p>This also includes all work-profile related settings. 46 */ 47 @SearchIndexable 48 public class MoreSecurityPrivacyFragment extends DashboardFragment { 49 private static final String TAG = "MoreSecurityPrivacyFragment"; 50 private static final String KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS = 51 "privacy_lock_screen_work_profile_notifications"; 52 53 @Override getMetricsCategory()54 public int getMetricsCategory() { 55 return SettingsEnums.MORE_SECURITY_PRIVACY_SETTINGS; 56 } 57 58 @Override getPreferenceScreenResId()59 protected int getPreferenceScreenResId() { 60 return R.xml.more_security_privacy_settings; 61 } 62 63 @Override getCategoryKey()64 public String getCategoryKey() { 65 return CategoryKey.CATEGORY_MORE_SECURITY_PRIVACY_SETTINGS; 66 } 67 68 @Override getLogTag()69 protected String getLogTag() { 70 return TAG; 71 } 72 73 @Override onCreate(Bundle icicle)74 public void onCreate(Bundle icicle) { 75 super.onCreate(icicle); 76 List<EnterpriseOverrideString> privacyOverrideStrings = 77 SafetyCenterUtils.getEnterpriseOverrideStringForPrivacyEntries(); 78 for (int i = 0; i < privacyOverrideStrings.size(); i++) { 79 EnterpriseOverrideString overrideString = privacyOverrideStrings.get(i); 80 replaceEnterpriseStringTitle( 81 overrideString.getPreferenceKey(), 82 overrideString.getOverrideKey(), 83 overrideString.getResource()); 84 } 85 List<EnterpriseOverrideString> securityOverrideStrings = 86 SafetyCenterUtils.getEnterpriseOverrideStringForSecurityEntries(); 87 for (int i = 0; i < securityOverrideStrings.size(); i++) { 88 EnterpriseOverrideString overrideString = securityOverrideStrings.get(i); 89 replaceEnterpriseStringTitle( 90 overrideString.getPreferenceKey(), 91 overrideString.getOverrideKey(), 92 overrideString.getResource()); 93 } 94 } 95 96 /** see confirmPatternThenDisableAndClear */ 97 @Override onActivityResult(int requestCode, int resultCode, Intent data)98 public void onActivityResult(int requestCode, int resultCode, Intent data) { 99 if (use(TrustAgentListPreferenceController.class) 100 .handleActivityResult(requestCode, resultCode)) { 101 return; 102 } 103 if (use(LockUnificationPreferenceController.class) 104 .handleActivityResult(requestCode, resultCode, data)) { 105 return; 106 } 107 super.onActivityResult(requestCode, resultCode, data); 108 } 109 110 @Override createPreferenceControllers(Context context)111 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 112 return buildPreferenceControllers(context, getSettingsLifecycle(), this /* host*/); 113 } 114 buildPreferenceControllers( Context context, Lifecycle lifecycle, DashboardFragment host)115 private static List<AbstractPreferenceController> buildPreferenceControllers( 116 Context context, Lifecycle lifecycle, DashboardFragment host) { 117 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 118 controllers.addAll(SafetyCenterUtils.getControllersForAdvancedPrivacy(context, lifecycle)); 119 controllers.addAll( 120 SafetyCenterUtils.getControllersForAdvancedSecurity(context, lifecycle, host)); 121 return controllers; 122 } 123 124 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 125 new BaseSearchIndexProvider(R.xml.more_security_privacy_settings) { 126 /** 127 * If SafetyCenter is disabled, all of these entries will be in the More Security 128 * Settings and the Privacy page, and we don't want to index these entries. 129 */ 130 @Override 131 public List<SearchIndexableResource> getXmlResourcesToIndex( 132 Context context, boolean enabled) { 133 // NOTE: This check likely should be moved to the super method. This is done 134 // here to avoid potentially undesired side effects for existing implementors. 135 if (!isPageSearchEnabled(context)) { 136 return null; 137 } 138 return super.getXmlResourcesToIndex(context, enabled); 139 } 140 141 @Override 142 public List<AbstractPreferenceController> createPreferenceControllers( 143 Context context) { 144 return buildPreferenceControllers(context, null, null); 145 } 146 147 @Override 148 public List<String> getNonIndexableKeys(Context context) { 149 final List<String> keys = super.getNonIndexableKeys(context); 150 final int profileUserId = 151 Utils.getManagedProfileId( 152 UserManager.get(context), UserHandle.myUserId()); 153 // If work profile is supported, we should keep the search result. 154 if (profileUserId != UserHandle.USER_NULL) { 155 return keys; 156 } 157 158 // Otherwise, we should hide the search result. 159 keys.add(KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS); 160 return keys; 161 } 162 163 @Override 164 protected boolean isPageSearchEnabled(Context context) { 165 return SafetyCenterManagerWrapper.get().isEnabled(context); 166 } 167 }; 168 } 169