1 /* 2 * Copyright (C) 2017 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.password; 18 19 import android.app.admin.DevicePolicyManager; 20 21 /** 22 * List of screen lock type options that are available in ChooseLockGeneric. Provides the key and 23 * the associated quality, and also some helper functions to translate between them. 24 */ 25 public enum ScreenLockType { 26 27 NONE( 28 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 29 "unlock_set_off"), 30 SWIPE( 31 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 32 "unlock_set_none"), 33 PATTERN( 34 DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, 35 "unlock_set_pattern"), 36 PIN( 37 DevicePolicyManager.PASSWORD_QUALITY_NUMERIC, 38 DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX, 39 "unlock_set_pin"), 40 PASSWORD( 41 DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC, 42 DevicePolicyManager.PASSWORD_QUALITY_COMPLEX, 43 "unlock_set_password"), 44 MANAGED( 45 DevicePolicyManager.PASSWORD_QUALITY_MANAGED, 46 "unlock_set_managed"); 47 48 /** 49 * The default quality of the type of lock used. For example, in the case of PIN, the default 50 * quality if PASSWORD_QUALITY_NUMERIC, while the highest quality is 51 * PASSWORD_QUALITY_NUMERIC_COMPLEX. 52 */ 53 public final int defaultQuality; 54 55 /** 56 * The highest quality for the given type of lock. For example, in the case of password, the 57 * default quality is PASSWORD_QUALITY_ALPHABETIC, but the highest possible quality is 58 * PASSWORD_QUALITY_COMPLEX. 59 */ 60 public final int maxQuality; 61 62 public final String preferenceKey; 63 ScreenLockType(int quality, String preferenceKey)64 ScreenLockType(int quality, String preferenceKey) { 65 this(quality, quality, preferenceKey); 66 } 67 ScreenLockType(int defaultQuality, int maxQuality, String preferenceKey)68 ScreenLockType(int defaultQuality, int maxQuality, String preferenceKey) { 69 this.defaultQuality = defaultQuality; 70 this.maxQuality = maxQuality; 71 this.preferenceKey = preferenceKey; 72 } 73 74 /** 75 * Gets the screen lock type for the given quality. Note that this method assumes that a screen 76 * lock is enabled, which means if the quality is 77 * {@link DevicePolicyManager#PASSWORD_QUALITY_UNSPECIFIED}, the returned type will be 78 * {@link #SWIPE} and not {@link #NONE}. 79 */ fromQuality(int quality)80 public static ScreenLockType fromQuality(int quality) { 81 switch (quality) { 82 case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: 83 return ScreenLockType.PATTERN; 84 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: 85 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: 86 return ScreenLockType.PIN; 87 case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: 88 case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: 89 case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: 90 return ScreenLockType.PASSWORD; 91 case DevicePolicyManager.PASSWORD_QUALITY_MANAGED: 92 return ScreenLockType.MANAGED; 93 case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: 94 return ScreenLockType.SWIPE; 95 } 96 return null; 97 } 98 fromKey(String key)99 public static ScreenLockType fromKey(String key) { 100 for (ScreenLockType lock : ScreenLockType.values()) { 101 if (lock.preferenceKey.equals(key)) { 102 return lock; 103 } 104 } 105 return null; 106 } 107 } 108