Merge pull request #725 from grote/usb-respect-backup-setting

Don't back up to USB, if backup disabled
This commit is contained in:
Torsten Grote 2024-08-21 17:06:44 -03:00 committed by GitHub
commit 5b085b6518
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,6 +5,7 @@
package com.stevesoltys.seedvault
import android.app.backup.IBackupManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
@ -37,6 +38,7 @@ class UsbIntentReceiver : UsbMonitor() {
// using KoinComponent would crash robolectric tests :(
private val settingsManager: SettingsManager by lazy { get().get() }
private val metadataManager: MetadataManager by lazy { get().get() }
private val backupManager: IBackupManager by lazy { get().get() }
override fun shouldMonitorStatus(context: Context, action: String, device: UsbDevice): Boolean {
if (action != ACTION_USB_DEVICE_ATTACHED) return false
@ -67,8 +69,10 @@ class UsbIntentReceiver : UsbMonitor() {
// this starts an app backup afterwards
i.putExtra(EXTRA_START_APP_BACKUP, true)
startForegroundService(context, i)
} else {
} else if (backupManager.isBackupEnabled) {
AppBackupWorker.scheduleNow(context, reschedule = false)
} else {
Log.d(TAG, "Neither files nor app backup enabled, do nothing.")
}
}