summaryrefslogtreecommitdiffstats
path: root/core/java/com/android/internal/widget/LockPatternUtils.java
diff options
context:
space:
mode:
authorAdrian Roos <roosa@google.com>2015-04-16 17:11:20 -0700
committerAdrian Roos <roosa@google.com>2015-04-28 11:49:00 -0700
commit8150d2a2a12b38598fd55d8ae3c3b5662ec3520f (patch)
treedf0c100c35959c7317b8255865cdadf791364ec6 /core/java/com/android/internal/widget/LockPatternUtils.java
parentc8240411c38b78ac8095f6e8067f7bcc7046f502 (diff)
downloadframeworks_base-8150d2a2a12b38598fd55d8ae3c3b5662ec3520f.zip
frameworks_base-8150d2a2a12b38598fd55d8ae3c3b5662ec3520f.tar.gz
frameworks_base-8150d2a2a12b38598fd55d8ae3c3b5662ec3520f.tar.bz2
Require explicit userId in LockPatternUtils
Bug: 18931518 Change-Id: Ib03f37df9135f0324a998c62d165d8eea46328c8
Diffstat (limited to 'core/java/com/android/internal/widget/LockPatternUtils.java')
-rw-r--r--core/java/com/android/internal/widget/LockPatternUtils.java215
1 files changed, 58 insertions, 157 deletions
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index 1096e34..53c0184 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -20,6 +20,7 @@ import android.Manifest;
import android.app.ActivityManagerNative;
import android.app.admin.DevicePolicyManager;
import android.app.trust.TrustManager;
+import android.bluetooth.BluetoothClass;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
@@ -188,67 +189,55 @@ public class LockPatternUtils {
return mLockSettingsService;
}
- public int getRequestedMinimumPasswordLength() {
- return getDevicePolicyManager().getPasswordMinimumLength(null, getCurrentOrCallingUserId());
+ public int getRequestedMinimumPasswordLength(int userId) {
+ return getDevicePolicyManager().getPasswordMinimumLength(null, userId);
}
/**
* Gets the device policy password mode. If the mode is non-specific, returns
* MODE_PATTERN which allows the user to choose anything.
*/
- public int getRequestedPasswordQuality() {
- return getDevicePolicyManager().getPasswordQuality(null, getCurrentOrCallingUserId());
- }
-
- public int getRequestedPasswordHistoryLength() {
- return getRequestedPasswordHistoryLength(getCurrentOrCallingUserId());
+ public int getRequestedPasswordQuality(int userId) {
+ return getDevicePolicyManager().getPasswordQuality(null, userId);
}
private int getRequestedPasswordHistoryLength(int userId) {
return getDevicePolicyManager().getPasswordHistoryLength(null, userId);
}
- public int getRequestedPasswordMinimumLetters() {
- return getDevicePolicyManager().getPasswordMinimumLetters(null,
- getCurrentOrCallingUserId());
+ public int getRequestedPasswordMinimumLetters(int userId) {
+ return getDevicePolicyManager().getPasswordMinimumLetters(null, userId);
}
- public int getRequestedPasswordMinimumUpperCase() {
- return getDevicePolicyManager().getPasswordMinimumUpperCase(null,
- getCurrentOrCallingUserId());
+ public int getRequestedPasswordMinimumUpperCase(int userId) {
+ return getDevicePolicyManager().getPasswordMinimumUpperCase(null, userId);
}
- public int getRequestedPasswordMinimumLowerCase() {
- return getDevicePolicyManager().getPasswordMinimumLowerCase(null,
- getCurrentOrCallingUserId());
+ public int getRequestedPasswordMinimumLowerCase(int userId) {
+ return getDevicePolicyManager().getPasswordMinimumLowerCase(null, userId);
}
- public int getRequestedPasswordMinimumNumeric() {
- return getDevicePolicyManager().getPasswordMinimumNumeric(null,
- getCurrentOrCallingUserId());
+ public int getRequestedPasswordMinimumNumeric(int userId) {
+ return getDevicePolicyManager().getPasswordMinimumNumeric(null, userId);
}
- public int getRequestedPasswordMinimumSymbols() {
- return getDevicePolicyManager().getPasswordMinimumSymbols(null,
- getCurrentOrCallingUserId());
+ public int getRequestedPasswordMinimumSymbols(int userId) {
+ return getDevicePolicyManager().getPasswordMinimumSymbols(null, userId);
}
- public int getRequestedPasswordMinimumNonLetter() {
- return getDevicePolicyManager().getPasswordMinimumNonLetter(null,
- getCurrentOrCallingUserId());
+ public int getRequestedPasswordMinimumNonLetter(int userId) {
+ return getDevicePolicyManager().getPasswordMinimumNonLetter(null, userId);
}
- public void reportFailedPasswordAttempt() {
- int userId = getCurrentOrCallingUserId();
+ public void reportFailedPasswordAttempt(int userId) {
getDevicePolicyManager().reportFailedPasswordAttempt(userId);
getTrustManager().reportUnlockAttempt(false /* authenticated */, userId);
getTrustManager().reportRequireCredentialEntry(userId);
}
- public void reportSuccessfulPasswordAttempt() {
- getDevicePolicyManager().reportSuccessfulPasswordAttempt(getCurrentOrCallingUserId());
- getTrustManager().reportUnlockAttempt(true /* authenticated */,
- getCurrentOrCallingUserId());
+ public void reportSuccessfulPasswordAttempt(int userId) {
+ getDevicePolicyManager().reportSuccessfulPasswordAttempt(userId);
+ getTrustManager().reportUnlockAttempt(true /* authenticated */, userId);
}
public void setCurrentUser(int userId) {
@@ -267,15 +256,15 @@ public class LockPatternUtils {
}
}
- 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();
- }
- }
+// 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();
+// }
+// }
/**
* Check to see if a pattern matches the saved pattern.
@@ -286,8 +275,7 @@ public class LockPatternUtils {
* @param challenge The challenge to verify against the pattern
* @return the attestation that the challenge was verified, or null.
*/
- public byte[] verifyPattern(List<LockPatternView.Cell> pattern, long challenge) {
- final int userId = getCurrentOrCallingUserId();
+ public byte[] verifyPattern(List<LockPatternView.Cell> pattern, long challenge, int userId) {
try {
return getLockSettings().verifyPattern(patternToString(pattern), challenge, userId);
} catch (RemoteException re) {
@@ -301,8 +289,7 @@ public class LockPatternUtils {
* @param pattern The pattern to check.
* @return Whether the pattern matches the stored one.
*/
- public boolean checkPattern(List<LockPatternView.Cell> pattern) {
- final int userId = getCurrentOrCallingUserId();
+ public boolean checkPattern(List<LockPatternView.Cell> pattern, int userId) {
try {
return getLockSettings().checkPattern(patternToString(pattern), userId);
} catch (RemoteException re) {
@@ -319,8 +306,7 @@ public class LockPatternUtils {
* @param challenge The challenge to verify against the password
* @return the attestation that the challenge was verified, or null.
*/
- public byte[] verifyPassword(String password, long challenge) {
- final int userId = getCurrentOrCallingUserId();
+ public byte[] verifyPassword(String password, long challenge, int userId) {
try {
return getLockSettings().verifyPassword(password, challenge, userId);
} catch (RemoteException re) {
@@ -334,8 +320,7 @@ public class LockPatternUtils {
* @param password The password to check.
* @return Whether the password matches the stored one.
*/
- public boolean checkPassword(String password) {
- final int userId = getCurrentOrCallingUserId();
+ public boolean checkPassword(String password, int userId) {
try {
return getLockSettings().checkPassword(password, userId);
} catch (RemoteException re) {
@@ -348,8 +333,7 @@ public class LockPatternUtils {
* Note that this also clears vold's copy of the password.
* @return Whether the vold password matches or not.
*/
- public boolean checkVoldPassword() {
- final int userId = getCurrentOrCallingUserId();
+ public boolean checkVoldPassword(int userId) {
try {
return getLockSettings().checkVoldPassword(userId);
} catch (RemoteException re) {
@@ -364,8 +348,7 @@ public class LockPatternUtils {
* @param password The password to check.
* @return Whether the password matches any in the history.
*/
- public boolean checkPasswordHistory(String password) {
- int userId = getCurrentOrCallingUserId();
+ public boolean checkPasswordHistory(String password, int userId) {
String passwordHashString = new String(
passwordToHash(password, userId), StandardCharsets.UTF_8);
String passwordHistory = getString(PASSWORD_HISTORY_KEY, userId);
@@ -374,7 +357,7 @@ public class LockPatternUtils {
}
// Password History may be too long...
int passwordHashLength = passwordHashString.length();
- int passwordHistoryLength = getRequestedPasswordHistoryLength();
+ int passwordHistoryLength = getRequestedPasswordHistoryLength(userId);
if(passwordHistoryLength == 0) {
return false;
}
@@ -416,16 +399,8 @@ public class LockPatternUtils {
*
* @return True if the user has ever chosen a pattern.
*/
- public boolean isPatternEverChosen() {
- return getBoolean(PATTERN_EVER_CHOSEN_KEY, false, getCurrentOrCallingUserId());
- }
-
- /**
- * Used by device policy manager to validate the current password
- * information it has.
- */
- public int getActivePasswordQuality() {
- return getActivePasswordQuality(getCurrentOrCallingUserId());
+ public boolean isPatternEverChosen(int userId) {
+ return getBoolean(PATTERN_EVER_CHOSEN_KEY, false, userId);
}
/**
@@ -448,10 +423,6 @@ public class LockPatternUtils {
return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
}
- public void clearLock() {
- clearLock(getCurrentOrCallingUserId());
- }
-
/**
* Clear any lock pattern or password.
*/
@@ -479,16 +450,6 @@ public class LockPatternUtils {
}
/**
- * Disable showing lock screen at all when the DevicePolicyManager allows it.
- * This is only meaningful if pattern, pin or password are not set.
- *
- * @param disable Disables lock screen when true
- */
- public void setLockScreenDisabled(boolean disable) {
- setLockScreenDisabled(disable, getCurrentOrCallingUserId());
- }
-
- /**
* Disable showing lock screen at all for a given user.
* This is only meaningful if pattern, pin or password are not set.
*
@@ -505,21 +466,16 @@ public class LockPatternUtils {
*
* @return true if lock screen is disabled
*/
- public boolean isLockScreenDisabled() {
- return !isSecure() &&
- getBoolean(DISABLE_LOCKSCREEN_KEY, false, getCurrentOrCallingUserId());
+ public boolean isLockScreenDisabled(int userId) {
+ return !isSecure(userId) &&
+ getBoolean(DISABLE_LOCKSCREEN_KEY, false, userId);
}
/**
* Save a lock pattern.
* @param pattern The new pattern to save.
- * @param savedPattern The previously saved pattern, or null if none
+ * @param userId the user whose pattern is to be saved.
*/
- public void saveLockPattern(List<LockPatternView.Cell> pattern,
- String savedPattern) {
- this.saveLockPattern(pattern, savedPattern, getCurrentOrCallingUserId());
- }
-
public void saveLockPattern(List<LockPatternView.Cell> pattern, int userId) {
this.saveLockPattern(pattern, null, userId);
}
@@ -588,8 +544,7 @@ public class LockPatternUtils {
updateCryptoUserInfo(userId);
}
- public void setOwnerInfoEnabled(boolean enabled) {
- int userId = getCurrentOrCallingUserId();
+ public void setOwnerInfoEnabled(boolean enabled, int userId) {
setBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, enabled, userId);
updateCryptoUserInfo(userId);
}
@@ -598,11 +553,7 @@ public class LockPatternUtils {
return getString(LOCK_SCREEN_OWNER_INFO, userId);
}
- public boolean isOwnerInfoEnabled() {
- return isOwnerInfoEnabled(getCurrentOrCallingUserId());
- }
-
- private boolean isOwnerInfoEnabled(int userId) {
+ public boolean isOwnerInfoEnabled(int userId) {
return getBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, false, userId);
}
@@ -724,21 +675,10 @@ public class LockPatternUtils {
/**
* 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.
+ * password.
* @param password The password to save
* @param savedPassword The previously saved lock password, or null if none
* @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
- */
- public void saveLockPassword(String password, String savedPassword, int quality) {
- saveLockPassword(password, savedPassword, quality, getCurrentOrCallingUserId());
- }
-
- /**
- * 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.
- * @param password The password to save
- * @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
* @param userHandle The userId of the user to change the password for
*/
public void saveLockPassword(String password, String savedPassword, int quality,
@@ -865,16 +805,6 @@ public class LockPatternUtils {
}
/**
- * Retrieves the quality mode we're in.
- * {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
- *
- * @return stored password quality
- */
- public int getKeyguardStoredPasswordQuality() {
- return getKeyguardStoredPasswordQuality(getCurrentOrCallingUserId());
- }
-
- /**
* Retrieves the quality mode for {@param userHandle}.
* {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
*
@@ -997,13 +927,6 @@ public class LockPatternUtils {
}
/**
- * @return Whether the lock screen is secured.
- */
- public boolean isSecure() {
- return isSecure(getCurrentOrCallingUserId());
- }
-
- /**
* @param userId the user for which to report the value
* @return Whether the lock screen is secured.
*/
@@ -1012,13 +935,6 @@ public class LockPatternUtils {
return isLockPatternEnabled(mode, userId) || isLockPasswordEnabled(mode, userId);
}
- /**
- * @return Whether the lock password is enabled
- */
- public boolean isLockPasswordEnabled() {
- return isLockPasswordEnabled(getCurrentOrCallingUserId());
- }
-
public boolean isLockPasswordEnabled(int userId) {
return isLockPasswordEnabled(getKeyguardStoredPasswordQuality(userId), userId);
}
@@ -1035,10 +951,6 @@ public class LockPatternUtils {
/**
* @return Whether the lock pattern is enabled
*/
- public boolean isLockPatternEnabled() {
- return isLockPatternEnabled(getCurrentOrCallingUserId());
- }
-
public boolean isLockPatternEnabled(int userId) {
return isLockPatternEnabled(getKeyguardStoredPasswordQuality(userId), userId);
}
@@ -1051,16 +963,14 @@ public class LockPatternUtils {
/**
* @return Whether the visible pattern is enabled.
*/
- public boolean isVisiblePatternEnabled() {
- return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, false, getCurrentOrCallingUserId());
+ public boolean isVisiblePatternEnabled(int userId) {
+ return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, false, userId);
}
/**
* Set whether the visible pattern is enabled.
*/
- public void setVisiblePatternEnabled(boolean enabled) {
- int userId = getCurrentOrCallingUserId();
-
+ public void setVisiblePatternEnabled(boolean enabled, int userId) {
setBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, enabled, userId);
// Update for crypto if owner
@@ -1095,9 +1005,9 @@ public class LockPatternUtils {
* pattern until the deadline has passed.
* @return the chosen deadline.
*/
- public long setLockoutAttemptDeadline() {
+ public long setLockoutAttemptDeadline(int userId) {
final long deadline = SystemClock.elapsedRealtime() + FAILED_ATTEMPT_TIMEOUT_MS;
- setLong(LOCKOUT_ATTEMPT_DEADLINE, deadline, getCurrentOrCallingUserId());
+ setLong(LOCKOUT_ATTEMPT_DEADLINE, deadline, userId);
return deadline;
}
@@ -1106,8 +1016,8 @@ public class LockPatternUtils {
* attempt to enter his/her lock pattern, or 0 if the user is welcome to
* enter a pattern.
*/
- public long getLockoutAttemptDeadline() {
- final long deadline = getLong(LOCKOUT_ATTEMPT_DEADLINE, 0L, getCurrentOrCallingUserId());
+ public long getLockoutAttemptDeadline(int userId) {
+ final long deadline = getLong(LOCKOUT_ATTEMPT_DEADLINE, 0L, userId);
final long now = SystemClock.elapsedRealtime();
if (deadline < now || deadline > (now + FAILED_ATTEMPT_TIMEOUT_MS)) {
return 0L;
@@ -1166,21 +1076,12 @@ public class LockPatternUtils {
}
}
- public void setPowerButtonInstantlyLocks(boolean enabled) {
- setBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, enabled, getCurrentOrCallingUserId());
- }
-
- public boolean getPowerButtonInstantlyLocks() {
- return getBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, true,
- getCurrentOrCallingUserId());
- }
-
- public void setEnabledTrustAgents(Collection<ComponentName> activeTrustAgents) {
- setEnabledTrustAgents(activeTrustAgents, getCurrentOrCallingUserId());
+ public void setPowerButtonInstantlyLocks(boolean enabled, int userId) {
+ setBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, enabled, userId);
}
- public List<ComponentName> getEnabledTrustAgents() {
- return getEnabledTrustAgents(getCurrentOrCallingUserId());
+ public boolean getPowerButtonInstantlyLocks(int userId) {
+ return getBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, true, userId);
}
public void setEnabledTrustAgents(Collection<ComponentName> activeTrustAgents, int userId) {
@@ -1192,7 +1093,7 @@ public class LockPatternUtils {
sb.append(cn.flattenToShortString());
}
setString(ENABLED_TRUST_AGENTS, sb.toString(), userId);
- getTrustManager().reportEnabledTrustAgentsChanged(getCurrentOrCallingUserId());
+ getTrustManager().reportEnabledTrustAgentsChanged(userId);
}
public List<ComponentName> getEnabledTrustAgents(int userId) {