diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageRootFetcher.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageRootFetcher.kt index 600f1057..1a74f4df 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageRootFetcher.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageRootFetcher.kt @@ -49,10 +49,11 @@ internal interface RemovableStorageListener { fun onStorageChanged() } -internal class StorageRootFetcher(private val context: Context) { +internal class StorageRootFetcher(private val context: Context, private val isRestore: Boolean) { private val packageManager = context.packageManager private val contentResolver = context.contentResolver + private val whitelistedAuthorities = context.resources.getStringArray(R.array.storage_authority_whitelist) private var listener: RemovableStorageListener? = null private val observer = object : ContentObserver(Handler()) { @@ -85,7 +86,7 @@ internal class StorageRootFetcher(private val context: Context) { roots.addAll(getRoots(providerInfo)) } } - checkOrAddUsbRoot(roots) + if (isAuthoritySupported(AUTHORITY_STORAGE)) checkOrAddUsbRoot(roots) return roots } @@ -165,9 +166,17 @@ internal class StorageRootFetcher(private val context: Context) { } else if (authority == AUTHORITY_DOWNLOADS) { Log.w(TAG, "Not supporting $AUTHORITY_DOWNLOADS") false + } else if (!isAuthoritySupported(authority)) { + Log.w(TAG, "Authority $authority is not white-listed, ignoring...") + false } else true } + private fun isAuthoritySupported(authority: String): Boolean { + // just restrict where to store backups, restoring can be more free for forward compatibility + return isRestore || whitelistedAuthorities.contains(authority) + } + private fun Cursor.getString(columnName: String): String? { val index = getColumnIndex(columnName) return if (index != -1) getString(index) else null diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageViewModel.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageViewModel.kt index 598121bc..60d38376 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageViewModel.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageViewModel.kt @@ -37,7 +37,7 @@ internal abstract class StorageViewModel(private val app: Application) : Android protected val mLocationChecked = MutableLiveEvent() internal val locationChecked: LiveEvent get() = mLocationChecked - private val storageRootFetcher by lazy { StorageRootFetcher(app) } + private val storageRootFetcher by lazy { StorageRootFetcher(app, isRestoreOperation) } private var storageRoot: StorageRoot? = null internal var isSetupWizard: Boolean = false diff --git a/app/src/main/res/values/config.xml b/app/src/main/res/values/config.xml index 313d635a..be0bbc9e 100644 --- a/app/src/main/res/values/config.xml +++ b/app/src/main/res/values/config.xml @@ -1,4 +1,11 @@ true + + + com.android.externalstorage.documents + org.nextcloud.documents + org.nextcloud.beta.documents + +