Merge "Fix race condition in checkPattern and verifyPattern." into cw-f-dev
This commit is contained in:
@@ -4,6 +4,7 @@ import android.os.AsyncTask;
|
|||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils.RequestThrottledException;
|
import com.android.internal.widget.LockPatternUtils.RequestThrottledException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,11 +62,19 @@ public final class LockPatternChecker {
|
|||||||
final OnVerifyCallback callback) {
|
final OnVerifyCallback callback) {
|
||||||
AsyncTask<Void, Void, byte[]> task = new AsyncTask<Void, Void, byte[]>() {
|
AsyncTask<Void, Void, byte[]> task = new AsyncTask<Void, Void, byte[]>() {
|
||||||
private int mThrottleTimeout;
|
private int mThrottleTimeout;
|
||||||
|
private List<LockPatternView.Cell> patternCopy;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
// Make a copy of the pattern to prevent race conditions.
|
||||||
|
// No need to clone the individual cells because they are immutable.
|
||||||
|
patternCopy = new ArrayList(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected byte[] doInBackground(Void... args) {
|
protected byte[] doInBackground(Void... args) {
|
||||||
try {
|
try {
|
||||||
return utils.verifyPattern(pattern, challenge, userId);
|
return utils.verifyPattern(patternCopy, challenge, userId);
|
||||||
} catch (RequestThrottledException ex) {
|
} catch (RequestThrottledException ex) {
|
||||||
mThrottleTimeout = ex.getTimeoutMs();
|
mThrottleTimeout = ex.getTimeoutMs();
|
||||||
return null;
|
return null;
|
||||||
@@ -95,11 +104,19 @@ public final class LockPatternChecker {
|
|||||||
final OnCheckCallback callback) {
|
final OnCheckCallback callback) {
|
||||||
AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() {
|
AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() {
|
||||||
private int mThrottleTimeout;
|
private int mThrottleTimeout;
|
||||||
|
private List<LockPatternView.Cell> patternCopy;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
// Make a copy of the pattern to prevent race conditions.
|
||||||
|
// No need to clone the individual cells because they are immutable.
|
||||||
|
patternCopy = new ArrayList(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(Void... args) {
|
protected Boolean doInBackground(Void... args) {
|
||||||
try {
|
try {
|
||||||
return utils.checkPattern(pattern, userId, callback::onEarlyMatched);
|
return utils.checkPattern(patternCopy, userId, callback::onEarlyMatched);
|
||||||
} catch (RequestThrottledException ex) {
|
} catch (RequestThrottledException ex) {
|
||||||
mThrottleTimeout = ex.getTimeoutMs();
|
mThrottleTimeout = ex.getTimeoutMs();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user