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.Service
import android.app.backup.BackupManager 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.app.backup.IBackupManager
import android.content.Context import android.content.Context
import android.content.Context.BACKUP_SERVICE // ktlint-disable no-unused-imports
import android.content.Intent import android.content.Intent
import android.os.IBinder import android.os.IBinder
import android.os.RemoteException import android.os.RemoteException
@ -55,22 +53,27 @@ class ConfigurableBackupTransportService : Service(), KoinComponent {
@WorkerThread @WorkerThread
fun requestBackup(context: Context) { fun requestBackup(context: Context) {
val packageService: PackageService = get().get() val backupManager: IBackupManager = get().get()
val packages = packageService.eligiblePackages if (backupManager.isBackupEnabled) {
val appTotals = packageService.expectedAppTotals val packageService: PackageService = get().get()
val packages = packageService.eligiblePackages
val appTotals = packageService.expectedAppTotals
val observer = NotificationBackupObserver(context, packages.size, appTotals) val result = try {
val result = try { Log.d(TAG, "Backup is enabled, request backup...")
val backupManager: IBackupManager = get().get() val observer = NotificationBackupObserver(context, packages.size, appTotals)
backupManager.requestBackup(packages, observer, BackupMonitor(), 0) backupManager.requestBackup(packages, observer, BackupMonitor(), 0)
} catch (e: RemoteException) { } catch (e: RemoteException) {
Log.e(TAG, "Error during backup: ", e) Log.e(TAG, "Error during backup: ", e)
val nm: BackupNotificationManager = get().get() val nm: BackupNotificationManager = get().get()
nm.onBackupError() nm.onBackupError()
} }
if (result == BackupManager.SUCCESS) { if (result == BackupManager.SUCCESS) {
Log.i(TAG, "Backup succeeded ") Log.i(TAG, "Backup succeeded ")
} else {
Log.e(TAG, "Backup failed: $result")
}
} else { } else {
Log.e(TAG, "Backup failed: $result") Log.i(TAG, "Backup is not enabled")
} }
} }