blob: 1395fd9e348234941aa048c059fef157755b40b5 [file] [log] [blame]
Jim Millerdcb3d842012-08-23 19:18:12 -07001/*
2 * Copyright (C) 2012 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 */
Jim Miller5ecd8112013-01-09 18:50:26 -080016package com.android.keyguard;
Jim Millerdcb3d842012-08-23 19:18:12 -070017
Lucas Dupin8968f6a2019-08-09 17:41:15 -070018import static com.android.systemui.DejankUtils.whitelistIpcs;
19
Jim Millerdcb3d842012-08-23 19:18:12 -070020import android.app.admin.DevicePolicyManager;
21import android.content.Context;
Jim Miller52a61332014-11-12 19:29:51 -080022import android.telephony.SubscriptionManager;
Jim Millerdcb3d842012-08-23 19:18:12 -070023
24import com.android.internal.telephony.IccCardConstants;
25import com.android.internal.widget.LockPatternUtils;
Dave Mankoffe2294692019-08-14 11:53:13 -040026import com.android.systemui.Dependency;
Jim Millerdcb3d842012-08-23 19:18:12 -070027
Dave Mankofff44b13a2019-10-03 17:29:58 -040028import javax.inject.Inject;
29import javax.inject.Singleton;
30
31@Singleton
Jim Millerdcb3d842012-08-23 19:18:12 -070032public class KeyguardSecurityModel {
Adrian Roos46842d92014-03-27 14:58:03 +010033
Jim Millerdcb3d842012-08-23 19:18:12 -070034 /**
Adrian Roosc2e01682015-01-15 23:20:20 +010035 * The different types of security available.
36 * @see KeyguardSecurityContainer#showSecurityScreen
Jim Millerdcb3d842012-08-23 19:18:12 -070037 */
Jorim Jaggia005f1b2014-04-16 19:06:10 +020038 public enum SecurityMode {
Jim Miller63f9b812012-10-15 15:58:01 -070039 Invalid, // NULL state
Jim Millerdcb3d842012-08-23 19:18:12 -070040 None, // No security enabled
41 Pattern, // Unlock by drawing a pattern.
Daniel Sandler69bdee72012-10-23 16:45:50 -040042 Password, // Unlock by entering an alphanumeric password
43 PIN, // Strictly numeric password
Jim Millerdcb3d842012-08-23 19:18:12 -070044 SimPin, // Unlock by entering a sim pin.
45 SimPuk // Unlock by entering a sim puk
46 }
47
Adrian Roosc2e01682015-01-15 23:20:20 +010048 private final Context mContext;
49 private final boolean mIsPukScreenAvailable;
50
Jim Millerdcb3d842012-08-23 19:18:12 -070051 private LockPatternUtils mLockPatternUtils;
52
Dave Mankofff44b13a2019-10-03 17:29:58 -040053 @Inject
Jim Millerdcb3d842012-08-23 19:18:12 -070054 KeyguardSecurityModel(Context context) {
55 mContext = context;
56 mLockPatternUtils = new LockPatternUtils(context);
Adrian Roosc2e01682015-01-15 23:20:20 +010057 mIsPukScreenAvailable = mContext.getResources().getBoolean(
58 com.android.internal.R.bool.config_enable_puk_unlock_screen);
Jim Millerdcb3d842012-08-23 19:18:12 -070059 }
60
61 void setLockPatternUtils(LockPatternUtils utils) {
62 mLockPatternUtils = utils;
63 }
64
Dave Mankofff44b13a2019-10-03 17:29:58 -040065 public SecurityMode getSecurityMode(int userId) {
Dave Mankoffe2294692019-08-14 11:53:13 -040066 KeyguardUpdateMonitor monitor = Dependency.get(KeyguardUpdateMonitor.class);
Adrian Roosc2e01682015-01-15 23:20:20 +010067
Adrian Roosc2e01682015-01-15 23:20:20 +010068 if (mIsPukScreenAvailable && SubscriptionManager.isValidSubscriptionId(
69 monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED))) {
70 return SecurityMode.SimPuk;
71 }
72
Pengquan Meng4b267df2017-10-11 17:43:33 -070073 if (SubscriptionManager.isValidSubscriptionId(
74 monitor.getNextSubIdForState(IccCardConstants.State.PIN_REQUIRED))) {
75 return SecurityMode.SimPin;
76 }
77
Lucas Dupin8968f6a2019-08-09 17:41:15 -070078 // TODO(b/140034863)
79 final int security = whitelistIpcs(() ->
80 mLockPatternUtils.getActivePasswordQuality(userId));
Adrian Roosc2e01682015-01-15 23:20:20 +010081 switch (security) {
82 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
83 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
84 return SecurityMode.PIN;
85
86 case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
87 case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
88 case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
Toni Barzic79675b32016-03-29 18:31:49 -070089 case DevicePolicyManager.PASSWORD_QUALITY_MANAGED:
Adrian Roosc2e01682015-01-15 23:20:20 +010090 return SecurityMode.Password;
91
92 case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
93 return SecurityMode.Pattern;
94 case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED:
95 return SecurityMode.None;
96
97 default:
98 throw new IllegalStateException("Unknown security quality:" + security);
99 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700100 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700101}