Move Settings.Secure backup flags into BackupStateManager
This commit is contained in:
parent
109e0ae281
commit
09074c5dff
3 changed files with 15 additions and 9 deletions
|
@ -17,7 +17,6 @@ import android.os.ServiceManager.getService
|
|||
import android.os.StrictMode
|
||||
import android.os.UserHandle
|
||||
import android.os.UserManager
|
||||
import android.provider.Settings
|
||||
import androidx.work.ExistingPeriodicWorkPolicy.UPDATE
|
||||
import androidx.work.WorkManager
|
||||
import com.google.android.material.color.DynamicColors
|
||||
|
@ -148,6 +147,7 @@ open class App : Application() {
|
|||
private val metadataManager: MetadataManager by inject()
|
||||
private val backupManager: IBackupManager by inject()
|
||||
private val pluginManager: StoragePluginManager by inject()
|
||||
private val backupStateManager: BackupStateManager by inject()
|
||||
|
||||
/**
|
||||
* The responsibility for the current token was moved to the [SettingsManager]
|
||||
|
@ -168,7 +168,7 @@ open class App : Application() {
|
|||
* Introduced in the first half of 2024 and can be removed after a suitable migration period.
|
||||
*/
|
||||
protected open fun migrateToOwnScheduling() {
|
||||
if (!isFrameworkSchedulingEnabled()) { // already on own scheduling
|
||||
if (!backupStateManager.isFrameworkSchedulingEnabled) { // already on own scheduling
|
||||
// fix things for removable drive users who had a job scheduled here before
|
||||
if (pluginManager.isOnRemovableDrive) AppBackupWorker.unschedule(applicationContext)
|
||||
return
|
||||
|
@ -184,10 +184,6 @@ open class App : Application() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun isFrameworkSchedulingEnabled(): Boolean = Settings.Secure.getInt(
|
||||
contentResolver, Settings.Secure.BACKUP_SCHEDULING_ENABLED, 1
|
||||
) == 1 // 1 means enabled which is the default
|
||||
|
||||
}
|
||||
|
||||
const val MAGIC_PACKAGE_MANAGER: String = PACKAGE_MANAGER_SENTINEL
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
package com.stevesoltys.seedvault
|
||||
|
||||
import android.content.Context
|
||||
import android.provider.Settings
|
||||
import android.provider.Settings.Secure.BACKUP_AUTO_RESTORE
|
||||
import android.provider.Settings.Secure.BACKUP_SCHEDULING_ENABLED
|
||||
import android.util.Log
|
||||
import androidx.work.WorkInfo.State.RUNNING
|
||||
import androidx.work.WorkManager
|
||||
|
@ -22,6 +25,7 @@ class BackupStateManager(
|
|||
) {
|
||||
|
||||
private val workManager = WorkManager.getInstance(context)
|
||||
private val contentResolver = context.contentResolver
|
||||
|
||||
val isBackupRunning: Flow<Boolean> = combine(
|
||||
flow = ConfigurableBackupTransportService.isRunning,
|
||||
|
@ -37,4 +41,10 @@ class BackupStateManager(
|
|||
appBackupRunning || filesBackupRunning || workInfoState == RUNNING
|
||||
}
|
||||
|
||||
val isAutoRestoreEnabled: Boolean
|
||||
get() = Settings.Secure.getInt(contentResolver, BACKUP_AUTO_RESTORE, 1) == 1
|
||||
|
||||
val isFrameworkSchedulingEnabled: Boolean
|
||||
get() = Settings.Secure.getInt(contentResolver, BACKUP_SCHEDULING_ENABLED, 1) == 1
|
||||
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import android.os.PowerManager
|
||||
import android.os.RemoteException
|
||||
import android.provider.Settings
|
||||
import android.provider.Settings.Secure.BACKUP_AUTO_RESTORE
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
|
@ -25,6 +23,7 @@ import androidx.preference.PreferenceFragmentCompat
|
|||
import androidx.preference.TwoStatePreference
|
||||
import androidx.work.WorkInfo
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.stevesoltys.seedvault.BackupStateManager
|
||||
import com.stevesoltys.seedvault.R
|
||||
import com.stevesoltys.seedvault.permitDiskReads
|
||||
import com.stevesoltys.seedvault.plugins.StoragePluginManager
|
||||
|
@ -41,6 +40,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
|
||||
private val viewModel: SettingsViewModel by sharedViewModel()
|
||||
private val storagePluginManager: StoragePluginManager by inject()
|
||||
private val backupStateManager: BackupStateManager by inject()
|
||||
private val backupManager: IBackupManager by inject()
|
||||
|
||||
private lateinit var backup: TwoStatePreference
|
||||
|
@ -251,7 +251,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
|
||||
private fun setAutoRestoreState() {
|
||||
activity?.contentResolver?.let {
|
||||
autoRestore.isChecked = Settings.Secure.getInt(it, BACKUP_AUTO_RESTORE, 1) == 1
|
||||
autoRestore.isChecked = backupStateManager.isAutoRestoreEnabled
|
||||
}
|
||||
val storage = this.storageProperties
|
||||
if (storage?.isUsb == true) {
|
||||
|
|
Loading…
Reference in a new issue