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