Fall back to internal storage...

if external private storage is unavailable
pull/3973/head
Alex Baker 4 weeks ago
parent 94ad2a381e
commit 8e9f27c46e

@ -378,7 +378,7 @@ class Preferences @JvmOverloads constructor(
val backupDirectory: Uri?
get() = getDirectory(R.string.p_backup_dir, "backups")
val externalStorage: Uri
val appPrivateStorage: Uri
get() = root.uri
val attachmentsDirectory: Uri?
@ -412,13 +412,12 @@ class Preferences @JvmOverloads constructor(
?: getDefaultFileLocation(name)?.let { Uri.fromFile(it) }
private val root: DocumentFile
get() = DocumentFile.fromFile(context.getExternalFilesDir(null)!!)
get() = DocumentFile.fromFile(context.getExternalFilesDir(null) ?: context.filesDir)
private fun getDefaultFileLocation(type: String): File? {
val externalFilesDir = context.getExternalFilesDir(null) ?: return null
val path = String.format("%s/%s", externalFilesDir.absolutePath, type)
val file = File(path)
return if (file.isDirectory || file.mkdirs()) file else null
val baseDir = context.getExternalFilesDir(null) ?: context.filesDir
val path = File(baseDir, type)
return if (path.isDirectory || path.mkdirs()) path else null
}
private fun hasWritePermission(context: Context, uri: Uri): Boolean =

@ -2,6 +2,7 @@ package org.tasks.preferences
import android.content.ContentResolver
import android.content.Context
import android.net.Uri
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
@ -51,8 +52,16 @@ class PreferencesViewModel @Inject constructor(
get() = isStale(lastDriveBackup.value) && isStale(lastAndroidBackup.value)
val usingPrivateStorage: Boolean
get() = preferences.backupDirectory.let {
it == null || it.toString().startsWith(preferences.externalStorage.toString())
get() = preferences.backupDirectory.let { backupDir ->
val backupDirStr = backupDir?.toString() ?: return true
context
.getExternalFilesDir(null)
?.let {
if (backupDirStr.startsWith(Uri.fromFile(it).toString())) {
return true
}
}
return backupDirStr.startsWith(Uri.fromFile(context.filesDir).toString())
}
val driveAccount: String?

@ -257,7 +257,7 @@ class Backups : InjectingPreferenceFragment() {
pref.summary = """
$location
${requireContext().getString(R.string.backup_location_warning, FileHelper.uri2String(preferences.externalStorage))}
${requireContext().getString(R.string.backup_location_warning, FileHelper.uri2String(preferences.appPrivateStorage))}
""".trimIndent()
} else {
pref.icon = null

Loading…
Cancel
Save