Explain better how we force initialization via the SettingsManager
This commit is contained in:
parent
3a717b109d
commit
25962ed307
3 changed files with 19 additions and 2 deletions
|
@ -32,6 +32,7 @@ internal class DocumentsProviderBackupPlugin(
|
||||||
// check if storage is already initialized
|
// check if storage is already initialized
|
||||||
if (storage.isInitialized()) return false
|
if (storage.isInitialized()) return false
|
||||||
|
|
||||||
|
// TODO consider not creating new RestoreSets, but continue working within the existing one.
|
||||||
// reset current storage
|
// reset current storage
|
||||||
storage.reset(newToken)
|
storage.reset(newToken)
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package com.stevesoltys.seedvault.settings
|
package com.stevesoltys.seedvault.settings
|
||||||
|
|
||||||
|
import android.app.backup.RestoreSet
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.hardware.usb.UsbDevice
|
import android.hardware.usb.UsbDevice
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.annotation.UiThread
|
import androidx.annotation.UiThread
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
|
import com.stevesoltys.seedvault.transport.ConfigurableBackupTransport
|
||||||
import java.util.concurrent.ConcurrentSkipListSet
|
import java.util.concurrent.ConcurrentSkipListSet
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
|
@ -44,7 +46,6 @@ class SettingsManager(context: Context) {
|
||||||
.putString(PREF_KEY_STORAGE_NAME, storage.name)
|
.putString(PREF_KEY_STORAGE_NAME, storage.name)
|
||||||
.putBoolean(PREF_KEY_STORAGE_IS_USB, storage.isUsb)
|
.putBoolean(PREF_KEY_STORAGE_IS_USB, storage.isUsb)
|
||||||
.apply()
|
.apply()
|
||||||
isStorageChanging.set(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getStorage(): Storage? {
|
fun getStorage(): Storage? {
|
||||||
|
@ -56,7 +57,21 @@ class SettingsManager(context: Context) {
|
||||||
return Storage(uri, name, isUsb)
|
return Storage(uri, name, isUsb)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO find a better solution for this hack abusing the settings manager
|
/**
|
||||||
|
* When [ConfigurableBackupTransport.initializeDevice] we try to avoid deleting all stored data,
|
||||||
|
* as this gets frequently called after network errors by SAF cloud providers.
|
||||||
|
*
|
||||||
|
* This method allows us to force a re-initialization of the underlying storage root
|
||||||
|
* when we change to a new storage provider.
|
||||||
|
* Currently, this causes us to create a new [RestoreSet].
|
||||||
|
*
|
||||||
|
* As part of the initialization, [getAndResetIsStorageChanging] should get called
|
||||||
|
* to prevent future calls from causing re-initializations.
|
||||||
|
*/
|
||||||
|
fun forceStorageInitialization() {
|
||||||
|
isStorageChanging.set(true)
|
||||||
|
}
|
||||||
|
|
||||||
fun getAndResetIsStorageChanging(): Boolean {
|
fun getAndResetIsStorageChanging(): Boolean {
|
||||||
return isStorageChanging.getAndSet(false)
|
return isStorageChanging.getAndSet(false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ internal class BackupStorageViewModel(
|
||||||
|
|
||||||
override fun onLocationSet(uri: Uri) {
|
override fun onLocationSet(uri: Uri) {
|
||||||
val isUsb = saveStorage(uri)
|
val isUsb = saveStorage(uri)
|
||||||
|
settingsManager.forceStorageInitialization()
|
||||||
|
|
||||||
// initialize the new location, will also generate a new backup token
|
// initialize the new location, will also generate a new backup token
|
||||||
val observer = InitializationObserver()
|
val observer = InitializationObserver()
|
||||||
|
|
Loading…
Reference in a new issue