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