am 8f589d01: Merge "[LockSettings] migrate patterns to be indexed at \'1\'" into mnc-dev
* commit '8f589d01d15efe88f3678b22db97223c01a54225': [LockSettings] migrate patterns to be indexed at '1'
This commit is contained in:
@@ -841,7 +841,7 @@ public class LockPatternUtils {
|
|||||||
|
|
||||||
final byte[] bytes = string.getBytes();
|
final byte[] bytes = string.getBytes();
|
||||||
for (int i = 0; i < bytes.length; i++) {
|
for (int i = 0; i < bytes.length; i++) {
|
||||||
byte b = bytes[i];
|
byte b = (byte) (bytes[i] - '1');
|
||||||
result.add(LockPatternView.Cell.of(b / 3, b % 3));
|
result.add(LockPatternView.Cell.of(b / 3, b % 3));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -861,7 +861,21 @@ public class LockPatternUtils {
|
|||||||
byte[] res = new byte[patternSize];
|
byte[] res = new byte[patternSize];
|
||||||
for (int i = 0; i < patternSize; i++) {
|
for (int i = 0; i < patternSize; i++) {
|
||||||
LockPatternView.Cell cell = pattern.get(i);
|
LockPatternView.Cell cell = pattern.get(i);
|
||||||
res[i] = (byte) (cell.getRow() * 3 + cell.getColumn());
|
res[i] = (byte) (cell.getRow() * 3 + cell.getColumn() + '1');
|
||||||
|
}
|
||||||
|
return new String(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String patternStringToBaseZero(String pattern) {
|
||||||
|
if (pattern == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
final int patternSize = pattern.length();
|
||||||
|
|
||||||
|
byte[] res = new byte[patternSize];
|
||||||
|
final byte[] bytes = pattern.getBytes();
|
||||||
|
for (int i = 0; i < patternSize; i++) {
|
||||||
|
res[i] = (byte) (bytes[i] - '1');
|
||||||
}
|
}
|
||||||
return new String(res);
|
return new String(res);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -502,12 +502,21 @@ public class LockSettingsService extends ILockSettings.Stub {
|
|||||||
return doVerifyPattern(pattern, true, challenge, userId);
|
return doVerifyPattern(pattern, true, challenge, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private VerifyCredentialResponse doVerifyPattern(String pattern, boolean hasChallenge, long challenge,
|
private VerifyCredentialResponse doVerifyPattern(String pattern, boolean hasChallenge,
|
||||||
int userId) throws RemoteException {
|
long challenge, int userId) throws RemoteException {
|
||||||
checkPasswordReadPermission(userId);
|
checkPasswordReadPermission(userId);
|
||||||
CredentialHash storedHash = mStorage.readPatternHash(userId);
|
CredentialHash storedHash = mStorage.readPatternHash(userId);
|
||||||
return verifyCredential(userId, storedHash, pattern, hasChallenge,
|
boolean shouldReEnrollBaseZero = storedHash != null && storedHash.isBaseZeroPattern;
|
||||||
challenge,
|
|
||||||
|
String patternToVerify;
|
||||||
|
if (shouldReEnrollBaseZero) {
|
||||||
|
patternToVerify = LockPatternUtils.patternStringToBaseZero(pattern);
|
||||||
|
} else {
|
||||||
|
patternToVerify = pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
VerifyCredentialResponse response = verifyCredential(userId, storedHash, patternToVerify,
|
||||||
|
hasChallenge, challenge,
|
||||||
new CredentialUtil() {
|
new CredentialUtil() {
|
||||||
@Override
|
@Override
|
||||||
public void setCredential(String pattern, String oldPattern, int userId)
|
public void setCredential(String pattern, String oldPattern, int userId)
|
||||||
@@ -517,11 +526,19 @@ public class LockSettingsService extends ILockSettings.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] toHash(String pattern, int userId) {
|
public byte[] toHash(String pattern, int userId) {
|
||||||
return mLockPatternUtils.patternToHash(
|
return LockPatternUtils.patternToHash(
|
||||||
mLockPatternUtils.stringToPattern(pattern));
|
LockPatternUtils.stringToPattern(pattern));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (response.getResponseCode() == VerifyCredentialResponse.RESPONSE_OK
|
||||||
|
&& shouldReEnrollBaseZero) {
|
||||||
|
setLockPattern(pattern, patternToVerify, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ class LockSettingsStorage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private static final String SYSTEM_DIRECTORY = "/system/";
|
private static final String SYSTEM_DIRECTORY = "/system/";
|
||||||
private static final String LOCK_PATTERN_FILE = "gatekeeper.gesture.key";
|
private static final String LOCK_PATTERN_FILE = "gatekeeper.pattern.key";
|
||||||
|
private static final String BASE_ZERO_LOCK_PATTERN_FILE = "gatekeeper.gesture.key";
|
||||||
private static final String LEGACY_LOCK_PATTERN_FILE = "gesture.key";
|
private static final String LEGACY_LOCK_PATTERN_FILE = "gesture.key";
|
||||||
private static final String LOCK_PASSWORD_FILE = "gatekeeper.password.key";
|
private static final String LOCK_PASSWORD_FILE = "gatekeeper.password.key";
|
||||||
private static final String LEGACY_LOCK_PASSWORD_FILE = "password.key";
|
private static final String LEGACY_LOCK_PASSWORD_FILE = "password.key";
|
||||||
@@ -81,10 +82,18 @@ class LockSettingsStorage {
|
|||||||
CredentialHash(byte[] hash, int version) {
|
CredentialHash(byte[] hash, int version) {
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
this.isBaseZeroPattern = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CredentialHash(byte[] hash, boolean isBaseZeroPattern) {
|
||||||
|
this.hash = hash;
|
||||||
|
this.version = VERSION_GATEKEEPER;
|
||||||
|
this.isBaseZeroPattern = isBaseZeroPattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] hash;
|
byte[] hash;
|
||||||
int version;
|
int version;
|
||||||
|
boolean isBaseZeroPattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LockSettingsStorage(Context context, Callback callback) {
|
public LockSettingsStorage(Context context, Callback callback) {
|
||||||
@@ -219,6 +228,11 @@ class LockSettingsStorage {
|
|||||||
return new CredentialHash(stored, CredentialHash.VERSION_GATEKEEPER);
|
return new CredentialHash(stored, CredentialHash.VERSION_GATEKEEPER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stored = readFile(getBaseZeroLockPatternFilename(userId));
|
||||||
|
if (stored != null && stored.length > 0) {
|
||||||
|
return new CredentialHash(stored, true);
|
||||||
|
}
|
||||||
|
|
||||||
stored = readFile(getLegacyLockPatternFilename(userId));
|
stored = readFile(getLegacyLockPatternFilename(userId));
|
||||||
if (stored != null && stored.length > 0) {
|
if (stored != null && stored.length > 0) {
|
||||||
return new CredentialHash(stored, CredentialHash.VERSION_LEGACY);
|
return new CredentialHash(stored, CredentialHash.VERSION_LEGACY);
|
||||||
@@ -227,6 +241,7 @@ class LockSettingsStorage {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean hasPassword(int userId) {
|
public boolean hasPassword(int userId) {
|
||||||
return hasFile(getLockPasswordFilename(userId)) ||
|
return hasFile(getLockPasswordFilename(userId)) ||
|
||||||
hasFile(getLegacyLockPasswordFilename(userId));
|
hasFile(getLegacyLockPasswordFilename(userId));
|
||||||
@@ -234,6 +249,7 @@ class LockSettingsStorage {
|
|||||||
|
|
||||||
public boolean hasPattern(int userId) {
|
public boolean hasPattern(int userId) {
|
||||||
return hasFile(getLockPatternFilename(userId)) ||
|
return hasFile(getLockPatternFilename(userId)) ||
|
||||||
|
hasFile(getBaseZeroLockPatternFilename(userId)) ||
|
||||||
hasFile(getLegacyLockPatternFilename(userId));
|
hasFile(getLegacyLockPatternFilename(userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,6 +317,13 @@ class LockSettingsStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteFile(String name) {
|
||||||
|
File f = new File(name);
|
||||||
|
if (f != null) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void writePatternHash(byte[] hash, int userId) {
|
public void writePatternHash(byte[] hash, int userId) {
|
||||||
mStoredCredentialType = hash == null
|
mStoredCredentialType = hash == null
|
||||||
? CredentialHash.TYPE_NONE
|
? CredentialHash.TYPE_NONE
|
||||||
@@ -345,6 +368,10 @@ class LockSettingsStorage {
|
|||||||
return getLockCredentialFilePathForUser(userId, LEGACY_LOCK_PASSWORD_FILE);
|
return getLockCredentialFilePathForUser(userId, LEGACY_LOCK_PASSWORD_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getBaseZeroLockPatternFilename(int userId) {
|
||||||
|
return getLockCredentialFilePathForUser(userId, BASE_ZERO_LOCK_PATTERN_FILE);
|
||||||
|
}
|
||||||
|
|
||||||
private String getLockCredentialFilePathForUser(int userId, String basename) {
|
private String getLockCredentialFilePathForUser(int userId, String basename) {
|
||||||
userId = getUserParentOrSelfId(userId);
|
userId = getUserParentOrSelfId(userId);
|
||||||
String dataSystemDirectory =
|
String dataSystemDirectory =
|
||||||
|
|||||||
Reference in New Issue
Block a user