|
|
@ -1685,10 +1685,13 @@ public class Helper {
|
|
|
|
static void authenticate(final FragmentActivity activity, final LifecycleOwner owner,
|
|
|
|
static void authenticate(final FragmentActivity activity, final LifecycleOwner owner,
|
|
|
|
Boolean enabled, final
|
|
|
|
Boolean enabled, final
|
|
|
|
Runnable authenticated, final Runnable cancelled) {
|
|
|
|
Runnable authenticated, final Runnable cancelled) {
|
|
|
|
|
|
|
|
Log.i("Authenticate " + activity);
|
|
|
|
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
|
|
|
String pin = prefs.getString("pin", null);
|
|
|
|
String pin = prefs.getString("pin", null);
|
|
|
|
|
|
|
|
|
|
|
|
if (enabled != null || TextUtils.isEmpty(pin)) {
|
|
|
|
if (enabled != null || TextUtils.isEmpty(pin)) {
|
|
|
|
|
|
|
|
Log.i("Authenticate biometric enabled=" + enabled);
|
|
|
|
BiometricPrompt.PromptInfo.Builder info = new BiometricPrompt.PromptInfo.Builder()
|
|
|
|
BiometricPrompt.PromptInfo.Builder info = new BiometricPrompt.PromptInfo.Builder()
|
|
|
|
.setTitle(activity.getString(enabled == null ? R.string.app_name : R.string.title_setup_biometrics));
|
|
|
|
.setTitle(activity.getString(enabled == null ? R.string.app_name : R.string.title_setup_biometrics));
|
|
|
|
|
|
|
|
|
|
|
@ -1709,7 +1712,7 @@ public class Helper {
|
|
|
|
new BiometricPrompt.AuthenticationCallback() {
|
|
|
|
new BiometricPrompt.AuthenticationCallback() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onAuthenticationError(final int errorCode, @NonNull final CharSequence errString) {
|
|
|
|
public void onAuthenticationError(final int errorCode, @NonNull final CharSequence errString) {
|
|
|
|
Log.w("Biometric error " + errorCode + ": " + errString);
|
|
|
|
Log.w("Authenticate biometric error " + errorCode + ": " + errString);
|
|
|
|
|
|
|
|
|
|
|
|
if (errorCode != BiometricPrompt.ERROR_NEGATIVE_BUTTON &&
|
|
|
|
if (errorCode != BiometricPrompt.ERROR_NEGATIVE_BUTTON &&
|
|
|
|
errorCode != BiometricPrompt.ERROR_CANCELED &&
|
|
|
|
errorCode != BiometricPrompt.ERROR_CANCELED &&
|
|
|
@ -1728,14 +1731,14 @@ public class Helper {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
|
|
|
|
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
|
|
|
|
Log.i("Biometric succeeded");
|
|
|
|
Log.i("Authenticate biometric succeeded");
|
|
|
|
setAuthenticated(activity);
|
|
|
|
setAuthenticated(activity);
|
|
|
|
ApplicationEx.getMainHandler().post(authenticated);
|
|
|
|
ApplicationEx.getMainHandler().post(authenticated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onAuthenticationFailed() {
|
|
|
|
public void onAuthenticationFailed() {
|
|
|
|
Log.w("Biometric failed");
|
|
|
|
Log.w("Authenticate biometric failed");
|
|
|
|
ApplicationEx.getMainHandler().post(cancelled);
|
|
|
|
ApplicationEx.getMainHandler().post(cancelled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -1758,11 +1761,13 @@ public class Helper {
|
|
|
|
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
|
|
|
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
|
|
|
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
|
|
|
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
|
|
|
public void onDestroy() {
|
|
|
|
public void onDestroy() {
|
|
|
|
|
|
|
|
Log.i("Authenticate destroyed");
|
|
|
|
ApplicationEx.getMainHandler().post(cancelPrompt);
|
|
|
|
ApplicationEx.getMainHandler().post(cancelPrompt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Log.i("Authenticate PIN");
|
|
|
|
final View dview = LayoutInflater.from(activity).inflate(R.layout.dialog_pin_ask, null);
|
|
|
|
final View dview = LayoutInflater.from(activity).inflate(R.layout.dialog_pin_ask, null);
|
|
|
|
final EditText etPin = dview.findViewById(R.id.etPin);
|
|
|
|
final EditText etPin = dview.findViewById(R.id.etPin);
|
|
|
|
|
|
|
|
|
|
|
@ -1775,22 +1780,26 @@ public class Helper {
|
|
|
|
String pin = prefs.getString("pin", "");
|
|
|
|
String pin = prefs.getString("pin", "");
|
|
|
|
String entered = etPin.getText().toString();
|
|
|
|
String entered = etPin.getText().toString();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Authenticate PIN ok=" + pin.equals(entered));
|
|
|
|
if (pin.equals(entered)) {
|
|
|
|
if (pin.equals(entered)) {
|
|
|
|
setAuthenticated(activity);
|
|
|
|
setAuthenticated(activity);
|
|
|
|
ApplicationEx.getMainHandler().post(authenticated);
|
|
|
|
ApplicationEx.getMainHandler().post(authenticated);
|
|
|
|
} else
|
|
|
|
} else {
|
|
|
|
ApplicationEx.getMainHandler().post(cancelled);
|
|
|
|
ApplicationEx.getMainHandler().post(cancelled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
|
|
Log.i("Authenticate PIN cancelled");
|
|
|
|
ApplicationEx.getMainHandler().post(cancelled);
|
|
|
|
ApplicationEx.getMainHandler().post(cancelled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
|
|
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
|
|
|
|
Log.i("Authenticate PIN dismissed");
|
|
|
|
ApplicationEx.getMainHandler().post(cancelled);
|
|
|
|
ApplicationEx.getMainHandler().post(cancelled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -1857,11 +1866,14 @@ public class Helper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void setAuthenticated(Context context) {
|
|
|
|
static void setAuthenticated(Context context) {
|
|
|
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
|
|
|
Log.i("Authenticated now=" + now);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
prefs.edit().putLong("last_authentication", new Date().getTime()).apply();
|
|
|
|
prefs.edit().putLong("last_authentication", now.getTime()).apply();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void clearAuthentication(Context context) {
|
|
|
|
static void clearAuthentication(Context context) {
|
|
|
|
|
|
|
|
Log.i("Authenticate clear");
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
prefs.edit().remove("last_authentication").apply();
|
|
|
|
prefs.edit().remove("last_authentication").apply();
|
|
|
|
}
|
|
|
|
}
|
|
|
|