summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nancy Zheng <nzheng@google.com> 2016-10-07 18:00:24 +0000
committer android-build-merger <android-build-merger@google.com> 2016-10-07 18:00:24 +0000
commitce2cef46b36b4529c00c6ebf992c7f50930c6e59 (patch)
tree8241dfed82b55a63e6f2316be1b6980f48014191
parent66fd2a5d1b8ecbd991e2227ae6da592b47b38b37 (diff)
parent9475460e6627351d267450793b67c383089b551b (diff)
Fix race condition in checkPattern and verifyPattern.
am: 9475460e66 Change-Id: I88a9304c1f7d23b70cb23988112fc6c34db51338
-rw-r--r--core/java/com/android/internal/widget/LockPatternChecker.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/core/java/com/android/internal/widget/LockPatternChecker.java b/core/java/com/android/internal/widget/LockPatternChecker.java
index df9b0ddc1804..6defd1e8d9f2 100644
--- a/core/java/com/android/internal/widget/LockPatternChecker.java
+++ b/core/java/com/android/internal/widget/LockPatternChecker.java
@@ -4,6 +4,7 @@ import android.os.AsyncTask;
import com.android.internal.widget.LockPatternUtils.RequestThrottledException;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -61,11 +62,19 @@ public final class LockPatternChecker {
final OnVerifyCallback callback) {
AsyncTask<Void, Void, byte[]> task = new AsyncTask<Void, Void, byte[]>() {
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
protected byte[] doInBackground(Void... args) {
try {
- return utils.verifyPattern(pattern, challenge, userId);
+ return utils.verifyPattern(patternCopy, challenge, userId);
} catch (RequestThrottledException ex) {
mThrottleTimeout = ex.getTimeoutMs();
return null;
@@ -95,11 +104,19 @@ public final class LockPatternChecker {
final OnCheckCallback callback) {
AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() {
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
protected Boolean doInBackground(Void... args) {
try {
- return utils.checkPattern(pattern, userId, callback::onEarlyMatched);
+ return utils.checkPattern(patternCopy, userId, callback::onEarlyMatched);
} catch (RequestThrottledException ex) {
mThrottleTimeout = ex.getTimeoutMs();
return false;