Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await Filesystem.requestPermissions() hangs forever #1839

Closed
TDola opened this issue Oct 11, 2023 · 5 comments · Fixed by #1990
Closed

await Filesystem.requestPermissions() hangs forever #1839

TDola opened this issue Oct 11, 2023 · 5 comments · Fixed by #1990

Comments

@TDola
Copy link

TDola commented Oct 11, 2023

Bug Report

Plugin(s)

capacitor/filesystem

Capacitor Version

Latest Dependencies:

  @capacitor/cli: 5.5.0
  @capacitor/core: 5.5.0
  @capacitor/android: 5.5.0
  @capacitor/ios: 5.5.0

Installed Dependencies:

  @capacitor/cli: 5.5.0
  @capacitor/android: 5.5.0
  @capacitor/core: 5.5.0
  @capacitor/ios: 5.5.0

Platform(s)

Android

Current Behavior

If you await the result, or .then() the result, it never resolves when the user click allow.

Expected Behavior

The promise should resolve

Code Reproduction

https://github.com/TDola/capacitor-file-system-request-error/tree/master

// be certain the permission is not already granted, go into app settings and disable storage permission if it is enabled
import { Filesystem } from '@capacitor/filesystem'
const results = await Filesystem.requestPermissions()
console.log(results)

Other Technical Details

Running inside android API 26 emulator

Additional Context

image
It does console log this, and it does grant the permission. So if you force quit and reload, it does resolve the promise the second time
image

I don't really know Java, but I am trying to trace this, and I notice in this function
node_modules/@capacitor/filesystem/android/src/main/java/com/capacitorjs/plugins/filesystem/FilesystemPlugin.java

private void permissionCallback(PluginCall call) {
        if (!isStoragePermissionGranted()) {
            Logger.debug(getLogTag(), "User denied storage permission");
            call.reject(PERMISSION_DENIED_ERROR);
            return;
        }

        switch (call.getMethodName()) {
            case "appendFile":
            case "writeFile":
                writeFile(call);
                break;
            case "deleteFile":
                deleteFile(call);
                break;
            case "mkdir":
                mkdir(call);
                break;
            case "rmdir":
                rmdir(call);
                break;
            case "rename":
                rename(call);
                break;
            case "copy":
                copy(call);
                break;
            case "readFile":
                readFile(call);
                break;
            case "readdir":
                readdir(call);
                break;
            case "getUri":
                getUri(call);
                break;
            case "stat":
                stat(call);
                break;
            case "downloadFile":
                downloadFile(call);
                break;
        }
    }

call.resolve() is never called. I don't know how getMethodName works but there isn't a case for requestPermission or a default

So I added this to the end

            default:
                JSObject permissionsResultJSON = new JSObject();
                permissionsResultJSON.put(PUBLIC_STORAGE, "granted");
                call.resolve(permissionsResultJSON);

And it seems to have made it happy

@Ionitron
Copy link
Collaborator

This issue needs more information before it can be addressed.
In particular, the reporter needs to provide a minimal sample app that demonstrates the issue.
If no sample app is provided within 15 days, the issue will be closed.

Please see the Contributing Guide for how to create a Sample App.

Thanks!
Ionitron 💙

@TDola
Copy link
Author

TDola commented Oct 17, 2023

This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed.

Please see the Contributing Guide for how to create a Sample App.

Thanks! Ionitron 💙

Here is a repo that reproduces the issue.
https://github.com/TDola/capacitor-file-system-request-error/tree/master
It is a bit restrictive in what emulator can run it because the code in the example app requires a very new version of javascript, but API 29 was the sweet spot. But my original test was done on API 26. On API 30 the problem does not happen because storage permission is granted by default.

@ionitron-bot
Copy link

ionitron-bot bot commented Oct 18, 2023

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

@agustinramos
Copy link

Hi @TDola @Ionitron

I leave PR with the fix

#1981

Copy link

ionitron-bot bot commented Jan 30, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Jan 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants