Skip to content

Permission not requested on Android 10 when targeting API 33 #586

@alexisGandar

Description

@alexisGandar

Bug Report

When writing file in this path " window.cordova.file.externalRootDirectory + 'Download' " it always throws a permission error on getFile action. The bug occur when upgrading on cordova-plugin-file V8 and cordova-android V12 and only on device with Android 10 and bellow. It does work on cordova-plugin-file V7 and cordova-android V11

Problem

The modal that request user authorisation for writing (WRITE_EXTERNAL_STORAGE) does not pop on screen witch lead to an INVALID_MODIFICATION_ERR (code 9) because the permission is not granted

What is expected to happen?

The modal that request the permission is displayed.

What does actually happen?

The modal does not appear

Information

I found out that when writing a file the following action are executed in FileUtils.java :

  • ResolveLocalFileSystemURI
  • RequestAllFileSystem
  • GetFile
  • GetFileMetaData
  • Write

The permission is checked on the "Write" step but on Android 10 (for reasons that I can't explain) the permission seems to be required at the GetFile steps.

I did patch this issus by editing the GetFile steps in order to always ask for permission if needed on this step but I am not sure of the concequencies of this edit : see pull request #587

Command or Code

To reproduce the problem try to save a file with "writeFile" to " window.cordova.file.externalRootDirectory + 'Download'

Environment, Platform, Device

Android 10 with cordova-plugin-file V8 and cordova-android V12

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions