improve message when storage access framework access permission is revoked
This commit is contained in:
		| @@ -2,12 +2,15 @@ using System; | ||||
| using System.Collections.Generic; | ||||
| using System.IO; | ||||
| using System.Linq; | ||||
| using System.Runtime.Serialization; | ||||
| using Android; | ||||
| using Android.Content; | ||||
| using Android.Database; | ||||
| using Android.OS; | ||||
| using Android.Provider; | ||||
| using Java.IO; | ||||
| using KeePassLib.Serialization; | ||||
| using Console = System.Console; | ||||
|  | ||||
| namespace keepass2android.Io | ||||
| { | ||||
| @@ -51,7 +54,20 @@ namespace keepass2android.Io | ||||
|  | ||||
| 		public Stream OpenFileForRead(IOConnectionInfo ioc) | ||||
| 		{ | ||||
| 			return _ctx.ContentResolver.OpenInputStream(Android.Net.Uri.Parse(ioc.Path)); | ||||
| 		    try | ||||
|             {  | ||||
| 		        return _ctx.ContentResolver.OpenInputStream(Android.Net.Uri.Parse(ioc.Path)); | ||||
| 		    } | ||||
| 		    catch (Exception e) | ||||
| 		    { | ||||
| 		        if (e.Message.Contains("requires that you obtain access using ACTION_OPEN_DOCUMENT")) | ||||
| 		        { | ||||
| 		            //looks like permission was revoked. | ||||
| 		            throw new DocumentAccessRevokedException(); | ||||
| 		        } | ||||
| 		        throw; | ||||
| 		    } | ||||
| 			 | ||||
| 		} | ||||
|  | ||||
| 		public IWriteTransaction OpenWriteTransaction(IOConnectionInfo ioc, bool useFileTransaction) | ||||
| @@ -267,7 +283,26 @@ namespace keepass2android.Io | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	class AndroidContentWriteTransaction : IWriteTransaction | ||||
|     public class DocumentAccessRevokedException : Exception | ||||
|     { | ||||
|         public DocumentAccessRevokedException() | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public DocumentAccessRevokedException(string message) : base(message) | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public DocumentAccessRevokedException(string message, Exception innerException) : base(message, innerException) | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         protected DocumentAccessRevokedException(SerializationInfo info, StreamingContext context) : base(info, context) | ||||
|         { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     class AndroidContentWriteTransaction : IWriteTransaction | ||||
| 	{ | ||||
| 		private readonly string _path; | ||||
| 		private readonly Context _ctx; | ||||
|   | ||||
| @@ -63,7 +63,8 @@ namespace keepass2android | ||||
| 		AskDeletePermanentlyItems, | ||||
| 		AskDeletePermanentlyItemsNoRecycle, | ||||
| 		InOfflineMode, | ||||
| 		DuplicateTitle, | ||||
|         DocumentAccessRevoked, | ||||
|         DuplicateTitle, | ||||
| 		TemplateTitle_IdCard, | ||||
| 		TemplateField_IdCard_Name, | ||||
| 		TemplateField_IdCard_PlaceOfIssue, | ||||
|   | ||||
| @@ -403,6 +403,8 @@ | ||||
|   <string name="IconVisibilityInfo_Android8_btnSettings">Open settings</string> | ||||
|   <string name="DontCare">I don\'t care</string> | ||||
|  | ||||
|   <string name="DocumentAccessRevoked">The file is no longer accessible to Keepass2Android. Either it was removed or the access permissions have been revoked. Please use re-open the file, e.g. using Change database.</string> | ||||
|  | ||||
| 	<string name="PreloadDatabaseEnabled_title">Pre-load database file</string> | ||||
| 	<string name="PreloadDatabaseEnabled_summary">Start background loading or downloading of the database file during password entry.</string> | ||||
|  | ||||
|   | ||||
| @@ -714,7 +714,10 @@ namespace keepass2android | ||||
| 			string errorMessage = e.Message; | ||||
| 			if (e is OfflineModeException) | ||||
| 				errorMessage = GetResourceString(UiStringKey.InOfflineMode); | ||||
| 			return errorMessage; | ||||
| 		    if (e is DocumentAccessRevokedException) | ||||
| 		        errorMessage = GetResourceString(UiStringKey.DocumentAccessRevoked); | ||||
|  | ||||
|             return errorMessage; | ||||
| 		} | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Philipp Crocoll
					Philipp Crocoll