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 import android.provider.SearchIndexableResource; 25 26 import com.android.settings.R; 27 import com.android.settings.dashboard.DashboardFragment; 28 import com.android.settings.search.BaseSearchIndexProvider; 29 import com.android.settings.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 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 SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 91 new SecuritySearchIndexProvider(); 92 93 private static class SecuritySearchIndexProvider extends BaseSearchIndexProvider { 94 95 @Override getXmlResourcesToIndex( Context context, boolean enabled)96 public List<SearchIndexableResource> getXmlResourcesToIndex( 97 Context context, boolean enabled) { 98 final SearchIndexableResource sir = new SearchIndexableResource(context); 99 sir.xmlResId = R.xml.encryption_and_credential; 100 return Arrays.asList(sir); 101 } 102 103 @Override createPreferenceControllers(Context context)104 public List<AbstractPreferenceController> createPreferenceControllers(Context context) { 105 return buildPreferenceControllers(context, null /* lifecycle */); 106 } 107 108 @Override isPageSearchEnabled(Context context)109 protected boolean isPageSearchEnabled(Context context) { 110 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); 111 return um.isAdminUser(); 112 } 113 } 114 } 115