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; |
Dave Mankoff | e229469 | 2019-08-14 11:53:13 -0400 | [diff] [blame] | 26 | import com.android.systemui.Dependency; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 27 | |
Dave Mankoff | f44b13a | 2019-10-03 17:29:58 -0400 | [diff] [blame] | 28 | import javax.inject.Inject; |
| 29 | import javax.inject.Singleton; |
| 30 | |
| 31 | @Singleton |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 32 | public class KeyguardSecurityModel { |
Adrian Roos | 46842d9 | 2014-03-27 14:58:03 +0100 | [diff] [blame] | 33 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 34 | /** |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 35 | * The different types of security available. |
| 36 | * @see KeyguardSecurityContainer#showSecurityScreen |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 37 | */ |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 38 | public enum SecurityMode { |
Jim Miller | 63f9b81 | 2012-10-15 15:58:01 -0700 | [diff] [blame] | 39 | Invalid, // NULL state |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 40 | None, // No security enabled |
| 41 | Pattern, // Unlock by drawing a pattern. |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 42 | Password, // Unlock by entering an alphanumeric password |
| 43 | PIN, // Strictly numeric password |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 44 | SimPin, // Unlock by entering a sim pin. |
| 45 | SimPuk // Unlock by entering a sim puk |
| 46 | } |
| 47 | |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 48 | private final Context mContext; |
| 49 | private final boolean mIsPukScreenAvailable; |
| 50 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 51 | private LockPatternUtils mLockPatternUtils; |
| 52 | |
Dave Mankoff | f44b13a | 2019-10-03 17:29:58 -0400 | [diff] [blame] | 53 | @Inject |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 54 | KeyguardSecurityModel(Context context) { |
| 55 | mContext = context; |
| 56 | mLockPatternUtils = new LockPatternUtils(context); |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 57 | mIsPukScreenAvailable = mContext.getResources().getBoolean( |
| 58 | com.android.internal.R.bool.config_enable_puk_unlock_screen); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void setLockPatternUtils(LockPatternUtils utils) { |
| 62 | mLockPatternUtils = utils; |
| 63 | } |
| 64 | |
Dave Mankoff | f44b13a | 2019-10-03 17:29:58 -0400 | [diff] [blame] | 65 | public SecurityMode getSecurityMode(int userId) { |
Dave Mankoff | e229469 | 2019-08-14 11:53:13 -0400 | [diff] [blame] | 66 | KeyguardUpdateMonitor monitor = Dependency.get(KeyguardUpdateMonitor.class); |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 67 | |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 68 | if (mIsPukScreenAvailable && SubscriptionManager.isValidSubscriptionId( |
| 69 | monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED))) { |
| 70 | return SecurityMode.SimPuk; |
| 71 | } |
| 72 | |
Pengquan Meng | 4b267df | 2017-10-11 17:43:33 -0700 | [diff] [blame] | 73 | if (SubscriptionManager.isValidSubscriptionId( |
| 74 | monitor.getNextSubIdForState(IccCardConstants.State.PIN_REQUIRED))) { |
| 75 | return SecurityMode.SimPin; |
| 76 | } |
| 77 | |
Lucas Dupin | 8968f6a | 2019-08-09 17:41:15 -0700 | [diff] [blame] | 78 | // TODO(b/140034863) |
| 79 | final int security = whitelistIpcs(() -> |
| 80 | mLockPatternUtils.getActivePasswordQuality(userId)); |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 81 | 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 Barzic | 79675b3 | 2016-03-29 18:31:49 -0700 | [diff] [blame] | 89 | case DevicePolicyManager.PASSWORD_QUALITY_MANAGED: |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 90 | 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 Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 100 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 101 | } |