mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-11-25 18:52:19 -05:00
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:
parent
80d1788c60
commit
832722a90e
@ -253,7 +253,7 @@ namespace keepass2android.Io
|
||||
if (ioc.IsLocalFile())
|
||||
{
|
||||
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);
|
||||
if ((extDirectory != null) && (ioc.Path.StartsWith(extDirectory.CanonicalPath)))
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Java.IO;
|
||||
using KeePassLib.Serialization;
|
||||
|
||||
@ -53,7 +54,7 @@ namespace keepass2android.Io
|
||||
try
|
||||
{
|
||||
File filesDir = context.FilesDir.CanonicalFile;
|
||||
File noBackupDir = context.NoBackupFilesDir.CanonicalFile;
|
||||
File noBackupDir = GetInternalDirectory(context).CanonicalFile;
|
||||
File ourFile = new File(path).CanonicalFile;
|
||||
//http://www.java2s.com/Tutorial/Java/0180__File/Checkswhetherthechilddirectoryisasubdirectoryofthebasedirectory.htm
|
||||
|
||||
@ -93,5 +94,13 @@ namespace keepass2android.Io
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ namespace keepass2android
|
||||
}
|
||||
catch (DuplicateUuidsException e)
|
||||
{
|
||||
Kp2aLog.LogUnexpectedError(e);
|
||||
Kp2aLog.Log(e.ToString());
|
||||
Finish(false, _app.GetResourceString(UiStringKey.DuplicateUuidsError) + " " + e.Message + _app.GetResourceString(UiStringKey.DuplicateUuidsErrorAdditional), Exception);
|
||||
return;
|
||||
}
|
||||
|
@ -123,20 +123,7 @@ namespace keepass2android
|
||||
RequestPermissions(new[] {Manifest.Permission.UseFingerprint}, FingerprintPermissionRequestCode);
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
//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;
|
||||
}
|
||||
TrySetupSamsung();
|
||||
|
||||
}
|
||||
FindViewById(Resource.Id.container_fingerprint_unlock).Visibility = _samsungFingerprint == null
|
||||
@ -144,6 +131,26 @@ namespace keepass2android
|
||||
: 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
|
||||
{
|
||||
get { return App.Kp2a.GetDb().CurrentFingerprintPrefKey; }
|
||||
@ -194,7 +201,9 @@ namespace keepass2android
|
||||
FingerprintModule fpModule = new FingerprintModule(this);
|
||||
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;
|
||||
}
|
||||
if (!fpModule.FingerprintManager.HasEnrolledFingerprints)
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:versionCode="78"
|
||||
android:versionName="1.0.0-b"
|
||||
android:versionCode="79"
|
||||
android:versionName="1.0.0-c"
|
||||
package="keepass2android.keepass2android"
|
||||
android:installLocation="auto">
|
||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
|
||||
|
@ -760,11 +760,12 @@ namespace keepass2android
|
||||
|
||||
private IOConnectionInfo ImportFileToInternalDirectory(IOConnectionInfo sourceIoc)
|
||||
{
|
||||
Java.IO.File internalDirectory = IoUtil.GetInternalDirectory(Activity);
|
||||
string targetPath = UrlUtil.GetFileName(sourceIoc.Path);
|
||||
targetPath = targetPath.Trim("|\\?*<\":>+[]/'".ToCharArray());
|
||||
if (targetPath == "")
|
||||
targetPath = "imported";
|
||||
if (new File(Activity.NoBackupFilesDir, targetPath).Exists())
|
||||
if (new File(internalDirectory, targetPath).Exists())
|
||||
{
|
||||
int c = 1;
|
||||
var ext = UrlUtil.GetExtension(targetPath);
|
||||
@ -775,9 +776,9 @@ namespace keepass2android
|
||||
targetPath = filenameWithoutExt + c;
|
||||
if (!String.IsNullOrEmpty(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);
|
||||
return targetIoc;
|
||||
|
Loading…
Reference in New Issue
Block a user