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.settings.security; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.os.UserManager; 22 23 import com.android.settings.R; 24 import com.android.settings.dashboard.DashboardFragment; 25 import com.android.settings.search.BaseSearchIndexProvider; 26 import com.android.settingslib.core.AbstractPreferenceController; 27 import com.android.settingslib.core.lifecycle.Lifecycle; 28 import com.android.settingslib.search.SearchIndexable; 29 30 import java.util.ArrayList; 31 import java.util.List; 32 33 /** 34 * Install certificate from storage settings. 35 */ 36 @SearchIndexable 37 public class InstallCertificateFromStorage extends DashboardFragment { 38 39 private static final String TAG = "InstallCertificateFromStorage"; 40 41 @Override getMetricsCategory()42 public int getMetricsCategory() { 43 return SettingsEnums.INSTALL_CERTIFICATE_FROM_STORAGE; 44 } 45 46 @Override getPreferenceScreenResId()47 protected int getPreferenceScreenResId() { 48 return R.xml.install_certificate_from_storage; 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 buildPreferenceControllers(Context context, Lifecycle lifecycle)61 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, 62 Lifecycle lifecycle) { 63 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 64 controllers.add(new InstallCaCertificatePreferenceController(context)); 65 controllers.add(new InstallUserCertificatePreferenceController(context)); 66 controllers.add(new InstallWifiCertificatePreferenceController(context)); 67 return controllers; 68 } 69 70 @Override getHelpResource()71 public int getHelpResource() { 72 return R.string.help_url_install_certificate; 73 } 74 75 /** 76 * For Search. Please keep it in sync when updating "createPreferenceHierarchy()" 77 */ 78 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 79 new BaseSearchIndexProvider(R.xml.install_certificate_from_storage) { 80 @Override 81 public List<AbstractPreferenceController> createPreferenceControllers( 82 Context context) { 83 return buildPreferenceControllers(context, null /* lifecycle */); 84 } 85 86 @Override 87 protected boolean isPageSearchEnabled(Context context) { 88 final UserManager um = (UserManager) context.getSystemService( 89 Context.USER_SERVICE); 90 return um.isAdminUser(); 91 } 92 }; 93 } 94