diff options
author | Rowan Decker <smasher816@gmail.com> | 2012-12-17 19:44:38 +0100 |
---|---|---|
committer | Rowan Decker <smasher816@gmail.com> | 2012-12-30 19:22:59 +0100 |
commit | 9f1827b6358cd490116549ad1c447da16544c226 (patch) | |
tree | 4c7ccaaf2b1ea4b6d6fac7b912bd1adcac92b20a /core/java/com/android/internal/widget/LockPatternUtils.java | |
parent | 6e7ad8adea65fdb92fa0838aba038f5561f83135 (diff) | |
download | frameworks_base-9f1827b6358cd490116549ad1c447da16544c226.zip frameworks_base-9f1827b6358cd490116549ad1c447da16544c226.tar.gz frameworks_base-9f1827b6358cd490116549ad1c447da16544c226.tar.bz2 |
Framwork: Add support for variable size pattern lockscreen (Part 1/2)
Part 2: http://review.cyanogenmod.org/#/c/28534/2
Forward port of: http://review.cyanogenmod.org/#/c/20613/
The default size has been replaced with a constant PATTERN_SIZE_DEFAULT=3
It now parses the longInt as a byte, no longer requiring a get/set Int function.
Negative numbers and sizes over 127 do not make sense, so a byte works well.
In addition the logging has been removed.
Patch Set 1-2: Initial port
Patch Set 3-5: New implementation using seperate file for non standard sizes
Patch Set 6: Use AOSP code style
Patch Set 7-9: Remove static code
Patch Set 10: Correct a comment
Change-Id: Ia06fc5a7dc2819f78843fddcf1470d85ebe2ad13
Diffstat (limited to 'core/java/com/android/internal/widget/LockPatternUtils.java')
-rw-r--r-- | core/java/com/android/internal/widget/LockPatternUtils.java | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java index 5453a0b..797b58f 100644 --- a/core/java/com/android/internal/widget/LockPatternUtils.java +++ b/core/java/com/android/internal/widget/LockPatternUtils.java @@ -103,6 +103,11 @@ public class LockPatternUtils { public static final int MIN_LOCK_PATTERN_SIZE = 4; /** + * The default size of the pattern lockscreen. Ex: 3x3 + */ + public static final byte PATTERN_SIZE_DEFAULT = 3; + + /** * The minimum number of dots the user must include in a wrong pattern * attempt for it to be counted against the counts that affect * {@link #FAILED_ATTEMPTS_BEFORE_TIMEOUT} and {@link #FAILED_ATTEMPTS_BEFORE_RESET} @@ -515,7 +520,7 @@ public class LockPatternUtils { */ public void saveLockPattern(List<LockPatternView.Cell> pattern, boolean isFallback) { // Compute the hash - final byte[] hash = LockPatternUtils.patternToHash(pattern); + final byte[] hash = patternToHash(pattern); try { getLockSettings().setLockPattern(hash, getCurrentOrCallingUserId()); DevicePolicyManager dpm = getDevicePolicyManager(); @@ -759,13 +764,16 @@ public class LockPatternUtils { * @param string The pattern serialized with {@link #patternToString} * @return The pattern. */ - public static List<LockPatternView.Cell> stringToPattern(String string) { + public List<LockPatternView.Cell> stringToPattern(String string) { List<LockPatternView.Cell> result = Lists.newArrayList(); + final byte size = getLockPatternSize(); + LockPatternView.Cell.updateSize(size); + 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)); + result.add(LockPatternView.Cell.of(b / size, b % size, size)); } return result; } @@ -775,7 +783,7 @@ public class LockPatternUtils { * @param pattern The pattern. * @return The pattern in string form. */ - public static String patternToString(List<LockPatternView.Cell> pattern) { + public String patternToString(List<LockPatternView.Cell> pattern) { if (pattern == null) { return ""; } @@ -784,7 +792,7 @@ public class LockPatternUtils { 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()); + res[i] = (byte) (cell.getRow() * getLockPatternSize() + cell.getColumn()); } return new String(res); } @@ -796,7 +804,7 @@ public class LockPatternUtils { * @param pattern the gesture pattern. * @return the hash of the pattern in a byte array. */ - private static byte[] patternToHash(List<LockPatternView.Cell> pattern) { + private byte[] patternToHash(List<LockPatternView.Cell> pattern) { if (pattern == null) { return null; } @@ -805,7 +813,7 @@ public class LockPatternUtils { 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()); + res[i] = (byte) (cell.getRow() * getLockPatternSize() + cell.getColumn()); } try { MessageDigest md = MessageDigest.getInstance("SHA-1"); @@ -974,6 +982,24 @@ public class LockPatternUtils { } /** + * @return the pattern lockscreen size + */ + public byte getLockPatternSize() { + try { + return getLockSettings().getLockPatternSize(getCurrentOrCallingUserId()); + } catch (RemoteException re) { + return PATTERN_SIZE_DEFAULT; + } + } + + /** + * Set the pattern lockscreen size + */ + public void setLockPatternSize(long size) { + setLong(Settings.Secure.LOCK_PATTERN_SIZE, size); + } + + /** * Set and store the lockout deadline, meaning the user can't attempt his/her unlock * pattern until the deadline has passed. * @return the chosen deadline. |