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 android.app.settings.SettingsEnums; 19 import android.content.Context; 20 import android.content.Intent; 21 22 import com.android.settings.R; 23 import com.android.settings.biometrics.combination.CombinedBiometricStatusPreferenceController; 24 import com.android.settings.biometrics.face.FaceStatusPreferenceController; 25 import com.android.settings.biometrics.fingerprint.FingerprintStatusPreferenceController; 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.search.BaseSearchIndexProvider; 30 import com.android.settings.security.trustagent.TrustAgentListPreferenceController; 31 import com.android.settings.widget.PreferenceCategoryController; 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.ArrayList; 37 import java.util.List; 38 39 @SearchIndexable 40 public class SecuritySettings extends DashboardFragment { 41 42 private static final String TAG = "SecuritySettings"; 43 protected static final String SECURITY_CATEGORY = "security_category"; 44 45 public static final int CHANGE_TRUST_AGENT_SETTINGS = 126; 46 public static final int UNIFY_LOCK_CONFIRM_PROFILE_REQUEST = 129; 47 public static final int UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 130; 48 49 @Override getMetricsCategory()50 public int getMetricsCategory() { 51 return SettingsEnums.SECURITY; 52 } 53 54 @Override getPreferenceScreenResId()55 protected int getPreferenceScreenResId() { 56 return R.xml.security_dashboard_settings; 57 } 58 59 @Override getLogTag()60 protected String getLogTag() { 61 return TAG; 62 } 63 64 @Override getHelpResource()65 public int getHelpResource() { 66 return R.string.help_url_security; 67 } 68 69 @Override createPreferenceControllers(Context context)70 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 71 return buildPreferenceControllers(context, getSettingsLifecycle(), this /* host*/); 72 } 73 74 /** 75 * see confirmPatternThenDisableAndClear 76 */ 77 @Override onActivityResult(int requestCode, int resultCode, Intent data)78 public void onActivityResult(int requestCode, int resultCode, Intent data) { 79 if (use(TrustAgentListPreferenceController.class) 80 .handleActivityResult(requestCode, resultCode)) { 81 return; 82 } 83 if (use(LockUnificationPreferenceController.class) 84 .handleActivityResult(requestCode, resultCode, data)) { 85 return; 86 } 87 super.onActivityResult(requestCode, resultCode, data); 88 } 89 startUnification()90 void startUnification() { 91 use(LockUnificationPreferenceController.class).startUnification(); 92 } 93 updateUnificationPreference()94 void updateUnificationPreference() { 95 use(LockUnificationPreferenceController.class).updateState(null); 96 } 97 buildPreferenceControllers(Context context, Lifecycle lifecycle, SecuritySettings host)98 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, 99 Lifecycle lifecycle, SecuritySettings host) { 100 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 101 final List<AbstractPreferenceController> securityPreferenceControllers = new ArrayList<>(); 102 securityPreferenceControllers.add(new FaceStatusPreferenceController(context, lifecycle)); 103 securityPreferenceControllers.add(new FingerprintStatusPreferenceController( 104 context, lifecycle)); 105 securityPreferenceControllers.add(new CombinedBiometricStatusPreferenceController( 106 context, lifecycle)); 107 securityPreferenceControllers.add(new ChangeScreenLockPreferenceController(context, host)); 108 controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY) 109 .setChildren(securityPreferenceControllers)); 110 controllers.addAll(securityPreferenceControllers); 111 112 return controllers; 113 } 114 115 /** 116 * For Search. Please keep it in sync when updating "createPreferenceHierarchy()" 117 */ 118 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 119 new BaseSearchIndexProvider(R.xml.security_dashboard_settings) { 120 121 @Override 122 public List<AbstractPreferenceController> createPreferenceControllers(Context 123 context) { 124 return buildPreferenceControllers(context, null /* lifecycle */, 125 null /* host*/); 126 } 127 128 @Override 129 protected boolean isPageSearchEnabled(Context context) { 130 return !FeatureFactory.getFeatureFactory().getSecuritySettingsFeatureProvider() 131 .hasAlternativeSecuritySettingsFragment() 132 && !SafetyCenterManagerWrapper.get().isEnabled(context); 133 } 134 }; 135 136 @Override getSettingsLifecycle()137 public Lifecycle getSettingsLifecycle() { 138 return super.getSettingsLifecycle(); 139 } 140 } 141