diff --git a/src/keepass2android/CreateDatabaseActivity.cs b/src/keepass2android/CreateDatabaseActivity.cs index a0ab4bc3..82cbdb24 100644 --- a/src/keepass2android/CreateDatabaseActivity.cs +++ b/src/keepass2android/CreateDatabaseActivity.cs @@ -103,15 +103,7 @@ namespace keepass2android if (_restoringInstanceState) return; - string defaulFilename = _keyfileFilename; - if (_keyfileFilename == null) - { - defaulFilename = _keyfileFilename = SdDir + "keyfile.txt"; - if (defaulFilename.StartsWith("file://") == false) - defaulFilename = "file://" + defaulFilename; - } - - new FileSelectHelper(this, false, RequestCodeKeyFile).StartFileChooser(defaulFilename); + 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) { @@ -343,14 +341,38 @@ namespace keepass2android { if (requestCode == RequestCodeKeyFile) { - string filename = Util.IntentToFilename(data, this); - if (filename != null) + if (data.Data.Scheme == "content") { + 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(Resource.Id.keyfile_filename).Text = _keyfileFilename; FindViewById(Resource.Id.keyfile_filename).Visibility = ViewStates.Visible; + } - } if (requestCode == RequestCodeDbFilename) { diff --git a/src/keepass2android/PasswordActivity.cs b/src/keepass2android/PasswordActivity.cs index 600cf20d..013f1306 100644 --- a/src/keepass2android/PasswordActivity.cs +++ b/src/keepass2android/PasswordActivity.cs @@ -1390,10 +1390,16 @@ namespace keepass2android private void PerformLoadDatabaseWithCompositeKey(CompositeKey compositeKey) { CheckBox cbQuickUnlock = (CheckBox) FindViewById(Resource.Id.enable_quickunlock); + if (cbQuickUnlock == null) + throw new NullPointerException("cpQuickUnlock"); App.Kp2a.SetQuickUnlockEnabled(cbQuickUnlock.Checked); if (App.Kp2a.OfflineMode != _loadDbTaskOffline) { + if (_loadDbTask == null) + throw new NullPointerException("_loadDbTask"); + if (App.Kp2a == null) + throw new NullPointerException("App.Kp2a"); //keep the loading result if we loaded in online-mode (now offline) and the task is completed if (!App.Kp2a.OfflineMode || !_loadDbTask.IsCompleted) { @@ -1532,11 +1538,11 @@ namespace keepass2android protected override void OnPause() { - base.OnPause(); if (_fingerprintDec != null) { _fingerprintDec.StopListening(); } + base.OnPause(); } private void SetPasswordTypeface(TextView textView) @@ -1607,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) diff --git a/src/keepass2android/Properties/AndroidManifest_net.xml b/src/keepass2android/Properties/AndroidManifest_net.xml index f9b6a89b..13132bdc 100644 --- a/src/keepass2android/Properties/AndroidManifest_net.xml +++ b/src/keepass2android/Properties/AndroidManifest_net.xml @@ -1,6 +1,6 @@  diff --git a/src/keepass2android/QuickUnlock.cs b/src/keepass2android/QuickUnlock.cs index 36aa3ab4..727c1b6b 100644 --- a/src/keepass2android/QuickUnlock.cs +++ b/src/keepass2android/QuickUnlock.cs @@ -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() diff --git a/src/keepass2android/Utils/Util.cs b/src/keepass2android/Utils/Util.cs index fea6ad2f..eba2c9f3 100644 --- a/src/keepass2android/Utils/Util.cs +++ b/src/keepass2android/Utils/Util.cs @@ -482,6 +482,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; + + } } }