fix Fingerprint issue with older Samsung devices (IsHardwareDetected=false). Now fallback correctly to Samsung Fingerprint API.

This commit is contained in:
Philipp Crocoll 2016-08-21 03:32:57 +02:00
parent c1da91e0ef
commit 199f900f4b
2 changed files with 24 additions and 4 deletions

View File

@ -126,9 +126,7 @@ namespace keepass2android
TrySetupSamsung();
}
FindViewById(Resource.Id.container_fingerprint_unlock).Visibility = _samsungFingerprint == null
? ViewStates.Visible
: ViewStates.Gone;
}
private bool TrySetupSamsung()
@ -142,6 +140,9 @@ namespace keepass2android
SetError(Resource.String.fingerprint_no_enrolled);
}
ShowRadioButtons();
FindViewById(Resource.Id.container_fingerprint_unlock).Visibility = _samsungFingerprint == null
? ViewStates.Visible
: ViewStates.Gone;
return true;
}
catch (Exception)

View File

@ -140,7 +140,10 @@ namespace keepass2android
RegisterReceiver(_intentReceiver, filter);
if ((int) Build.VERSION.SdkInt >= 23)
RequestPermissions(new[] {Manifest.Permission.UseFingerprint}, FingerprintPermissionRequestCode);
{
Kp2aLog.Log("requesting fingerprint permission");
RequestPermissions(new[] { Manifest.Permission.UseFingerprint }, FingerprintPermissionRequestCode);
}
else
{
@ -157,6 +160,9 @@ namespace keepass2android
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
Kp2aLog.Log("OnRequestPermissionsResult " + (requestCode == FingerprintPermissionRequestCode) +
((grantResults.Length > 0) && (grantResults[0] == Permission.Granted)));
if (requestCode == FingerprintPermissionRequestCode && grantResults[0] == Permission.Granted)
{
var btn = FindViewById<ImageButton>(Resource.Id.fingerprintbtn);
@ -169,11 +175,13 @@ namespace keepass2android
b.Show();
};
_fingerprintPermissionGranted = true;
Kp2aLog.Log("_fingerprintPermissionGranted");
}
}
public void OnFingerprintError(string message)
{
Kp2aLog.Log("fingerprint error: " + message);
var btn = FindViewById<ImageButton>(Resource.Id.fingerprintbtn);
btn.SetImageResource(Resource.Drawable.ic_fingerprint_error);
@ -187,6 +195,7 @@ namespace keepass2android
public void OnFingerprintAuthSucceeded()
{
Kp2aLog.Log("OnFingerprintAuthSucceeded");
_fingerprintIdentifier.StopListening();
var btn = FindViewById<ImageButton>(Resource.Id.fingerprintbtn);
@ -206,6 +215,7 @@ namespace keepass2android
}
private void InitFingerprintUnlock()
{
Kp2aLog.Log("InitFingerprintUnlock");
var btn = FindViewById<ImageButton>(Resource.Id.fingerprintbtn);
try
{
@ -221,23 +231,28 @@ namespace keepass2android
if (_fingerprintPermissionGranted)
{
FingerprintModule fpModule = new FingerprintModule(this);
Kp2aLog.Log("fpModule.FingerprintManager.IsHardwareDetected=" + fpModule.FingerprintManager.IsHardwareDetected);
if (fpModule.FingerprintManager.IsHardwareDetected) //see FingerprintSetupActivity
_fingerprintIdentifier = new FingerprintDecryption(fpModule, App.Kp2a.GetDb().CurrentFingerprintPrefKey, this,
App.Kp2a.GetDb().CurrentFingerprintPrefKey);
else _fingerprintIdentifier = null; //force re-init Samsung
}
if (_fingerprintIdentifier == null)
{
try
{
Kp2aLog.Log("trying Samsung Fingerprint API...");
_fingerprintIdentifier = new FingerprintSamsungIdentifier(this);
btn.Click += (sender, args) =>
{
if (_fingerprintIdentifier.Init())
_fingerprintIdentifier.StartListening(this, this);
};
Kp2aLog.Log("trying Samsung Fingerprint API...Seems to work!");
}
catch (Exception)
{
Kp2aLog.Log("trying Samsung Fingerprint API...failed.");
FindViewById<ImageButton>(Resource.Id.fingerprintbtn).Visibility = ViewStates.Gone;
return;
}
@ -246,11 +261,13 @@ namespace keepass2android
if (_fingerprintIdentifier.Init())
{
Kp2aLog.Log("successfully initialized fingerprint.");
btn.SetImageResource(Resource.Drawable.ic_fp_40px);
_fingerprintIdentifier.StartListening(this, this);
}
else
{
Kp2aLog.Log("failed to initialize fingerprint.");
//key invalidated permanently
btn.SetImageResource(Resource.Drawable.ic_fingerprint_error);
btn.Tag = GetString(Resource.String.fingerprint_unlock_failed);
@ -261,6 +278,7 @@ namespace keepass2android
}
catch (Exception e)
{
Kp2aLog.Log("Error initializing Fingerprint Unlock: " + e);
btn.SetImageResource(Resource.Drawable.ic_fingerprint_error);
btn.Tag = "Error initializing Fingerprint Unlock: " + e;
@ -335,6 +353,7 @@ namespace keepass2android
base.OnPause();
if (_fingerprintIdentifier != null)
{
Kp2aLog.Log("FP: Stop listening");
_fingerprintIdentifier.StopListening();
}
}