• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.car.developeroptions.security;
18 
19 import static com.android.car.developeroptions.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 import android.provider.SearchIndexableResource;
25 
26 import com.android.car.developeroptions.R;
27 import com.android.car.developeroptions.dashboard.DashboardFragment;
28 import com.android.car.developeroptions.search.BaseSearchIndexProvider;
29 import com.android.car.developeroptions.widget.PreferenceCategoryController;
30 import com.android.settingslib.core.AbstractPreferenceController;
31 import com.android.settingslib.core.lifecycle.Lifecycle;
32 import com.android.settingslib.search.SearchIndexable;
33 
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
37 
38 /**
39  * Encryption and Credential settings.
40  */
41 @SearchIndexable
42 public class EncryptionAndCredential extends DashboardFragment {
43 
44     private static final String TAG = "EncryptionAndCredential";
45 
46     @Override
getMetricsCategory()47     public int getMetricsCategory() {
48         return SettingsEnums.ENCRYPTION_AND_CREDENTIAL;
49     }
50 
51     @Override
getLogTag()52     protected String getLogTag() {
53         return TAG;
54     }
55 
56     @Override
createPreferenceControllers(Context context)57     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
58         return buildPreferenceControllers(context, getSettingsLifecycle());
59     }
60 
61     @Override
getPreferenceScreenResId()62     protected int getPreferenceScreenResId() {
63         return R.xml.encryption_and_credential;
64     }
65 
buildPreferenceControllers(Context context, Lifecycle lifecycle)66     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
67             Lifecycle lifecycle) {
68         final List<AbstractPreferenceController> controllers = new ArrayList<>();
69         final EncryptionStatusPreferenceController encryptStatusController =
70                 new EncryptionStatusPreferenceController(context,
71                         PREF_KEY_ENCRYPTION_DETAIL_PAGE);
72         controllers.add(encryptStatusController);
73         controllers.add(new PreferenceCategoryController(context,
74                 "encryption_and_credentials_status_category").setChildren(
75                 Arrays.asList(encryptStatusController)));
76         controllers.add(new CredentialStoragePreferenceController(context));
77         controllers.add(new UserCredentialsPreferenceController(context));
78         controllers.add(new ResetCredentialsPreferenceController(context, lifecycle));
79         controllers.add(new InstallCredentialsPreferenceController(context));
80         return controllers;
81     }
82 
83     @Override
getHelpResource()84     public int getHelpResource() {
85         return R.string.help_url_encryption;
86     }
87 
88     /**
89      * For Search. Please keep it in sync when updating "createPreferenceHierarchy()"
90      */
91     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
92             new SecuritySearchIndexProvider();
93 
94     private static class SecuritySearchIndexProvider extends BaseSearchIndexProvider {
95 
96         @Override
getXmlResourcesToIndex( Context context, boolean enabled)97         public List<SearchIndexableResource> getXmlResourcesToIndex(
98                 Context context, boolean enabled) {
99             final SearchIndexableResource sir = new SearchIndexableResource(context);
100             sir.xmlResId = R.xml.encryption_and_credential;
101             return Arrays.asList(sir);
102         }
103 
104         @Override
createPreferenceControllers(Context context)105         public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
106             return buildPreferenceControllers(context, null /* lifecycle */);
107         }
108 
109         @Override
isPageSearchEnabled(Context context)110         protected boolean isPageSearchEnabled(Context context) {
111             final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
112             return um.isAdminUser();
113         }
114     }
115 }
116