Loading core/java/com/android/internal/widget/LockPatternChecker.java 0 → 100644 +146 −0 Original line number Diff line number Diff line package com.android.internal.widget; import android.os.AsyncTask; import java.util.List; /** * Helper class to check/verify PIN/Password/Pattern asynchronously. */ public final class LockPatternChecker { /** * Interface for a callback to be invoked after security check. */ public interface OnCheckCallback { /** * Invoked when a security check is finished. * * @param matched Whether the PIN/Password/Pattern matches the stored one. */ void onChecked(boolean matched); } /** * Interface for a callback to be invoked after security verification. */ public interface OnVerifyCallback { /** * Invoked when a security verification is finished. * * @param attestation The attestation that the challenge was verified, or null. */ void onVerified(byte[] attestation); } /** * Verify a pattern asynchronously. * * @param utils The LockPatternUtils instance to use. * @param pattern The pattern to check. * @param challenge The challenge to verify against the pattern. * @param userId The user to check against the pattern. * @param callback The callback to be invoked with the verification result. */ public static AsyncTask<?, ?, ?> verifyPattern(final LockPatternUtils utils, final List<LockPatternView.Cell> pattern, final long challenge, final int userId, final OnVerifyCallback callback) { AsyncTask<Void, Void, byte[]> task = new AsyncTask<Void, Void, byte[]>() { @Override protected byte[] doInBackground(Void... args) { return utils.verifyPattern(pattern, challenge, userId); } @Override protected void onPostExecute(byte[] result) { callback.onVerified(result); } }; task.execute(); return task; } /** * Checks a pattern asynchronously. * * @param utils The LockPatternUtils instance to use. * @param pattern The pattern to check. * @param userId The user to check against the pattern. * @param callback The callback to be invoked with the check result. */ public static AsyncTask<?, ?, ?> checkPattern(final LockPatternUtils utils, final List<LockPatternView.Cell> pattern, final int userId, final OnCheckCallback callback) { AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() { @Override protected Boolean doInBackground(Void... args) { return utils.checkPattern(pattern, userId); } @Override protected void onPostExecute(Boolean result) { callback.onChecked(result); } }; task.execute(); return task; } /** * Verify a password asynchronously. * * @param utils The LockPatternUtils instance to use. * @param password The password to check. * @param challenge The challenge to verify against the pattern. * @param userId The user to check against the pattern. * @param callback The callback to be invoked with the verification result. */ public static AsyncTask<?, ?, ?> verifyPassword(final LockPatternUtils utils, final String password, final long challenge, final int userId, final OnVerifyCallback callback) { AsyncTask<Void, Void, byte[]> task = new AsyncTask<Void, Void, byte[]>() { @Override protected byte[] doInBackground(Void... args) { return utils.verifyPassword(password, challenge, userId); } @Override protected void onPostExecute(byte[] result) { callback.onVerified(result); } }; task.execute(); return task; } /** * Checks a password asynchronously. * * @param utils The LockPatternUtils instance to use. * @param password The password to check. * @param userId The user to check against the pattern. * @param callback The callback to be invoked with the check result. */ public static AsyncTask<?, ?, ?> checkPassword(final LockPatternUtils utils, final String password, final int userId, final OnCheckCallback callback) { AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() { @Override protected Boolean doInBackground(Void... args) { return utils.checkPassword(password, userId); } @Override protected void onPostExecute(Boolean result) { callback.onChecked(result); } }; task.execute(); return task; } } packages/Keyguard/src/com/android/keyguard/KeyguardAbsKeyInputView.java +28 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.keyguard; import android.content.Context; import android.os.AsyncTask; import android.os.CountDownTimer; import android.os.SystemClock; import android.util.AttributeSet; Loading @@ -25,6 +26,7 @@ import android.view.KeyEvent; import android.view.View; import android.widget.LinearLayout; import com.android.internal.widget.LockPatternChecker; import com.android.internal.widget.LockPatternUtils; /** Loading @@ -34,6 +36,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout implements KeyguardSecurityView, EmergencyButton.EmergencyButtonCallback { protected KeyguardSecurityCallback mCallback; protected LockPatternUtils mLockPatternUtils; protected AsyncTask<?, ?, ?> mPendingLockCheck; protected SecurityMessageDisplay mSecurityMessageDisplay; protected View mEcaView; protected boolean mEnableHaptics; Loading Loading @@ -106,8 +109,27 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout } protected void verifyPasswordAndUnlock() { String entry = getPasswordText(); if (mLockPatternUtils.checkPassword(entry, KeyguardUpdateMonitor.getCurrentUser())) { final String entry = getPasswordText(); setPasswordEntryEnabled(false); if (mPendingLockCheck != null) { mPendingLockCheck.cancel(false); } mPendingLockCheck = LockPatternChecker.checkPassword( mLockPatternUtils, entry, KeyguardUpdateMonitor.getCurrentUser(), new LockPatternChecker.OnCheckCallback() { @Override public void onChecked(boolean matched) { setPasswordEntryEnabled(true); mPendingLockCheck = null; onPasswordChecked(entry, matched); } }); } private void onPasswordChecked(String entry, boolean matched) { if (matched) { mCallback.reportUnlockAttempt(true); mCallback.dismiss(true); } else { Loading Loading @@ -165,7 +187,10 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout @Override public void onPause() { if (mPendingLockCheck != null) { mPendingLockCheck.cancel(false); mPendingLockCheck = null; } } @Override Loading packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java +29 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Rect; import android.os.AsyncTask; import android.os.CountDownTimer; import android.os.SystemClock; import android.text.TextUtils; Loading @@ -32,6 +33,7 @@ import android.view.animation.AnimationUtils; import android.view.animation.Interpolator; import android.widget.LinearLayout; import com.android.internal.widget.LockPatternChecker; import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternView; Loading Loading @@ -59,6 +61,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit private CountDownTimer mCountdownTimer = null; private LockPatternUtils mLockPatternUtils; private AsyncTask<?, ?, ?> mPendingLockCheck; private LockPatternView mLockPatternView; private KeyguardSecurityCallback mCallback; Loading Loading @@ -214,8 +217,28 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit mCallback.userActivity(); } public void onPatternDetected(List<LockPatternView.Cell> pattern) { if (mLockPatternUtils.checkPattern(pattern, KeyguardUpdateMonitor.getCurrentUser())) { public void onPatternDetected(final List<LockPatternView.Cell> pattern) { mLockPatternView.disableInput(); if (mPendingLockCheck != null) { mPendingLockCheck.cancel(false); } mPendingLockCheck = LockPatternChecker.checkPattern( mLockPatternUtils, pattern, KeyguardUpdateMonitor.getCurrentUser(), new LockPatternChecker.OnCheckCallback() { @Override public void onChecked(boolean matched) { mLockPatternView.enableInput(); mPendingLockCheck = null; onPatternChecked(pattern, matched); } }); } private void onPatternChecked(List<LockPatternView.Cell> pattern, boolean matched) { if (matched) { mCallback.reportUnlockAttempt(true); mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Correct); mCallback.dismiss(true); Loading Loading @@ -277,6 +300,10 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit mCountdownTimer.cancel(); mCountdownTimer = null; } if (mPendingLockCheck != null) { mPendingLockCheck.cancel(false); mPendingLockCheck = null; } } @Override Loading Loading
core/java/com/android/internal/widget/LockPatternChecker.java 0 → 100644 +146 −0 Original line number Diff line number Diff line package com.android.internal.widget; import android.os.AsyncTask; import java.util.List; /** * Helper class to check/verify PIN/Password/Pattern asynchronously. */ public final class LockPatternChecker { /** * Interface for a callback to be invoked after security check. */ public interface OnCheckCallback { /** * Invoked when a security check is finished. * * @param matched Whether the PIN/Password/Pattern matches the stored one. */ void onChecked(boolean matched); } /** * Interface for a callback to be invoked after security verification. */ public interface OnVerifyCallback { /** * Invoked when a security verification is finished. * * @param attestation The attestation that the challenge was verified, or null. */ void onVerified(byte[] attestation); } /** * Verify a pattern asynchronously. * * @param utils The LockPatternUtils instance to use. * @param pattern The pattern to check. * @param challenge The challenge to verify against the pattern. * @param userId The user to check against the pattern. * @param callback The callback to be invoked with the verification result. */ public static AsyncTask<?, ?, ?> verifyPattern(final LockPatternUtils utils, final List<LockPatternView.Cell> pattern, final long challenge, final int userId, final OnVerifyCallback callback) { AsyncTask<Void, Void, byte[]> task = new AsyncTask<Void, Void, byte[]>() { @Override protected byte[] doInBackground(Void... args) { return utils.verifyPattern(pattern, challenge, userId); } @Override protected void onPostExecute(byte[] result) { callback.onVerified(result); } }; task.execute(); return task; } /** * Checks a pattern asynchronously. * * @param utils The LockPatternUtils instance to use. * @param pattern The pattern to check. * @param userId The user to check against the pattern. * @param callback The callback to be invoked with the check result. */ public static AsyncTask<?, ?, ?> checkPattern(final LockPatternUtils utils, final List<LockPatternView.Cell> pattern, final int userId, final OnCheckCallback callback) { AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() { @Override protected Boolean doInBackground(Void... args) { return utils.checkPattern(pattern, userId); } @Override protected void onPostExecute(Boolean result) { callback.onChecked(result); } }; task.execute(); return task; } /** * Verify a password asynchronously. * * @param utils The LockPatternUtils instance to use. * @param password The password to check. * @param challenge The challenge to verify against the pattern. * @param userId The user to check against the pattern. * @param callback The callback to be invoked with the verification result. */ public static AsyncTask<?, ?, ?> verifyPassword(final LockPatternUtils utils, final String password, final long challenge, final int userId, final OnVerifyCallback callback) { AsyncTask<Void, Void, byte[]> task = new AsyncTask<Void, Void, byte[]>() { @Override protected byte[] doInBackground(Void... args) { return utils.verifyPassword(password, challenge, userId); } @Override protected void onPostExecute(byte[] result) { callback.onVerified(result); } }; task.execute(); return task; } /** * Checks a password asynchronously. * * @param utils The LockPatternUtils instance to use. * @param password The password to check. * @param userId The user to check against the pattern. * @param callback The callback to be invoked with the check result. */ public static AsyncTask<?, ?, ?> checkPassword(final LockPatternUtils utils, final String password, final int userId, final OnCheckCallback callback) { AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() { @Override protected Boolean doInBackground(Void... args) { return utils.checkPassword(password, userId); } @Override protected void onPostExecute(Boolean result) { callback.onChecked(result); } }; task.execute(); return task; } }
packages/Keyguard/src/com/android/keyguard/KeyguardAbsKeyInputView.java +28 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.keyguard; import android.content.Context; import android.os.AsyncTask; import android.os.CountDownTimer; import android.os.SystemClock; import android.util.AttributeSet; Loading @@ -25,6 +26,7 @@ import android.view.KeyEvent; import android.view.View; import android.widget.LinearLayout; import com.android.internal.widget.LockPatternChecker; import com.android.internal.widget.LockPatternUtils; /** Loading @@ -34,6 +36,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout implements KeyguardSecurityView, EmergencyButton.EmergencyButtonCallback { protected KeyguardSecurityCallback mCallback; protected LockPatternUtils mLockPatternUtils; protected AsyncTask<?, ?, ?> mPendingLockCheck; protected SecurityMessageDisplay mSecurityMessageDisplay; protected View mEcaView; protected boolean mEnableHaptics; Loading Loading @@ -106,8 +109,27 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout } protected void verifyPasswordAndUnlock() { String entry = getPasswordText(); if (mLockPatternUtils.checkPassword(entry, KeyguardUpdateMonitor.getCurrentUser())) { final String entry = getPasswordText(); setPasswordEntryEnabled(false); if (mPendingLockCheck != null) { mPendingLockCheck.cancel(false); } mPendingLockCheck = LockPatternChecker.checkPassword( mLockPatternUtils, entry, KeyguardUpdateMonitor.getCurrentUser(), new LockPatternChecker.OnCheckCallback() { @Override public void onChecked(boolean matched) { setPasswordEntryEnabled(true); mPendingLockCheck = null; onPasswordChecked(entry, matched); } }); } private void onPasswordChecked(String entry, boolean matched) { if (matched) { mCallback.reportUnlockAttempt(true); mCallback.dismiss(true); } else { Loading Loading @@ -165,7 +187,10 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout @Override public void onPause() { if (mPendingLockCheck != null) { mPendingLockCheck.cancel(false); mPendingLockCheck = null; } } @Override Loading
packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java +29 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Rect; import android.os.AsyncTask; import android.os.CountDownTimer; import android.os.SystemClock; import android.text.TextUtils; Loading @@ -32,6 +33,7 @@ import android.view.animation.AnimationUtils; import android.view.animation.Interpolator; import android.widget.LinearLayout; import com.android.internal.widget.LockPatternChecker; import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternView; Loading Loading @@ -59,6 +61,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit private CountDownTimer mCountdownTimer = null; private LockPatternUtils mLockPatternUtils; private AsyncTask<?, ?, ?> mPendingLockCheck; private LockPatternView mLockPatternView; private KeyguardSecurityCallback mCallback; Loading Loading @@ -214,8 +217,28 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit mCallback.userActivity(); } public void onPatternDetected(List<LockPatternView.Cell> pattern) { if (mLockPatternUtils.checkPattern(pattern, KeyguardUpdateMonitor.getCurrentUser())) { public void onPatternDetected(final List<LockPatternView.Cell> pattern) { mLockPatternView.disableInput(); if (mPendingLockCheck != null) { mPendingLockCheck.cancel(false); } mPendingLockCheck = LockPatternChecker.checkPattern( mLockPatternUtils, pattern, KeyguardUpdateMonitor.getCurrentUser(), new LockPatternChecker.OnCheckCallback() { @Override public void onChecked(boolean matched) { mLockPatternView.enableInput(); mPendingLockCheck = null; onPatternChecked(pattern, matched); } }); } private void onPatternChecked(List<LockPatternView.Cell> pattern, boolean matched) { if (matched) { mCallback.reportUnlockAttempt(true); mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Correct); mCallback.dismiss(true); Loading Loading @@ -277,6 +300,10 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit mCountdownTimer.cancel(); mCountdownTimer = null; } if (mPendingLockCheck != null) { mPendingLockCheck.cancel(false); mPendingLockCheck = null; } } @Override Loading