Only request app backup when it is actually enabled

This commit is contained in:
Torsten Grote 2021-06-22 11:01:55 -03:00 committed by Chirayu Desai
parent 1ff8e54748
commit a4cbb0b6df

View file

@ -2,10 +2,8 @@ package com.stevesoltys.seedvault.transport
import android.app.Service
import android.app.backup.BackupManager
import android.app.backup.BackupManager.FLAG_NON_INCREMENTAL_BACKUP // ktlint-disable no-unused-imports
import android.app.backup.IBackupManager
import android.content.Context
import android.content.Context.BACKUP_SERVICE // ktlint-disable no-unused-imports
import android.content.Intent
import android.os.IBinder
import android.os.RemoteException
@ -55,13 +53,15 @@ class ConfigurableBackupTransportService : Service(), KoinComponent {
@WorkerThread
fun requestBackup(context: Context) {
val backupManager: IBackupManager = get().get()
if (backupManager.isBackupEnabled) {
val packageService: PackageService = get().get()
val packages = packageService.eligiblePackages
val appTotals = packageService.expectedAppTotals
val observer = NotificationBackupObserver(context, packages.size, appTotals)
val result = try {
val backupManager: IBackupManager = get().get()
Log.d(TAG, "Backup is enabled, request backup...")
val observer = NotificationBackupObserver(context, packages.size, appTotals)
backupManager.requestBackup(packages, observer, BackupMonitor(), 0)
} catch (e: RemoteException) {
Log.e(TAG, "Error during backup: ", e)
@ -73,4 +73,7 @@ fun requestBackup(context: Context) {
} else {
Log.e(TAG, "Backup failed: $result")
}
} else {
Log.i(TAG, "Backup is not enabled")
}
}