Merge "Simplify FingerprintSettings" into mnc-dev
This commit is contained in:
@@ -81,6 +81,7 @@ public class FingerprintSettings extends SubSettings {
|
|||||||
* result.
|
* result.
|
||||||
*/
|
*/
|
||||||
static final int RESULT_FINISHED = RESULT_FIRST_USER;
|
static final int RESULT_FINISHED = RESULT_FIRST_USER;
|
||||||
|
private static final long LOCKOUT_DURATION = 30000; // time we have to wait for fp to reset, ms
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Intent getIntent() {
|
public Intent getIntent() {
|
||||||
@@ -129,7 +130,7 @@ public class FingerprintSettings extends SubSettings {
|
|||||||
|
|
||||||
private FingerprintManager mFingerprintManager;
|
private FingerprintManager mFingerprintManager;
|
||||||
private CancellationSignal mFingerprintCancel;
|
private CancellationSignal mFingerprintCancel;
|
||||||
private int mMaxFingerprintAttempts;
|
private boolean mInFingerprintLockout;
|
||||||
private byte[] mToken;
|
private byte[] mToken;
|
||||||
private boolean mLaunchedConfirm;
|
private boolean mLaunchedConfirm;
|
||||||
private Drawable mHighlightDrawable;
|
private Drawable mHighlightDrawable;
|
||||||
@@ -185,32 +186,16 @@ public class FingerprintSettings extends SubSettings {
|
|||||||
case MSG_FINGER_AUTH_SUCCESS:
|
case MSG_FINGER_AUTH_SUCCESS:
|
||||||
mFingerprintCancel = null;
|
mFingerprintCancel = null;
|
||||||
highlightFingerprintItem(msg.arg1);
|
highlightFingerprintItem(msg.arg1);
|
||||||
retryFingerprint(true);
|
retryFingerprint();
|
||||||
break;
|
break;
|
||||||
case MSG_FINGER_AUTH_FAIL:
|
case MSG_FINGER_AUTH_FAIL:
|
||||||
mFingerprintCancel = null;
|
// No action required... fingerprint will allow up to 5 of these
|
||||||
retryFingerprint(true);
|
|
||||||
break;
|
break;
|
||||||
case MSG_FINGER_AUTH_ERROR: {
|
case MSG_FINGER_AUTH_ERROR:
|
||||||
mFingerprintCancel = null;
|
handleError(msg.arg1 /* errMsgId */, (CharSequence) msg.obj /* errStr */ );
|
||||||
// get activity will be null on a screen rotation
|
|
||||||
final Activity activity = getActivity();
|
|
||||||
if (activity != null) {
|
|
||||||
CharSequence errString = (CharSequence) msg.obj;
|
|
||||||
Toast.makeText(activity, errString , Toast.LENGTH_SHORT);
|
|
||||||
}
|
|
||||||
final int errMsgId = msg.arg1;
|
|
||||||
if (errMsgId != FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
|
|
||||||
retryFingerprint(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case MSG_FINGER_AUTH_HELP: {
|
case MSG_FINGER_AUTH_HELP: {
|
||||||
final Activity activity = getActivity();
|
// Not used
|
||||||
if (activity != null) {
|
|
||||||
CharSequence helpString = (CharSequence) msg.obj;
|
|
||||||
Toast.makeText(activity, helpString , Toast.LENGTH_SHORT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -218,22 +203,45 @@ public class FingerprintSettings extends SubSettings {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private void stopFingerprint() {
|
private void stopFingerprint() {
|
||||||
if (mFingerprintCancel != null) {
|
if (mFingerprintCancel != null && !mFingerprintCancel.isCanceled()) {
|
||||||
mFingerprintCancel.cancel();
|
mFingerprintCancel.cancel();
|
||||||
mFingerprintCancel = null;
|
|
||||||
}
|
}
|
||||||
|
mFingerprintCancel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void retryFingerprint(boolean resetAttempts) {
|
/**
|
||||||
if (resetAttempts) {
|
* @param errMsgId
|
||||||
mMaxFingerprintAttempts = 0;
|
*/
|
||||||
|
protected void handleError(int errMsgId, CharSequence msg) {
|
||||||
|
mFingerprintCancel = null;
|
||||||
|
switch (errMsgId) {
|
||||||
|
case FingerprintManager.FINGERPRINT_ERROR_CANCELED:
|
||||||
|
return; // Only happens if we get preempted by another activity. Ignored.
|
||||||
|
case FingerprintManager.FINGERPRINT_ERROR_LOCKOUT:
|
||||||
|
mInFingerprintLockout = true;
|
||||||
|
// We've been locked out. Reset after 30s.
|
||||||
|
if (!mHandler.hasCallbacks(mFingerprintLockoutReset)) {
|
||||||
|
mHandler.postDelayed(mFingerprintLockoutReset,
|
||||||
|
LOCKOUT_DURATION);
|
||||||
|
}
|
||||||
|
// Fall through to show message
|
||||||
|
default:
|
||||||
|
// Activity can be null on a screen rotation.
|
||||||
|
final Activity activity = getActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
Toast.makeText(activity, msg , Toast.LENGTH_SHORT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (mMaxFingerprintAttempts < MAX_RETRY_ATTEMPTS && mFingerprintCancel == null) {
|
retryFingerprint(); // start again
|
||||||
|
}
|
||||||
|
|
||||||
|
private void retryFingerprint() {
|
||||||
|
if (!mInFingerprintLockout) {
|
||||||
mFingerprintCancel = new CancellationSignal();
|
mFingerprintCancel = new CancellationSignal();
|
||||||
mFingerprintManager.authenticate(null, mFingerprintCancel, 0 /* flags */,
|
mFingerprintManager.authenticate(null, mFingerprintCancel, 0 /* flags */,
|
||||||
mAuthCallback, null);
|
mAuthCallback, null);
|
||||||
}
|
}
|
||||||
mMaxFingerprintAttempts++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -361,7 +369,7 @@ public class FingerprintSettings extends SubSettings {
|
|||||||
|
|
||||||
private void updatePreferences() {
|
private void updatePreferences() {
|
||||||
createPreferenceHierarchy();
|
createPreferenceHierarchy();
|
||||||
retryFingerprint(true);
|
retryFingerprint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -508,6 +516,14 @@ public class FingerprintSettings extends SubSettings {
|
|||||||
updatePreferences();
|
updatePreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Runnable mFingerprintLockoutReset = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mInFingerprintLockout = false;
|
||||||
|
retryFingerprint();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public static class RenameDeleteDialog extends DialogFragment {
|
public static class RenameDeleteDialog extends DialogFragment {
|
||||||
|
|
||||||
private Fingerprint mFp;
|
private Fingerprint mFp;
|
||||||
|
Reference in New Issue
Block a user