Bug fixes:

* make sure we never have an invalid startIndex in PwGroup.SearchEvalAdd
 * make sure AndroidContentStorage does never throw (not if permission denial exception occurs) and make sure we always return a reason for read-only. Also don't return read-only when it's not.
 * StopListening doesn't log Invalid State Exception as unexpected
This commit is contained in:
Philipp Crocoll 2016-01-18 21:18:22 +01:00
parent 311316ea50
commit aaa6b371e0
5 changed files with 38 additions and 19 deletions

View File

@ -990,7 +990,7 @@ namespace KeePassLib
if (contextString.Length > SearchContextStringMaxLength) if (contextString.Length > SearchContextStringMaxLength)
{ {
// Start 10% before actual data, and don't run over // Start 10% before actual data, and don't run over
var startPos = Math.Min(matchPos - (SearchContextStringMaxLength / 10), contextString.Length - SearchContextStringMaxLength); var startPos = Math.Max(0, Math.Min(matchPos - (SearchContextStringMaxLength / 10), contextString.Length - SearchContextStringMaxLength));
contextString = "… " + contextString.Substring(startPos, SearchContextStringMaxLength) + ((startPos + SearchContextStringMaxLength < contextString.Length) ? " …" : null); contextString = "… " + contextString.Substring(startPos, SearchContextStringMaxLength) + ((startPos + SearchContextStringMaxLength < contextString.Length) ? " …" : null);
} }
resultContexts[pe.Uuid] = new KeyValuePair<string, string>(contextFieldName, contextString); resultContexts[pe.Uuid] = new KeyValuePair<string, string>(contextFieldName, contextString);

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Android.Content; using Android.Content;
using Android.Database;
using Android.OS; using Android.OS;
using Android.Provider; using Android.Provider;
using KeePassLib.Serialization; using KeePassLib.Serialization;
@ -208,6 +209,9 @@ namespace keepass2android.Io
public bool IsReadOnly(IOConnectionInfo ioc, OptionalOut<UiStringKey> reason = null) public bool IsReadOnly(IOConnectionInfo ioc, OptionalOut<UiStringKey> reason = null)
{
ICursor cursor = null;
try
{ {
//on pre-Kitkat devices, we can't write content:// files //on pre-Kitkat devices, we can't write content:// files
if (!IsKitKatOrLater) if (!IsKitKatOrLater)
@ -221,10 +225,8 @@ namespace keepass2android.Io
//KitKat or later... //KitKat or later...
var uri = Android.Net.Uri.Parse(ioc.Path); var uri = Android.Net.Uri.Parse(ioc.Path);
var cursor = _ctx.ContentResolver.Query(uri, null, null, null, null, null); cursor = _ctx.ContentResolver.Query(uri, null, null, null, null, null);
try
{
if (cursor != null && cursor.MoveToFirst()) if (cursor != null && cursor.MoveToFirst())
{ {
int flags = cursor.GetInt(cursor.GetColumnIndex(DocumentsContract.Document.ColumnFlags)); int flags = cursor.GetInt(cursor.GetColumnIndex(DocumentsContract.Document.ColumnFlags));
@ -235,14 +237,23 @@ namespace keepass2android.Io
reason.Result = UiStringKey.ReadOnlyReason_ReadOnlyFlag; reason.Result = UiStringKey.ReadOnlyReason_ReadOnlyFlag;
return true; return true;
} }
else return false;
} }
else throw new Exception("couldn't move to first result element");
}
catch (Exception e)
{
Kp2aLog.LogUnexpectedError(e);
//better return false here. We don't really know what happened (as this is unexpected).
//let the user try to write the file. If it fails they will get an exception string.
return false;
} }
finally finally
{ {
if (cursor != null) if (cursor != null)
cursor.Close(); cursor.Close();
} }
return true;
} }
} }

View File

@ -134,7 +134,11 @@ namespace keepass2android
} }
catch (IllegalStateException ise) catch (IllegalStateException ise)
{ {
Kp2aLog.LogUnexpectedError(ise); Kp2aLog.Log(ise.ToString());
}
catch (System.Exception e)
{
Kp2aLog.LogUnexpectedError(e);
} }
} }
} }

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="71" android:versionCode="73"
android:versionName="1.0.0 preview 4" android:versionName="1.0.0 preview 6"
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

@ -616,6 +616,7 @@
<string name="PreviewWarning">Please note! This is a preview release and might come with some flaws! If you experience *anything* unexpected, please let me know (on Codeplex or by email).</string> <string name="PreviewWarning">Please note! This is a preview release and might come with some flaws! If you experience *anything* unexpected, please let me know (on Codeplex or by email).</string>
<string name="PreviewErrorReports"> Whenever you see a question if you want to enable error reports, please do so!</string>
<string name="Continue">Continue</string> <string name="Continue">Continue</string>
<string name="NoFilenameWarning">The URI you have entered does not look like a filename. Are you sure this is a valid file?</string> <string name="NoFilenameWarning">The URI you have entered does not look like a filename. Are you sure this is a valid file?</string>
@ -655,7 +656,7 @@
</string> </string>
<string name="ChangeLog_1_0_0"> <string name="ChangeLog_1_0_0">
Version 1.0.0 - preview 4\n Version 1.0.0 - preview 5\n
* Fingerprint Unlock (requires Android 6.0+ or a Samsung device)\n * Fingerprint Unlock (requires Android 6.0+ or a Samsung device)\n
* Added support for entry templates\n * Added support for entry templates\n
* Added "work offline" mode\n * Added "work offline" mode\n
@ -663,6 +664,9 @@
* Auto-complete mode for field names\n * Auto-complete mode for field names\n
* Allow to remove items from recent files list\n * Allow to remove items from recent files list\n
* Request permissions at runtime in Android 6.0\n * Request permissions at runtime in Android 6.0\n
* Bug fixes (in built-in keyboard, when selecting icons)\n
* Included option to send error reports\n
* Added help messages at several points\n
* more to come...\n * more to come...\n
</string> </string>