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 package com.android.settings.security; 17 18 import static com.android.settings.security.EncryptionStatusPreferenceController.PREF_KEY_ENCRYPTION_SECURITY_PAGE; 19 20 import android.app.settings.SettingsEnums; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.provider.SearchIndexableResource; 24 25 import com.android.settings.R; 26 import com.android.settings.biometrics.face.FaceProfileStatusPreferenceController; 27 import com.android.settings.biometrics.face.FaceStatusPreferenceController; 28 import com.android.settings.biometrics.fingerprint.FingerprintProfileStatusPreferenceController; 29 import com.android.settings.biometrics.fingerprint.FingerprintStatusPreferenceController; 30 import com.android.settings.dashboard.DashboardFragment; 31 import com.android.settings.enterprise.EnterprisePrivacyPreferenceController; 32 import com.android.settings.search.BaseSearchIndexProvider; 33 import com.android.settings.security.trustagent.ManageTrustAgentsPreferenceController; 34 import com.android.settings.security.trustagent.TrustAgentListPreferenceController; 35 import com.android.settings.widget.PreferenceCategoryController; 36 import com.android.settingslib.core.AbstractPreferenceController; 37 import com.android.settingslib.core.lifecycle.Lifecycle; 38 import com.android.settingslib.search.SearchIndexable; 39 40 import java.util.ArrayList; 41 import java.util.List; 42 43 @SearchIndexable 44 public class SecuritySettings extends DashboardFragment { 45 46 private static final String TAG = "SecuritySettings"; 47 private static final String SECURITY_CATEGORY = "security_category"; 48 private static final String WORK_PROFILE_SECURITY_CATEGORY = "security_category_profile"; 49 50 public static final int CHANGE_TRUST_AGENT_SETTINGS = 126; 51 public static final int UNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 128; 52 public static final int UNIFY_LOCK_CONFIRM_PROFILE_REQUEST = 129; 53 public static final int UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 130; 54 55 @Override getMetricsCategory()56 public int getMetricsCategory() { 57 return SettingsEnums.SECURITY; 58 } 59 60 @Override getPreferenceScreenResId()61 protected int getPreferenceScreenResId() { 62 return R.xml.security_dashboard_settings; 63 } 64 65 @Override getLogTag()66 protected String getLogTag() { 67 return TAG; 68 } 69 70 @Override getHelpResource()71 public int getHelpResource() { 72 return R.string.help_url_security; 73 } 74 75 @Override createPreferenceControllers(Context context)76 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 77 return buildPreferenceControllers(context, getSettingsLifecycle(), this /* host*/); 78 } 79 80 /** 81 * see confirmPatternThenDisableAndClear 82 */ 83 @Override onActivityResult(int requestCode, int resultCode, Intent data)84 public void onActivityResult(int requestCode, int resultCode, Intent data) { 85 if (use(TrustAgentListPreferenceController.class) 86 .handleActivityResult(requestCode, resultCode)) { 87 return; 88 } 89 if (use(LockUnificationPreferenceController.class) 90 .handleActivityResult(requestCode, resultCode, data)) { 91 return; 92 } 93 super.onActivityResult(requestCode, resultCode, data); 94 } 95 startUnification()96 void startUnification() { 97 use(LockUnificationPreferenceController.class).startUnification(); 98 } 99 updateUnificationPreference()100 void updateUnificationPreference() { 101 use(LockUnificationPreferenceController.class).updateState(null); 102 } 103 buildPreferenceControllers(Context context, Lifecycle lifecycle, SecuritySettings host)104 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, 105 Lifecycle lifecycle, SecuritySettings host) { 106 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 107 controllers.add(new EnterprisePrivacyPreferenceController(context)); 108 controllers.add(new ManageTrustAgentsPreferenceController(context)); 109 controllers.add(new ScreenPinningPreferenceController(context)); 110 controllers.add(new SimLockPreferenceController(context)); 111 controllers.add(new EncryptionStatusPreferenceController(context, 112 PREF_KEY_ENCRYPTION_SECURITY_PAGE)); 113 controllers.add(new TrustAgentListPreferenceController(context, host, lifecycle)); 114 115 final List<AbstractPreferenceController> securityPreferenceControllers = new ArrayList<>(); 116 securityPreferenceControllers.add(new FaceStatusPreferenceController(context)); 117 securityPreferenceControllers.add(new FingerprintStatusPreferenceController(context)); 118 securityPreferenceControllers.add(new ChangeScreenLockPreferenceController(context, host)); 119 controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY) 120 .setChildren(securityPreferenceControllers)); 121 controllers.addAll(securityPreferenceControllers); 122 123 final List<AbstractPreferenceController> profileSecurityControllers = new ArrayList<>(); 124 profileSecurityControllers.add(new ChangeProfileScreenLockPreferenceController( 125 context, host)); 126 profileSecurityControllers.add(new LockUnificationPreferenceController(context, host)); 127 profileSecurityControllers.add(new VisiblePatternProfilePreferenceController( 128 context, lifecycle)); 129 profileSecurityControllers.add(new FaceProfileStatusPreferenceController(context)); 130 profileSecurityControllers.add(new FingerprintProfileStatusPreferenceController(context)); 131 controllers.add(new PreferenceCategoryController(context, WORK_PROFILE_SECURITY_CATEGORY) 132 .setChildren(profileSecurityControllers)); 133 controllers.addAll(profileSecurityControllers); 134 135 return controllers; 136 } 137 138 /** 139 * For Search. Please keep it in sync when updating "createPreferenceHierarchy()" 140 */ 141 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 142 new BaseSearchIndexProvider() { 143 144 @Override 145 public List<SearchIndexableResource> getXmlResourcesToIndex( 146 Context context, boolean enabled) { 147 final List<SearchIndexableResource> index = new ArrayList<>(); 148 // Append the rest of the settings 149 final SearchIndexableResource sir = new SearchIndexableResource(context); 150 sir.xmlResId = R.xml.security_dashboard_settings; 151 index.add(sir); 152 return index; 153 } 154 155 @Override 156 public List<AbstractPreferenceController> createPreferenceControllers(Context 157 context) { 158 return buildPreferenceControllers(context, null /* lifecycle */, 159 null /* host*/); 160 } 161 }; 162 } 163