mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-12-22 06:58:50 -05:00
Fix bug in creating databases with keyfile (GUI was not working)
Tried to fix fingerprint issue, but probably without effect
This commit is contained in:
parent
59480b8369
commit
b635140753
@ -103,16 +103,8 @@ namespace keepass2android
|
||||
if (_restoringInstanceState)
|
||||
return;
|
||||
|
||||
string defaulFilename = _keyfileFilename;
|
||||
if (_keyfileFilename == null)
|
||||
{
|
||||
defaulFilename = _keyfileFilename = SdDir + "keyfile.txt";
|
||||
if (defaulFilename.StartsWith("file://") == false)
|
||||
defaulFilename = "file://" + defaulFilename;
|
||||
}
|
||||
|
||||
StartFileChooser(defaulFilename, RequestCodeKeyFile, false);
|
||||
|
||||
Util.ShowBrowseDialog(this, RequestCodeKeyFile, false, true);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -193,7 +185,13 @@ namespace keepass2android
|
||||
{
|
||||
try
|
||||
{
|
||||
newKey.AddUserKey(new KcpKeyFile(_keyfileFilename));
|
||||
var ioc = IOConnectionInfo.FromPath(_keyfileFilename);
|
||||
using (var stream = App.Kp2a.GetFileStorage(ioc).OpenFileForRead(ioc))
|
||||
{
|
||||
byte[] keyfileData = Util.StreamToMemoryStream(stream).ToArray();
|
||||
newKey.AddUserKey(new KcpKeyFile(keyfileData, ioc, true));
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@ -362,13 +360,37 @@ namespace keepass2android
|
||||
{
|
||||
if (requestCode == RequestCodeKeyFile)
|
||||
{
|
||||
string filename = Util.IntentToFilename(data, this);
|
||||
if (filename != null)
|
||||
if (data.Data.Scheme == "content")
|
||||
{
|
||||
_keyfileFilename = ConvertFilenameToIocPath(filename);
|
||||
FindViewById<TextView>(Resource.Id.keyfile_filename).Text = _keyfileFilename;
|
||||
FindViewById(Resource.Id.keyfile_filename).Visibility = ViewStates.Visible;
|
||||
if ((int)Build.VERSION.SdkInt >= 19)
|
||||
{
|
||||
//try to take persistable permissions
|
||||
try
|
||||
{
|
||||
Kp2aLog.Log("TakePersistableUriPermission");
|
||||
var takeFlags = data.Flags
|
||||
& (ActivityFlags.GrantReadUriPermission
|
||||
| ActivityFlags.GrantWriteUriPermission);
|
||||
this.ContentResolver.TakePersistableUriPermission(data.Data, takeFlags);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Kp2aLog.Log(e.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string filename = Util.IntentToFilename(data, this);
|
||||
if (filename == null)
|
||||
filename = data.DataString;
|
||||
|
||||
|
||||
_keyfileFilename = ConvertFilenameToIocPath(filename);
|
||||
FindViewById<TextView>(Resource.Id.keyfile_filename).Text = _keyfileFilename;
|
||||
FindViewById(Resource.Id.keyfile_filename).Visibility = ViewStates.Visible;
|
||||
|
||||
}
|
||||
if (requestCode == RequestCodeDbFilename)
|
||||
{
|
||||
|
@ -1538,11 +1538,11 @@ namespace keepass2android
|
||||
|
||||
protected override void OnPause()
|
||||
{
|
||||
base.OnPause();
|
||||
if (_fingerprintDec != null)
|
||||
{
|
||||
_fingerprintDec.StopListening();
|
||||
}
|
||||
base.OnPause();
|
||||
}
|
||||
|
||||
private void SetPasswordTypeface(TextView textView)
|
||||
@ -1613,21 +1613,7 @@ namespace keepass2android
|
||||
|
||||
private static MemoryStream StreamToMemoryStream(Stream stream)
|
||||
{
|
||||
var memoryStream = stream as MemoryStream;
|
||||
if (memoryStream == null)
|
||||
{
|
||||
// Read the stream into memory
|
||||
int capacity = 4096; // Default initial capacity, if stream can't report it.
|
||||
if (stream.CanSeek)
|
||||
{
|
||||
capacity = (int) stream.Length;
|
||||
}
|
||||
memoryStream = new MemoryStream(capacity);
|
||||
stream.CopyTo(memoryStream);
|
||||
stream.Close();
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
return memoryStream;
|
||||
return Util.StreamToMemoryStream(stream);
|
||||
}
|
||||
|
||||
protected override void OnSaveInstanceState(Bundle outState)
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:versionCode="81"
|
||||
android:versionName="1.0.0-e"
|
||||
android:versionCode="83"
|
||||
android:versionName="1.0.0-f"
|
||||
package="keepass2android.keepass2android"
|
||||
android:installLocation="auto">
|
||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
|
||||
|
@ -361,12 +361,13 @@ namespace keepass2android
|
||||
|
||||
protected override void OnPause()
|
||||
{
|
||||
base.OnPause();
|
||||
if (_fingerprintIdentifier != null)
|
||||
{
|
||||
Kp2aLog.Log("FP: Stop listening");
|
||||
_fingerprintIdentifier.StopListening();
|
||||
}
|
||||
|
||||
base.OnPause();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
|
@ -511,6 +511,27 @@ namespace keepass2android
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static MemoryStream StreamToMemoryStream(Stream stream)
|
||||
{
|
||||
|
||||
var memoryStream = stream as MemoryStream;
|
||||
if (memoryStream == null)
|
||||
{
|
||||
// Read the stream into memory
|
||||
int capacity = 4096; // Default initial capacity, if stream can't report it.
|
||||
if (stream.CanSeek)
|
||||
{
|
||||
capacity = (int) stream.Length;
|
||||
}
|
||||
memoryStream = new MemoryStream(capacity);
|
||||
stream.CopyTo(memoryStream);
|
||||
stream.Close();
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
return memoryStream;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user