1 /*
2  * Copyright (C) 2017 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 static com.android.settings.security.EncryptionStatusPreferenceController.PREF_KEY_ENCRYPTION_DETAIL_PAGE;
20 
21 import android.app.settings.SettingsEnums;
22 import android.content.Context;
23 import android.os.UserManager;
24 
25 import com.android.settings.R;
26 import com.android.settings.dashboard.DashboardFragment;
27 import com.android.settings.search.BaseSearchIndexProvider;
28 import com.android.settings.widget.PreferenceCategoryController;
29 import com.android.settingslib.core.AbstractPreferenceController;
30 import com.android.settingslib.core.lifecycle.Lifecycle;
31 import com.android.settingslib.search.SearchIndexable;
32 
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.List;
36 
37 /**
38  * Encryption and Credential settings.
39  */
40 @SearchIndexable
41 public class EncryptionAndCredential extends DashboardFragment {
42 
43     private static final String TAG = "EncryptionAndCredential";
44 
45     @Override
getMetricsCategory()46     public int getMetricsCategory() {
47         return SettingsEnums.ENCRYPTION_AND_CREDENTIAL;
48     }
49 
50     @Override
getLogTag()51     protected String getLogTag() {
52         return TAG;
53     }
54 
55     @Override
createPreferenceControllers(Context context)56     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
57         return buildPreferenceControllers(context, getSettingsLifecycle());
58     }
59 
60     @Override
getPreferenceScreenResId()61     protected int getPreferenceScreenResId() {
62         return R.xml.encryption_and_credential;
63     }
64 
buildPreferenceControllers(Context context, Lifecycle lifecycle)65     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
66             Lifecycle lifecycle) {
67         final List<AbstractPreferenceController> controllers = new ArrayList<>();
68         final EncryptionStatusPreferenceController encryptStatusController =
69                 new EncryptionStatusPreferenceController(context,
70                         PREF_KEY_ENCRYPTION_DETAIL_PAGE);
71         controllers.add(encryptStatusController);
72         controllers.add(new PreferenceCategoryController(context,
73                 "encryption_and_credentials_status_category").setChildren(
74                 Arrays.asList(encryptStatusController)));
75         controllers.add(new CredentialStoragePreferenceController(context));
76         controllers.add(new UserCredentialsPreferenceController(context));
77         controllers.add(new ResetCredentialsPreferenceController(context, lifecycle));
78         controllers.add(new InstallCertificatePreferenceController(context));
79         return controllers;
80     }
81 
82     @Override
getHelpResource()83     public int getHelpResource() {
84         return R.string.help_url_encryption;
85     }
86 
87     /**
88      * For Search. Please keep it in sync when updating "createPreferenceHierarchy()"
89      */
90     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
91             new BaseSearchIndexProvider(R.xml.encryption_and_credential) {
92                 @Override
93                 public List<AbstractPreferenceController> createPreferenceControllers(
94                         Context context) {
95                     return buildPreferenceControllers(context, null /* lifecycle */);
96                 }
97 
98                 @Override
99                 protected boolean isPageSearchEnabled(Context context) {
100                     final UserManager um = (UserManager) context.getSystemService(
101                             Context.USER_SERVICE);
102                     return um.isAdminUser();
103                 }
104             };
105 }
106