Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1 | /* |
| 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 Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 16 | package com.android.keyguard; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 17 | |
Lucas Dupin | 8968f6a | 2019-08-09 17:41:15 -0700 | [diff] [blame^] | 18 | import static com.android.systemui.DejankUtils.whitelistIpcs; |
| 19 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 20 | import android.app.admin.DevicePolicyManager; |
| 21 | import android.content.Context; |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 22 | import android.telephony.SubscriptionManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 23 | |
| 24 | import com.android.internal.telephony.IccCardConstants; |
| 25 | import com.android.internal.widget.LockPatternUtils; |
| 26 | |
| 27 | public class KeyguardSecurityModel { |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 28 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 29 | /** |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 30 | * The different types of security available. |
| 31 | * @see KeyguardSecurityContainer#showSecurityScreen |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 32 | */ |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 33 | public enum SecurityMode { |
Jim Miller | 63f9b81 | 2012-10-15 15:58:01 -0700 | [diff] [blame] | 34 | Invalid, // NULL state |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 35 | None, // No security enabled |
| 36 | Pattern, // Unlock by drawing a pattern. |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 37 | Password, // Unlock by entering an alphanumeric password |
| 38 | PIN, // Strictly numeric password |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 39 | SimPin, // Unlock by entering a sim pin. |
| 40 | SimPuk // Unlock by entering a sim puk |
| 41 | } |
| 42 | |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 43 | private final Context mContext; |
| 44 | private final boolean mIsPukScreenAvailable; |
| 45 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 46 | private LockPatternUtils mLockPatternUtils; |
| 47 | |
| 48 | KeyguardSecurityModel(Context context) { |
| 49 | mContext = context; |
| 50 | mLockPatternUtils = new LockPatternUtils(context); |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 51 | mIsPukScreenAvailable = mContext.getResources().getBoolean( |
| 52 | com.android.internal.R.bool.config_enable_puk_unlock_screen); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void setLockPatternUtils(LockPatternUtils utils) { |
| 56 | mLockPatternUtils = utils; |
| 57 | } |
| 58 | |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 59 | SecurityMode getSecurityMode(int userId) { |
Jim Miller | 52a6133 | 2014-11-12 19:29:51 -0800 | [diff] [blame] | 60 | KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext); |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 61 | |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 62 | if (mIsPukScreenAvailable && SubscriptionManager.isValidSubscriptionId( |
| 63 | monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED))) { |
| 64 | return SecurityMode.SimPuk; |
| 65 | } |
| 66 | |
Pengquan Meng | 4b267df | 2017-10-11 17:43:33 -0700 | [diff] [blame] | 67 | if (SubscriptionManager.isValidSubscriptionId( |
| 68 | monitor.getNextSubIdForState(IccCardConstants.State.PIN_REQUIRED))) { |
| 69 | return SecurityMode.SimPin; |
| 70 | } |
| 71 | |
Lucas Dupin | 8968f6a | 2019-08-09 17:41:15 -0700 | [diff] [blame^] | 72 | // TODO(b/140034863) |
| 73 | final int security = whitelistIpcs(() -> |
| 74 | mLockPatternUtils.getActivePasswordQuality(userId)); |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 75 | switch (security) { |
| 76 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
| 77 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: |
| 78 | return SecurityMode.PIN; |
| 79 | |
| 80 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: |
| 81 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: |
| 82 | case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: |
Toni Barzic | 79675b3 | 2016-03-29 18:31:49 -0700 | [diff] [blame] | 83 | case DevicePolicyManager.PASSWORD_QUALITY_MANAGED: |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 84 | return SecurityMode.Password; |
| 85 | |
| 86 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
| 87 | return SecurityMode.Pattern; |
| 88 | case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: |
| 89 | return SecurityMode.None; |
| 90 | |
| 91 | default: |
| 92 | throw new IllegalStateException("Unknown security quality:" + security); |
| 93 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 94 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 95 | } |