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