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 20 .PREF_KEY_ENCRYPTION_DETAIL_PAGE; 21 22 import android.content.Context; 23 import android.os.UserManager; 24 import android.provider.SearchIndexableResource; 25 26 import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 27 import com.android.settings.R; 28 import com.android.settings.dashboard.DashboardFragment; 29 import com.android.settings.search.BaseSearchIndexProvider; 30 import com.android.settings.widget.PreferenceCategoryController; 31 import com.android.settingslib.core.AbstractPreferenceController; 32 import com.android.settingslib.core.lifecycle.Lifecycle; 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 public class EncryptionAndCredential extends DashboardFragment { 42 43 private static final String TAG = "EncryptionAndCredential"; 44 45 @Override 46 public int getMetricsCategory() { 47 return MetricsEvent.ENCRYPTION_AND_CREDENTIAL; 48 } 49 50 @Override 51 protected String getLogTag() { 52 return TAG; 53 } 54 55 @Override 56 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 57 return buildPreferenceControllers(context, getLifecycle()); 58 } 59 60 @Override 61 protected int getPreferenceScreenResId() { 62 return R.xml.encryption_and_credential; 63 } 64 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 InstallCredentialsPreferenceController(context)); 79 return controllers; 80 } 81 82 @Override 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 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 104 public List<AbstractPreferenceController> createPreferenceControllers(Context context) { 105 return buildPreferenceControllers(context, null /* lifecycle */); 106 } 107 108 @Override 109 protected boolean isPageSearchEnabled(Context context) { 110 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); 111 return um.isAdminUser(); 112 } 113 } 114 } 115