Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Could not load your database.' error #1096

Closed
johnd0e opened this issue Sep 10, 2021 · 7 comments
Closed

'Could not load your database.' error #1096

johnd0e opened this issue Sep 10, 2021 · 7 comments

Comments

@johnd0e
Copy link

johnd0e commented Sep 10, 2021

I keep my database on Google Drive.
And (from time to time) KeePassDX has difficulties to open it on start

Could not load your database. java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.docs.storagebackend.StorageBackendContentProvider from ProcessRecord{7ccec12 22497:com.kunzisoft.keepass.free/u0a401} (pid=22497, uid=10401) requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
@J-Jamet
Copy link
Member

J-Jamet commented Sep 10, 2021

Please fill in the bug template correctly with the version of the applications used and be more specific in describing the problem conditions.
Linked to #1066 #1067 #1071 #1094

@johnd0e
Copy link
Author

johnd0e commented Sep 11, 2021

Describe the bug
I keep my database on Google Drive.
Sometimes (not often) when starting KeePassDX I get such error:

Could not load your database. java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.docs.storagebackend.StorageBackendContentProvider from ProcessRecord{7ccec12 22497:com.kunzisoft.keepass.free/u0a401} (pid=22497, uid=10401) requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs

After that my database disappers from the list, but I am able to readd it again in usual way (picking in filemanager).

To Reproduce
Steps to reproduce the behavior:

  1. Start KeePassDX from launcher
  2. See toast with error

Expected behavior
Either no error, or some clear and descriptive dialog.

KeePass Database

  • Created with: Windows KeePass 2.47
  • Version: 2
  • Location: Remote file retrieved with GDrive app
  • Size: 127KB
  • Contains attachment: No

KeePassDX (please complete the following information):

  • Version: 3.0
  • Build: Free
  • Language: English

Android (please complete the following information):

  • Device: LG ThinQ V35
  • Version: 10

Additional context
I'm also using KeePass 2.48.1 on my Windows machine, with local database, syncing it with GDrive using KPSync For Google Drive 4.0.7.0 plugin.

@J-Jamet
Copy link
Member

J-Jamet commented Sep 11, 2021

Thanks for formatting the issue.
This behavior of Google Drive has already been reported in the wiki.
The exception is raised when the content provider of Google Drive is no longer able to provide the rights to the file.
I think the file is invalidated for safety because it has not finished synchronizing internally.
As you say, it is enough to reselect the file from its location.

https://github.com/Kunzisoft/KeePassDX/wiki/File-Manager-and-Sync#compatibility
#1089

@johnd0e
Copy link
Author

johnd0e commented Sep 13, 2021

This behavior of Google Drive has already been reported in the wiki.

I do not feel that it is enough to file it in the wiki.
If this exception is known and expected - then you could display user-friendly dialog with "reopen" button instead of brief and weird toast.

Also from your explanation I haven't figured out if your code makes use of persist permissions:
https://developer.android.com/training/data-storage/shared/documents-files#persist-permissions

@J-Jamet
Copy link
Member

J-Jamet commented Sep 14, 2021

If this exception is known and expected - then you could display user-friendly dialog with "reopen" button instead of brief and weird toast.

This is not an expected behavior because by definition it is an exception.

Also from your explanation I haven't figured out if your code makes use of persist permissions:
https://developer.android.com/training/data-storage/shared/documents-files#persist-permissions

private fun persistUriPermission(contentResolver: ContentResolver?,

https://github.com/Kunzisoft/KeePassDX/wiki/File-Manager-and-Sync#why-disparate-compatibility

@johnd0e
Copy link
Author

johnd0e commented Sep 14, 2021

This is not an expected behavior because by definition it is an exception.

If some operation is known to be exception-prone, then it is possible to process exceptions and present them in user-friendly form. I mean some dialog, which would contain a hint what was wrong and how to fix that (e.g. adding "Reopen datavase" button right to that dialog).

@J-Jamet
Copy link
Member

J-Jamet commented Sep 14, 2021

But this exception (java.lang.SecurityException: Permission Denial) should not happen, adding a dialog is just a workaround.

I don't know why this is happening to you for the database URI but the only cases I've referenced is an already fixed problem related to key file permissions. What I put in the related issues #1066 #1067 #1071 #1094

Either you have used the 3.0.0 beta version of KeePassDX (#1066) with a key file and you only need to reselect the file once with the stable version 3.0.0 to solve the problem and you made a mistake in writing the issue.

Either as you describe, it comes from the main URI of the database from Google Drive, so it's a problem in the file manager. And I'm not going to make a specific dialog for each error case without being able to test all the errors that I don't even know exist due to the unwanted behavior of external applications...

If this exception happens for the main database URI it means that the file permissions have been released in another way and not by KeePassDX so it's up to the application that releases the URI to know what it's doing.

Displaying the exception in a dialog or in a snackbar does not change the use of the application, is only a change of view and does not solve a problem.
A reopen database button assumes that an exception is normal and will not work in the majority of exceptions.
Normally you should not even be able to reopen the database if there is this Permission Denial exception because it clearly means that there is no permission allowed!

I added the URI check on purpose to know if it was possible to open the database or not. Maybe the exception is raised in your case because Google Drive has not finished synchronizing your file in its cache, I don't know and KeePassDX doesn't have to know, just ask if it has the right or not. If Google Drive answers no but actually has the permissions, I can't do anything.

So I'm not going to counteract unintended behavior of external file provider with weird tricks based on URIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants