android-browser-helper icon indicating copy to clipboard operation
android-browser-helper copied to clipboard

File Handling: Fails from most apps due to read-only permission

Open marto55555 opened this issue 3 months ago • 2 comments

Describe the bug When opening a file from most apps, into my TWA, it fails with the following error message: Failed to open a file - no read / write permissions: .... From my testing, it seems to happen because most apps send the files as read-only, instead of read and write.

To Reproduce Steps to reproduce the behavior:

  1. Install a demo TWA that registers a file handler, for any file format of your choosing
  2. Open "Files by Google", tap on the 3 dots on a file (in the same file format as step 1) > Open with > demo TWA
  3. The TWA launches, but without receiving the file
  4. See error in Logcat: Failed to open a file - no read / write permissions: ...

Expected behavior The file should be received, even if it's read-only.

For example, Chrome's File Handling API on Windows allows opening read-only files too.

How Chrome seems to behave with read-only files on Windows

In JS, on the launchParams's FileSystemFileHandle I can call getFile() to read the file without any issues.

However, calling FileSystemFileHandle.createWritable() throws an error: NoModificationAllowedError: Failed to execute 'createWritable' on 'FileSystemFileHandle': Cannot write to a read-only file.

Code Snippets It seems to be caused by this check: https://github.com/GoogleChrome/android-browser-helper/blob/ba8eb4d4aa9df52828a5050ce585434e1587d3d3/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivity.java#L318-L323

@orbital17 Could you please change it, so that it only checks for Intent.FLAG_GRANT_READ_URI_PERMISSION?

Additional context For comparison, when using the classic built-in Files app (com.google.android.documentsui) to do Open with > demo TWA, the file is received successfully, because it's sent with read and write permission.

marto55555 avatar Oct 13 '25 08:10 marto55555