Merge pull request #53 from grote/50-oem-storage-whitelist
Allow OEMs to configure backup storage whitelist
This commit is contained in:
commit
34d0eb15ca
7 changed files with 42 additions and 8 deletions
10
app/src/debug/res/values/config.xml
Normal file
10
app/src/debug/res/values/config.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?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>
|
|
@ -58,7 +58,7 @@
|
|||
android:label="@string/restore_title"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="com.stevesoltys.seedvault.restore.RESTORE_BACKUP" />
|
||||
<action android:name="com.stevesoltys.seedvault.RESTORE_BACKUP" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
|
|
@ -14,7 +14,7 @@ const val REQUEST_CODE_RECOVERY_CODE = 3
|
|||
const val INTENT_EXTRA_IS_RESTORE = "isRestore"
|
||||
const val INTENT_EXTRA_IS_SETUP_WIZARD = "isSetupWizard"
|
||||
|
||||
private const val ACTION_SETUP_WIZARD = "com.stevesoltys.seedvault.restore.RESTORE_BACKUP"
|
||||
private const val ACTION_SETUP_WIZARD = "com.stevesoltys.seedvault.RESTORE_BACKUP"
|
||||
|
||||
private val TAG = RequireProvisioningActivity::class.java.name
|
||||
|
||||
|
|
|
@ -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,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<bool name="show_restore_in_settings">true</bool>
|
||||
<!--
|
||||
Normally, restoring from backup is only available during initial device setup.
|
||||
You can make it always available at your own risk.
|
||||
Keep in mind that the Auto-Restore feature works independently from this.
|
||||
|
||||
Launch an intent with the action "com.stevesoltys.seedvault.RESTORE_BACKUP"
|
||||
to trigger restore during device setup.
|
||||
-->
|
||||
<bool name="show_restore_in_settings">false</bool>
|
||||
|
||||
<!-- Add only storage that is also available when restoring from backup (e.g. initial device setup) -->
|
||||
<string-array name="storage_authority_whitelist">
|
||||
<item>com.android.externalstorage.documents</item>
|
||||
<item>org.nextcloud.documents</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
buildscript {
|
||||
|
||||
ext.kotlin_version = '1.3.50'
|
||||
ext.kotlin_version = '1.3.61'
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
|
@ -10,7 +10,7 @@ buildscript {
|
|||
}
|
||||
dependencies {
|
||||
// newer versions require us to remove targetSdkVersion from Manifest
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
classpath 'com.android.tools.build:gradle:3.5.3'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
|
Loading…
Add table
Reference in a new issue