Handle revoked database file access with reselect flow - #2572
empratyush wants to merge 5 commits into
Conversation
Handle SecurityException from takePersistableUriPermission separately so revoked or missing SAF grants are visible in logs before the generic fallback.
FileNotFoundException is already mapped inside database stream parsing, but openInputStream can fail before parsing starts. Convert FileNotFoundException and SecurityException from opening the URI into FileNotFoundDatabaseException so a later change can prompt the user to reselect the file.
Pass EXTRA_INITIAL_URI to SAF so re-selecting a known file starts near its previous location.
Detect missing persisted read access before loading database metadata and launch SAF with the previous URI as the initial picker location.
demo.mp4Demo video of the original and dev versions running on a stock Google Pixel. cc @J-Jamet |
|
This feature is interesting and really improves the workflow. It might be a good idea to add a button to remove the link, but that can be done later. It looks promising. I’ll take a look at the code in version 4.6.0. (it will need to be merged with the latest changes because a refactoring is in progress in version 4.5.0.) |
Thanks! Just ping me when it needs rebasing. |
|
I found another workaround that fixes the issue. When I open KeePassDX and see the file path instead of the database name (which usually means I'm about to get a "permission revoked" error), I don't try to open the database or remove and re-add it. Instead, I tap "Open Existing Vault" at the bottom and simply reselect the same database file. That restores access and fixes the issue. |
|
The Open Existing Vault workaround only works sometimes for me. Very often I still get stuck being unable to open the db until I remove and readd the db file... (4.4.5 from Fdroid) |
|
Is it not possible to request from the file manager access to an entire folder instead? Would that solve the problem? Actually based on the linked other project above it seems like a working solution: |
Summary
This PR improves the recovery flow when Android/SAF revokes access to the selected database file. Instead of requiring users to remove and re-add the database, KeePassDX now prompts them to reselect the file directly, opening the picker near the previous file location when possible.
Changes
KeePassDX now detects revoked persisted access before opening the database, treats revoked or missing URI access as an inaccessible database, and routes the user into the reselect-file flow.
Background
I have been using KeePassXC for a long time, with my database synced through Nextcloud. After switching to a new device, the Nextcloud app started behaving strangely and would crash when I tried to open the database through SAF. So I switched to FolderSync Pro instead.
At first, everything worked fine. The issue started after I modified an entry from the desktop side. KeePassDX then showed:
The workaround was to remove the database from KeePassDX and add it again. That fixed it temporarily, but the issue came back every time the database was modified from the desktop side.
My assumption is that FolderSync Pro recreates the database file during sync, or at least Android treats it that way, which invalidates the existing SAF permission grant.
This PR adds a smoother recovery flow for that case: when access to the database file is revoked, KeePassDX now lets the user reselect the same database file instead of requiring them to remove and re-add it manually.
One more thing I noticed during the workaround: after removing and re-adding the same database, the database password was fetched automatically after the biometric prompt. I am not sure if that behavior is expected.