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.settings.SettingsEnums; 20 import android.content.Context; 21 import android.os.UserHandle; 22 23 import com.android.internal.widget.LockPatternUtils; 24 import com.android.settings.R; 25 import com.android.settings.dashboard.DashboardFragment; 26 import com.android.settings.search.BaseSearchIndexProvider; 27 import com.android.settings.security.OwnerInfoPreferenceController; 28 import com.android.settingslib.core.AbstractPreferenceController; 29 import com.android.settingslib.search.SearchIndexable; 30 31 import java.util.ArrayList; 32 import java.util.List; 33 34 @SearchIndexable 35 public class ScreenLockSettings extends DashboardFragment 36 implements OwnerInfoPreferenceController.OwnerInfoCallback { 37 38 private static final String TAG = "ScreenLockSettings"; 39 40 private static final int MY_USER_ID = UserHandle.myUserId(); 41 private LockPatternUtils mLockPatternUtils; 42 43 @Override getMetricsCategory()44 public int getMetricsCategory() { 45 return SettingsEnums.SCREEN_LOCK_SETTINGS; 46 } 47 48 @Override getPreferenceScreenResId()49 protected int getPreferenceScreenResId() { 50 return R.xml.screen_lock_settings; 51 } 52 53 @Override getLogTag()54 protected String getLogTag() { 55 return TAG; 56 } 57 58 @Override createPreferenceControllers(Context context)59 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 60 mLockPatternUtils = new LockPatternUtils(context); 61 return buildPreferenceControllers(context, this /* parent */, mLockPatternUtils); 62 } 63 64 @Override onOwnerInfoUpdated()65 public void onOwnerInfoUpdated() { 66 use(OwnerInfoPreferenceController.class).updateSummary(); 67 } 68 buildPreferenceControllers(Context context, DashboardFragment parent, LockPatternUtils lockPatternUtils)69 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, 70 DashboardFragment parent, LockPatternUtils lockPatternUtils) { 71 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 72 controllers.add(new PatternVisiblePreferenceController( 73 context, MY_USER_ID, lockPatternUtils)); 74 controllers.add(new PowerButtonInstantLockPreferenceController( 75 context, MY_USER_ID, lockPatternUtils)); 76 controllers.add(new LockAfterTimeoutPreferenceController( 77 context, MY_USER_ID, lockPatternUtils)); 78 controllers.add(new OwnerInfoPreferenceController(context, parent)); 79 return controllers; 80 } 81 82 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 83 new BaseSearchIndexProvider(R.xml.screen_lock_settings) { 84 85 @Override 86 public List<AbstractPreferenceController> createPreferenceControllers( 87 Context context) { 88 return buildPreferenceControllers(context, null /* parent */, 89 new LockPatternUtils(context)); 90 } 91 }; 92 } 93