itkach / aard2-android

Aard2 for Android, a simple dictionary app
GNU General Public License v3.0
458 stars 97 forks source link

Doesn't support reading external sdcard on Android 11? #119

Closed ghost closed 3 years ago

ghost commented 3 years ago

I have been using Aard 2 for a while now. Worked like a charm till Android 10 but now on Android 11, the app is unable to read external sdcard. I have tried letting the app automatically search for dictionaries like it does on the first run and yes I tried adding manually by clicking the '+' icon. During manually selecting dictionaries, app is unable to read anything under /storage (although it is able to read files under /storage/emulated/0 (internal storage)). I can't find my external sdcard under /mnt either. And yes, everything is fine with external sdcard (other apps can read and write fine).

aard2

sdcard

Device Info:

itkach commented 3 years ago

Probably related to Storage updates in Android 11, I'll need to investigate

itkach commented 3 years ago

According to Android docs, apps that target Android 9 (API level 28) or lower are opted out of scoped storage "temporarily" (whatever that means), so everything should work as before, but that doesn't appear to be the case on Android 11. Targeting API level 29 and setting the value of requestLegacyExternalStorage to true also has no effect on Android 11, as far as I can tell. So it looks like, contrary to documentation, there's actually no way to opt out of the new storage model and scanning or browsing external SD card file-manager style as implemented today is no longer possible - should be replaced with Storage Access Framework based implementation. This also probably means bumping min sdk version to API Level 19 (Android 4.4)

itkach commented 3 years ago

I was wrong, requestLegacyExternalStorage set to true while targeting API level 29 (which is now minimum for updates to be accepted in Play store) does opt out of scoped storage. The new restriction in Android 11 appears to be that listing content of/storage is no longer allowed, but looks like it's possible to hack around that, like so: 89f066feaf8c04ca6fa741476c9fe38176a7e33f. So that's the good news. The bad news is that this opting out of scoped storage will not be possible once applications are forced to target API level 30 (Android 11) and newer, but Storage Access Framework does not provide a way to work with files directly (working with dictionary files requires random access file interface). So unless Google radically improves Storage Access Framework (and it is in dire need of improvement, to put it mildly) no further updates will be publishable to the Play store soon enough.

francwalter commented 3 years ago

As I understand, Google is superseding external sdcards since a while (beginning Kitkat).

But for Aard2 does this just mean, that use of dictionaries on internal sdcard will be still possible on API 30+?

itkach commented 3 years ago

But for Aard2 does this just mean, that use of dictionaries on internal sdcard will be still possible on API 30+?

I am not so sure. The goal is to restrict application's access to data/files and always have user authorize such access explicitly at a granular level - this is not really about internal vs external storage, so I wouldn't be surprised if in the future direct file access will only be available with files that application "owns". If that happens then the current implementation won't work at all. The app will have to download dictionaries itself, or allow users to "upload" dictionaries to the app so that dictionary files can be written to that one special application directory Android gives access to, or have users copy files over to that directory on their computer. Or Storage Access Framework could provide proper API, but seeing the sorry state it's in I wouldn't hold my breath.

itkach commented 3 years ago

@TuxKruger can you pls test https://github.com/itkach/aard2-android/releases/tag/0.45 and see if it fixes the issue for you?

ghost commented 3 years ago

@TuxKruger can you pls test https://github.com/itkach/aard2-android/releases/tag/0.45 and see if it fixes the issue for you?

@itkach, yeah it fixed the issue, the app is able to read external sdcard.

ghost commented 3 years ago

After using the pre-release for 2 days now, I can confirm that this external sdcard issue is fixed, I think I should close the issue now.