OneBusAway / onebusaway-android

The official Android app for OneBusAway
http://www.onebusaway.org/
Other
464 stars 291 forks source link

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

Open amrhossamdev opened 2 months ago

amrhossamdev commented 2 months ago

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

david-allison commented 2 months ago

(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:

amrhossamdev commented 2 months ago

Thanks for your help. I appreciate it!