am 09235d10
: am 82b3e62a
: am 4692a48c
: am c4bfea20
: am 3f38173f
: am 3a7690b1
: am 8184ea52
: Add lockout after trying to enter PIN / Password too often
* commit '09235d1065b501aa8a42e0767d72c15e7b846bae': Add lockout after trying to enter PIN / Password too often
This commit is contained in:
@@ -25,8 +25,10 @@ import android.app.Fragment;
|
|||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.CountDownTimer;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
@@ -71,7 +73,9 @@ public class ConfirmLockPassword extends PreferenceActivity {
|
|||||||
private PasswordEntryKeyboardHelper mKeyboardHelper;
|
private PasswordEntryKeyboardHelper mKeyboardHelper;
|
||||||
private PasswordEntryKeyboardView mKeyboardView;
|
private PasswordEntryKeyboardView mKeyboardView;
|
||||||
private Button mContinueButton;
|
private Button mContinueButton;
|
||||||
|
private int mNumWrongConfirmAttempts;
|
||||||
|
private CountDownTimer mCountdownTimer;
|
||||||
|
private boolean mIsAlpha;
|
||||||
|
|
||||||
// required constructor for fragments
|
// required constructor for fragments
|
||||||
public ConfirmLockPasswordFragment() {
|
public ConfirmLockPasswordFragment() {
|
||||||
@@ -102,29 +106,27 @@ public class ConfirmLockPassword extends PreferenceActivity {
|
|||||||
|
|
||||||
mKeyboardView = (PasswordEntryKeyboardView) view.findViewById(R.id.keyboard);
|
mKeyboardView = (PasswordEntryKeyboardView) view.findViewById(R.id.keyboard);
|
||||||
mHeaderText = (TextView) view.findViewById(R.id.headerText);
|
mHeaderText = (TextView) view.findViewById(R.id.headerText);
|
||||||
final boolean isAlpha = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC == storedQuality
|
mIsAlpha = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC == storedQuality
|
||||||
|| DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == storedQuality
|
|| DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == storedQuality
|
||||||
|| DevicePolicyManager.PASSWORD_QUALITY_COMPLEX == storedQuality;
|
|| DevicePolicyManager.PASSWORD_QUALITY_COMPLEX == storedQuality;
|
||||||
mHeaderText.setText(isAlpha ? R.string.lockpassword_confirm_your_password_header
|
mHeaderText.setText(getDefaultHeader());
|
||||||
: R.string.lockpassword_confirm_your_pin_header);
|
|
||||||
|
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
mKeyboardHelper = new PasswordEntryKeyboardHelper(activity,
|
mKeyboardHelper = new PasswordEntryKeyboardHelper(activity,
|
||||||
mKeyboardView, mPasswordEntry);
|
mKeyboardView, mPasswordEntry);
|
||||||
mKeyboardHelper.setKeyboardMode(isAlpha ?
|
mKeyboardHelper.setKeyboardMode(mIsAlpha ?
|
||||||
PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA
|
PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA
|
||||||
: PasswordEntryKeyboardHelper.KEYBOARD_MODE_NUMERIC);
|
: PasswordEntryKeyboardHelper.KEYBOARD_MODE_NUMERIC);
|
||||||
mKeyboardView.requestFocus();
|
mKeyboardView.requestFocus();
|
||||||
|
|
||||||
int currentType = mPasswordEntry.getInputType();
|
int currentType = mPasswordEntry.getInputType();
|
||||||
mPasswordEntry.setInputType(isAlpha ? currentType
|
mPasswordEntry.setInputType(mIsAlpha ? currentType
|
||||||
: (InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD));
|
: (InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD));
|
||||||
|
|
||||||
// Update the breadcrumb (title) if this is embedded in a PreferenceActivity
|
// Update the breadcrumb (title) if this is embedded in a PreferenceActivity
|
||||||
if (activity instanceof PreferenceActivity) {
|
if (activity instanceof PreferenceActivity) {
|
||||||
final PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
|
final PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
|
||||||
int id = isAlpha ? R.string.lockpassword_confirm_your_password_header
|
int id = getDefaultHeader();
|
||||||
: R.string.lockpassword_confirm_your_pin_header;
|
|
||||||
CharSequence title = getText(id);
|
CharSequence title = getText(id);
|
||||||
preferenceActivity.showBreadCrumbs(title, title);
|
preferenceActivity.showBreadCrumbs(title, title);
|
||||||
}
|
}
|
||||||
@@ -132,10 +134,19 @@ public class ConfirmLockPassword extends PreferenceActivity {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getDefaultHeader() {
|
||||||
|
return mIsAlpha ? R.string.lockpassword_confirm_your_password_header
|
||||||
|
: R.string.lockpassword_confirm_your_pin_header;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
mKeyboardView.requestFocus();
|
mKeyboardView.requestFocus();
|
||||||
|
if (mCountdownTimer != null) {
|
||||||
|
mCountdownTimer.cancel();
|
||||||
|
mCountdownTimer = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -143,6 +154,10 @@ public class ConfirmLockPassword extends PreferenceActivity {
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
super.onResume();
|
super.onResume();
|
||||||
mKeyboardView.requestFocus();
|
mKeyboardView.requestFocus();
|
||||||
|
long deadline = mLockPatternUtils.getLockoutAttemptDeadline();
|
||||||
|
if (deadline != 0) {
|
||||||
|
handleAttemptLockout(deadline);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNext() {
|
private void handleNext() {
|
||||||
@@ -155,10 +170,40 @@ public class ConfirmLockPassword extends PreferenceActivity {
|
|||||||
getActivity().setResult(RESULT_OK, intent);
|
getActivity().setResult(RESULT_OK, intent);
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
} else {
|
} else {
|
||||||
showError(R.string.lockpattern_need_to_unlock_wrong);
|
if (++mNumWrongConfirmAttempts >= LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT) {
|
||||||
|
long deadline = mLockPatternUtils.setLockoutAttemptDeadline();
|
||||||
|
handleAttemptLockout(deadline);
|
||||||
|
} else {
|
||||||
|
showError(R.string.lockpattern_need_to_unlock_wrong);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleAttemptLockout(long elapsedRealtimeDeadline) {
|
||||||
|
long elapsedRealtime = SystemClock.elapsedRealtime();
|
||||||
|
showError(R.string.lockpattern_too_many_failed_confirmation_attempts_header, 0);
|
||||||
|
mPasswordEntry.setEnabled(false);
|
||||||
|
mCountdownTimer = new CountDownTimer(
|
||||||
|
elapsedRealtimeDeadline - elapsedRealtime,
|
||||||
|
LockPatternUtils.FAILED_ATTEMPT_COUNTDOWN_INTERVAL_MS) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTick(long millisUntilFinished) {
|
||||||
|
final int secondsCountdown = (int) (millisUntilFinished / 1000);
|
||||||
|
mHeaderText.setText(getString(
|
||||||
|
R.string.lockpattern_too_many_failed_confirmation_attempts_footer,
|
||||||
|
secondsCountdown));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
mPasswordEntry.setEnabled(true);
|
||||||
|
mHeaderText.setText(getDefaultHeader());
|
||||||
|
mNumWrongConfirmAttempts = 0;
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
||||||
case R.id.next_button:
|
case R.id.next_button:
|
||||||
@@ -173,14 +218,23 @@ public class ConfirmLockPassword extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showError(int msg) {
|
private void showError(int msg) {
|
||||||
|
showError(msg, ERROR_MESSAGE_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Runnable mResetErrorRunnable = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
mHeaderText.setText(getDefaultHeader());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private void showError(int msg, long timeout) {
|
||||||
mHeaderText.setText(msg);
|
mHeaderText.setText(msg);
|
||||||
mHeaderText.announceForAccessibility(mHeaderText.getText());
|
mHeaderText.announceForAccessibility(mHeaderText.getText());
|
||||||
mPasswordEntry.setText(null);
|
mPasswordEntry.setText(null);
|
||||||
mHandler.postDelayed(new Runnable() {
|
mHandler.removeCallbacks(mResetErrorRunnable);
|
||||||
public void run() {
|
if (timeout != 0) {
|
||||||
mHeaderText.setText(R.string.lockpassword_confirm_your_password_header);
|
mHandler.postDelayed(mResetErrorRunnable, timeout);
|
||||||
}
|
}
|
||||||
}, ERROR_MESSAGE_TIMEOUT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// {@link OnEditorActionListener} methods.
|
// {@link OnEditorActionListener} methods.
|
||||||
|
Reference in New Issue
Block a user