fix for crash on Android 4.x (NoBackupFilesDir is ApiLevel >= 21)

try to fall back to Samsung fingerprint API even on Android 6
-> 1.0.0c
This commit is contained in:
Philipp Crocoll 2016-04-13 19:52:26 +02:00
parent 80d1788c60
commit 832722a90e
6 changed files with 42 additions and 23 deletions

View File

@ -253,7 +253,7 @@ namespace keepass2android.Io
if (ioc.IsLocalFile()) if (ioc.IsLocalFile())
{ {
bool requiresPermission = !(ioc.Path.StartsWith(activity.Activity.FilesDir.CanonicalPath) bool requiresPermission = !(ioc.Path.StartsWith(activity.Activity.FilesDir.CanonicalPath)
|| ioc.Path.StartsWith(activity.Activity.NoBackupFilesDir.CanonicalPath)); || ioc.Path.StartsWith(IoUtil.GetInternalDirectory(activity.Activity).CanonicalPath));
var extDirectory = activity.Activity.GetExternalFilesDir(null); var extDirectory = activity.Activity.GetExternalFilesDir(null);
if ((extDirectory != null) && (ioc.Path.StartsWith(extDirectory.CanonicalPath))) if ((extDirectory != null) && (ioc.Path.StartsWith(extDirectory.CanonicalPath)))

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Android.Content; using Android.Content;
using Android.OS;
using Java.IO; using Java.IO;
using KeePassLib.Serialization; using KeePassLib.Serialization;
@ -53,7 +54,7 @@ namespace keepass2android.Io
try try
{ {
File filesDir = context.FilesDir.CanonicalFile; File filesDir = context.FilesDir.CanonicalFile;
File noBackupDir = context.NoBackupFilesDir.CanonicalFile; File noBackupDir = GetInternalDirectory(context).CanonicalFile;
File ourFile = new File(path).CanonicalFile; File ourFile = new File(path).CanonicalFile;
//http://www.java2s.com/Tutorial/Java/0180__File/Checkswhetherthechilddirectoryisasubdirectoryofthebasedirectory.htm //http://www.java2s.com/Tutorial/Java/0180__File/Checkswhetherthechilddirectoryisasubdirectoryofthebasedirectory.htm
@ -93,5 +94,13 @@ namespace keepass2android.Io
writeTransaction.CommitWrite(); writeTransaction.CommitWrite();
} }
} }
public static Java.IO.File GetInternalDirectory(Context ctx)
{
if ((int)Android.OS.Build.VERSION.SdkInt >= 21)
return ctx.NoBackupFilesDir;
else
return ctx.FilesDir;
}
} }
} }

View File

@ -101,7 +101,7 @@ namespace keepass2android
} }
catch (DuplicateUuidsException e) catch (DuplicateUuidsException e)
{ {
Kp2aLog.LogUnexpectedError(e); Kp2aLog.Log(e.ToString());
Finish(false, _app.GetResourceString(UiStringKey.DuplicateUuidsError) + " " + e.Message + _app.GetResourceString(UiStringKey.DuplicateUuidsErrorAdditional), Exception); Finish(false, _app.GetResourceString(UiStringKey.DuplicateUuidsError) + " " + e.Message + _app.GetResourceString(UiStringKey.DuplicateUuidsErrorAdditional), Exception);
return; return;
} }

View File

@ -123,20 +123,7 @@ namespace keepass2android
RequestPermissions(new[] {Manifest.Permission.UseFingerprint}, FingerprintPermissionRequestCode); RequestPermissions(new[] {Manifest.Permission.UseFingerprint}, FingerprintPermissionRequestCode);
else else
{ {
try TrySetupSamsung();
{
//try to create a Samsung ID object
_samsungFingerprint = new FingerprintSamsungIdentifier(this);
if (!_samsungFingerprint.Init())
{
SetError(Resource.String.fingerprint_no_enrolled);
}
ShowRadioButtons();
}
catch (Exception)
{
_samsungFingerprint = null;
}
} }
FindViewById(Resource.Id.container_fingerprint_unlock).Visibility = _samsungFingerprint == null FindViewById(Resource.Id.container_fingerprint_unlock).Visibility = _samsungFingerprint == null
@ -144,6 +131,26 @@ namespace keepass2android
: ViewStates.Gone; : ViewStates.Gone;
} }
private bool TrySetupSamsung()
{
try
{
//try to create a Samsung ID object
_samsungFingerprint = new FingerprintSamsungIdentifier(this);
if (!_samsungFingerprint.Init())
{
SetError(Resource.String.fingerprint_no_enrolled);
}
ShowRadioButtons();
return true;
}
catch (Exception)
{
_samsungFingerprint = null;
return false;
}
}
string CurrentPreferenceKey string CurrentPreferenceKey
{ {
get { return App.Kp2a.GetDb().CurrentFingerprintPrefKey; } get { return App.Kp2a.GetDb().CurrentFingerprintPrefKey; }
@ -194,7 +201,9 @@ namespace keepass2android
FingerprintModule fpModule = new FingerprintModule(this); FingerprintModule fpModule = new FingerprintModule(this);
if (!fpModule.FingerprintManager.IsHardwareDetected) if (!fpModule.FingerprintManager.IsHardwareDetected)
{ {
SetError(Resource.String.fingerprint_hardware_error); //seems like not all Samsung Devices (e.g. Note 4) don't support the Android 6 fingerprint API
if (!TrySetupSamsung())
SetError(Resource.String.fingerprint_hardware_error);
return; return;
} }
if (!fpModule.FingerprintManager.HasEnrolledFingerprints) if (!fpModule.FingerprintManager.HasEnrolledFingerprints)

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="78" android:versionCode="79"
android:versionName="1.0.0-b" android:versionName="1.0.0-c"
package="keepass2android.keepass2android" package="keepass2android.keepass2android"
android:installLocation="auto"> android:installLocation="auto">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" /> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />

View File

@ -760,11 +760,12 @@ namespace keepass2android
private IOConnectionInfo ImportFileToInternalDirectory(IOConnectionInfo sourceIoc) private IOConnectionInfo ImportFileToInternalDirectory(IOConnectionInfo sourceIoc)
{ {
Java.IO.File internalDirectory = IoUtil.GetInternalDirectory(Activity);
string targetPath = UrlUtil.GetFileName(sourceIoc.Path); string targetPath = UrlUtil.GetFileName(sourceIoc.Path);
targetPath = targetPath.Trim("|\\?*<\":>+[]/'".ToCharArray()); targetPath = targetPath.Trim("|\\?*<\":>+[]/'".ToCharArray());
if (targetPath == "") if (targetPath == "")
targetPath = "imported"; targetPath = "imported";
if (new File(Activity.NoBackupFilesDir, targetPath).Exists()) if (new File(internalDirectory, targetPath).Exists())
{ {
int c = 1; int c = 1;
var ext = UrlUtil.GetExtension(targetPath); var ext = UrlUtil.GetExtension(targetPath);
@ -775,9 +776,9 @@ namespace keepass2android
targetPath = filenameWithoutExt + c; targetPath = filenameWithoutExt + c;
if (!String.IsNullOrEmpty(ext)) if (!String.IsNullOrEmpty(ext))
targetPath += "." + ext; targetPath += "." + ext;
} while (new File(Activity.NoBackupFilesDir, targetPath).Exists()); } while (new File(internalDirectory, targetPath).Exists());
} }
var targetIoc = IOConnectionInfo.FromPath(new File(Activity.NoBackupFilesDir, targetPath).CanonicalPath); var targetIoc = IOConnectionInfo.FromPath(new File(internalDirectory, targetPath).CanonicalPath);
IoUtil.Copy(targetIoc, sourceIoc, App.Kp2a); IoUtil.Copy(targetIoc, sourceIoc, App.Kp2a);
return targetIoc; return targetIoc;