Skip to content

Keep the content URI when the picked file's path is not writable - #3319

Open
cheblin wants to merge 1 commit into
PhilippC:mainfrom
cheblin:fix/picker-content-uri
Open

cheblin wants to merge 1 commit into
PhilippC:mainfrom
cheblin:fix/picker-content-uri

Conversation

@cheblin

@cheblin cheblin commented Oct 2, 2026

Copy link
Copy Markdown

📝 Description

On Xiaomi HyperOS the system picker is replaced by HyperOS's own "Private access" picker, and providers such as MIUI File Manager and Downloads also return the file path (_data). Util.IntentToFilename prefers that path when the file exists, so the database is opened as a local file. On Android 11+ a file of the shared storage is readable by its path but not writable, so KP2A shows "The file you selected is read-only for Keepass2Android due to restrictions on Android 4.4+..." and asks to copy it. The content URI granted by the picker does allow writing (mode=0x3 in dumpsys activity permissions).

The fix uses the path only if it is writable (File.CanWrite()), otherwise it keeps the content URI. All callers already fall back to data.DataString when IntentToFilename returns null, except one in FileSelectActivity (RequestCodeEditIoc), which now does the same.

🔗 Related Issue

None found.

🛠️ Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

✅ Checklist

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have added/updated tests that prove my fix is effective or that my feature works. No test project covers the file selection.
  • All new and existing tests passed locally.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have built the app locally, verified that it builds and tested the changes thoroughly. Built with the .NET 10 Android workload (36.1), tested on a Xiaomi phone with HyperOS: the database picked through the HyperOS picker now opens writable.

Pickers like the one of HyperOS ("Private access") also return the file
path (_data). On Android 11+ a file of the shared storage is readable but
not writable by its path, so the database opened read-only and asked to be
copied, while the content URI itself grants writing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant