blob: f987fc55704db7a6dc8f45cb8f9425cc49ab1937 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.internal.widget;
18
Jason parksf7b3cd42011-01-27 09:28:25 -060019import com.android.internal.R;
20import com.android.internal.telephony.ITelephony;
21import com.google.android.collect.Lists;
22
Amith Yamasani4b4b9542012-09-14 13:36:29 -070023import android.app.ActivityManagerNative;
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080024import android.app.admin.DevicePolicyManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.ContentResolver;
Jim Miller31f90b62010-01-20 13:35:20 -080026import android.content.Context;
Steven Ross329979c2011-09-28 11:42:56 -040027import android.content.Intent;
Danielle Millett58396982011-09-30 13:55:07 -040028import android.content.pm.PackageManager;
Amith Yamasani52c489c2012-03-28 11:42:42 -070029import android.os.Binder;
Jason parksf7b3cd42011-01-27 09:28:25 -060030import android.os.IBinder;
Amith Yamasani52c489c2012-03-28 11:42:42 -070031import android.os.Process;
Jim Miller69ac9882010-02-24 15:35:05 -080032import android.os.RemoteException;
33import android.os.ServiceManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.os.SystemClock;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070035import android.os.UserHandle;
Jason parksf7b3cd42011-01-27 09:28:25 -060036import android.os.storage.IMountService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.provider.Settings;
Brian Carlstrom5cfee3f2011-05-31 01:00:15 -070038import android.security.KeyStore;
Jim Miller69ac9882010-02-24 15:35:05 -080039import android.telephony.TelephonyManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.text.TextUtils;
41import android.util.Log;
John Wang0f7b3f82011-05-31 11:20:55 -070042import android.view.View;
Jim Miller69ac9882010-02-24 15:35:05 -080043import android.widget.Button;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
Brian Carlstrom929a1c22011-02-01 21:54:09 -080045import java.security.MessageDigest;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import java.security.NoSuchAlgorithmException;
Jim Miller11b019d2010-01-20 16:34:45 -080047import java.security.SecureRandom;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import java.util.List;
49
50/**
Brian Carlstrom5cfee3f2011-05-31 01:00:15 -070051 * Utilities for the lock pattern and its settings.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 */
53public class LockPatternUtils {
54
Jim Millercb3521e2011-10-03 20:42:26 -070055 private static final String OPTION_ENABLE_FACELOCK = "enable_facelock";
56
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 private static final String TAG = "LockPatternUtils";
Jim Miller69aa4a92009-12-22 19:03:28 -080058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 /**
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 Miller4f369952011-08-19 18:29:22 -070082
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 Project9066cfe2009-03-03 19:31:44 -080089 /**
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 Miller4f369952011-08-19 18:29:22 -070099 public static final int MIN_PATTERN_REGISTER_FAIL = MIN_LOCK_PATTERN_SIZE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100
Danielle Millett925a7d82012-03-19 18:02:20 -0400101 /**
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 Yamasani52c489c2012-03-28 11:42:42 -0700107 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 Miller69aa4a92009-12-22 19:03:28 -0800110 public final static String PASSWORD_TYPE_KEY = "lockscreen.password_type";
Jim Miller6edf2632011-09-05 16:03:14 -0700111 public static final String PASSWORD_TYPE_ALTERNATE_KEY = "lockscreen.password_type_alternate";
Amith Yamasani52c489c2012-03-28 11:42:42 -0700112 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 Miller6edf2632011-09-05 16:03:14 -0700115 public final static String LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK
116 = "lockscreen.biometric_weak_fallback";
Danielle Millett7a072192011-10-03 17:36:01 -0400117 public final static String BIOMETRIC_WEAK_EVER_CHOSEN_KEY
118 = "lockscreen.biometricweakeverchosen";
Jim Millera4edd152012-01-06 18:24:04 -0800119 public final static String LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS
120 = "lockscreen.power_button_instantly_locks";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121
Amith Yamasani52c489c2012-03-28 11:42:42 -0700122 protected final static String PASSWORD_HISTORY_KEY = "lockscreen.passwordhistory";
Konstantin Lopyrev863f22d2010-05-12 17:16:58 -0700123
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800124 private final Context mContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 private final ContentResolver mContentResolver;
Jim Miller31f90b62010-01-20 13:35:20 -0800126 private DevicePolicyManager mDevicePolicyManager;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700127 private ILockSettings mLockSettingsService;
Jim Milleree82f8f2012-10-01 16:26:18 -0700128
129 // The current user is set by KeyguardViewMediator and shared by all LockPatternUtils.
130 private static volatile int sCurrentUserId = UserHandle.USER_NULL;
Dianne Hackbornde4c26f2011-07-17 13:42:47 -0700131
Jim Millercd709882010-03-25 18:24:02 -0700132 public DevicePolicyManager getDevicePolicyManager() {
Jim Miller5b0fb3a2010-02-23 13:46:35 -0800133 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 Yamasani52c489c2012-03-28 11:42:42 -0700143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 /**
145 * @param contentResolver Used to look up and save settings.
146 */
Jim Miller31f90b62010-01-20 13:35:20 -0800147 public LockPatternUtils(Context context) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800148 mContext = context;
Jim Miller31f90b62010-01-20 13:35:20 -0800149 mContentResolver = context.getContentResolver();
Amith Yamasani52c489c2012-03-28 11:42:42 -0700150 }
Jim Miller69aa4a92009-12-22 19:03:28 -0800151
Amith Yamasani52c489c2012-03-28 11:42:42 -0700152 private ILockSettings getLockSettings() {
153 if (mLockSettingsService == null) {
154 mLockSettingsService = ILockSettings.Stub.asInterface(
155 (IBinder) ServiceManager.getService("lock_settings"));
Brad Fitzpatrick90881002010-08-23 18:30:08 -0700156 }
Amith Yamasani52c489c2012-03-28 11:42:42 -0700157 return mLockSettingsService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 }
159
Jim Miller31f90b62010-01-20 13:35:20 -0800160 public int getRequestedMinimumPasswordLength() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700161 return getDevicePolicyManager().getPasswordMinimumLength(null, getCurrentOrCallingUserId());
Jim Miller31f90b62010-01-20 13:35:20 -0800162 }
163
Jim Miller31f90b62010-01-20 13:35:20 -0800164 /**
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 Miller31f90b62010-01-20 13:35:20 -0800167 */
Jim Millercd709882010-03-25 18:24:02 -0700168 public int getRequestedPasswordQuality() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700169 return getDevicePolicyManager().getPasswordQuality(null, getCurrentOrCallingUserId());
Jim Miller31f90b62010-01-20 13:35:20 -0800170 }
171
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700172 public int getRequestedPasswordHistoryLength() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700173 return getDevicePolicyManager().getPasswordHistoryLength(null, getCurrentOrCallingUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700174 }
175
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700176 public int getRequestedPasswordMinimumLetters() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700177 return getDevicePolicyManager().getPasswordMinimumLetters(null,
178 getCurrentOrCallingUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700179 }
180
181 public int getRequestedPasswordMinimumUpperCase() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700182 return getDevicePolicyManager().getPasswordMinimumUpperCase(null,
183 getCurrentOrCallingUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700184 }
185
186 public int getRequestedPasswordMinimumLowerCase() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700187 return getDevicePolicyManager().getPasswordMinimumLowerCase(null,
188 getCurrentOrCallingUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700189 }
190
191 public int getRequestedPasswordMinimumNumeric() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700192 return getDevicePolicyManager().getPasswordMinimumNumeric(null,
193 getCurrentOrCallingUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700194 }
195
196 public int getRequestedPasswordMinimumSymbols() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700197 return getDevicePolicyManager().getPasswordMinimumSymbols(null,
198 getCurrentOrCallingUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700199 }
200
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700201 public int getRequestedPasswordMinimumNonLetter() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700202 return getDevicePolicyManager().getPasswordMinimumNonLetter(null,
203 getCurrentOrCallingUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700204 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700205
Jim Miller31f90b62010-01-20 13:35:20 -0800206 /**
207 * Returns the actual password mode, as set by keyguard after updating the password.
208 *
209 * @return
210 */
Jim Miller31f90b62010-01-20 13:35:20 -0800211 public void reportFailedPasswordAttempt() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700212 getDevicePolicyManager().reportFailedPasswordAttempt(getCurrentOrCallingUserId());
Jim Miller31f90b62010-01-20 13:35:20 -0800213 }
214
215 public void reportSuccessfulPasswordAttempt() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700216 getDevicePolicyManager().reportSuccessfulPasswordAttempt(getCurrentOrCallingUserId());
Jim Miller31f90b62010-01-20 13:35:20 -0800217 }
218
Amith Yamasani52c489c2012-03-28 11:42:42 -0700219 public void setCurrentUser(int userId) {
Jim Milleree82f8f2012-10-01 16:26:18 -0700220 sCurrentUserId = userId;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700221 }
222
Amith Yamasanif882f1a2012-04-10 15:13:39 -0700223 public int getCurrentUser() {
Jim Milleree82f8f2012-10-01 16:26:18 -0700224 if (sCurrentUserId != UserHandle.USER_NULL) {
Jim Miller25645d82012-09-21 14:47:54 -0700225 // Someone is regularly updating using setCurrentUser() use that value.
Jim Milleree82f8f2012-10-01 16:26:18 -0700226 return sCurrentUserId;
Jim Miller25645d82012-09-21 14:47:54 -0700227 }
228 try {
229 return ActivityManagerNative.getDefault().getCurrentUser().id;
230 } catch (RemoteException re) {
231 return UserHandle.USER_OWNER;
Amith Yamasanif882f1a2012-04-10 15:13:39 -0700232 }
233 }
234
Amith Yamasani52c489c2012-03-28 11:42:42 -0700235 public void removeUser(int userId) {
Jim Miller25645d82012-09-21 14:47:54 -0700236 try {
237 getLockSettings().removeUser(userId);
238 } catch (RemoteException re) {
239 Log.e(TAG, "Couldn't remove lock settings for user " + userId);
Amith Yamasani52c489c2012-03-28 11:42:42 -0700240 }
241 }
242
243 private int getCurrentOrCallingUserId() {
244 int callingUid = Binder.getCallingUid();
245 if (callingUid == android.os.Process.SYSTEM_UID) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700246 // 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 Yamasani52c489c2012-03-28 11:42:42 -0700249 } else {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700250 return UserHandle.getUserId(callingUid);
Amith Yamasani52c489c2012-03-28 11:42:42 -0700251 }
252 }
253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 /**
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 Miller69aa4a92009-12-22 19:03:28 -0800258 * @return Whether the pattern matches the stored one.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 */
260 public boolean checkPattern(List<LockPatternView.Cell> pattern) {
Kenny Rootdf8bfe02012-09-21 15:00:25 -0700261 final int userId = getCurrentOrCallingUserId();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 try {
Kenny Rootdf8bfe02012-09-21 15:00:25 -0700263 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 Yamasani52c489c2012-03-28 11:42:42 -0700268 } catch (RemoteException re) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 return true;
270 }
271 }
272
273 /**
Jim Miller69aa4a92009-12-22 19:03:28 -0800274 * 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 Project9066cfe2009-03-03 19:31:44 -0800278 */
Jim Miller69aa4a92009-12-22 19:03:28 -0800279 public boolean checkPassword(String password) {
Kenny Rootdf8bfe02012-09-21 15:00:25 -0700280 final int userId = getCurrentOrCallingUserId();
Jim Miller69aa4a92009-12-22 19:03:28 -0800281 try {
Kenny Rootdf8bfe02012-09-21 15:00:25 -0700282 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 Yamasani52c489c2012-03-28 11:42:42 -0700288 } catch (RemoteException re) {
Jim Miller69aa4a92009-12-22 19:03:28 -0800289 return true;
290 }
291 }
292
293 /**
Konstantin Lopyrev863f22d2010-05-12 17:16:58 -0700294 * 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 Lopyrev32558232010-05-20 16:18:05 -0700303 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 Lopyrev863f22d2010-05-12 17:16:58 -0700318 }
319
320 /**
Jim Miller69aa4a92009-12-22 19:03:28 -0800321 * Check to see if the user has stored a lock pattern.
322 * @return Whether a saved pattern exists.
323 */
324 public boolean savedPatternExists() {
Amith Yamasani52c489c2012-03-28 11:42:42 -0700325 try {
326 return getLockSettings().havePattern(getCurrentOrCallingUserId());
327 } catch (RemoteException re) {
328 return false;
329 }
Jim Miller69aa4a92009-12-22 19:03:28 -0800330 }
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 Yamasani52c489c2012-03-28 11:42:42 -0700337 try {
338 return getLockSettings().havePassword(getCurrentOrCallingUserId());
339 } catch (RemoteException re) {
340 return false;
341 }
Jim Miller69aa4a92009-12-22 19:03:28 -0800342 }
343
344 /**
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700345 * 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 Millera4edd152012-01-06 18:24:04 -0800351 return getBoolean(PATTERN_EVER_CHOSEN_KEY, false);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700352 }
353
354 /**
Danielle Millett7a072192011-10-03 17:36:01 -0400355 * 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 Millera4edd152012-01-06 18:24:04 -0800361 return getBoolean(BIOMETRIC_WEAK_EVER_CHOSEN_KEY, false);
Danielle Millett7a072192011-10-03 17:36:01 -0400362 }
363
364 /**
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700365 * Used by device policy manager to validate the current password
366 * information it has.
367 */
368 public int getActivePasswordQuality() {
Jim Millercd709882010-03-25 18:24:02 -0700369 int activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
Danielle Millettc8fb5322011-10-04 12:18:51 -0400370 // 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 Millercd709882010-03-25 18:24:02 -0700375 case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700376 if (isLockPatternEnabled()) {
Jim Millercd709882010-03-25 18:24:02 -0700377 activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700378 }
Jim Millercd709882010-03-25 18:24:02 -0700379 break;
Danielle Millettc8fb5322011-10-04 12:18:51 -0400380 case DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK:
381 if (isBiometricWeakInstalled()) {
382 activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK;
383 }
384 break;
Jim Millercd709882010-03-25 18:24:02 -0700385 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700386 if (isLockPasswordEnabled()) {
Jim Millercd709882010-03-25 18:24:02 -0700387 activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700388 }
Jim Millercd709882010-03-25 18:24:02 -0700389 break;
390 case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700391 if (isLockPasswordEnabled()) {
Jim Millercd709882010-03-25 18:24:02 -0700392 activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700393 }
Jim Millercd709882010-03-25 18:24:02 -0700394 break;
395 case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
396 if (isLockPasswordEnabled()) {
397 activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC;
398 }
399 break;
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700400 case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
401 if (isLockPasswordEnabled()) {
402 activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
403 }
404 break;
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700405 }
Danielle Millettc8fb5322011-10-04 12:18:51 -0400406
Jim Millercd709882010-03-25 18:24:02 -0700407 return activePasswordQuality;
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700408 }
Jim Millercd709882010-03-25 18:24:02 -0700409
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700410 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800411 * Clear any lock pattern or password.
412 */
Steven Ross329979c2011-09-28 11:42:56 -0400413 public void clearLock(boolean isFallback) {
414 if(!isFallback) deleteGallery();
Jim Millercd709882010-03-25 18:24:02 -0700415 saveLockPassword(null, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800416 setLockPatternEnabled(false);
417 saveLockPattern(null);
Jim Miller93708af12012-01-25 18:26:12 -0800418 setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
Jim Miller6edf2632011-09-05 16:03:14 -0700419 setLong(PASSWORD_TYPE_ALTERNATE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800420 }
Jim Miller5b0fb3a2010-02-23 13:46:35 -0800421
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800422 /**
Jim Miller2a98a4c2010-11-19 18:49:26 -0800423 * 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 Ross3553c292011-09-30 15:48:40 -0400443 * Calls back SetupFaceLock to delete the temporary gallery file
Steven Ross329979c2011-09-28 11:42:56 -0400444 */
445 public void deleteTempGallery() {
Danielle Millett574e49e2012-03-27 16:17:10 -0400446 Intent intent = new Intent().setAction("com.android.facelock.DELETE_GALLERY");
Steven Ross3553c292011-09-30 15:48:40 -0400447 intent.putExtra("deleteTempGallery", true);
Danielle Millett574e49e2012-03-27 16:17:10 -0400448 mContext.sendBroadcast(intent);
Steven Ross329979c2011-09-28 11:42:56 -0400449 }
450
451 /**
452 * Calls back SetupFaceLock to delete the gallery file when the lock type is changed
453 */
454 void deleteGallery() {
Danielle Millett58396982011-09-30 13:55:07 -0400455 if(usingBiometricWeak()) {
Danielle Millett574e49e2012-03-27 16:17:10 -0400456 Intent intent = new Intent().setAction("com.android.facelock.DELETE_GALLERY");
Steven Ross329979c2011-09-28 11:42:56 -0400457 intent.putExtra("deleteGallery", true);
Danielle Millett574e49e2012-03-27 16:17:10 -0400458 mContext.sendBroadcast(intent);
Steven Ross329979c2011-09-28 11:42:56 -0400459 }
460 }
461
462 /**
Jim Miller6edf2632011-09-05 16:03:14 -0700463 * Save a lock pattern.
464 * @param pattern The new pattern to save.
Danielle Millett2364a222011-12-21 17:02:32 -0500465 */
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 Miller6edf2632011-09-05 16:03:14 -0700473 * @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 Project9066cfe2009-03-03 19:31:44 -0800476 // Compute the hash
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700477 final byte[] hash = LockPatternUtils.patternToHash(pattern);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 try {
Amith Yamasani52c489c2012-03-28 11:42:42 -0700479 getLockSettings().setLockPattern(hash, getCurrentOrCallingUserId());
Dianne Hackborn2509d3c2010-03-08 12:54:25 -0800480 DevicePolicyManager dpm = getDevicePolicyManager();
Brian Carlstrome2afc242011-06-02 16:21:55 -0700481 KeyStore keyStore = KeyStore.getInstance();
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800482 if (pattern != null) {
Brian Carlstrome2afc242011-06-02 16:21:55 -0700483 keyStore.password(patternToString(pattern));
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800484 setBoolean(PATTERN_EVER_CHOSEN_KEY, true);
Jim Miller6edf2632011-09-05 16:03:14 -0700485 if (!isFallback) {
Steven Ross329979c2011-09-28 11:42:56 -0400486 deleteGallery();
Jim Miller6edf2632011-09-05 16:03:14 -0700487 setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
Danielle Millett2364a222011-12-21 17:02:32 -0500488 dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING,
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700489 pattern.size(), 0, 0, 0, 0, 0, 0, getCurrentOrCallingUserId());
Jim Miller6edf2632011-09-05 16:03:14 -0700490 } else {
491 setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK);
492 setLong(PASSWORD_TYPE_ALTERNATE_KEY,
493 DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
Danielle Millett044a0a72011-11-07 15:42:12 -0500494 finishBiometricWeak();
Danielle Millett2364a222011-12-21 17:02:32 -0500495 dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK,
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700496 0, 0, 0, 0, 0, 0, 0, getCurrentOrCallingUserId());
Jim Miller6edf2632011-09-05 16:03:14 -0700497 }
Dianne Hackborn2509d3c2010-03-08 12:54:25 -0800498 } else {
Brian Carlstrome2afc242011-06-02 16:21:55 -0700499 if (keyStore.isEmpty()) {
500 keyStore.reset();
501 }
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700502 dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0,
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700503 0, 0, 0, 0, 0, getCurrentOrCallingUserId());
Jim Miller31f90b62010-01-20 13:35:20 -0800504 }
Amith Yamasani52c489c2012-03-28 11:42:42 -0700505 } catch (RemoteException re) {
506 Log.e(TAG, "Couldn't save lock pattern " + re);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 }
508 }
509
510 /**
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700511 * Compute the password quality from the given password string.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800512 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700513 static public int computePasswordQuality(String password) {
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800514 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 Miller5b0fb3a2010-02-23 13:46:35 -0800524
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700525 if (hasNonDigit && hasDigit) {
526 return DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC;
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800527 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800528 if (hasNonDigit) {
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700529 return DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800530 }
531 if (hasDigit) {
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700532 return DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800533 }
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700534 return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800535 }
Jim Miller5b0fb3a2010-02-23 13:46:35 -0800536
Jason parksf7b3cd42011-01-27 09:28:25 -0600537 /** Update the encryption password if it is enabled **/
538 private void updateEncryptionPassword(String password) {
539 DevicePolicyManager dpm = getDevicePolicyManager();
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700540 if (dpm.getStorageEncryptionStatus(getCurrentOrCallingUserId())
541 != DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE) {
Jason parksf7b3cd42011-01-27 09:28:25 -0600542 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 Hackborn9327f4f2010-01-29 10:38:29 -0800559 /**
Jim Millercd709882010-03-25 18:24:02 -0700560 * Save a lock password. Does not ensure that the password is as good
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800561 * as the requested mode, but will adjust the mode to be as good as the
562 * pattern.
Jim Miller69aa4a92009-12-22 19:03:28 -0800563 * @param password The password to save
Jim Millercd709882010-03-25 18:24:02 -0700564 * @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
Jim Miller69aa4a92009-12-22 19:03:28 -0800565 */
Jim Millercd709882010-03-25 18:24:02 -0700566 public void saveLockPassword(String password, int quality) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700567 this.saveLockPassword(password, quality, false, getCurrentOrCallingUserId());
Jim Miller6edf2632011-09-05 16:03:14 -0700568 }
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 Yamasani599dd7c2012-09-14 23:20:08 -0700579 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 Miller69aa4a92009-12-22 19:03:28 -0800592 // Compute the hash
Jim Miller11b019d2010-01-20 16:34:45 -0800593 final byte[] hash = passwordToHash(password);
Jim Miller69aa4a92009-12-22 19:03:28 -0800594 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700595 getLockSettings().setLockPassword(hash, userHandle);
Dianne Hackborn2509d3c2010-03-08 12:54:25 -0800596 DevicePolicyManager dpm = getDevicePolicyManager();
Brian Carlstrome2afc242011-06-02 16:21:55 -0700597 KeyStore keyStore = KeyStore.getInstance();
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800598 if (password != null) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700599 if (userHandle == UserHandle.USER_OWNER) {
600 // Update the encryption password.
601 updateEncryptionPassword(password);
Jason parksf7b3cd42011-01-27 09:28:25 -0600602
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700603 // Update the keystore password
604 keyStore.password(password);
605 }
Brian Carlstrom5cfee3f2011-05-31 01:00:15 -0700606
Jim Millercd709882010-03-25 18:24:02 -0700607 int computedQuality = computePasswordQuality(password);
Jim Miller6edf2632011-09-05 16:03:14 -0700608 if (!isFallback) {
Steven Ross329979c2011-09-28 11:42:56 -0400609 deleteGallery();
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700610 setLong(PASSWORD_TYPE_KEY, Math.max(quality, computedQuality), userHandle);
Danielle Millett2364a222011-12-21 17:02:32 -0500611 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 Yamasani599dd7c2012-09-14 23:20:08 -0700636 numbers, symbols, nonletter, userHandle);
Danielle Millett2364a222011-12-21 17:02:32 -0500637 } else {
638 // The password is not anything.
639 dpm.setActivePasswordState(
640 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700641 0, 0, 0, 0, 0, 0, 0, userHandle);
Danielle Millett2364a222011-12-21 17:02:32 -0500642 }
Jim Miller6edf2632011-09-05 16:03:14 -0700643 } else {
Danielle Millett2364a222011-12-21 17:02:32 -0500644 // Case where it's a fallback for biometric weak
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700645 setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK,
646 userHandle);
647 setLong(PASSWORD_TYPE_ALTERNATE_KEY, Math.max(quality, computedQuality),
648 userHandle);
Danielle Millett044a0a72011-11-07 15:42:12 -0500649 finishBiometricWeak();
Danielle Millett2364a222011-12-21 17:02:32 -0500650 dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK,
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700651 0, 0, 0, 0, 0, 0, 0, userHandle);
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700652 }
Konstantin Lopyrev863f22d2010-05-12 17:16:58 -0700653 // Add the password to the password history. We assume all
654 // password
655 // hashes have the same length for simplicity of implementation.
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700656 String passwordHistory = getString(PASSWORD_HISTORY_KEY, userHandle);
Konstantin Lopyrev863f22d2010-05-12 17:16:58 -0700657 if (passwordHistory == null) {
658 passwordHistory = new String();
659 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700660 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 Yamasani599dd7c2012-09-14 23:20:08 -0700671 setString(PASSWORD_HISTORY_KEY, passwordHistory, userHandle);
Dianne Hackborn2509d3c2010-03-08 12:54:25 -0800672 } else {
Brian Carlstrome2afc242011-06-02 16:21:55 -0700673 // 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 Hackborn2509d3c2010-03-08 12:54:25 -0800678 dpm.setActivePasswordState(
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700679 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0, 0, 0, 0, 0, 0,
680 userHandle);
Jim Miller31f90b62010-01-20 13:35:20 -0800681 }
Amith Yamasani52c489c2012-03-28 11:42:42 -0700682 } catch (RemoteException re) {
Jim Miller69aa4a92009-12-22 19:03:28 -0800683 // Cant do much
Amith Yamasani52c489c2012-03-28 11:42:42 -0700684 Log.e(TAG, "Unable to save lock password " + re);
Jim Miller69aa4a92009-12-22 19:03:28 -0800685 }
686 }
687
Jim Millercd709882010-03-25 18:24:02 -0700688 /**
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 Miller6edf2632011-09-05 16:03:14 -0700695 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 Millett58396982011-09-30 13:55:07 -0400707 /**
708 * @return true if the lockscreen method is set to biometric weak
709 */
Jim Miller6edf2632011-09-05 16:03:14 -0700710 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 Miller69aa4a92009-12-22 19:03:28 -0800714 }
715
716 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 * 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 Miller69aa4a92009-12-22 19:03:28 -0800750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 /*
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 Miller69aa4a92009-12-22 19:03:28 -0800758 private static byte[] patternToHash(List<LockPatternView.Cell> pattern) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 if (pattern == null) {
760 return null;
761 }
Jim Miller69aa4a92009-12-22 19:03:28 -0800762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 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 Miller11b019d2010-01-20 16:34:45 -0800778 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 Miller69aa4a92009-12-22 19:03:28 -0800793 /*
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 Carlstrom5cfee3f2011-05-31 01:00:15 -0700800 public byte[] passwordToHash(String password) {
Jim Miller69aa4a92009-12-22 19:03:28 -0800801 if (password == null) {
802 return null;
803 }
804 String algo = null;
805 byte[] hashed = null;
806 try {
Jim Miller11b019d2010-01-20 16:34:45 -0800807 byte[] saltedPassword = (password + getSalt()).getBytes();
Jim Miller69aa4a92009-12-22 19:03:28 -0800808 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 Millett73da5fe2011-09-13 16:20:05 -0400828 * @return Whether the lock password is enabled, or if it is set as a backup for biometric weak
Jim Miller69aa4a92009-12-22 19:03:28 -0800829 */
830 public boolean isLockPasswordEnabled() {
831 long mode = getLong(PASSWORD_TYPE_KEY, 0);
Danielle Millett73da5fe2011-09-13 16:20:05 -0400832 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 Millett58396982011-09-30 13:55:07 -0400843 (usingBiometricWeak() && backupEnabled));
Jim Miller69aa4a92009-12-22 19:03:28 -0800844 }
845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 /**
Danielle Millett73da5fe2011-09-13 16:20:05 -0400847 * @return Whether the lock pattern is enabled, or if it is set as a backup for biometric weak
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 */
849 public boolean isLockPatternEnabled() {
Danielle Millett73da5fe2011-09-13 16:20:05 -0400850 final boolean backupEnabled =
851 getLong(PASSWORD_TYPE_ALTERNATE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING)
852 == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
853
Jim Millera4edd152012-01-06 18:24:04 -0800854 return getBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, false)
Danielle Millett73da5fe2011-09-13 16:20:05 -0400855 && (getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING)
856 == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING ||
Danielle Millett58396982011-09-30 13:55:07 -0400857 (usingBiometricWeak() && backupEnabled));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 }
859
860 /**
Danielle Millett58396982011-09-30 13:55:07 -0400861 * @return Whether biometric weak lock is installed and that the front facing camera exists
Jim Miller6edf2632011-09-05 16:03:14 -0700862 */
Danielle Millett58396982011-09-30 13:55:07 -0400863 public boolean isBiometricWeakInstalled() {
Danielle Millett58396982011-09-30 13:55:07 -0400864 // 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 Yamasani599dd7c2012-09-14 23:20:08 -0700876 if (getDevicePolicyManager().getCameraDisabled(null, getCurrentOrCallingUserId())) {
Danielle Millett58396982011-09-30 13:55:07 -0400877 return false;
878 }
879
880
881 return true;
Jim Miller6edf2632011-09-05 16:03:14 -0700882 }
883
884 /**
Danielle Millett925a7d82012-03-19 18:02:20 -0400885 * 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 Project9066cfe2009-03-03 19:31:44 -0800907 * Set whether the lock pattern is enabled.
908 */
909 public void setLockPatternEnabled(boolean enabled) {
Amith Yamasani156c4352010-03-05 17:10:03 -0800910 setBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 }
912
913 /**
914 * @return Whether the visible pattern is enabled.
915 */
916 public boolean isVisiblePatternEnabled() {
Jim Millera4edd152012-01-06 18:24:04 -0800917 return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 }
919
920 /**
921 * Set whether the visible pattern is enabled.
922 */
923 public void setVisiblePatternEnabled(boolean enabled) {
Amith Yamasani156c4352010-03-05 17:10:03 -0800924 setBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 }
926
927 /**
928 * @return Whether tactile feedback for the pattern is enabled.
929 */
930 public boolean isTactileFeedbackEnabled() {
Jim Millera4edd152012-01-06 18:24:04 -0800931 return getBoolean(Settings.Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 }
933
934 /**
935 * Set whether tactile feedback for the pattern is enabled.
936 */
937 public void setTactileFeedbackEnabled(boolean enabled) {
Amith Yamasani156c4352010-03-05 17:10:03 -0800938 setBoolean(Settings.Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED, enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 }
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 Millera4edd152012-01-06 18:24:04 -0800972 return getBoolean(LOCKOUT_PERMANENT_KEY, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 }
974
975 /**
976 * Set the state of whether the device is permanently locked, meaning the user
Karl Rosaen678771b2009-08-21 14:00:26 -0700977 * must authenticate via other means.
978 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 * @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 Project9066cfe2009-03-03 19:31:44 -0800985 }
986
John Wang0f7b3f82011-05-31 11:20:55 -0700987 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 Miller1f56edc2011-11-07 19:00:48 -0800997 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 Project9066cfe2009-03-03 19:31:44 -08001002 /**
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 Yamasani8fd96ec2012-09-21 17:48:49 -07001007 String nextAlarm = Settings.System.getStringForUser(mContentResolver,
1008 Settings.System.NEXT_ALARM_FORMATTED, UserHandle.USER_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 if (nextAlarm == null || TextUtils.isEmpty(nextAlarm)) {
1010 return null;
1011 }
1012 return nextAlarm;
1013 }
1014
Jim Millera4edd152012-01-06 18:24:04 -08001015 private boolean getBoolean(String secureSettingKey, boolean defaultValue) {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001016 try {
1017 return getLockSettings().getBoolean(secureSettingKey, defaultValue,
1018 getCurrentOrCallingUserId());
1019 } catch (RemoteException re) {
1020 return defaultValue;
1021 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001022 }
1023
Amith Yamasani156c4352010-03-05 17:10:03 -08001024 private void setBoolean(String secureSettingKey, boolean enabled) {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001025 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 Project9066cfe2009-03-03 19:31:44 -08001031 }
1032
Jim Millerf229e4d2012-09-12 20:32:50 -07001033 public int[] getUserDefinedWidgets() {
1034 int appWidgetId = -1;
Amith Yamasani8fd96ec2012-09-21 17:48:49 -07001035 String appWidgetIdString = Settings.Secure.getStringForUser(
1036 mContentResolver, Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID,
1037 UserHandle.USER_CURRENT);
Jim Millerf229e4d2012-09-12 20:32:50 -07001038 if (appWidgetIdString != null) {
1039 appWidgetId = (int) Integer.decode(appWidgetIdString);
1040 }
1041
1042 return new int[] { appWidgetId };
1043 }
1044
Michael Jurka20c41d52012-09-20 19:01:06 -07001045 public int getStatusWidget() {
1046 int appWidgetId = -1;
Amith Yamasani8fd96ec2012-09-21 17:48:49 -07001047 String appWidgetIdString = Settings.Secure.getStringForUser(
1048 mContentResolver, Settings.Secure.LOCK_SCREEN_STATUS_APPWIDGET_ID,
1049 UserHandle.USER_CURRENT);
Michael Jurka20c41d52012-09-20 19:01:06 -07001050 if (appWidgetIdString != null) {
1051 appWidgetId = (int) Integer.decode(appWidgetIdString);
1052 }
1053
1054 return appWidgetId;
1055 }
1056
Amith Yamasani52c489c2012-03-28 11:42:42 -07001057 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 Project9066cfe2009-03-03 19:31:44 -08001064 }
1065
Amith Yamasani156c4352010-03-05 17:10:03 -08001066 private void setLong(String secureSettingKey, long value) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001067 setLong(secureSettingKey, value, getCurrentOrCallingUserId());
1068 }
1069
1070 private void setLong(String secureSettingKey, long value, int userHandle) {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001071 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 Project9066cfe2009-03-03 19:31:44 -08001077 }
1078
Konstantin Lopyrev863f22d2010-05-12 17:16:58 -07001079 private String getString(String secureSettingKey) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001080 return getString(secureSettingKey, getCurrentOrCallingUserId());
1081 }
1082
1083 private String getString(String secureSettingKey, int userHandle) {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001084 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001085 return getLockSettings().getString(secureSettingKey, null, userHandle);
Amith Yamasani52c489c2012-03-28 11:42:42 -07001086 } catch (RemoteException re) {
1087 return null;
1088 }
Konstantin Lopyrev863f22d2010-05-12 17:16:58 -07001089 }
1090
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001091 private void setString(String secureSettingKey, String value, int userHandle) {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001092 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001093 getLockSettings().setString(secureSettingKey, value, userHandle);
Amith Yamasani52c489c2012-03-28 11:42:42 -07001094 } catch (RemoteException re) {
1095 // What can we do?
1096 Log.e(TAG, "Couldn't write string " + secureSettingKey + re);
1097 }
Konstantin Lopyrev863f22d2010-05-12 17:16:58 -07001098 }
1099
Jim Miller69aa4a92009-12-22 19:03:28 -08001100 public boolean isSecure() {
Jim Millercd709882010-03-25 18:24:02 -07001101 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 Lopyreva15dcfa2010-05-24 17:10:56 -07001105 || mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
1106 || mode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
Jim Millercd709882010-03-25 18:24:02 -07001107 final boolean secure = isPattern && isLockPatternEnabled() && savedPatternExists()
Danielle Millett73da5fe2011-09-13 16:20:05 -04001108 || isPassword && savedPasswordExists();
Jim Miller69aa4a92009-12-22 19:03:28 -08001109 return secure;
1110 }
Jim Miller69ac9882010-02-24 15:35:05 -08001111
1112 /**
John Wang0f7b3f82011-05-31 11:20:55 -07001113 * 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 Miller69ac9882010-02-24 15:35:05 -08001118 * If there's currently a call in progress, the button will take them to the call
1119 * @param button the button to update
Jim Miller3f5f83b2011-09-26 15:17:05 -07001120 * @param the phone state:
1121 * {@link TelephonyManager#CALL_STATE_IDLE}
1122 * {@link TelephonyManager#CALL_STATE_RINGING}
1123 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
Jim Miller1f56edc2011-11-07 19:00:48 -08001124 * @param shown indicates whether the given screen wants the emergency button to show at all
Jim Miller109f1fd2012-09-19 20:44:16 -07001125 * @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 Miller69ac9882010-02-24 15:35:05 -08001129 */
Jim Miller109f1fd2012-09-19 20:44:16 -07001130 public void updateEmergencyCallButtonState(Button button, int phoneState, boolean shown,
1131 boolean upperCase, boolean showIcon) {
Jim Miller1f56edc2011-11-07 19:00:48 -08001132 if (isEmergencyCallCapable() && shown) {
John Wang0f7b3f82011-05-31 11:20:55 -07001133 button.setVisibility(View.VISIBLE);
1134 } else {
1135 button.setVisibility(View.GONE);
1136 return;
1137 }
1138
Jim Miller69ac9882010-02-24 15:35:05 -08001139 int textId;
Jim Miller3f5f83b2011-09-26 15:17:05 -07001140 if (phoneState == TelephonyManager.CALL_STATE_OFFHOOK) {
Jim Miller69ac9882010-02-24 15:35:05 -08001141 // show "return to call" text and show phone icon
1142 textId = R.string.lockscreen_return_to_call;
Jim Miller109f1fd2012-09-19 20:44:16 -07001143 int phoneCallIcon = showIcon ? R.drawable.stat_sys_phone_call : 0;
Jim Miller69ac9882010-02-24 15:35:05 -08001144 button.setCompoundDrawablesWithIntrinsicBounds(phoneCallIcon, 0, 0, 0);
1145 } else {
1146 textId = R.string.lockscreen_emergency_call;
Jim Miller109f1fd2012-09-19 20:44:16 -07001147 int emergencyIcon = showIcon ? R.drawable.ic_emergency : 0;
Jim Miller69ac9882010-02-24 15:35:05 -08001148 button.setCompoundDrawablesWithIntrinsicBounds(emergencyIcon, 0, 0, 0);
1149 }
Jim Miller109f1fd2012-09-19 20:44:16 -07001150 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 Miller69ac9882010-02-24 15:35:05 -08001167 }
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 Millett044a0a72011-11-07 15:42:12 -05001186
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 Millera4edd152012-01-06 18:24:04 -08001198 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 Project9066cfe2009-03-03 19:31:44 -08001206}