• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
20 
21 import android.content.Context;
22 import android.os.UserHandle;
23 import android.support.v7.preference.Preference;
24 import android.support.v7.preference.PreferenceScreen;
25 
26 import com.android.internal.widget.LockPatternUtils;
27 import com.android.settings.core.BasePreferenceController;
28 import com.android.settings.notification.LockScreenNotificationPreferenceController;
29 import com.android.settings.overlay.FeatureFactory;
30 import com.android.settingslib.core.lifecycle.Lifecycle;
31 import com.android.settingslib.core.lifecycle.LifecycleObserver;
32 import com.android.settingslib.core.lifecycle.events.OnResume;
33 
34 public class LockScreenPreferenceController extends BasePreferenceController implements
35         LifecycleObserver, OnResume {
36 
37     static final String KEY_LOCKSCREEN_PREFERENCES = "lockscreen_preferences";
38 
39     private static final int MY_USER_ID = UserHandle.myUserId();
40     private final LockPatternUtils mLockPatternUtils;
41     private Preference mPreference;
42 
LockScreenPreferenceController(Context context, Lifecycle lifecycle)43     public LockScreenPreferenceController(Context context, Lifecycle lifecycle) {
44         super(context, KEY_LOCKSCREEN_PREFERENCES);
45         mLockPatternUtils = FeatureFactory.getFactory(context)
46                 .getSecurityFeatureProvider().getLockPatternUtils(context);
47         if (lifecycle != null) {
48             lifecycle.addObserver(this);
49         }
50     }
51 
52     @Override
displayPreference(PreferenceScreen screen)53     public void displayPreference(PreferenceScreen screen) {
54         super.displayPreference(screen);
55         mPreference = screen.findPreference(getPreferenceKey());
56     }
57 
58     @Override
getAvailabilityStatus()59     public int getAvailabilityStatus() {
60         if (!mLockPatternUtils.isSecure(MY_USER_ID)) {
61             return mLockPatternUtils.isLockScreenDisabled(MY_USER_ID)
62                     ? DISABLED_FOR_USER : AVAILABLE;
63         } else {
64             return mLockPatternUtils.getKeyguardStoredPasswordQuality(MY_USER_ID)
65                     == PASSWORD_QUALITY_UNSPECIFIED
66                     ? DISABLED_FOR_USER : AVAILABLE;
67         }
68     }
69 
70     @Override
updateState(Preference preference)71     public void updateState(Preference preference) {
72         preference.setSummary(
73                 LockScreenNotificationPreferenceController.getSummaryResource(mContext));
74     }
75 
76     @Override
onResume()77     public void onResume() {
78         mPreference.setVisible(isAvailable());
79     }
80 }
81