Skip to content

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

@marto55555

Description

@marto55555

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:

int granted = checkCallingOrSelfUriPermission(uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
if (granted != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Failed to open a file - no read / write permissions: " + uri);
return;
}

@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions