Cancel biometric prompt on pause

pull/180/head
M66B 5 years ago
parent 51ce845828
commit 5bc040a3f3

@ -206,7 +206,7 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
}; };
if (Helper.shouldAuthenticate(this)) if (Helper.shouldAuthenticate(this))
Helper.authenticate(ActivityMain.this, null, Helper.authenticate(ActivityMain.this, ActivityMain.this, null,
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {

@ -159,7 +159,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
public void onClick(View v) { public void onClick(View v) {
final boolean biometrics = prefs.getBoolean("biometrics", false); final boolean biometrics = prefs.getBoolean("biometrics", false);
Helper.authenticate(getActivity(), biometrics, new Runnable() { Helper.authenticate(getActivity(), getViewLifecycleOwner(), biometrics, new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {

@ -44,7 +44,6 @@ import android.os.LocaleList;
import android.os.Parcel; import android.os.Parcel;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.StatFs; import android.os.StatFs;
import android.provider.DocumentsContract;
import android.security.KeyChain; import android.security.KeyChain;
import android.security.KeyChainAliasCallback; import android.security.KeyChainAliasCallback;
import android.security.KeyChainException; import android.security.KeyChainException;
@ -1079,7 +1078,7 @@ public class Helper {
return false; return false;
} }
static void authenticate(final FragmentActivity activity, 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) {
final Handler handler = new Handler(); final Handler handler = new Handler();
@ -1104,7 +1103,7 @@ public class Helper {
? R.string.title_setup_biometrics_disable ? R.string.title_setup_biometrics_disable
: R.string.title_setup_biometrics_enable)); : R.string.title_setup_biometrics_enable));
BiometricPrompt prompt = new BiometricPrompt(activity, executor, final BiometricPrompt prompt = new BiometricPrompt(activity, executor,
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) {
@ -1140,6 +1139,16 @@ public class Helper {
}); });
prompt.authenticate(info.build()); prompt.authenticate(info.build());
owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
public void onPause() {
prompt.cancelAuthentication();
handler.post(cancelled);
owner.getLifecycle().removeObserver(this);
}
});
} else { } else {
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);

Loading…
Cancel
Save