quran / quran_android

a quran reading application for android
http://android.quran.com
GNU General Public License v3.0
2.01k stars 888 forks source link

Storage, file paths, and the future #705

Open ahmedre opened 7 years ago

ahmedre commented 7 years ago

The Problem

Historically, Quran has written to /sdcard/quran_android using the WRITE_EXTERNAL_STORAGE permission. In KitKat, the first signs of the fact that this wasn't Google's preference started appearing, with the permission no longer being needed to write to the app's own directory in /sdcard/Android/data. Marshmallow further made WRITE_EXTERNAL_STORAGE a dangerous permission, and there are many rumors that the days of this permission working are very limited.

Today

The current state of the world is as follows:

In addition, there's an "advanced setting" that lets the person customize the partition where we store data. The list of partitions is added via getExternalFilesDirs on KitKat and above, and by some hacks (reading /proc/mounts and /system/etc/vold.fstab files) on older versions.

Ideally, we should simplify things and prefer for people to store within the app's data directory moving forward.

Considerations

Points to keep in mind:

  1. a long long time ago, we did use getExternalFilesDir to store data, but people complained that they were losing their pages whenever they'd update the app. If this is true, hopefully this is fixed now, since we last tried this as the only option a really long time ago.

  2. using getExternalFilesDir prevents sharing of data files on multi-user devices due to sandboxing.

  3. people who upgrade from Lollipop to Marshmallow may be upset at "losing their data" if we decide to just write to getExternalFilesDirs.

  4. people often want to explicitly set a directory to use for Quran's files.

Proposed Solution

  1. Before Marshmallow, the behavior remains the same - default to /sdcard/quran_android.
  2. On Marshmallow and above, for existing installs of the app, continue to respect the settings present today.
  3. On Marshmallow and above for new installs of the app, default to using getExternalFilesDir, and perhaps add a small button with "Advanced" that would then take them to the setting in point 4 below.
  4. On all devices, an advanced setting would exist that's just a freeform text input, wherein the person can specify the path to use. This is the approach taken by the famous podcast app, PocketCasts. There're two settings - "Store podcasts on" (defaults to phone, but can select "custom folder"), and "Custom folder location" (disabled until "custom folder" is selected, and then defaults to getExternalFilesDir, but can be modified by the person using the app).

Thoughts?

ozbek commented 7 years ago

I don't understand how putting "freeform custom folder location" solves issue with WRITE_EXTERNAL_STORAGE permission.

ahmedre commented 7 years ago

you're right, it doesn't - but it's part of the fix so that we can remove all the hacky code that's trying to read the mounts and vold file and still support writing wherever for people who grant permissions (until one day, it's no longer possible, then we just set a maximum sdk on it).