Only request app backup when it is actually enabled
This commit is contained in:
parent
1ff8e54748
commit
a4cbb0b6df
1 changed files with 20 additions and 17 deletions
|
@ -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,13 +53,15 @@ class ConfigurableBackupTransportService : Service(), KoinComponent {
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
fun requestBackup(context: Context) {
|
fun requestBackup(context: Context) {
|
||||||
|
val backupManager: IBackupManager = get().get()
|
||||||
|
if (backupManager.isBackupEnabled) {
|
||||||
val packageService: PackageService = get().get()
|
val packageService: PackageService = get().get()
|
||||||
val packages = packageService.eligiblePackages
|
val packages = packageService.eligiblePackages
|
||||||
val appTotals = packageService.expectedAppTotals
|
val appTotals = packageService.expectedAppTotals
|
||||||
|
|
||||||
val observer = NotificationBackupObserver(context, packages.size, appTotals)
|
|
||||||
val result = try {
|
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)
|
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)
|
||||||
|
@ -73,4 +73,7 @@ fun requestBackup(context: Context) {
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Backup failed: $result")
|
Log.e(TAG, "Backup failed: $result")
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "Backup is not enabled")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue