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