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.security; 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.provider.SearchIndexableResource; 24 25 import com.android.settings.R; 26 import com.android.settings.dashboard.DashboardFragment; 27 import com.android.settings.overlay.FeatureFactory; 28 import com.android.settings.safetycenter.SafetyCenterManagerWrapper; 29 import com.android.settings.safetycenter.SafetyCenterUtils; 30 import com.android.settings.safetycenter.SafetyCenterUtils.EnterpriseOverrideString; 31 import com.android.settings.search.BaseSearchIndexProvider; 32 import com.android.settings.security.trustagent.TrustAgentListPreferenceController; 33 import com.android.settingslib.core.AbstractPreferenceController; 34 import com.android.settingslib.core.lifecycle.Lifecycle; 35 import com.android.settingslib.drawer.CategoryKey; 36 import com.android.settingslib.search.SearchIndexable; 37 38 import java.util.List; 39 40 /** 41 * An overflow menu for {@code SecuritySettings} containing advanced security settings. 42 * 43 * <p>This includes all work-profile related settings. 44 */ 45 @SearchIndexable 46 public class SecurityAdvancedSettings extends DashboardFragment { 47 48 private static final String TAG = "SecurityAdvancedSettings"; 49 50 /** Used in case of old Security settings when SafetyCenter is disabled */ 51 private static final String CATEGORY_SECURITY_LEGACY_ADVANCED_SETTINGS = 52 "com.android.settings.category.ia.legacy_advanced_security"; 53 54 @Override onCreate(Bundle icicle)55 public void onCreate(Bundle icicle) { 56 super.onCreate(icicle); 57 List<EnterpriseOverrideString> securityOverrideStrings = 58 SafetyCenterUtils.getEnterpriseOverrideStringForSecurityEntries(); 59 for (int i = 0; i < securityOverrideStrings.size(); i++) { 60 EnterpriseOverrideString overrideString = securityOverrideStrings.get(i); 61 replaceEnterpriseStringTitle( 62 overrideString.getPreferenceKey(), 63 overrideString.getOverrideKey(), 64 overrideString.getResource()); 65 } 66 } 67 68 @Override getMetricsCategory()69 public int getMetricsCategory() { 70 return SettingsEnums.SECURITY_ADVANCED; 71 } 72 73 @Override getCategoryKey()74 public String getCategoryKey() { 75 final Context context = getContext(); 76 if (context == null) { 77 return CATEGORY_SECURITY_LEGACY_ADVANCED_SETTINGS; 78 } else if (SafetyCenterManagerWrapper.get().isEnabled(context)) { 79 return CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS; 80 } else { 81 final SecuritySettingsFeatureProvider securitySettingsFeatureProvider = 82 FeatureFactory.getFactory(context).getSecuritySettingsFeatureProvider(); 83 84 if (securitySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment()) { 85 return securitySettingsFeatureProvider.getAlternativeAdvancedSettingsCategoryKey(); 86 } else { 87 return CATEGORY_SECURITY_LEGACY_ADVANCED_SETTINGS; 88 } 89 } 90 } 91 92 @Override getPreferenceScreenResId()93 protected int getPreferenceScreenResId() { 94 return R.xml.security_advanced_settings; 95 } 96 97 @Override getLogTag()98 protected String getLogTag() { 99 return TAG; 100 } 101 102 @Override createPreferenceControllers(Context context)103 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 104 return buildPreferenceControllers(context, getSettingsLifecycle(), this /* host*/); 105 } 106 107 /** see confirmPatternThenDisableAndClear */ 108 @Override onActivityResult(int requestCode, int resultCode, Intent data)109 public void onActivityResult(int requestCode, int resultCode, Intent data) { 110 if (use(TrustAgentListPreferenceController.class) 111 .handleActivityResult(requestCode, resultCode)) { 112 return; 113 } 114 if (use(LockUnificationPreferenceController.class) 115 .handleActivityResult(requestCode, resultCode, data)) { 116 return; 117 } 118 super.onActivityResult(requestCode, resultCode, data); 119 } 120 buildPreferenceControllers( Context context, Lifecycle lifecycle, DashboardFragment host)121 private static List<AbstractPreferenceController> buildPreferenceControllers( 122 Context context, Lifecycle lifecycle, DashboardFragment host) { 123 return SafetyCenterUtils.getControllersForAdvancedSecurity(context, lifecycle, host); 124 } 125 126 /** For Search. Please keep it in sync when updating "createPreferenceHierarchy()" */ 127 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 128 new BaseSearchIndexProvider(R.xml.security_advanced_settings) { 129 /** 130 * If SafetyCenter is enabled, all of these entries will be in the More Settings 131 * page, and we don't want to index these entries. 132 */ 133 @Override 134 public List<SearchIndexableResource> getXmlResourcesToIndex( 135 Context context, boolean enabled) { 136 // NOTE: This check likely should be moved to the super method. This is done 137 // here to avoid potentially undesired side effects for existing implementors. 138 if (!isPageSearchEnabled(context)) { 139 return null; 140 } 141 return super.getXmlResourcesToIndex(context, enabled); 142 } 143 144 @Override 145 public List<AbstractPreferenceController> createPreferenceControllers( 146 Context context) { 147 return buildPreferenceControllers( 148 context, null /* lifecycle */, null /* host*/); 149 } 150 151 @Override 152 protected boolean isPageSearchEnabled(Context context) { 153 return !SafetyCenterManagerWrapper.get().isEnabled(context); 154 } 155 }; 156 } 157