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:
- Install a demo TWA that registers a file handler, for any file format of your choosing
- Open "Files by Google", tap on the 3 dots on a file (in the same file format as step 1) > Open with > demo TWA
- The TWA launches, but without receiving the file
- 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.
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:
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'sFileSystemFileHandleI can callgetFile()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:
android-browser-helper/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivity.java
Lines 318 to 323 in ba8eb4d
@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.