Methods Summary |
---|
public boolean | addAppWidget(int widgetId, int index)
int[] widgets = getAppWidgets();
if (widgets == null) {
return false;
}
if (index < 0 || index > widgets.length) {
return false;
}
int[] newWidgets = new int[widgets.length + 1];
for (int i = 0, j = 0; i < newWidgets.length; i++) {
if (index == i) {
newWidgets[i] = widgetId;
i++;
}
if (i < newWidgets.length) {
newWidgets[i] = widgets[j];
j++;
}
}
writeAppWidgets(newWidgets);
return true;
|
private static int | categoryChar(char c)
if ('a" <= c && c <= 'z") return 0;
if ('A" <= c && c <= 'Z") return 1;
if ('0" <= c && c <= '9") return 2;
return 3;
|
public boolean | checkPassword(java.lang.String password)Check to see if a password matches the saved password. If no password exists,
always returns true.
final int userId = getCurrentOrCallingUserId();
try {
return getLockSettings().checkPassword(password, userId);
} catch (RemoteException re) {
return true;
}
|
public boolean | checkPasswordHistory(java.lang.String password)Check to see if a password matches any of the passwords stored in the
password history.
String passwordHashString = new String(
passwordToHash(password, getCurrentOrCallingUserId()));
String passwordHistory = getString(PASSWORD_HISTORY_KEY);
if (passwordHistory == null) {
return false;
}
// Password History may be too long...
int passwordHashLength = passwordHashString.length();
int passwordHistoryLength = getRequestedPasswordHistoryLength();
if(passwordHistoryLength == 0) {
return false;
}
int neededPasswordHistoryLength = passwordHashLength * passwordHistoryLength
+ passwordHistoryLength - 1;
if (passwordHistory.length() > neededPasswordHistoryLength) {
passwordHistory = passwordHistory.substring(0, neededPasswordHistoryLength);
}
return passwordHistory.contains(passwordHashString);
|
public boolean | checkPattern(java.util.List pattern)Check to see if a pattern matches the saved pattern. If no pattern exists,
always returns true.
final int userId = getCurrentOrCallingUserId();
try {
return getLockSettings().checkPattern(patternToString(pattern), userId);
} catch (RemoteException re) {
return true;
}
|
public boolean | checkVoldPassword()Check to see if vold already has the password.
Note that this also clears vold's copy of the password.
final int userId = getCurrentOrCallingUserId();
try {
return getLockSettings().checkVoldPassword(userId);
} catch (RemoteException re) {
return false;
}
|
public void | clearEncryptionPassword()Clears the encryption password.
updateEncryptionPassword(StorageManager.CRYPT_TYPE_DEFAULT, null);
|
public void | clearLock(boolean isFallback)
clearLock(isFallback, getCurrentOrCallingUserId());
|
public void | clearLock(boolean isFallback, int userHandle)Clear any lock pattern or password.
if(!isFallback) deleteGallery(userHandle);
saveLockPassword(null, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, isFallback,
userHandle);
setLockPatternEnabled(false, userHandle);
saveLockPattern(null, isFallback, userHandle);
setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userHandle);
setLong(PASSWORD_TYPE_ALTERNATE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
userHandle);
onAfterChangingPassword(userHandle);
|
private static java.lang.String | combineStrings(int[] list, java.lang.String separator)
int listLength = list.length;
switch (listLength) {
case 0: {
return "";
}
case 1: {
return Integer.toString(list[0]);
}
}
int strLength = 0;
int separatorLength = separator.length();
String[] stringList = new String[list.length];
for (int i = 0; i < listLength; i++) {
stringList[i] = Integer.toString(list[i]);
strLength += stringList[i].length();
if (i < listLength - 1) {
strLength += separatorLength;
}
}
StringBuilder sb = new StringBuilder(strLength);
for (int i = 0; i < listLength; i++) {
sb.append(list[i]);
if (i < listLength - 1) {
sb.append(separator);
}
}
return sb.toString();
|
public static int | computePasswordQuality(java.lang.String password)Compute the password quality from the given password string.
boolean hasDigit = false;
boolean hasNonDigit = false;
final int len = password.length();
for (int i = 0; i < len; i++) {
if (Character.isDigit(password.charAt(i))) {
hasDigit = true;
} else {
hasNonDigit = true;
}
}
if (hasNonDigit && hasDigit) {
return DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC;
}
if (hasNonDigit) {
return DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
}
if (hasDigit) {
return maxLengthSequence(password) > MAX_ALLOWED_SEQUENCE
? DevicePolicyManager.PASSWORD_QUALITY_NUMERIC
: DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX;
}
return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
void | deleteGallery(int userId)Calls back SetupFaceLock to delete the gallery file when the lock type is changed
if(usingBiometricWeak(userId)) {
Intent intent = new Intent().setAction("com.android.facelock.DELETE_GALLERY");
intent.putExtra("deleteGallery", true);
mContext.sendBroadcastAsUser(intent, new UserHandle(userId));
}
|
public void | deleteTempGallery()Calls back SetupFaceLock to delete the temporary gallery file
Intent intent = new Intent().setAction("com.android.facelock.DELETE_GALLERY");
intent.putExtra("deleteTempGallery", true);
mContext.sendBroadcast(intent);
|
private void | finishBiometricWeak(int userId)
setBoolean(BIOMETRIC_WEAK_EVER_CHOSEN_KEY, true, userId);
// Launch intent to show final screen, this also
// moves the temporary gallery to the actual gallery
Intent intent = new Intent();
intent.setClassName("com.android.facelock",
"com.android.facelock.SetupEndScreen");
mContext.startActivityAsUser(intent, new UserHandle(userId));
|
public int | getActivePasswordQuality()Used by device policy manager to validate the current password
information it has.
int activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
// Note we don't want to use getKeyguardStoredPasswordQuality() because we want this to
// return biometric_weak if that is being used instead of the backup
int quality =
(int) getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
switch (quality) {
case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
if (isLockPatternEnabled()) {
activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
}
break;
case DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK:
if (isBiometricWeakInstalled()) {
activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK;
}
break;
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
if (isLockPasswordEnabled()) {
activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
}
break;
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
if (isLockPasswordEnabled()) {
activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX;
}
break;
case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
if (isLockPasswordEnabled()) {
activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
}
break;
case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
if (isLockPasswordEnabled()) {
activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC;
}
break;
case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
if (isLockPasswordEnabled()) {
activePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
}
break;
}
return activePasswordQuality;
|
public int[] | getAppWidgets()
return getAppWidgets(UserHandle.USER_CURRENT);
|
private int[] | getAppWidgets(int userId)
String appWidgetIdString = Settings.Secure.getStringForUser(
mContentResolver, Settings.Secure.LOCK_SCREEN_APPWIDGET_IDS, userId);
String delims = ",";
if (appWidgetIdString != null && appWidgetIdString.length() > 0) {
String[] appWidgetStringIds = appWidgetIdString.split(delims);
int[] appWidgetIds = new int[appWidgetStringIds.length];
for (int i = 0; i < appWidgetStringIds.length; i++) {
String appWidget = appWidgetStringIds[i];
try {
appWidgetIds[i] = Integer.decode(appWidget);
} catch (NumberFormatException e) {
Log.d(TAG, "Error when parsing widget id " + appWidget);
return null;
}
}
return appWidgetIds;
}
return new int[0];
|
private boolean | getBoolean(java.lang.String secureSettingKey, boolean defaultValue, int userId)
try {
return getLockSettings().getBoolean(secureSettingKey, defaultValue, userId);
} catch (RemoteException re) {
return defaultValue;
}
|
private boolean | getBoolean(java.lang.String secureSettingKey, boolean defaultValue)
return getBoolean(secureSettingKey, defaultValue, getCurrentOrCallingUserId());
|
private int | getCurrentOrCallingUserId()
if (mMultiUserMode) {
// TODO: This is a little inefficient. See if all users of this are able to
// handle USER_CURRENT and pass that instead.
return getCurrentUser();
} else {
return UserHandle.getCallingUserId();
}
|
public int | getCurrentUser()
if (sCurrentUserId != UserHandle.USER_NULL) {
// Someone is regularly updating using setCurrentUser() use that value.
return sCurrentUserId;
}
try {
return ActivityManagerNative.getDefault().getCurrentUser().id;
} catch (RemoteException re) {
return UserHandle.USER_OWNER;
}
|
public android.app.admin.DevicePolicyManager | getDevicePolicyManager()
if (mDevicePolicyManager == null) {
mDevicePolicyManager =
(DevicePolicyManager)mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
if (mDevicePolicyManager == null) {
Log.e(TAG, "Can't get DevicePolicyManagerService: is it running?",
new IllegalStateException("Stack trace:"));
}
}
return mDevicePolicyManager;
|
public java.util.List | getEnabledTrustAgents()
return getEnabledTrustAgents(getCurrentOrCallingUserId());
|
public java.util.List | getEnabledTrustAgents(int userId)
String serialized = getString(ENABLED_TRUST_AGENTS, userId);
if (TextUtils.isEmpty(serialized)) {
return null;
}
String[] split = serialized.split(",");
ArrayList<ComponentName> activeTrustAgents = new ArrayList<ComponentName>(split.length);
for (String s : split) {
if (!TextUtils.isEmpty(s)) {
activeTrustAgents.add(ComponentName.unflattenFromString(s));
}
}
return activeTrustAgents;
|
public int | getFallbackAppWidgetId()
return Settings.Secure.getIntForUser(
mContentResolver,
Settings.Secure.LOCK_SCREEN_FALLBACK_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID,
UserHandle.USER_CURRENT);
|
public int | getKeyguardStoredPasswordQuality()Retrieves the quality mode we're in.
{@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
return getKeyguardStoredPasswordQuality(getCurrentOrCallingUserId());
|
public int | getKeyguardStoredPasswordQuality(int userHandle)Retrieves the quality mode for {@param userHandle}.
{@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
int quality = (int) getLong(PASSWORD_TYPE_KEY,
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userHandle);
// If the user has chosen to use weak biometric sensor, then return the backup locking
// method and treat biometric as a special case.
if (quality == DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK) {
quality = (int) getLong(PASSWORD_TYPE_ALTERNATE_KEY,
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userHandle);
}
return quality;
|
private ILockSettings | getLockSettings()
if (mLockSettingsService == null) {
ILockSettings service = ILockSettings.Stub.asInterface(
ServiceManager.getService("lock_settings"));
mLockSettingsService = service;
}
return mLockSettingsService;
|
public long | getLockoutAttemptDeadline()
final long deadline = getLong(LOCKOUT_ATTEMPT_DEADLINE, 0L);
final long now = SystemClock.elapsedRealtime();
if (deadline < now || deadline > (now + FAILED_ATTEMPT_TIMEOUT_MS)) {
return 0L;
}
return deadline;
|
private long | getLong(java.lang.String secureSettingKey, long defaultValue, int userHandle)
try {
return getLockSettings().getLong(secureSettingKey, defaultValue, userHandle);
} catch (RemoteException re) {
return defaultValue;
}
|
private long | getLong(java.lang.String secureSettingKey, long defaultValue)
try {
return getLockSettings().getLong(secureSettingKey, defaultValue,
getCurrentOrCallingUserId());
} catch (RemoteException re) {
return defaultValue;
}
|
public AlarmManager.AlarmClockInfo | getNextAlarm()
AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
return alarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
|
public java.lang.String | getOwnerInfo(int userId)
return getString(LOCK_SCREEN_OWNER_INFO);
|
public boolean | getPowerButtonInstantlyLocks()
return getBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, true);
|
public int | getRequestedMinimumPasswordLength()
return getDevicePolicyManager().getPasswordMinimumLength(null, getCurrentOrCallingUserId());
|
public int | getRequestedPasswordHistoryLength()
return getDevicePolicyManager().getPasswordHistoryLength(null, getCurrentOrCallingUserId());
|
public int | getRequestedPasswordMinimumLetters()
return getDevicePolicyManager().getPasswordMinimumLetters(null,
getCurrentOrCallingUserId());
|
public int | getRequestedPasswordMinimumLowerCase()
return getDevicePolicyManager().getPasswordMinimumLowerCase(null,
getCurrentOrCallingUserId());
|
public int | getRequestedPasswordMinimumNonLetter()
return getDevicePolicyManager().getPasswordMinimumNonLetter(null,
getCurrentOrCallingUserId());
|
public int | getRequestedPasswordMinimumNumeric()
return getDevicePolicyManager().getPasswordMinimumNumeric(null,
getCurrentOrCallingUserId());
|
public int | getRequestedPasswordMinimumSymbols()
return getDevicePolicyManager().getPasswordMinimumSymbols(null,
getCurrentOrCallingUserId());
|
public int | getRequestedPasswordMinimumUpperCase()
return getDevicePolicyManager().getPasswordMinimumUpperCase(null,
getCurrentOrCallingUserId());
|
public int | getRequestedPasswordQuality()Gets the device policy password mode. If the mode is non-specific, returns
MODE_PATTERN which allows the user to choose anything.
return getDevicePolicyManager().getPasswordQuality(null, getCurrentOrCallingUserId());
|
private java.lang.String | getSalt(int userId)
long salt = getLong(LOCK_PASSWORD_SALT_KEY, 0, userId);
if (salt == 0) {
try {
salt = SecureRandom.getInstance("SHA1PRNG").nextLong();
setLong(LOCK_PASSWORD_SALT_KEY, salt, userId);
Log.v(TAG, "Initialized lock password salt for user: " + userId);
} catch (NoSuchAlgorithmException e) {
// Throw an exception rather than storing a password we'll never be able to recover
throw new IllegalStateException("Couldn't get SecureRandom number", e);
}
}
return Long.toHexString(salt);
|
private java.lang.String | getString(java.lang.String secureSettingKey)
return getString(secureSettingKey, getCurrentOrCallingUserId());
|
private java.lang.String | getString(java.lang.String secureSettingKey, int userHandle)
try {
return getLockSettings().getString(secureSettingKey, null, userHandle);
} catch (RemoteException re) {
return null;
}
|
private android.telecom.TelecomManager | getTelecommManager()
return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
|
private android.app.trust.TrustManager | getTrustManager()
TrustManager trust = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
if (trust == null) {
Log.e(TAG, "Can't get TrustManagerService: is it running?",
new IllegalStateException("Stack trace:"));
}
return trust;
|
public boolean | getWidgetsEnabled()
return getWidgetsEnabled(getCurrentOrCallingUserId());
|
public boolean | getWidgetsEnabled(int userId)
return getBoolean(LOCKSCREEN_WIDGETS_ENABLED, false, userId);
|
public boolean | hasWidgetsEnabledInKeyguard(int userid)Determine whether the user has selected any non-system widgets in keyguard
int widgets[] = getAppWidgets(userid);
for (int i = 0; i < widgets.length; i++) {
if (widgets[i] > 0) {
return true;
}
}
return false;
|
public boolean | isBiometricWeakEverChosen()Return true if the user has ever chosen biometric weak. This is true even if biometric
weak is not current set.
return getBoolean(BIOMETRIC_WEAK_EVER_CHOSEN_KEY, false);
|
public boolean | isBiometricWeakInstalled()
// Check that it's installed
PackageManager pm = mContext.getPackageManager();
try {
pm.getPackageInfo("com.android.facelock", PackageManager.GET_ACTIVITIES);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
// Check that the camera is enabled
if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
return false;
}
if (getDevicePolicyManager().getCameraDisabled(null, getCurrentOrCallingUserId())) {
return false;
}
// TODO: If we decide not to proceed with Face Unlock as a trustlet, this must be changed
// back to returning true. If we become certain that Face Unlock will be a trustlet, this
// entire function and a lot of other code can be removed.
if (DEBUG) Log.d(TAG, "Forcing isBiometricWeakInstalled() to return false to disable it");
return false;
|
public boolean | isBiometricWeakLivelinessEnabled()
long currentFlag = getLong(Settings.Secure.LOCK_BIOMETRIC_WEAK_FLAGS, 0L);
return ((currentFlag & FLAG_BIOMETRIC_WEAK_LIVELINESS) != 0);
|
public boolean | isCredentialRequiredToDecrypt(boolean defaultValue)
final int value = Settings.Global.getInt(mContentResolver,
Settings.Global.REQUIRE_PASSWORD_TO_DECRYPT, -1);
return value == -1 ? defaultValue : (value != 0);
|
public static boolean | isDeviceEncrypted()Gets whether the device is encrypted.
IMountService mountService = IMountService.Stub.asInterface(
ServiceManager.getService("mount"));
try {
return mountService.getEncryptionState() != IMountService.ENCRYPTION_STATE_NONE
&& mountService.getPasswordType() != StorageManager.CRYPT_TYPE_DEFAULT;
} catch (RemoteException re) {
Log.e(TAG, "Error getting encryption state", re);
}
return true;
|
public static boolean | isDeviceEncryptionEnabled()Determine if the device supports encryption, even if it's set to default. This
differs from isDeviceEncrypted() in that it returns true even if the device is
encrypted with the default password.
final String status = SystemProperties.get("ro.crypto.state", "unsupported");
return "encrypted".equalsIgnoreCase(status);
|
public boolean | isEmergencyCallCapable()
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_voice_capable);
|
public boolean | isEmergencyCallEnabledWhileSimLocked()
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_enable_emergency_call_while_sim_locked);
|
public boolean | isInCall()
return getTelecommManager().isInCall();
|
public boolean | isLockPasswordEnabled()
long mode = getLong(PASSWORD_TYPE_KEY, 0);
long backupMode = getLong(PASSWORD_TYPE_ALTERNATE_KEY, 0);
final boolean passwordEnabled = mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC
|| mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC
|| mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX
|| mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
|| mode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
final boolean backupEnabled = backupMode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC
|| backupMode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC
|| backupMode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX
|| backupMode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
|| backupMode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
return savedPasswordExists() && (passwordEnabled ||
(usingBiometricWeak() && backupEnabled));
|
public boolean | isLockPatternEnabled()
return isLockPatternEnabled(getCurrentOrCallingUserId());
|
public boolean | isLockPatternEnabled(int userId)
final boolean backupEnabled =
getLong(PASSWORD_TYPE_ALTERNATE_KEY,
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userId)
== DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
return getBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, false, userId)
&& (getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
userId) == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING
|| (usingBiometricWeak(userId) && backupEnabled));
|
public boolean | isLockScreenDisabled()Determine if LockScreen can be disabled. This is used, for example, to tell if we should
show LockScreen or go straight to the home screen.
if (!isSecure() && getLong(DISABLE_LOCKSCREEN_KEY, 0) != 0) {
// Check if the number of switchable users forces the lockscreen.
final List<UserInfo> users = UserManager.get(mContext).getUsers(true);
final int userCount = users.size();
int switchableUsers = 0;
for (int i = 0; i < userCount; i++) {
if (users.get(i).supportsSwitchTo()) {
switchableUsers++;
}
}
return switchableUsers < 2;
}
return false;
|
public boolean | isOwnerInfoEnabled()
return getBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, false);
|
public boolean | isPatternEverChosen()Return true if the user has ever chosen a pattern. This is true even if the pattern is
currently cleared.
return getBoolean(PATTERN_EVER_CHOSEN_KEY, false);
|
public boolean | isPermanentlyLocked()
return getBoolean(LOCKOUT_PERMANENT_KEY, false);
|
public boolean | isPukUnlockScreenEnable()
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_enable_puk_unlock_screen);
|
public static boolean | isSafeModeEnabled()
try {
return IWindowManager.Stub.asInterface(
ServiceManager.getService("window")).isSafeModeEnabled();
} catch (RemoteException e) {
// Shouldn't happen!
}
return false;
|
public boolean | isSecure()
return isSecure(getCurrentOrCallingUserId());
|
public boolean | isSecure(int userId)
long mode = getKeyguardStoredPasswordQuality(userId);
final boolean isPattern = mode == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
final boolean isPassword = mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC
|| mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX
|| mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC
|| mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
|| mode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
final boolean secure =
isPattern && isLockPatternEnabled(userId) && savedPatternExists(userId)
|| isPassword && savedPasswordExists(userId);
return secure;
|
public boolean | isTactileFeedbackEnabled()
return Settings.System.getIntForUser(mContentResolver,
Settings.System.HAPTIC_FEEDBACK_ENABLED, 1, UserHandle.USER_CURRENT) != 0;
|
public boolean | isVisiblePatternEnabled()
return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, false);
|
private static int | maxDiffCategory(int category)
if (category == 0 || category == 1) return 1;
else if (category == 2) return 10;
return 0;
|
public static int | maxLengthSequence(java.lang.String string)
if (string.length() == 0) return 0;
char previousChar = string.charAt(0);
int category = categoryChar(previousChar); //current category of the sequence
int diff = 0; //difference between two consecutive characters
boolean hasDiff = false; //if we are currently targeting a sequence
int maxLength = 0; //maximum length of a sequence already found
int startSequence = 0; //where the current sequence started
for (int current = 1; current < string.length(); current++) {
char currentChar = string.charAt(current);
int categoryCurrent = categoryChar(currentChar);
int currentDiff = (int) currentChar - (int) previousChar;
if (categoryCurrent != category || Math.abs(currentDiff) > maxDiffCategory(category)) {
maxLength = Math.max(maxLength, current - startSequence);
startSequence = current;
hasDiff = false;
category = categoryCurrent;
}
else {
if(hasDiff && currentDiff != diff) {
maxLength = Math.max(maxLength, current - startSequence);
startSequence = current - 1;
}
diff = currentDiff;
hasDiff = true;
}
previousChar = currentChar;
}
maxLength = Math.max(maxLength, string.length() - startSequence);
return maxLength;
|
private void | onAfterChangingPassword(int userHandle)
getTrustManager().reportEnabledTrustAgentsChanged(userHandle);
|
public byte[] | passwordToHash(java.lang.String password, int userId)
if (password == null) {
return null;
}
String algo = null;
byte[] hashed = null;
try {
byte[] saltedPassword = (password + getSalt(userId)).getBytes();
byte[] sha1 = MessageDigest.getInstance(algo = "SHA-1").digest(saltedPassword);
byte[] md5 = MessageDigest.getInstance(algo = "MD5").digest(saltedPassword);
hashed = (toHex(sha1) + toHex(md5)).getBytes();
} catch (NoSuchAlgorithmException e) {
Log.w(TAG, "Failed to encode string because of missing algorithm: " + algo);
}
return hashed;
|
public static byte[] | patternToHash(java.util.List pattern)
if (pattern == null) {
return null;
}
final int patternSize = pattern.size();
byte[] res = new byte[patternSize];
for (int i = 0; i < patternSize; i++) {
LockPatternView.Cell cell = pattern.get(i);
res[i] = (byte) (cell.getRow() * 3 + cell.getColumn());
}
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] hash = md.digest(res);
return hash;
} catch (NoSuchAlgorithmException nsa) {
return res;
}
|
public static java.lang.String | patternToString(java.util.List pattern)Serialize a pattern.
if (pattern == null) {
return "";
}
final int patternSize = pattern.size();
byte[] res = new byte[patternSize];
for (int i = 0; i < patternSize; i++) {
LockPatternView.Cell cell = pattern.get(i);
res[i] = (byte) (cell.getRow() * 3 + cell.getColumn());
}
return new String(res);
|
public boolean | removeAppWidget(int widgetId)
int[] widgets = getAppWidgets();
if (widgets.length == 0) {
return false;
}
int[] newWidgets = new int[widgets.length - 1];
for (int i = 0, j = 0; i < widgets.length; i++) {
if (widgets[i] == widgetId) {
// continue...
} else if (j >= newWidgets.length) {
// we couldn't find the widget
return false;
} else {
newWidgets[j] = widgets[i];
j++;
}
}
writeAppWidgets(newWidgets);
return true;
|
public void | removeUser(int userId)
try {
getLockSettings().removeUser(userId);
} catch (RemoteException re) {
Log.e(TAG, "Couldn't remove lock settings for user " + userId);
}
|
public void | reportFailedPasswordAttempt()
int userId = getCurrentOrCallingUserId();
getDevicePolicyManager().reportFailedPasswordAttempt(userId);
getTrustManager().reportUnlockAttempt(false /* authenticated */, userId);
getTrustManager().reportRequireCredentialEntry(userId);
|
public void | reportSuccessfulPasswordAttempt()
getDevicePolicyManager().reportSuccessfulPasswordAttempt(getCurrentOrCallingUserId());
getTrustManager().reportUnlockAttempt(true /* authenticated */,
getCurrentOrCallingUserId());
|
public void | requireCredentialEntry(int userId)
getTrustManager().reportRequireCredentialEntry(userId);
|
public void | resumeCall()Resumes a call in progress. Typically launched from the EmergencyCall button
on various lockscreens.
getTelecommManager().showInCallScreen(false);
|
public void | saveLockPassword(java.lang.String password, int quality)Save a lock password. Does not ensure that the password is as good
as the requested mode, but will adjust the mode to be as good as the
pattern.
this.saveLockPassword(password, quality, false, getCurrentOrCallingUserId());
|
public void | saveLockPassword(java.lang.String password, int quality, boolean isFallback)Save a lock password. Does not ensure that the password is as good
as the requested mode, but will adjust the mode to be as good as the
pattern.
saveLockPassword(password, quality, isFallback, getCurrentOrCallingUserId());
|
public void | saveLockPassword(java.lang.String password, int quality, boolean isFallback, int userHandle)Save a lock password. Does not ensure that the password is as good
as the requested mode, but will adjust the mode to be as good as the
pattern.
try {
DevicePolicyManager dpm = getDevicePolicyManager();
if (!TextUtils.isEmpty(password)) {
getLockSettings().setLockPassword(password, userHandle);
int computedQuality = computePasswordQuality(password);
// Update the device encryption password.
if (userHandle == UserHandle.USER_OWNER
&& LockPatternUtils.isDeviceEncryptionEnabled()) {
if (!isCredentialRequiredToDecrypt(true)) {
clearEncryptionPassword();
} else {
boolean numeric = computedQuality
== DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
boolean numericComplex = computedQuality
== DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX;
int type = numeric || numericComplex ? StorageManager.CRYPT_TYPE_PIN
: StorageManager.CRYPT_TYPE_PASSWORD;
updateEncryptionPassword(type, password);
}
}
if (!isFallback) {
deleteGallery(userHandle);
setLong(PASSWORD_TYPE_KEY, Math.max(quality, computedQuality), userHandle);
if (computedQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
int letters = 0;
int uppercase = 0;
int lowercase = 0;
int numbers = 0;
int symbols = 0;
int nonletter = 0;
for (int i = 0; i < password.length(); i++) {
char c = password.charAt(i);
if (c >= 'A" && c <= 'Z") {
letters++;
uppercase++;
} else if (c >= 'a" && c <= 'z") {
letters++;
lowercase++;
} else if (c >= '0" && c <= '9") {
numbers++;
nonletter++;
} else {
symbols++;
nonletter++;
}
}
dpm.setActivePasswordState(Math.max(quality, computedQuality),
password.length(), letters, uppercase, lowercase,
numbers, symbols, nonletter, userHandle);
} else {
// The password is not anything.
dpm.setActivePasswordState(
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
0, 0, 0, 0, 0, 0, 0, userHandle);
}
} else {
// Case where it's a fallback for biometric weak
setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK,
userHandle);
setLong(PASSWORD_TYPE_ALTERNATE_KEY, Math.max(quality, computedQuality),
userHandle);
finishBiometricWeak(userHandle);
dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK,
0, 0, 0, 0, 0, 0, 0, userHandle);
}
// Add the password to the password history. We assume all
// password hashes have the same length for simplicity of implementation.
String passwordHistory = getString(PASSWORD_HISTORY_KEY, userHandle);
if (passwordHistory == null) {
passwordHistory = "";
}
int passwordHistoryLength = getRequestedPasswordHistoryLength();
if (passwordHistoryLength == 0) {
passwordHistory = "";
} else {
byte[] hash = passwordToHash(password, userHandle);
passwordHistory = new String(hash) + "," + passwordHistory;
// Cut it to contain passwordHistoryLength hashes
// and passwordHistoryLength -1 commas.
passwordHistory = passwordHistory.substring(0, Math.min(hash.length
* passwordHistoryLength + passwordHistoryLength - 1, passwordHistory
.length()));
}
setString(PASSWORD_HISTORY_KEY, passwordHistory, userHandle);
} else {
// Empty password
getLockSettings().setLockPassword(null, userHandle);
if (userHandle == UserHandle.USER_OWNER) {
// Set the encryption password to default.
updateEncryptionPassword(StorageManager.CRYPT_TYPE_DEFAULT, null);
}
dpm.setActivePasswordState(
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0, 0, 0, 0, 0, 0,
userHandle);
}
onAfterChangingPassword(userHandle);
} catch (RemoteException re) {
// Cant do much
Log.e(TAG, "Unable to save lock password " + re);
}
|
public void | saveLockPattern(java.util.List pattern)Save a lock pattern.
this.saveLockPattern(pattern, false);
|
public void | saveLockPattern(java.util.List pattern, boolean isFallback)Save a lock pattern.
this.saveLockPattern(pattern, isFallback, getCurrentOrCallingUserId());
|
public void | saveLockPattern(java.util.List pattern, boolean isFallback, int userId)Save a lock pattern.
try {
getLockSettings().setLockPattern(patternToString(pattern), userId);
DevicePolicyManager dpm = getDevicePolicyManager();
if (pattern != null) {
// Update the device encryption password.
if (userId == UserHandle.USER_OWNER
&& LockPatternUtils.isDeviceEncryptionEnabled()) {
final boolean required = isCredentialRequiredToDecrypt(true);
if (!required) {
clearEncryptionPassword();
} else {
String stringPattern = patternToString(pattern);
updateEncryptionPassword(StorageManager.CRYPT_TYPE_PATTERN, stringPattern);
}
}
setBoolean(PATTERN_EVER_CHOSEN_KEY, true, userId);
if (!isFallback) {
deleteGallery(userId);
setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, userId);
dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING,
pattern.size(), 0, 0, 0, 0, 0, 0, userId);
} else {
setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK, userId);
setLong(PASSWORD_TYPE_ALTERNATE_KEY,
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, userId);
finishBiometricWeak(userId);
dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK,
0, 0, 0, 0, 0, 0, 0, userId);
}
} else {
dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0,
0, 0, 0, 0, 0, userId);
}
onAfterChangingPassword(userId);
} catch (RemoteException re) {
Log.e(TAG, "Couldn't save lock pattern " + re);
}
|
public boolean | savedPasswordExists()Check to see if the user has stored a lock pattern.
return savedPasswordExists(getCurrentOrCallingUserId());
|
public boolean | savedPasswordExists(int userId)Check to see if the user has stored a lock pattern.
try {
return getLockSettings().havePassword(userId);
} catch (RemoteException re) {
return false;
}
|
public boolean | savedPatternExists()Check to see if the user has stored a lock pattern.
return savedPatternExists(getCurrentOrCallingUserId());
|
public boolean | savedPatternExists(int userId)Check to see if the user has stored a lock pattern.
try {
return getLockSettings().havePattern(userId);
} catch (RemoteException re) {
return false;
}
|
public void | setBiometricWeakLivelinessEnabled(boolean enabled)Set whether biometric weak liveliness is enabled.
long currentFlag = getLong(Settings.Secure.LOCK_BIOMETRIC_WEAK_FLAGS, 0L);
long newFlag;
if (enabled) {
newFlag = currentFlag | FLAG_BIOMETRIC_WEAK_LIVELINESS;
} else {
newFlag = currentFlag & ~FLAG_BIOMETRIC_WEAK_LIVELINESS;
}
setLong(Settings.Secure.LOCK_BIOMETRIC_WEAK_FLAGS, newFlag);
|
private void | setBoolean(java.lang.String secureSettingKey, boolean enabled, int userId)
try {
getLockSettings().setBoolean(secureSettingKey, enabled, userId);
} catch (RemoteException re) {
// What can we do?
Log.e(TAG, "Couldn't write boolean " + secureSettingKey + re);
}
|
private void | setBoolean(java.lang.String secureSettingKey, boolean enabled)
setBoolean(secureSettingKey, enabled, getCurrentOrCallingUserId());
|
public void | setCredentialRequiredToDecrypt(boolean required)
if (getCurrentUser() != UserHandle.USER_OWNER) {
Log.w(TAG, "Only device owner may call setCredentialRequiredForDecrypt()");
return;
}
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.REQUIRE_PASSWORD_TO_DECRYPT, required ? 1 : 0);
|
public void | setCurrentUser(int userId)
sCurrentUserId = userId;
|
public void | setEnabledTrustAgents(java.util.Collection activeTrustAgents)
setEnabledTrustAgents(activeTrustAgents, getCurrentOrCallingUserId());
|
public void | setEnabledTrustAgents(java.util.Collection activeTrustAgents, int userId)
StringBuilder sb = new StringBuilder();
for (ComponentName cn : activeTrustAgents) {
if (sb.length() > 0) {
sb.append(',");
}
sb.append(cn.flattenToShortString());
}
setString(ENABLED_TRUST_AGENTS, sb.toString(), userId);
getTrustManager().reportEnabledTrustAgentsChanged(getCurrentOrCallingUserId());
|
public void | setLockPatternEnabled(boolean enabled)Set whether the lock pattern is enabled.
setLockPatternEnabled(enabled, getCurrentOrCallingUserId());
|
public void | setLockPatternEnabled(boolean enabled, int userHandle)Set whether the lock pattern is enabled.
setBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, enabled, userHandle);
|
public void | setLockScreenDisabled(boolean disable)Disable showing lock screen at all when the DevicePolicyManager allows it.
This is only meaningful if pattern, pin or password are not set.
setLong(DISABLE_LOCKSCREEN_KEY, disable ? 1 : 0);
|
public long | setLockoutAttemptDeadline()Set and store the lockout deadline, meaning the user can't attempt his/her unlock
pattern until the deadline has passed.
final long deadline = SystemClock.elapsedRealtime() + FAILED_ATTEMPT_TIMEOUT_MS;
setLong(LOCKOUT_ATTEMPT_DEADLINE, deadline);
return deadline;
|
private void | setLong(java.lang.String secureSettingKey, long value, int userHandle)
try {
getLockSettings().setLong(secureSettingKey, value, userHandle);
} catch (RemoteException re) {
// What can we do?
Log.e(TAG, "Couldn't write long " + secureSettingKey + re);
}
|
private void | setLong(java.lang.String secureSettingKey, long value)
setLong(secureSettingKey, value, getCurrentOrCallingUserId());
|
public void | setOwnerInfo(java.lang.String info, int userId)
setString(LOCK_SCREEN_OWNER_INFO, info, userId);
updateCryptoUserInfo();
|
public void | setOwnerInfoEnabled(boolean enabled)
setBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, enabled);
updateCryptoUserInfo();
|
public void | setPermanentlyLocked(boolean locked)Set the state of whether the device is permanently locked, meaning the user
must authenticate via other means.
setBoolean(LOCKOUT_PERMANENT_KEY, locked);
|
public void | setPowerButtonInstantlyLocks(boolean enabled)
setBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, enabled);
|
private void | setString(java.lang.String secureSettingKey, java.lang.String value, int userHandle)
try {
getLockSettings().setString(secureSettingKey, value, userHandle);
} catch (RemoteException re) {
// What can we do?
Log.e(TAG, "Couldn't write string " + secureSettingKey + re);
}
|
public void | setVisiblePatternEnabled(boolean enabled)Set whether the visible pattern is enabled.
setBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, enabled);
// Update for crypto if owner
int userId = getCurrentOrCallingUserId();
if (userId != UserHandle.USER_OWNER) {
return;
}
IBinder service = ServiceManager.getService("mount");
if (service == null) {
Log.e(TAG, "Could not find the mount service to update the user info");
return;
}
IMountService mountService = IMountService.Stub.asInterface(service);
try {
mountService.setField(StorageManager.PATTERN_VISIBLE_KEY, enabled ? "1" : "0");
} catch (RemoteException e) {
Log.e(TAG, "Error changing pattern visible state", e);
}
|
public void | setWidgetsEnabled(boolean enabled)
setWidgetsEnabled(enabled, getCurrentOrCallingUserId());
|
public void | setWidgetsEnabled(boolean enabled, int userId)
setBoolean(LOCKSCREEN_WIDGETS_ENABLED, enabled, userId);
|
public static java.util.List | stringToPattern(java.lang.String string)Deserialize a pattern.
List<LockPatternView.Cell> result = Lists.newArrayList();
final byte[] bytes = string.getBytes();
for (int i = 0; i < bytes.length; i++) {
byte b = bytes[i];
result.add(LockPatternView.Cell.of(b / 3, b % 3));
}
return result;
|
private static java.lang.String | toHex(byte[] ary)
final String hex = "0123456789ABCDEF";
String ret = "";
for (int i = 0; i < ary.length; i++) {
ret += hex.charAt((ary[i] >> 4) & 0xf);
ret += hex.charAt(ary[i] & 0xf);
}
return ret;
|
private void | updateCryptoUserInfo()
int userId = getCurrentOrCallingUserId();
if (userId != UserHandle.USER_OWNER) {
return;
}
final String ownerInfo = isOwnerInfoEnabled() ? getOwnerInfo(userId) : "";
IBinder service = ServiceManager.getService("mount");
if (service == null) {
Log.e(TAG, "Could not find the mount service to update the user info");
return;
}
IMountService mountService = IMountService.Stub.asInterface(service);
try {
Log.d(TAG, "Setting owner info");
mountService.setField(StorageManager.OWNER_INFO_KEY, ownerInfo);
} catch (RemoteException e) {
Log.e(TAG, "Error changing user info", e);
}
|
public void | updateEmergencyCallButtonState(android.widget.Button button, boolean shown, boolean showIcon)Sets the emergency button visibility based on isEmergencyCallCapable().
If the emergency button is visible, sets the text on the emergency button
to indicate what action will be taken.
If there's currently a call in progress, the button will take them to the call
if (isEmergencyCallCapable() && shown) {
button.setVisibility(View.VISIBLE);
} else {
button.setVisibility(View.GONE);
return;
}
int textId;
if (isInCall()) {
// show "return to call" text and show phone icon
textId = R.string.lockscreen_return_to_call;
int phoneCallIcon = showIcon ? R.drawable.stat_sys_phone_call : 0;
button.setCompoundDrawablesWithIntrinsicBounds(phoneCallIcon, 0, 0, 0);
} else {
textId = R.string.lockscreen_emergency_call;
int emergencyIcon = showIcon ? R.drawable.ic_emergency : 0;
button.setCompoundDrawablesWithIntrinsicBounds(emergencyIcon, 0, 0, 0);
}
button.setText(textId);
|
private void | updateEncryptionPassword(int type, java.lang.String password)Update the encryption password if it is enabled
if (!isDeviceEncryptionEnabled()) {
return;
}
final IBinder service = ServiceManager.getService("mount");
if (service == null) {
Log.e(TAG, "Could not find the mount service to update the encryption password");
return;
}
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... dummy) {
IMountService mountService = IMountService.Stub.asInterface(service);
try {
mountService.changeEncryptionPassword(type, password);
} catch (RemoteException e) {
Log.e(TAG, "Error changing encryption password", e);
}
return null;
}
}.execute();
|
public boolean | usingBiometricWeak()
return usingBiometricWeak(getCurrentOrCallingUserId());
|
public boolean | usingBiometricWeak(int userId)
int quality = (int) getLong(
PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userId);
return quality == DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK;
|
private void | writeAppWidgets(int[] appWidgetIds)
Settings.Secure.putStringForUser(mContentResolver,
Settings.Secure.LOCK_SCREEN_APPWIDGET_IDS,
combineStrings(appWidgetIds, ","),
UserHandle.USER_CURRENT);
|
public void | writeFallbackAppWidgetId(int appWidgetId)
Settings.Secure.putIntForUser(mContentResolver,
Settings.Secure.LOCK_SCREEN_FALLBACK_APPWIDGET_ID,
appWidgetId,
UserHandle.USER_CURRENT);
|