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.screenlock; 18 19 import android.app.Fragment; 20 import android.content.Context; 21 import android.os.UserHandle; 22 import android.provider.SearchIndexableResource; 23 24 import com.android.internal.logging.nano.MetricsProto; 25 import com.android.internal.widget.LockPatternUtils; 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.search.Indexable; 30 import com.android.settings.security.OwnerInfoPreferenceController; 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.List; 36 37 public class ScreenLockSettings extends DashboardFragment 38 implements OwnerInfoPreferenceController.OwnerInfoCallback { 39 40 private static final String TAG = "ScreenLockSettings"; 41 42 private static final String KEY_LOCK_SCREEN_TITLE = "security_settings_password_sub_screen"; 43 44 private static final int MY_USER_ID = UserHandle.myUserId(); 45 private LockPatternUtils mLockPatternUtils; 46 47 @Override 48 public int getMetricsCategory() { 49 return MetricsProto.MetricsEvent.SCREEN_LOCK_SETTINGS; 50 } 51 52 @Override 53 protected int getPreferenceScreenResId() { 54 return R.xml.screen_lock_settings; 55 } 56 57 @Override 58 protected String getLogTag() { 59 return TAG; 60 } 61 62 @Override 63 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 64 mLockPatternUtils = new LockPatternUtils(context); 65 return buildPreferenceControllers(context, this /* parent */, getLifecycle(), 66 mLockPatternUtils); 67 } 68 69 @Override 70 public void onOwnerInfoUpdated() { 71 use(OwnerInfoPreferenceController.class).updateSummary(); 72 } 73 74 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, 75 Fragment parent, Lifecycle lifecycle, LockPatternUtils lockPatternUtils) { 76 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 77 controllers.add(new PatternVisiblePreferenceController( 78 context, MY_USER_ID, lockPatternUtils)); 79 controllers.add(new PowerButtonInstantLockPreferenceController( 80 context, MY_USER_ID, lockPatternUtils)); 81 controllers.add(new LockAfterTimeoutPreferenceController( 82 context, MY_USER_ID, lockPatternUtils)); 83 controllers.add(new OwnerInfoPreferenceController(context, parent, lifecycle)); 84 return controllers; 85 } 86 87 88 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 89 new BaseSearchIndexProvider() { 90 @Override 91 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, 92 boolean enabled) { 93 final ArrayList<SearchIndexableResource> result = new ArrayList<>(); 94 95 final SearchIndexableResource sir = new SearchIndexableResource(context); 96 sir.xmlResId = R.xml.screen_lock_settings; 97 result.add(sir); 98 return result; 99 } 100 101 @Override 102 public List<AbstractPreferenceController> createPreferenceControllers( 103 Context context) { 104 return buildPreferenceControllers(context, null /* parent */, 105 null /* lifecycle */, new LockPatternUtils(context)); 106 } 107 108 @Override 109 public List<String> getNonIndexableKeys(Context context) { 110 final List<String> keys = super.getNonIndexableKeys(context); 111 keys.add(KEY_LOCK_SCREEN_TITLE); 112 return keys; 113 } 114 }; 115 } 116