Merge pull request #692 from grote/679-consider-other-transports
Better scheduling co-existence with other transport
This commit is contained in:
commit
b07bb6bc48
3 changed files with 14 additions and 5 deletions
|
@ -33,6 +33,7 @@ import com.stevesoltys.seedvault.settings.AppListRetriever
|
||||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||||
import com.stevesoltys.seedvault.settings.SettingsViewModel
|
import com.stevesoltys.seedvault.settings.SettingsViewModel
|
||||||
import com.stevesoltys.seedvault.storage.storageModule
|
import com.stevesoltys.seedvault.storage.storageModule
|
||||||
|
import com.stevesoltys.seedvault.transport.TRANSPORT_ID
|
||||||
import com.stevesoltys.seedvault.transport.backup.backupModule
|
import com.stevesoltys.seedvault.transport.backup.backupModule
|
||||||
import com.stevesoltys.seedvault.transport.restore.restoreModule
|
import com.stevesoltys.seedvault.transport.restore.restoreModule
|
||||||
import com.stevesoltys.seedvault.ui.files.FileSelectionViewModel
|
import com.stevesoltys.seedvault.ui.files.FileSelectionViewModel
|
||||||
|
@ -185,6 +186,7 @@ open class App : Application() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (backupManager.currentTransport == TRANSPORT_ID) {
|
||||||
backupManager.setFrameworkSchedulingEnabledForUser(UserHandle.myUserId(), false)
|
backupManager.setFrameworkSchedulingEnabledForUser(UserHandle.myUserId(), false)
|
||||||
if (backupManager.isBackupEnabled && !pluginManager.isOnRemovableDrive) {
|
if (backupManager.isBackupEnabled && !pluginManager.isOnRemovableDrive) {
|
||||||
AppBackupWorker.schedule(applicationContext, settingsManager, UPDATE)
|
AppBackupWorker.schedule(applicationContext, settingsManager, UPDATE)
|
||||||
|
@ -192,6 +194,7 @@ open class App : Application() {
|
||||||
// cancel old D2D worker
|
// cancel old D2D worker
|
||||||
WorkManager.getInstance(this).cancelUniqueWork("APP_BACKUP")
|
WorkManager.getInstance(this).cancelUniqueWork("APP_BACKUP")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun isFrameworkSchedulingEnabled(): Boolean = Settings.Secure.getInt(
|
private fun isFrameworkSchedulingEnabled(): Boolean = Settings.Secure.getInt(
|
||||||
contentResolver, Settings.Secure.BACKUP_SCHEDULING_ENABLED, 1
|
contentResolver, Settings.Secure.BACKUP_SCHEDULING_ENABLED, 1
|
||||||
|
|
|
@ -18,6 +18,7 @@ import android.net.NetworkRequest
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.BadParcelableException
|
import android.os.BadParcelableException
|
||||||
import android.os.Process.myUid
|
import android.os.Process.myUid
|
||||||
|
import android.os.UserHandle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
@ -308,6 +309,8 @@ internal class SettingsViewModel(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun scheduleAppBackup(existingWorkPolicy: ExistingPeriodicWorkPolicy) {
|
fun scheduleAppBackup(existingWorkPolicy: ExistingPeriodicWorkPolicy) {
|
||||||
|
// disable framework scheduling, because another transport may have enabled it
|
||||||
|
backupManager.setFrameworkSchedulingEnabledForUser(UserHandle.myUserId(), false)
|
||||||
if (!pluginManager.isOnRemovableDrive && backupManager.isBackupEnabled) {
|
if (!pluginManager.isOnRemovableDrive && backupManager.isBackupEnabled) {
|
||||||
AppBackupWorker.schedule(app, settingsManager, existingWorkPolicy)
|
AppBackupWorker.schedule(app, settingsManager, existingWorkPolicy)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ package com.stevesoltys.seedvault.ui.storage
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.app.backup.IBackupManager
|
import android.app.backup.IBackupManager
|
||||||
import android.app.job.JobInfo
|
import android.app.job.JobInfo
|
||||||
|
import android.os.UserHandle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.work.ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE
|
import androidx.work.ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE
|
||||||
|
@ -100,6 +101,8 @@ internal class BackupStorageViewModel(
|
||||||
|
|
||||||
private fun scheduleBackupWorkers() {
|
private fun scheduleBackupWorkers() {
|
||||||
val storage = storagePluginManager.storageProperties ?: error("no storage available")
|
val storage = storagePluginManager.storageProperties ?: error("no storage available")
|
||||||
|
// disable framework scheduling, because another transport may have enabled it
|
||||||
|
backupManager.setFrameworkSchedulingEnabledForUser(UserHandle.myUserId(), false)
|
||||||
if (!storage.isUsb) {
|
if (!storage.isUsb) {
|
||||||
if (backupManager.isBackupEnabled) {
|
if (backupManager.isBackupEnabled) {
|
||||||
AppBackupWorker.schedule(app, settingsManager, CANCEL_AND_REENQUEUE)
|
AppBackupWorker.schedule(app, settingsManager, CANCEL_AND_REENQUEUE)
|
||||||
|
|
Loading…
Reference in a new issue