-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathPasscodeManagePasswordActivity.java
More file actions
112 lines (99 loc) · 4.28 KB
/
PasscodeManagePasswordActivity.java
File metadata and controls
112 lines (99 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package org.wordpress.passcodelock;
import android.os.Bundle;
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat;
import android.support.v4.os.CancellationSignal;
import android.view.View;
import android.widget.TextView;
public class PasscodeManagePasswordActivity extends AbstractPasscodeKeyboardActivity {
public static final String KEY_TYPE = "type";
private int type = -1;
private String unverifiedPasscode = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null) {
type = extras.getInt(KEY_TYPE, -1);
if (type ==0){
((TextView) findViewById(R.id.passcodelock_prompt)).setText(R.string.passcode_set_for_first_time);
}
}
}
@Override
public void onResume() {
super.onResume();
// Show fingerprint scanner if supported
if (mFingerprintManager.isHardwareDetected() &&
mFingerprintManager.hasEnrolledFingerprints() &&
type == PasscodePreferenceFragment.DISABLE_PASSLOCK) {
mFingerprintManager.authenticate(null, 0, mCancel = new CancellationSignal(), getFingerprintCallback(), null);
View view = findViewById(R.id.image_fingerprint);
view.setVisibility(View.VISIBLE);
}
}
@Override
protected void onPinLockInserted() {
String passLock = mPinCodeField.getText().toString();
mPinCodeField.setText("");
switch (type) {
case PasscodePreferenceFragment.DISABLE_PASSLOCK:
if (AppLockManager.getInstance().getCurrentAppLock().verifyPassword(passLock)) {
AppLockManager.getInstance().getCurrentAppLock().setPassword(null);
authenticationSucceeded();
} else {
showPasswordError();
}
break;
case PasscodePreferenceFragment.ENABLE_PASSLOCK:
if (unverifiedPasscode == null) {
((TextView) findViewById(R.id.passcodelock_prompt)).setText(R.string.passcode_re_enter_passcode);
unverifiedPasscode = passLock;
} else {
if (passLock.equals(unverifiedPasscode)) {
AppLockManager.getInstance().getCurrentAppLock().setPassword(passLock);
authenticationSucceeded();
} else {
unverifiedPasscode = null;
topMessage.setText(R.string.passcodelock_prompt_message);
showPasswordError();
}
}
break;
case PasscodePreferenceFragment.CHANGE_PASSWORD:
//verify old password
if (AppLockManager.getInstance().getCurrentAppLock().verifyPassword(passLock)) {
topMessage.setText(R.string.passcodelock_prompt_message);
type = PasscodePreferenceFragment.ENABLE_PASSLOCK;
} else {
showPasswordError();
}
break;
default:
break;
}
}
@Override
protected FingerprintManagerCompat.AuthenticationCallback getFingerprintCallback() {
return new FingerprintManagerCompat.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errMsgId, CharSequence errString) {
super.onAuthenticationError(errMsgId, errString);
}
@Override
public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
super.onAuthenticationHelp(helpMsgId, helpString);
}
@Override
public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
AppLockManager.getInstance().getCurrentAppLock().setPassword(null);
authenticationSucceeded();
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
authenticationFailed();
}
};
}
}