The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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.internal.widget; |
| 18 | |
Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 19 | import com.android.internal.R; |
| 20 | import com.android.internal.telephony.ITelephony; |
| 21 | import com.google.android.collect.Lists; |
| 22 | |
Amith Yamasani | 4b4b954 | 2012-09-14 13:36:29 -0700 | [diff] [blame] | 23 | import android.app.ActivityManagerNative; |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 24 | import android.app.admin.DevicePolicyManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.content.ContentResolver; |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 26 | import android.content.Context; |
Steven Ross | 329979c | 2011-09-28 11:42:56 -0400 | [diff] [blame] | 27 | import android.content.Intent; |
Danielle Millett | 5839698 | 2011-09-30 13:55:07 -0400 | [diff] [blame] | 28 | import android.content.pm.PackageManager; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 29 | import android.os.Binder; |
Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 30 | import android.os.IBinder; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 31 | import android.os.Process; |
Jim Miller | 69ac988 | 2010-02-24 15:35:05 -0800 | [diff] [blame] | 32 | import android.os.RemoteException; |
| 33 | import android.os.ServiceManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.os.SystemClock; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 35 | import android.os.UserHandle; |
Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 36 | import android.os.storage.IMountService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.provider.Settings; |
Brian Carlstrom | 5cfee3f | 2011-05-31 01:00:15 -0700 | [diff] [blame] | 38 | import android.security.KeyStore; |
Jim Miller | 69ac988 | 2010-02-24 15:35:05 -0800 | [diff] [blame] | 39 | import android.telephony.TelephonyManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.text.TextUtils; |
| 41 | import android.util.Log; |
John Wang | 0f7b3f8 | 2011-05-31 11:20:55 -0700 | [diff] [blame] | 42 | import android.view.View; |
Jim Miller | 69ac988 | 2010-02-24 15:35:05 -0800 | [diff] [blame] | 43 | import android.widget.Button; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
Brian Carlstrom | 929a1c2 | 2011-02-01 21:54:09 -0800 | [diff] [blame] | 45 | import java.security.MessageDigest; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import java.security.NoSuchAlgorithmException; |
Jim Miller | 11b019d | 2010-01-20 16:34:45 -0800 | [diff] [blame] | 47 | import java.security.SecureRandom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import java.util.List; |
| 49 | |
| 50 | /** |
Brian Carlstrom | 5cfee3f | 2011-05-31 01:00:15 -0700 | [diff] [blame] | 51 | * Utilities for the lock pattern and its settings. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | */ |
| 53 | public class LockPatternUtils { |
| 54 | |
Jim Miller | cb3521e | 2011-10-03 20:42:26 -0700 | [diff] [blame] | 55 | private static final String OPTION_ENABLE_FACELOCK = "enable_facelock"; |
| 56 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | private static final String TAG = "LockPatternUtils"; |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 58 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | /** |
| 60 | * The maximum number of incorrect attempts before the user is prevented |
| 61 | * from trying again for {@link #FAILED_ATTEMPT_TIMEOUT_MS}. |
| 62 | */ |
| 63 | public static final int FAILED_ATTEMPTS_BEFORE_TIMEOUT = 5; |
| 64 | |
| 65 | /** |
| 66 | * The number of incorrect attempts before which we fall back on an alternative |
| 67 | * method of verifying the user, and resetting their lock pattern. |
| 68 | */ |
| 69 | public static final int FAILED_ATTEMPTS_BEFORE_RESET = 20; |
| 70 | |
| 71 | /** |
| 72 | * How long the user is prevented from trying again after entering the |
| 73 | * wrong pattern too many times. |
| 74 | */ |
| 75 | public static final long FAILED_ATTEMPT_TIMEOUT_MS = 30000L; |
| 76 | |
| 77 | /** |
| 78 | * The interval of the countdown for showing progress of the lockout. |
| 79 | */ |
| 80 | public static final long FAILED_ATTEMPT_COUNTDOWN_INTERVAL_MS = 1000L; |
| 81 | |
Jim Miller | 4f36995 | 2011-08-19 18:29:22 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * This dictates when we start telling the user that continued failed attempts will wipe |
| 85 | * their device. |
| 86 | */ |
| 87 | public static final int FAILED_ATTEMPTS_BEFORE_WIPE_GRACE = 5; |
| 88 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | /** |
| 90 | * The minimum number of dots in a valid pattern. |
| 91 | */ |
| 92 | public static final int MIN_LOCK_PATTERN_SIZE = 4; |
| 93 | |
| 94 | /** |
| 95 | * The minimum number of dots the user must include in a wrong pattern |
| 96 | * attempt for it to be counted against the counts that affect |
| 97 | * {@link #FAILED_ATTEMPTS_BEFORE_TIMEOUT} and {@link #FAILED_ATTEMPTS_BEFORE_RESET} |
| 98 | */ |
Jim Miller | 4f36995 | 2011-08-19 18:29:22 -0700 | [diff] [blame] | 99 | public static final int MIN_PATTERN_REGISTER_FAIL = MIN_LOCK_PATTERN_SIZE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | |
Danielle Millett | 925a7d8 | 2012-03-19 18:02:20 -0400 | [diff] [blame] | 101 | /** |
| 102 | * The bit in LOCK_BIOMETRIC_WEAK_FLAGS to be used to indicate whether liveliness should |
| 103 | * be used |
| 104 | */ |
| 105 | public static final int FLAG_BIOMETRIC_WEAK_LIVELINESS = 0x1; |
| 106 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 107 | protected final static String LOCKOUT_PERMANENT_KEY = "lockscreen.lockedoutpermanently"; |
| 108 | protected final static String LOCKOUT_ATTEMPT_DEADLINE = "lockscreen.lockoutattemptdeadline"; |
| 109 | protected final static String PATTERN_EVER_CHOSEN_KEY = "lockscreen.patterneverchosen"; |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 110 | public final static String PASSWORD_TYPE_KEY = "lockscreen.password_type"; |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 111 | public static final String PASSWORD_TYPE_ALTERNATE_KEY = "lockscreen.password_type_alternate"; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 112 | protected final static String LOCK_PASSWORD_SALT_KEY = "lockscreen.password_salt"; |
| 113 | protected final static String DISABLE_LOCKSCREEN_KEY = "lockscreen.disabled"; |
| 114 | protected final static String LOCKSCREEN_OPTIONS = "lockscreen.options"; |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 115 | public final static String LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK |
| 116 | = "lockscreen.biometric_weak_fallback"; |
Danielle Millett | 7a07219 | 2011-10-03 17:36:01 -0400 | [diff] [blame] | 117 | public final static String BIOMETRIC_WEAK_EVER_CHOSEN_KEY |
| 118 | = "lockscreen.biometricweakeverchosen"; |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 119 | public final static String LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS |
| 120 | = "lockscreen.power_button_instantly_locks"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 122 | protected final static String PASSWORD_HISTORY_KEY = "lockscreen.passwordhistory"; |
Konstantin Lopyrev | 863f22d | 2010-05-12 17:16:58 -0700 | [diff] [blame] | 123 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 124 | private final Context mContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | private final ContentResolver mContentResolver; |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 126 | private DevicePolicyManager mDevicePolicyManager; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 127 | private ILockSettings mLockSettingsService; |
Jim Miller | ee82f8f | 2012-10-01 16:26:18 -0700 | [diff] [blame] | 128 | |
| 129 | // The current user is set by KeyguardViewMediator and shared by all LockPatternUtils. |
| 130 | private static volatile int sCurrentUserId = UserHandle.USER_NULL; |
Dianne Hackborn | de4c26f | 2011-07-17 13:42:47 -0700 | [diff] [blame] | 131 | |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 132 | public DevicePolicyManager getDevicePolicyManager() { |
Jim Miller | 5b0fb3a | 2010-02-23 13:46:35 -0800 | [diff] [blame] | 133 | if (mDevicePolicyManager == null) { |
| 134 | mDevicePolicyManager = |
| 135 | (DevicePolicyManager)mContext.getSystemService(Context.DEVICE_POLICY_SERVICE); |
| 136 | if (mDevicePolicyManager == null) { |
| 137 | Log.e(TAG, "Can't get DevicePolicyManagerService: is it running?", |
| 138 | new IllegalStateException("Stack trace:")); |
| 139 | } |
| 140 | } |
| 141 | return mDevicePolicyManager; |
| 142 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | /** |
| 145 | * @param contentResolver Used to look up and save settings. |
| 146 | */ |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 147 | public LockPatternUtils(Context context) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 148 | mContext = context; |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 149 | mContentResolver = context.getContentResolver(); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 150 | } |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 151 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 152 | private ILockSettings getLockSettings() { |
| 153 | if (mLockSettingsService == null) { |
| 154 | mLockSettingsService = ILockSettings.Stub.asInterface( |
| 155 | (IBinder) ServiceManager.getService("lock_settings")); |
Brad Fitzpatrick | 9088100 | 2010-08-23 18:30:08 -0700 | [diff] [blame] | 156 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 157 | return mLockSettingsService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 160 | public int getRequestedMinimumPasswordLength() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 161 | return getDevicePolicyManager().getPasswordMinimumLength(null, getCurrentOrCallingUserId()); |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 164 | /** |
| 165 | * Gets the device policy password mode. If the mode is non-specific, returns |
| 166 | * MODE_PATTERN which allows the user to choose anything. |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 167 | */ |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 168 | public int getRequestedPasswordQuality() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 169 | return getDevicePolicyManager().getPasswordQuality(null, getCurrentOrCallingUserId()); |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 172 | public int getRequestedPasswordHistoryLength() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 173 | return getDevicePolicyManager().getPasswordHistoryLength(null, getCurrentOrCallingUserId()); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 176 | public int getRequestedPasswordMinimumLetters() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 177 | return getDevicePolicyManager().getPasswordMinimumLetters(null, |
| 178 | getCurrentOrCallingUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | public int getRequestedPasswordMinimumUpperCase() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 182 | return getDevicePolicyManager().getPasswordMinimumUpperCase(null, |
| 183 | getCurrentOrCallingUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | public int getRequestedPasswordMinimumLowerCase() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 187 | return getDevicePolicyManager().getPasswordMinimumLowerCase(null, |
| 188 | getCurrentOrCallingUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | public int getRequestedPasswordMinimumNumeric() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 192 | return getDevicePolicyManager().getPasswordMinimumNumeric(null, |
| 193 | getCurrentOrCallingUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | public int getRequestedPasswordMinimumSymbols() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 197 | return getDevicePolicyManager().getPasswordMinimumSymbols(null, |
| 198 | getCurrentOrCallingUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 201 | public int getRequestedPasswordMinimumNonLetter() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 202 | return getDevicePolicyManager().getPasswordMinimumNonLetter(null, |
| 203 | getCurrentOrCallingUserId()); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 204 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 205 | |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 206 | /** |
| 207 | * Returns the actual password mode, as set by keyguard after updating the password. |
| 208 | * |
| 209 | * @return |
| 210 | */ |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 211 | public void reportFailedPasswordAttempt() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 212 | getDevicePolicyManager().reportFailedPasswordAttempt(getCurrentOrCallingUserId()); |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | public void reportSuccessfulPasswordAttempt() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 216 | getDevicePolicyManager().reportSuccessfulPasswordAttempt(getCurrentOrCallingUserId()); |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 219 | public void setCurrentUser(int userId) { |
Jim Miller | ee82f8f | 2012-10-01 16:26:18 -0700 | [diff] [blame] | 220 | sCurrentUserId = userId; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Amith Yamasani | f882f1a | 2012-04-10 15:13:39 -0700 | [diff] [blame] | 223 | public int getCurrentUser() { |
Jim Miller | ee82f8f | 2012-10-01 16:26:18 -0700 | [diff] [blame] | 224 | if (sCurrentUserId != UserHandle.USER_NULL) { |
Jim Miller | 25645d8 | 2012-09-21 14:47:54 -0700 | [diff] [blame] | 225 | // Someone is regularly updating using setCurrentUser() use that value. |
Jim Miller | ee82f8f | 2012-10-01 16:26:18 -0700 | [diff] [blame] | 226 | return sCurrentUserId; |
Jim Miller | 25645d8 | 2012-09-21 14:47:54 -0700 | [diff] [blame] | 227 | } |
| 228 | try { |
| 229 | return ActivityManagerNative.getDefault().getCurrentUser().id; |
| 230 | } catch (RemoteException re) { |
| 231 | return UserHandle.USER_OWNER; |
Amith Yamasani | f882f1a | 2012-04-10 15:13:39 -0700 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 235 | public void removeUser(int userId) { |
Jim Miller | 25645d8 | 2012-09-21 14:47:54 -0700 | [diff] [blame] | 236 | try { |
| 237 | getLockSettings().removeUser(userId); |
| 238 | } catch (RemoteException re) { |
| 239 | Log.e(TAG, "Couldn't remove lock settings for user " + userId); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
| 243 | private int getCurrentOrCallingUserId() { |
| 244 | int callingUid = Binder.getCallingUid(); |
| 245 | if (callingUid == android.os.Process.SYSTEM_UID) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 246 | // TODO: This is a little inefficient. See if all users of this are able to |
| 247 | // handle USER_CURRENT and pass that instead. |
| 248 | return getCurrentUser(); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 249 | } else { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 250 | return UserHandle.getUserId(callingUid); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | /** |
| 255 | * Check to see if a pattern matches the saved pattern. If no pattern exists, |
| 256 | * always returns true. |
| 257 | * @param pattern The pattern to check. |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 258 | * @return Whether the pattern matches the stored one. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | */ |
| 260 | public boolean checkPattern(List<LockPatternView.Cell> pattern) { |
Kenny Root | df8bfe0 | 2012-09-21 15:00:25 -0700 | [diff] [blame] | 261 | final int userId = getCurrentOrCallingUserId(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | try { |
Kenny Root | df8bfe0 | 2012-09-21 15:00:25 -0700 | [diff] [blame] | 263 | final boolean matched = getLockSettings().checkPattern(patternToHash(pattern), userId); |
| 264 | if (matched && (userId == UserHandle.USER_OWNER)) { |
| 265 | KeyStore.getInstance().password(patternToString(pattern)); |
| 266 | } |
| 267 | return matched; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 268 | } catch (RemoteException re) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | return true; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | /** |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 274 | * Check to see if a password matches the saved password. If no password exists, |
| 275 | * always returns true. |
| 276 | * @param password The password to check. |
| 277 | * @return Whether the password matches the stored one. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | */ |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 279 | public boolean checkPassword(String password) { |
Kenny Root | df8bfe0 | 2012-09-21 15:00:25 -0700 | [diff] [blame] | 280 | final int userId = getCurrentOrCallingUserId(); |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 281 | try { |
Kenny Root | df8bfe0 | 2012-09-21 15:00:25 -0700 | [diff] [blame] | 282 | final boolean matched = getLockSettings().checkPassword(passwordToHash(password), |
| 283 | userId); |
| 284 | if (matched && (userId == UserHandle.USER_OWNER)) { |
| 285 | KeyStore.getInstance().password(password); |
| 286 | } |
| 287 | return matched; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 288 | } catch (RemoteException re) { |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 289 | return true; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /** |
Konstantin Lopyrev | 863f22d | 2010-05-12 17:16:58 -0700 | [diff] [blame] | 294 | * Check to see if a password matches any of the passwords stored in the |
| 295 | * password history. |
| 296 | * |
| 297 | * @param password The password to check. |
| 298 | * @return Whether the password matches any in the history. |
| 299 | */ |
| 300 | public boolean checkPasswordHistory(String password) { |
| 301 | String passwordHashString = new String(passwordToHash(password)); |
| 302 | String passwordHistory = getString(PASSWORD_HISTORY_KEY); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 303 | if (passwordHistory == null) { |
| 304 | return false; |
| 305 | } |
| 306 | // Password History may be too long... |
| 307 | int passwordHashLength = passwordHashString.length(); |
| 308 | int passwordHistoryLength = getRequestedPasswordHistoryLength(); |
| 309 | if(passwordHistoryLength == 0) { |
| 310 | return false; |
| 311 | } |
| 312 | int neededPasswordHistoryLength = passwordHashLength * passwordHistoryLength |
| 313 | + passwordHistoryLength - 1; |
| 314 | if (passwordHistory.length() > neededPasswordHistoryLength) { |
| 315 | passwordHistory = passwordHistory.substring(0, neededPasswordHistoryLength); |
| 316 | } |
| 317 | return passwordHistory.contains(passwordHashString); |
Konstantin Lopyrev | 863f22d | 2010-05-12 17:16:58 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /** |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 321 | * Check to see if the user has stored a lock pattern. |
| 322 | * @return Whether a saved pattern exists. |
| 323 | */ |
| 324 | public boolean savedPatternExists() { |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 325 | try { |
| 326 | return getLockSettings().havePattern(getCurrentOrCallingUserId()); |
| 327 | } catch (RemoteException re) { |
| 328 | return false; |
| 329 | } |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Check to see if the user has stored a lock pattern. |
| 334 | * @return Whether a saved pattern exists. |
| 335 | */ |
| 336 | public boolean savedPasswordExists() { |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 337 | try { |
| 338 | return getLockSettings().havePassword(getCurrentOrCallingUserId()); |
| 339 | } catch (RemoteException re) { |
| 340 | return false; |
| 341 | } |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /** |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 345 | * Return true if the user has ever chosen a pattern. This is true even if the pattern is |
| 346 | * currently cleared. |
| 347 | * |
| 348 | * @return True if the user has ever chosen a pattern. |
| 349 | */ |
| 350 | public boolean isPatternEverChosen() { |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 351 | return getBoolean(PATTERN_EVER_CHOSEN_KEY, false); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | /** |
Danielle Millett | 7a07219 | 2011-10-03 17:36:01 -0400 | [diff] [blame] | 355 | * Return true if the user has ever chosen biometric weak. This is true even if biometric |
| 356 | * weak is not current set. |
| 357 | * |
| 358 | * @return True if the user has ever chosen biometric weak. |
| 359 | */ |
| 360 | public boolean isBiometricWeakEverChosen() { |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 361 | return getBoolean(BIOMETRIC_WEAK_EVER_CHOSEN_KEY, false); |
Danielle Millett | 7a07219 | 2011-10-03 17:36:01 -0400 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | /** |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 365 | * Used by device policy manager to validate the current password |
| 366 | * information it has. |
| 367 | */ |
| 368 | public int getActivePasswordQuality() { |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 369 | int activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
Danielle Millett | c8fb532 | 2011-10-04 12:18:51 -0400 | [diff] [blame] | 370 | // Note we don't want to use getKeyguardStoredPasswordQuality() because we want this to |
| 371 | // return biometric_weak if that is being used instead of the backup |
| 372 | int quality = |
| 373 | (int) getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); |
| 374 | switch (quality) { |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 375 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 376 | if (isLockPatternEnabled()) { |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 377 | activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_SOMETHING; |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 378 | } |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 379 | break; |
Danielle Millett | c8fb532 | 2011-10-04 12:18:51 -0400 | [diff] [blame] | 380 | case DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK: |
| 381 | if (isBiometricWeakInstalled()) { |
| 382 | activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK; |
| 383 | } |
| 384 | break; |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 385 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 386 | if (isLockPasswordEnabled()) { |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 387 | activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC; |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 388 | } |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 389 | break; |
| 390 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 391 | if (isLockPasswordEnabled()) { |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 392 | activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC; |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 393 | } |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 394 | break; |
| 395 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: |
| 396 | if (isLockPasswordEnabled()) { |
| 397 | activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC; |
| 398 | } |
| 399 | break; |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 400 | case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: |
| 401 | if (isLockPasswordEnabled()) { |
| 402 | activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_COMPLEX; |
| 403 | } |
| 404 | break; |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 405 | } |
Danielle Millett | c8fb532 | 2011-10-04 12:18:51 -0400 | [diff] [blame] | 406 | |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 407 | return activePasswordQuality; |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 408 | } |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 409 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 410 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 411 | * Clear any lock pattern or password. |
| 412 | */ |
Steven Ross | 329979c | 2011-09-28 11:42:56 -0400 | [diff] [blame] | 413 | public void clearLock(boolean isFallback) { |
| 414 | if(!isFallback) deleteGallery(); |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 415 | saveLockPassword(null, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 416 | setLockPatternEnabled(false); |
| 417 | saveLockPattern(null); |
Jim Miller | 93708af1 | 2012-01-25 18:26:12 -0800 | [diff] [blame] | 418 | setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 419 | setLong(PASSWORD_TYPE_ALTERNATE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 420 | } |
Jim Miller | 5b0fb3a | 2010-02-23 13:46:35 -0800 | [diff] [blame] | 421 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 422 | /** |
Jim Miller | 2a98a4c | 2010-11-19 18:49:26 -0800 | [diff] [blame] | 423 | * Disable showing lock screen at all when the DevicePolicyManager allows it. |
| 424 | * This is only meaningful if pattern, pin or password are not set. |
| 425 | * |
| 426 | * @param disable Disables lock screen when true |
| 427 | */ |
| 428 | public void setLockScreenDisabled(boolean disable) { |
| 429 | setLong(DISABLE_LOCKSCREEN_KEY, disable ? 1 : 0); |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Determine if LockScreen can be disabled. This is used, for example, to tell if we should |
| 434 | * show LockScreen or go straight to the home screen. |
| 435 | * |
| 436 | * @return true if lock screen is can be disabled |
| 437 | */ |
| 438 | public boolean isLockScreenDisabled() { |
| 439 | return !isSecure() && getLong(DISABLE_LOCKSCREEN_KEY, 0) != 0; |
| 440 | } |
| 441 | |
| 442 | /** |
Steven Ross | 3553c29 | 2011-09-30 15:48:40 -0400 | [diff] [blame] | 443 | * Calls back SetupFaceLock to delete the temporary gallery file |
Steven Ross | 329979c | 2011-09-28 11:42:56 -0400 | [diff] [blame] | 444 | */ |
| 445 | public void deleteTempGallery() { |
Danielle Millett | 574e49e | 2012-03-27 16:17:10 -0400 | [diff] [blame] | 446 | Intent intent = new Intent().setAction("com.android.facelock.DELETE_GALLERY"); |
Steven Ross | 3553c29 | 2011-09-30 15:48:40 -0400 | [diff] [blame] | 447 | intent.putExtra("deleteTempGallery", true); |
Danielle Millett | 574e49e | 2012-03-27 16:17:10 -0400 | [diff] [blame] | 448 | mContext.sendBroadcast(intent); |
Steven Ross | 329979c | 2011-09-28 11:42:56 -0400 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | /** |
| 452 | * Calls back SetupFaceLock to delete the gallery file when the lock type is changed |
| 453 | */ |
| 454 | void deleteGallery() { |
Danielle Millett | 5839698 | 2011-09-30 13:55:07 -0400 | [diff] [blame] | 455 | if(usingBiometricWeak()) { |
Danielle Millett | 574e49e | 2012-03-27 16:17:10 -0400 | [diff] [blame] | 456 | Intent intent = new Intent().setAction("com.android.facelock.DELETE_GALLERY"); |
Steven Ross | 329979c | 2011-09-28 11:42:56 -0400 | [diff] [blame] | 457 | intent.putExtra("deleteGallery", true); |
Danielle Millett | 574e49e | 2012-03-27 16:17:10 -0400 | [diff] [blame] | 458 | mContext.sendBroadcast(intent); |
Steven Ross | 329979c | 2011-09-28 11:42:56 -0400 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
| 462 | /** |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 463 | * Save a lock pattern. |
| 464 | * @param pattern The new pattern to save. |
Danielle Millett | 2364a22 | 2011-12-21 17:02:32 -0500 | [diff] [blame] | 465 | */ |
| 466 | public void saveLockPattern(List<LockPatternView.Cell> pattern) { |
| 467 | this.saveLockPattern(pattern, false); |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Save a lock pattern. |
| 472 | * @param pattern The new pattern to save. |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 473 | * @param isFallback Specifies if this is a fallback to biometric weak |
| 474 | */ |
| 475 | public void saveLockPattern(List<LockPatternView.Cell> pattern, boolean isFallback) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | // Compute the hash |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 477 | final byte[] hash = LockPatternUtils.patternToHash(pattern); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | try { |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 479 | getLockSettings().setLockPattern(hash, getCurrentOrCallingUserId()); |
Dianne Hackborn | 2509d3c | 2010-03-08 12:54:25 -0800 | [diff] [blame] | 480 | DevicePolicyManager dpm = getDevicePolicyManager(); |
Brian Carlstrom | e2afc24 | 2011-06-02 16:21:55 -0700 | [diff] [blame] | 481 | KeyStore keyStore = KeyStore.getInstance(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 482 | if (pattern != null) { |
Brian Carlstrom | e2afc24 | 2011-06-02 16:21:55 -0700 | [diff] [blame] | 483 | keyStore.password(patternToString(pattern)); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 484 | setBoolean(PATTERN_EVER_CHOSEN_KEY, true); |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 485 | if (!isFallback) { |
Steven Ross | 329979c | 2011-09-28 11:42:56 -0400 | [diff] [blame] | 486 | deleteGallery(); |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 487 | setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); |
Danielle Millett | 2364a22 | 2011-12-21 17:02:32 -0500 | [diff] [blame] | 488 | dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 489 | pattern.size(), 0, 0, 0, 0, 0, 0, getCurrentOrCallingUserId()); |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 490 | } else { |
| 491 | setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK); |
| 492 | setLong(PASSWORD_TYPE_ALTERNATE_KEY, |
| 493 | DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); |
Danielle Millett | 044a0a7 | 2011-11-07 15:42:12 -0500 | [diff] [blame] | 494 | finishBiometricWeak(); |
Danielle Millett | 2364a22 | 2011-12-21 17:02:32 -0500 | [diff] [blame] | 495 | dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 496 | 0, 0, 0, 0, 0, 0, 0, getCurrentOrCallingUserId()); |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 497 | } |
Dianne Hackborn | 2509d3c | 2010-03-08 12:54:25 -0800 | [diff] [blame] | 498 | } else { |
Brian Carlstrom | e2afc24 | 2011-06-02 16:21:55 -0700 | [diff] [blame] | 499 | if (keyStore.isEmpty()) { |
| 500 | keyStore.reset(); |
| 501 | } |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 502 | dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 503 | 0, 0, 0, 0, 0, getCurrentOrCallingUserId()); |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 504 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 505 | } catch (RemoteException re) { |
| 506 | Log.e(TAG, "Couldn't save lock pattern " + re); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | |
| 510 | /** |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 511 | * Compute the password quality from the given password string. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 512 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 513 | static public int computePasswordQuality(String password) { |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 514 | boolean hasDigit = false; |
| 515 | boolean hasNonDigit = false; |
| 516 | final int len = password.length(); |
| 517 | for (int i = 0; i < len; i++) { |
| 518 | if (Character.isDigit(password.charAt(i))) { |
| 519 | hasDigit = true; |
| 520 | } else { |
| 521 | hasNonDigit = true; |
| 522 | } |
| 523 | } |
Jim Miller | 5b0fb3a | 2010-02-23 13:46:35 -0800 | [diff] [blame] | 524 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 525 | if (hasNonDigit && hasDigit) { |
| 526 | return DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC; |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 527 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 528 | if (hasNonDigit) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 529 | return DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC; |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 530 | } |
| 531 | if (hasDigit) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 532 | return DevicePolicyManager.PASSWORD_QUALITY_NUMERIC; |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 533 | } |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 534 | return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 535 | } |
Jim Miller | 5b0fb3a | 2010-02-23 13:46:35 -0800 | [diff] [blame] | 536 | |
Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 537 | /** Update the encryption password if it is enabled **/ |
| 538 | private void updateEncryptionPassword(String password) { |
| 539 | DevicePolicyManager dpm = getDevicePolicyManager(); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 540 | if (dpm.getStorageEncryptionStatus(getCurrentOrCallingUserId()) |
| 541 | != DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE) { |
Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 542 | return; |
| 543 | } |
| 544 | |
| 545 | IBinder service = ServiceManager.getService("mount"); |
| 546 | if (service == null) { |
| 547 | Log.e(TAG, "Could not find the mount service to update the encryption password"); |
| 548 | return; |
| 549 | } |
| 550 | |
| 551 | IMountService mountService = IMountService.Stub.asInterface(service); |
| 552 | try { |
| 553 | mountService.changeEncryptionPassword(password); |
| 554 | } catch (RemoteException e) { |
| 555 | Log.e(TAG, "Error changing encryption password", e); |
| 556 | } |
| 557 | } |
| 558 | |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 559 | /** |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 560 | * Save a lock password. Does not ensure that the password is as good |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 561 | * as the requested mode, but will adjust the mode to be as good as the |
| 562 | * pattern. |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 563 | * @param password The password to save |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 564 | * @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 565 | */ |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 566 | public void saveLockPassword(String password, int quality) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 567 | this.saveLockPassword(password, quality, false, getCurrentOrCallingUserId()); |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Save a lock password. Does not ensure that the password is as good |
| 572 | * as the requested mode, but will adjust the mode to be as good as the |
| 573 | * pattern. |
| 574 | * @param password The password to save |
| 575 | * @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} |
| 576 | * @param isFallback Specifies if this is a fallback to biometric weak |
| 577 | */ |
| 578 | public void saveLockPassword(String password, int quality, boolean isFallback) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 579 | saveLockPassword(password, quality, isFallback, getCurrentOrCallingUserId()); |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * Save a lock password. Does not ensure that the password is as good |
| 584 | * as the requested mode, but will adjust the mode to be as good as the |
| 585 | * pattern. |
| 586 | * @param password The password to save |
| 587 | * @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} |
| 588 | * @param isFallback Specifies if this is a fallback to biometric weak |
| 589 | * @param userHandle The userId of the user to change the password for |
| 590 | */ |
| 591 | public void saveLockPassword(String password, int quality, boolean isFallback, int userHandle) { |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 592 | // Compute the hash |
Jim Miller | 11b019d | 2010-01-20 16:34:45 -0800 | [diff] [blame] | 593 | final byte[] hash = passwordToHash(password); |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 594 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 595 | getLockSettings().setLockPassword(hash, userHandle); |
Dianne Hackborn | 2509d3c | 2010-03-08 12:54:25 -0800 | [diff] [blame] | 596 | DevicePolicyManager dpm = getDevicePolicyManager(); |
Brian Carlstrom | e2afc24 | 2011-06-02 16:21:55 -0700 | [diff] [blame] | 597 | KeyStore keyStore = KeyStore.getInstance(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 598 | if (password != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 599 | if (userHandle == UserHandle.USER_OWNER) { |
| 600 | // Update the encryption password. |
| 601 | updateEncryptionPassword(password); |
Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 602 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 603 | // Update the keystore password |
| 604 | keyStore.password(password); |
| 605 | } |
Brian Carlstrom | 5cfee3f | 2011-05-31 01:00:15 -0700 | [diff] [blame] | 606 | |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 607 | int computedQuality = computePasswordQuality(password); |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 608 | if (!isFallback) { |
Steven Ross | 329979c | 2011-09-28 11:42:56 -0400 | [diff] [blame] | 609 | deleteGallery(); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 610 | setLong(PASSWORD_TYPE_KEY, Math.max(quality, computedQuality), userHandle); |
Danielle Millett | 2364a22 | 2011-12-21 17:02:32 -0500 | [diff] [blame] | 611 | if (computedQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| 612 | int letters = 0; |
| 613 | int uppercase = 0; |
| 614 | int lowercase = 0; |
| 615 | int numbers = 0; |
| 616 | int symbols = 0; |
| 617 | int nonletter = 0; |
| 618 | for (int i = 0; i < password.length(); i++) { |
| 619 | char c = password.charAt(i); |
| 620 | if (c >= 'A' && c <= 'Z') { |
| 621 | letters++; |
| 622 | uppercase++; |
| 623 | } else if (c >= 'a' && c <= 'z') { |
| 624 | letters++; |
| 625 | lowercase++; |
| 626 | } else if (c >= '0' && c <= '9') { |
| 627 | numbers++; |
| 628 | nonletter++; |
| 629 | } else { |
| 630 | symbols++; |
| 631 | nonletter++; |
| 632 | } |
| 633 | } |
| 634 | dpm.setActivePasswordState(Math.max(quality, computedQuality), |
| 635 | password.length(), letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 636 | numbers, symbols, nonletter, userHandle); |
Danielle Millett | 2364a22 | 2011-12-21 17:02:32 -0500 | [diff] [blame] | 637 | } else { |
| 638 | // The password is not anything. |
| 639 | dpm.setActivePasswordState( |
| 640 | DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 641 | 0, 0, 0, 0, 0, 0, 0, userHandle); |
Danielle Millett | 2364a22 | 2011-12-21 17:02:32 -0500 | [diff] [blame] | 642 | } |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 643 | } else { |
Danielle Millett | 2364a22 | 2011-12-21 17:02:32 -0500 | [diff] [blame] | 644 | // Case where it's a fallback for biometric weak |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 645 | setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK, |
| 646 | userHandle); |
| 647 | setLong(PASSWORD_TYPE_ALTERNATE_KEY, Math.max(quality, computedQuality), |
| 648 | userHandle); |
Danielle Millett | 044a0a7 | 2011-11-07 15:42:12 -0500 | [diff] [blame] | 649 | finishBiometricWeak(); |
Danielle Millett | 2364a22 | 2011-12-21 17:02:32 -0500 | [diff] [blame] | 650 | dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 651 | 0, 0, 0, 0, 0, 0, 0, userHandle); |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 652 | } |
Konstantin Lopyrev | 863f22d | 2010-05-12 17:16:58 -0700 | [diff] [blame] | 653 | // Add the password to the password history. We assume all |
| 654 | // password |
| 655 | // hashes have the same length for simplicity of implementation. |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 656 | String passwordHistory = getString(PASSWORD_HISTORY_KEY, userHandle); |
Konstantin Lopyrev | 863f22d | 2010-05-12 17:16:58 -0700 | [diff] [blame] | 657 | if (passwordHistory == null) { |
| 658 | passwordHistory = new String(); |
| 659 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 660 | int passwordHistoryLength = getRequestedPasswordHistoryLength(); |
| 661 | if (passwordHistoryLength == 0) { |
| 662 | passwordHistory = ""; |
| 663 | } else { |
| 664 | passwordHistory = new String(hash) + "," + passwordHistory; |
| 665 | // Cut it to contain passwordHistoryLength hashes |
| 666 | // and passwordHistoryLength -1 commas. |
| 667 | passwordHistory = passwordHistory.substring(0, Math.min(hash.length |
| 668 | * passwordHistoryLength + passwordHistoryLength - 1, passwordHistory |
| 669 | .length())); |
| 670 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 671 | setString(PASSWORD_HISTORY_KEY, passwordHistory, userHandle); |
Dianne Hackborn | 2509d3c | 2010-03-08 12:54:25 -0800 | [diff] [blame] | 672 | } else { |
Brian Carlstrom | e2afc24 | 2011-06-02 16:21:55 -0700 | [diff] [blame] | 673 | // Conditionally reset the keystore if empty. If |
| 674 | // non-empty, we are just switching key guard type |
| 675 | if (keyStore.isEmpty()) { |
| 676 | keyStore.reset(); |
| 677 | } |
Dianne Hackborn | 2509d3c | 2010-03-08 12:54:25 -0800 | [diff] [blame] | 678 | dpm.setActivePasswordState( |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 679 | DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0, 0, 0, 0, 0, 0, |
| 680 | userHandle); |
Jim Miller | 31f90b6 | 2010-01-20 13:35:20 -0800 | [diff] [blame] | 681 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 682 | } catch (RemoteException re) { |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 683 | // Cant do much |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 684 | Log.e(TAG, "Unable to save lock password " + re); |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 688 | /** |
| 689 | * Retrieves the quality mode we're in. |
| 690 | * {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} |
| 691 | * |
| 692 | * @return stored password quality |
| 693 | */ |
| 694 | public int getKeyguardStoredPasswordQuality() { |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 695 | int quality = |
| 696 | (int) getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); |
| 697 | // If the user has chosen to use weak biometric sensor, then return the backup locking |
| 698 | // method and treat biometric as a special case. |
| 699 | if (quality == DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK) { |
| 700 | quality = |
| 701 | (int) getLong(PASSWORD_TYPE_ALTERNATE_KEY, |
| 702 | DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); |
| 703 | } |
| 704 | return quality; |
| 705 | } |
| 706 | |
Danielle Millett | 5839698 | 2011-09-30 13:55:07 -0400 | [diff] [blame] | 707 | /** |
| 708 | * @return true if the lockscreen method is set to biometric weak |
| 709 | */ |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 710 | public boolean usingBiometricWeak() { |
| 711 | int quality = |
| 712 | (int) getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); |
| 713 | return quality == DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK; |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 717 | * Deserialize a pattern. |
| 718 | * @param string The pattern serialized with {@link #patternToString} |
| 719 | * @return The pattern. |
| 720 | */ |
| 721 | public static List<LockPatternView.Cell> stringToPattern(String string) { |
| 722 | List<LockPatternView.Cell> result = Lists.newArrayList(); |
| 723 | |
| 724 | final byte[] bytes = string.getBytes(); |
| 725 | for (int i = 0; i < bytes.length; i++) { |
| 726 | byte b = bytes[i]; |
| 727 | result.add(LockPatternView.Cell.of(b / 3, b % 3)); |
| 728 | } |
| 729 | return result; |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * Serialize a pattern. |
| 734 | * @param pattern The pattern. |
| 735 | * @return The pattern in string form. |
| 736 | */ |
| 737 | public static String patternToString(List<LockPatternView.Cell> pattern) { |
| 738 | if (pattern == null) { |
| 739 | return ""; |
| 740 | } |
| 741 | final int patternSize = pattern.size(); |
| 742 | |
| 743 | byte[] res = new byte[patternSize]; |
| 744 | for (int i = 0; i < patternSize; i++) { |
| 745 | LockPatternView.Cell cell = pattern.get(i); |
| 746 | res[i] = (byte) (cell.getRow() * 3 + cell.getColumn()); |
| 747 | } |
| 748 | return new String(res); |
| 749 | } |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 751 | /* |
| 752 | * Generate an SHA-1 hash for the pattern. Not the most secure, but it is |
| 753 | * at least a second level of protection. First level is that the file |
| 754 | * is in a location only readable by the system process. |
| 755 | * @param pattern the gesture pattern. |
| 756 | * @return the hash of the pattern in a byte array. |
| 757 | */ |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 758 | private static byte[] patternToHash(List<LockPatternView.Cell> pattern) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | if (pattern == null) { |
| 760 | return null; |
| 761 | } |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 763 | final int patternSize = pattern.size(); |
| 764 | byte[] res = new byte[patternSize]; |
| 765 | for (int i = 0; i < patternSize; i++) { |
| 766 | LockPatternView.Cell cell = pattern.get(i); |
| 767 | res[i] = (byte) (cell.getRow() * 3 + cell.getColumn()); |
| 768 | } |
| 769 | try { |
| 770 | MessageDigest md = MessageDigest.getInstance("SHA-1"); |
| 771 | byte[] hash = md.digest(res); |
| 772 | return hash; |
| 773 | } catch (NoSuchAlgorithmException nsa) { |
| 774 | return res; |
| 775 | } |
| 776 | } |
| 777 | |
Jim Miller | 11b019d | 2010-01-20 16:34:45 -0800 | [diff] [blame] | 778 | private String getSalt() { |
| 779 | long salt = getLong(LOCK_PASSWORD_SALT_KEY, 0); |
| 780 | if (salt == 0) { |
| 781 | try { |
| 782 | salt = SecureRandom.getInstance("SHA1PRNG").nextLong(); |
| 783 | setLong(LOCK_PASSWORD_SALT_KEY, salt); |
| 784 | Log.v(TAG, "Initialized lock password salt"); |
| 785 | } catch (NoSuchAlgorithmException e) { |
| 786 | // Throw an exception rather than storing a password we'll never be able to recover |
| 787 | throw new IllegalStateException("Couldn't get SecureRandom number", e); |
| 788 | } |
| 789 | } |
| 790 | return Long.toHexString(salt); |
| 791 | } |
| 792 | |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 793 | /* |
| 794 | * Generate a hash for the given password. To avoid brute force attacks, we use a salted hash. |
| 795 | * Not the most secure, but it is at least a second level of protection. First level is that |
| 796 | * the file is in a location only readable by the system process. |
| 797 | * @param password the gesture pattern. |
| 798 | * @return the hash of the pattern in a byte array. |
| 799 | */ |
Brian Carlstrom | 5cfee3f | 2011-05-31 01:00:15 -0700 | [diff] [blame] | 800 | public byte[] passwordToHash(String password) { |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 801 | if (password == null) { |
| 802 | return null; |
| 803 | } |
| 804 | String algo = null; |
| 805 | byte[] hashed = null; |
| 806 | try { |
Jim Miller | 11b019d | 2010-01-20 16:34:45 -0800 | [diff] [blame] | 807 | byte[] saltedPassword = (password + getSalt()).getBytes(); |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 808 | byte[] sha1 = MessageDigest.getInstance(algo = "SHA-1").digest(saltedPassword); |
| 809 | byte[] md5 = MessageDigest.getInstance(algo = "MD5").digest(saltedPassword); |
| 810 | hashed = (toHex(sha1) + toHex(md5)).getBytes(); |
| 811 | } catch (NoSuchAlgorithmException e) { |
| 812 | Log.w(TAG, "Failed to encode string because of missing algorithm: " + algo); |
| 813 | } |
| 814 | return hashed; |
| 815 | } |
| 816 | |
| 817 | private static String toHex(byte[] ary) { |
| 818 | final String hex = "0123456789ABCDEF"; |
| 819 | String ret = ""; |
| 820 | for (int i = 0; i < ary.length; i++) { |
| 821 | ret += hex.charAt((ary[i] >> 4) & 0xf); |
| 822 | ret += hex.charAt(ary[i] & 0xf); |
| 823 | } |
| 824 | return ret; |
| 825 | } |
| 826 | |
| 827 | /** |
Danielle Millett | 73da5fe | 2011-09-13 16:20:05 -0400 | [diff] [blame] | 828 | * @return Whether the lock password is enabled, or if it is set as a backup for biometric weak |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 829 | */ |
| 830 | public boolean isLockPasswordEnabled() { |
| 831 | long mode = getLong(PASSWORD_TYPE_KEY, 0); |
Danielle Millett | 73da5fe | 2011-09-13 16:20:05 -0400 | [diff] [blame] | 832 | long backupMode = getLong(PASSWORD_TYPE_ALTERNATE_KEY, 0); |
| 833 | final boolean passwordEnabled = mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC |
| 834 | || mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC |
| 835 | || mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC |
| 836 | || mode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX; |
| 837 | final boolean backupEnabled = backupMode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC |
| 838 | || backupMode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC |
| 839 | || backupMode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC |
| 840 | || backupMode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX; |
| 841 | |
| 842 | return savedPasswordExists() && (passwordEnabled || |
Danielle Millett | 5839698 | 2011-09-30 13:55:07 -0400 | [diff] [blame] | 843 | (usingBiometricWeak() && backupEnabled)); |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 844 | } |
| 845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 846 | /** |
Danielle Millett | 73da5fe | 2011-09-13 16:20:05 -0400 | [diff] [blame] | 847 | * @return Whether the lock pattern is enabled, or if it is set as a backup for biometric weak |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | */ |
| 849 | public boolean isLockPatternEnabled() { |
Danielle Millett | 73da5fe | 2011-09-13 16:20:05 -0400 | [diff] [blame] | 850 | final boolean backupEnabled = |
| 851 | getLong(PASSWORD_TYPE_ALTERNATE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) |
| 852 | == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING; |
| 853 | |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 854 | return getBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, false) |
Danielle Millett | 73da5fe | 2011-09-13 16:20:05 -0400 | [diff] [blame] | 855 | && (getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) |
| 856 | == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING || |
Danielle Millett | 5839698 | 2011-09-30 13:55:07 -0400 | [diff] [blame] | 857 | (usingBiometricWeak() && backupEnabled)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /** |
Danielle Millett | 5839698 | 2011-09-30 13:55:07 -0400 | [diff] [blame] | 861 | * @return Whether biometric weak lock is installed and that the front facing camera exists |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 862 | */ |
Danielle Millett | 5839698 | 2011-09-30 13:55:07 -0400 | [diff] [blame] | 863 | public boolean isBiometricWeakInstalled() { |
Danielle Millett | 5839698 | 2011-09-30 13:55:07 -0400 | [diff] [blame] | 864 | // Check that it's installed |
| 865 | PackageManager pm = mContext.getPackageManager(); |
| 866 | try { |
| 867 | pm.getPackageInfo("com.android.facelock", PackageManager.GET_ACTIVITIES); |
| 868 | } catch (PackageManager.NameNotFoundException e) { |
| 869 | return false; |
| 870 | } |
| 871 | |
| 872 | // Check that the camera is enabled |
| 873 | if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) { |
| 874 | return false; |
| 875 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 876 | if (getDevicePolicyManager().getCameraDisabled(null, getCurrentOrCallingUserId())) { |
Danielle Millett | 5839698 | 2011-09-30 13:55:07 -0400 | [diff] [blame] | 877 | return false; |
| 878 | } |
| 879 | |
| 880 | |
| 881 | return true; |
Jim Miller | 6edf263 | 2011-09-05 16:03:14 -0700 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | /** |
Danielle Millett | 925a7d8 | 2012-03-19 18:02:20 -0400 | [diff] [blame] | 885 | * Set whether biometric weak liveliness is enabled. |
| 886 | */ |
| 887 | public void setBiometricWeakLivelinessEnabled(boolean enabled) { |
| 888 | long currentFlag = getLong(Settings.Secure.LOCK_BIOMETRIC_WEAK_FLAGS, 0L); |
| 889 | long newFlag; |
| 890 | if (enabled) { |
| 891 | newFlag = currentFlag | FLAG_BIOMETRIC_WEAK_LIVELINESS; |
| 892 | } else { |
| 893 | newFlag = currentFlag & ~FLAG_BIOMETRIC_WEAK_LIVELINESS; |
| 894 | } |
| 895 | setLong(Settings.Secure.LOCK_BIOMETRIC_WEAK_FLAGS, newFlag); |
| 896 | } |
| 897 | |
| 898 | /** |
| 899 | * @return Whether the biometric weak liveliness is enabled. |
| 900 | */ |
| 901 | public boolean isBiometricWeakLivelinessEnabled() { |
| 902 | long currentFlag = getLong(Settings.Secure.LOCK_BIOMETRIC_WEAK_FLAGS, 0L); |
| 903 | return ((currentFlag & FLAG_BIOMETRIC_WEAK_LIVELINESS) != 0); |
| 904 | } |
| 905 | |
| 906 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | * Set whether the lock pattern is enabled. |
| 908 | */ |
| 909 | public void setLockPatternEnabled(boolean enabled) { |
Amith Yamasani | 156c435 | 2010-03-05 17:10:03 -0800 | [diff] [blame] | 910 | setBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | /** |
| 914 | * @return Whether the visible pattern is enabled. |
| 915 | */ |
| 916 | public boolean isVisiblePatternEnabled() { |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 917 | return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | /** |
| 921 | * Set whether the visible pattern is enabled. |
| 922 | */ |
| 923 | public void setVisiblePatternEnabled(boolean enabled) { |
Amith Yamasani | 156c435 | 2010-03-05 17:10:03 -0800 | [diff] [blame] | 924 | setBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | /** |
| 928 | * @return Whether tactile feedback for the pattern is enabled. |
| 929 | */ |
| 930 | public boolean isTactileFeedbackEnabled() { |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 931 | return getBoolean(Settings.Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | /** |
| 935 | * Set whether tactile feedback for the pattern is enabled. |
| 936 | */ |
| 937 | public void setTactileFeedbackEnabled(boolean enabled) { |
Amith Yamasani | 156c435 | 2010-03-05 17:10:03 -0800 | [diff] [blame] | 938 | setBoolean(Settings.Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED, enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | /** |
| 942 | * Set and store the lockout deadline, meaning the user can't attempt his/her unlock |
| 943 | * pattern until the deadline has passed. |
| 944 | * @return the chosen deadline. |
| 945 | */ |
| 946 | public long setLockoutAttemptDeadline() { |
| 947 | final long deadline = SystemClock.elapsedRealtime() + FAILED_ATTEMPT_TIMEOUT_MS; |
| 948 | setLong(LOCKOUT_ATTEMPT_DEADLINE, deadline); |
| 949 | return deadline; |
| 950 | } |
| 951 | |
| 952 | /** |
| 953 | * @return The elapsed time in millis in the future when the user is allowed to |
| 954 | * attempt to enter his/her lock pattern, or 0 if the user is welcome to |
| 955 | * enter a pattern. |
| 956 | */ |
| 957 | public long getLockoutAttemptDeadline() { |
| 958 | final long deadline = getLong(LOCKOUT_ATTEMPT_DEADLINE, 0L); |
| 959 | final long now = SystemClock.elapsedRealtime(); |
| 960 | if (deadline < now || deadline > (now + FAILED_ATTEMPT_TIMEOUT_MS)) { |
| 961 | return 0L; |
| 962 | } |
| 963 | return deadline; |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * @return Whether the user is permanently locked out until they verify their |
| 968 | * credentials. Occurs after {@link #FAILED_ATTEMPTS_BEFORE_RESET} failed |
| 969 | * attempts. |
| 970 | */ |
| 971 | public boolean isPermanentlyLocked() { |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 972 | return getBoolean(LOCKOUT_PERMANENT_KEY, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | /** |
| 976 | * Set the state of whether the device is permanently locked, meaning the user |
Karl Rosaen | 678771b | 2009-08-21 14:00:26 -0700 | [diff] [blame] | 977 | * must authenticate via other means. |
| 978 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 979 | * @param locked Whether the user is permanently locked out until they verify their |
| 980 | * credentials. Occurs after {@link #FAILED_ATTEMPTS_BEFORE_RESET} failed |
| 981 | * attempts. |
| 982 | */ |
| 983 | public void setPermanentlyLocked(boolean locked) { |
| 984 | setBoolean(LOCKOUT_PERMANENT_KEY, locked); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 985 | } |
| 986 | |
John Wang | 0f7b3f8 | 2011-05-31 11:20:55 -0700 | [diff] [blame] | 987 | public boolean isEmergencyCallCapable() { |
| 988 | return mContext.getResources().getBoolean( |
| 989 | com.android.internal.R.bool.config_voice_capable); |
| 990 | } |
| 991 | |
| 992 | public boolean isPukUnlockScreenEnable() { |
| 993 | return mContext.getResources().getBoolean( |
| 994 | com.android.internal.R.bool.config_enable_puk_unlock_screen); |
| 995 | } |
| 996 | |
Jim Miller | 1f56edc | 2011-11-07 19:00:48 -0800 | [diff] [blame] | 997 | public boolean isEmergencyCallEnabledWhileSimLocked() { |
| 998 | return mContext.getResources().getBoolean( |
| 999 | com.android.internal.R.bool.config_enable_emergency_call_while_sim_locked); |
| 1000 | } |
| 1001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | /** |
| 1003 | * @return A formatted string of the next alarm (for showing on the lock screen), |
| 1004 | * or null if there is no next alarm. |
| 1005 | */ |
| 1006 | public String getNextAlarm() { |
Amith Yamasani | 8fd96ec | 2012-09-21 17:48:49 -0700 | [diff] [blame] | 1007 | String nextAlarm = Settings.System.getStringForUser(mContentResolver, |
| 1008 | Settings.System.NEXT_ALARM_FORMATTED, UserHandle.USER_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | if (nextAlarm == null || TextUtils.isEmpty(nextAlarm)) { |
| 1010 | return null; |
| 1011 | } |
| 1012 | return nextAlarm; |
| 1013 | } |
| 1014 | |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 1015 | private boolean getBoolean(String secureSettingKey, boolean defaultValue) { |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1016 | try { |
| 1017 | return getLockSettings().getBoolean(secureSettingKey, defaultValue, |
| 1018 | getCurrentOrCallingUserId()); |
| 1019 | } catch (RemoteException re) { |
| 1020 | return defaultValue; |
| 1021 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
Amith Yamasani | 156c435 | 2010-03-05 17:10:03 -0800 | [diff] [blame] | 1024 | private void setBoolean(String secureSettingKey, boolean enabled) { |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1025 | try { |
| 1026 | getLockSettings().setBoolean(secureSettingKey, enabled, getCurrentOrCallingUserId()); |
| 1027 | } catch (RemoteException re) { |
| 1028 | // What can we do? |
| 1029 | Log.e(TAG, "Couldn't write boolean " + secureSettingKey + re); |
| 1030 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | } |
| 1032 | |
Jim Miller | f229e4d | 2012-09-12 20:32:50 -0700 | [diff] [blame] | 1033 | public int[] getUserDefinedWidgets() { |
| 1034 | int appWidgetId = -1; |
Amith Yamasani | 8fd96ec | 2012-09-21 17:48:49 -0700 | [diff] [blame] | 1035 | String appWidgetIdString = Settings.Secure.getStringForUser( |
| 1036 | mContentResolver, Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID, |
| 1037 | UserHandle.USER_CURRENT); |
Jim Miller | f229e4d | 2012-09-12 20:32:50 -0700 | [diff] [blame] | 1038 | if (appWidgetIdString != null) { |
| 1039 | appWidgetId = (int) Integer.decode(appWidgetIdString); |
| 1040 | } |
| 1041 | |
| 1042 | return new int[] { appWidgetId }; |
| 1043 | } |
| 1044 | |
Michael Jurka | 20c41d5 | 2012-09-20 19:01:06 -0700 | [diff] [blame] | 1045 | public int getStatusWidget() { |
| 1046 | int appWidgetId = -1; |
Amith Yamasani | 8fd96ec | 2012-09-21 17:48:49 -0700 | [diff] [blame] | 1047 | String appWidgetIdString = Settings.Secure.getStringForUser( |
| 1048 | mContentResolver, Settings.Secure.LOCK_SCREEN_STATUS_APPWIDGET_ID, |
| 1049 | UserHandle.USER_CURRENT); |
Michael Jurka | 20c41d5 | 2012-09-20 19:01:06 -0700 | [diff] [blame] | 1050 | if (appWidgetIdString != null) { |
| 1051 | appWidgetId = (int) Integer.decode(appWidgetIdString); |
| 1052 | } |
| 1053 | |
| 1054 | return appWidgetId; |
| 1055 | } |
| 1056 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1057 | private long getLong(String secureSettingKey, long defaultValue) { |
| 1058 | try { |
| 1059 | return getLockSettings().getLong(secureSettingKey, defaultValue, |
| 1060 | getCurrentOrCallingUserId()); |
| 1061 | } catch (RemoteException re) { |
| 1062 | return defaultValue; |
| 1063 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1064 | } |
| 1065 | |
Amith Yamasani | 156c435 | 2010-03-05 17:10:03 -0800 | [diff] [blame] | 1066 | private void setLong(String secureSettingKey, long value) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1067 | setLong(secureSettingKey, value, getCurrentOrCallingUserId()); |
| 1068 | } |
| 1069 | |
| 1070 | private void setLong(String secureSettingKey, long value, int userHandle) { |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1071 | try { |
| 1072 | getLockSettings().setLong(secureSettingKey, value, getCurrentOrCallingUserId()); |
| 1073 | } catch (RemoteException re) { |
| 1074 | // What can we do? |
| 1075 | Log.e(TAG, "Couldn't write long " + secureSettingKey + re); |
| 1076 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1077 | } |
| 1078 | |
Konstantin Lopyrev | 863f22d | 2010-05-12 17:16:58 -0700 | [diff] [blame] | 1079 | private String getString(String secureSettingKey) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1080 | return getString(secureSettingKey, getCurrentOrCallingUserId()); |
| 1081 | } |
| 1082 | |
| 1083 | private String getString(String secureSettingKey, int userHandle) { |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1084 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1085 | return getLockSettings().getString(secureSettingKey, null, userHandle); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1086 | } catch (RemoteException re) { |
| 1087 | return null; |
| 1088 | } |
Konstantin Lopyrev | 863f22d | 2010-05-12 17:16:58 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1091 | private void setString(String secureSettingKey, String value, int userHandle) { |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1092 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1093 | getLockSettings().setString(secureSettingKey, value, userHandle); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1094 | } catch (RemoteException re) { |
| 1095 | // What can we do? |
| 1096 | Log.e(TAG, "Couldn't write string " + secureSettingKey + re); |
| 1097 | } |
Konstantin Lopyrev | 863f22d | 2010-05-12 17:16:58 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 1100 | public boolean isSecure() { |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 1101 | long mode = getKeyguardStoredPasswordQuality(); |
| 1102 | final boolean isPattern = mode == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING; |
| 1103 | final boolean isPassword = mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC |
| 1104 | || mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1105 | || mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC |
| 1106 | || mode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX; |
Jim Miller | cd70988 | 2010-03-25 18:24:02 -0700 | [diff] [blame] | 1107 | final boolean secure = isPattern && isLockPatternEnabled() && savedPatternExists() |
Danielle Millett | 73da5fe | 2011-09-13 16:20:05 -0400 | [diff] [blame] | 1108 | || isPassword && savedPasswordExists(); |
Jim Miller | 69aa4a9 | 2009-12-22 19:03:28 -0800 | [diff] [blame] | 1109 | return secure; |
| 1110 | } |
Jim Miller | 69ac988 | 2010-02-24 15:35:05 -0800 | [diff] [blame] | 1111 | |
| 1112 | /** |
John Wang | 0f7b3f8 | 2011-05-31 11:20:55 -0700 | [diff] [blame] | 1113 | * Sets the emergency button visibility based on isEmergencyCallCapable(). |
| 1114 | * |
| 1115 | * If the emergency button is visible, sets the text on the emergency button |
| 1116 | * to indicate what action will be taken. |
| 1117 | * |
Jim Miller | 69ac988 | 2010-02-24 15:35:05 -0800 | [diff] [blame] | 1118 | * If there's currently a call in progress, the button will take them to the call |
| 1119 | * @param button the button to update |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 1120 | * @param the phone state: |
| 1121 | * {@link TelephonyManager#CALL_STATE_IDLE} |
| 1122 | * {@link TelephonyManager#CALL_STATE_RINGING} |
| 1123 | * {@link TelephonyManager#CALL_STATE_OFFHOOK} |
Jim Miller | 1f56edc | 2011-11-07 19:00:48 -0800 | [diff] [blame] | 1124 | * @param shown indicates whether the given screen wants the emergency button to show at all |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 1125 | * @param button |
| 1126 | * @param phoneState |
| 1127 | * @param shown shown if true; hidden if false |
| 1128 | * @param upperCase if true, converts button label string to upper case |
Jim Miller | 69ac988 | 2010-02-24 15:35:05 -0800 | [diff] [blame] | 1129 | */ |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 1130 | public void updateEmergencyCallButtonState(Button button, int phoneState, boolean shown, |
| 1131 | boolean upperCase, boolean showIcon) { |
Jim Miller | 1f56edc | 2011-11-07 19:00:48 -0800 | [diff] [blame] | 1132 | if (isEmergencyCallCapable() && shown) { |
John Wang | 0f7b3f8 | 2011-05-31 11:20:55 -0700 | [diff] [blame] | 1133 | button.setVisibility(View.VISIBLE); |
| 1134 | } else { |
| 1135 | button.setVisibility(View.GONE); |
| 1136 | return; |
| 1137 | } |
| 1138 | |
Jim Miller | 69ac988 | 2010-02-24 15:35:05 -0800 | [diff] [blame] | 1139 | int textId; |
Jim Miller | 3f5f83b | 2011-09-26 15:17:05 -0700 | [diff] [blame] | 1140 | if (phoneState == TelephonyManager.CALL_STATE_OFFHOOK) { |
Jim Miller | 69ac988 | 2010-02-24 15:35:05 -0800 | [diff] [blame] | 1141 | // show "return to call" text and show phone icon |
| 1142 | textId = R.string.lockscreen_return_to_call; |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 1143 | int phoneCallIcon = showIcon ? R.drawable.stat_sys_phone_call : 0; |
Jim Miller | 69ac988 | 2010-02-24 15:35:05 -0800 | [diff] [blame] | 1144 | button.setCompoundDrawablesWithIntrinsicBounds(phoneCallIcon, 0, 0, 0); |
| 1145 | } else { |
| 1146 | textId = R.string.lockscreen_emergency_call; |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 1147 | int emergencyIcon = showIcon ? R.drawable.ic_emergency : 0; |
Jim Miller | 69ac988 | 2010-02-24 15:35:05 -0800 | [diff] [blame] | 1148 | button.setCompoundDrawablesWithIntrinsicBounds(emergencyIcon, 0, 0, 0); |
| 1149 | } |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 1150 | if (upperCase) { |
| 1151 | CharSequence original = mContext.getResources().getText(textId); |
| 1152 | String upper = original != null ? original.toString().toUpperCase() : null; |
| 1153 | button.setText(upper); |
| 1154 | } else { |
| 1155 | button.setText(textId); |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | /** |
| 1160 | * @deprecated |
| 1161 | * @param button |
| 1162 | * @param phoneState |
| 1163 | * @param shown |
| 1164 | */ |
| 1165 | public void updateEmergencyCallButtonState(Button button, int phoneState, boolean shown) { |
| 1166 | updateEmergencyCallButtonState(button, phoneState, shown, false, true); |
Jim Miller | 69ac988 | 2010-02-24 15:35:05 -0800 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | /** |
| 1170 | * Resumes a call in progress. Typically launched from the EmergencyCall button |
| 1171 | * on various lockscreens. |
| 1172 | * |
| 1173 | * @return true if we were able to tell InCallScreen to show. |
| 1174 | */ |
| 1175 | public boolean resumeCall() { |
| 1176 | ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); |
| 1177 | try { |
| 1178 | if (phone != null && phone.showCallScreen()) { |
| 1179 | return true; |
| 1180 | } |
| 1181 | } catch (RemoteException e) { |
| 1182 | // What can we do? |
| 1183 | } |
| 1184 | return false; |
| 1185 | } |
Danielle Millett | 044a0a7 | 2011-11-07 15:42:12 -0500 | [diff] [blame] | 1186 | |
| 1187 | private void finishBiometricWeak() { |
| 1188 | setBoolean(BIOMETRIC_WEAK_EVER_CHOSEN_KEY, true); |
| 1189 | |
| 1190 | // Launch intent to show final screen, this also |
| 1191 | // moves the temporary gallery to the actual gallery |
| 1192 | Intent intent = new Intent(); |
| 1193 | intent.setClassName("com.android.facelock", |
| 1194 | "com.android.facelock.SetupEndScreen"); |
| 1195 | mContext.startActivity(intent); |
| 1196 | } |
| 1197 | |
Jim Miller | a4edd15 | 2012-01-06 18:24:04 -0800 | [diff] [blame] | 1198 | public void setPowerButtonInstantlyLocks(boolean enabled) { |
| 1199 | setBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, enabled); |
| 1200 | } |
| 1201 | |
| 1202 | public boolean getPowerButtonInstantlyLocks() { |
| 1203 | return getBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, true); |
| 1204 | } |
| 1205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1206 | } |