summaryrefslogtreecommitdiffstats
path: root/core/java/com/android/internal/widget/LockPatternUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/com/android/internal/widget/LockPatternUtils.java')
-rw-r--r--core/java/com/android/internal/widget/LockPatternUtils.java72
1 files changed, 69 insertions, 3 deletions
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index 5dc91d2..92f520b 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -462,7 +462,8 @@ public class LockPatternUtils {
// well, we tried...
}
- if (userHandle == UserHandle.USER_OWNER) {
+ if (userHandle == UserHandle.USER_OWNER
+ && !isSeparateEncryptionPasswordEnabled()) {
// Set the encryption password to default.
updateEncryptionPassword(StorageManager.CRYPT_TYPE_DEFAULT, null);
}
@@ -523,7 +524,8 @@ public class LockPatternUtils {
// Update the device encryption password.
if (userId == UserHandle.USER_OWNER
- && LockPatternUtils.isDeviceEncryptionEnabled()) {
+ && LockPatternUtils.isDeviceEncryptionEnabled()
+ && !isSeparateEncryptionPasswordEnabled()) {
if (!shouldEncryptWithCredentials(true)) {
clearEncryptionPassword();
} else {
@@ -732,7 +734,8 @@ public class LockPatternUtils {
// Update the device encryption password.
if (userHandle == UserHandle.USER_OWNER
- && LockPatternUtils.isDeviceEncryptionEnabled()) {
+ && LockPatternUtils.isDeviceEncryptionEnabled()
+ && !isSeparateEncryptionPasswordEnabled()) {
if (!shouldEncryptWithCredentials(true)) {
clearEncryptionPassword();
} else {
@@ -1089,6 +1092,69 @@ public class LockPatternUtils {
}
}
+ private void updateEncryptionPasswordFromPassword(String password) {
+ if (!TextUtils.isEmpty(password)) {
+ int computedQuality = computePasswordQuality(password);
+ 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);
+ } else {
+ clearEncryptionPassword();
+ }
+ }
+
+ /**
+ * Set the encryption password separately from the lockscreen password.
+ *
+ * @param password The password to save
+ */
+ public void setSeparateEncryptionPassword(String password) {
+ updateEncryptionPasswordFromPassword(password);
+ setSeparateEncryptionPasswordEnabled(true);
+ }
+
+ /**
+ * Replace the separate encryption password by tying it to the lockscreen
+ * password. No change will occur if the provided lockscreen password is
+ * incorrect.
+ *
+ * @param password The current lockscreen password
+ * @return Whether the lockscreen password was correct.
+ */
+ public void replaceSeparateEncryptionPassword(String password) {
+ updateEncryptionPasswordFromPassword(password);
+ setSeparateEncryptionPasswordEnabled(false);
+ }
+
+ /**
+ * Replace the separate encryption password by tying it to the lockscreen
+ * pattern. No change will occur if the provided lockscreen password is
+ * incorrect.
+ *
+ * @param pattern The current lockscreen pattern
+ * @return Whether the lockscreen pattern was correct.
+ */
+ public void replaceSeparateEncryptionPasswordWithPattern(List<LockPatternView.Cell> pattern) {
+ String stringPattern = patternToString(pattern);
+ updateEncryptionPassword(StorageManager.CRYPT_TYPE_PATTERN, stringPattern);
+ setSeparateEncryptionPasswordEnabled(false);
+ }
+
+ /**
+ * @return Whether the encryption password is separate from the lockscreen password.
+ */
+ public boolean isSeparateEncryptionPasswordEnabled() {
+ return getBoolean(Settings.Secure.LOCK_SEPARATE_ENCRYPTION_PASSWORD, false, UserHandle.USER_OWNER);
+ }
+
+ private void setSeparateEncryptionPasswordEnabled(boolean enabled) {
+ setBoolean(Settings.Secure.LOCK_SEPARATE_ENCRYPTION_PASSWORD, enabled, UserHandle.USER_OWNER);
+ }
+
/**
* @return Whether tactile feedback for the pattern is enabled.
*/