onebusaway-android icon indicating copy to clipboard operation
onebusaway-android copied to clipboard

[BUG] Backup Storage Functionality Broken on Android 13 and Above - Storage Permissions

Open amrhossamdev opened this issue 9 months ago • 2 comments

Summary:

We got a report from a user with Android version 33 that he can't grant permissions for saving a backup in the storage, I started to investigate and I found that we use permissions READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE now replaced with READ_MEDIA_IMAGES and READ_MEDIA_VIDEO for higher android version from API 33 and above. See android docs

I tested this on my Android 13 emulator and can confirm it's broken.

Useful discussion/articles:

Steps to reproduce:

  1. Go to the settings
  2. Try to save a backup to storage

Expected behavior:

Dialog pop-up asking for the permissions

Observed behavior:

No dialog asking for permission

Device and Android version:

Android Version: 13 - API 33

Video

Screencast from 04-28-2024 11:35:15 PM.webm

amrhossamdev avatar Apr 28 '24 20:04 amrhossamdev

(just caught the issue link, great timing!)

READ_MEDIA_IMAGES and READ_MEDIA_VIDEO are not going to be sufficient for your intention

You want to look into ACTION_OPEN_DOCUMENT_TREE to obtain permissions to write to a folder on external storage (incl. cloud providers).

Note that this uses a androidx.documentfile.provider.DocumentFile, but this should be sufficient for writing backups.

https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT_TREE

Additional Reading

CommonsWare has a great series on the Android 10/11 storage changes:

https://commonsware.com/blog/2019/10/19/scoped-storage-stories-saf-basics.html

Also see:

  • https://developer.android.com/about/versions/11/privacy/storage
  • https://source.android.com/docs/core/storage/scoped

david-allison avatar Apr 29 '24 15:04 david-allison

Thanks for your help. I appreciate it!

amrhossamdev avatar Apr 29 '24 15:04 amrhossamdev