Add a configurable white-list for backup storage
This commit is contained in:
parent
f246d16492
commit
49ce4b393f
3 changed files with 19 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -37,7 +37,7 @@ internal abstract class StorageViewModel(private val app: Application) : Android
|
|||
protected val mLocationChecked = MutableLiveEvent<LocationResult>()
|
||||
internal val locationChecked: LiveEvent<LocationResult> 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
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<bool name="show_restore_in_settings">true</bool>
|
||||
|
||||
<string-array name="storage_authority_whitelist">
|
||||
<item>com.android.externalstorage.documents</item>
|
||||
<item>org.nextcloud.documents</item>
|
||||
<item>org.nextcloud.beta.documents</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue