declare foreground service type also when starting service
This commit is contained in:
parent
ff3956d9c4
commit
dc92e41aa8
2 changed files with 11 additions and 3 deletions
|
@ -7,6 +7,7 @@ package org.calyxos.backup.storage.backup
|
||||||
|
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
@ -30,7 +31,8 @@ public abstract class BackupService : Service() {
|
||||||
Log.d(TAG, "onStartCommand $intent $flags $startId")
|
Log.d(TAG, "onStartCommand $intent $flags $startId")
|
||||||
startForeground(
|
startForeground(
|
||||||
NOTIFICATION_ID_BACKUP,
|
NOTIFICATION_ID_BACKUP,
|
||||||
n.getBackupNotification(R.string.notification_backup_scanning)
|
n.getBackupNotification(R.string.notification_backup_scanning),
|
||||||
|
FOREGROUND_SERVICE_TYPE_MANIFEST,
|
||||||
)
|
)
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
val success = storageBackup.runBackup(backupObserver)
|
val success = storageBackup.runBackup(backupObserver)
|
||||||
|
@ -38,7 +40,8 @@ public abstract class BackupService : Service() {
|
||||||
// only prune old backups when backup run was successful
|
// only prune old backups when backup run was successful
|
||||||
startForeground(
|
startForeground(
|
||||||
NOTIFICATION_ID_PRUNE,
|
NOTIFICATION_ID_PRUNE,
|
||||||
n.getPruneNotification(R.string.notification_prune)
|
n.getPruneNotification(R.string.notification_prune),
|
||||||
|
FOREGROUND_SERVICE_TYPE_MANIFEST,
|
||||||
)
|
)
|
||||||
storageBackup.pruneOldBackups(backupObserver)
|
storageBackup.pruneOldBackups(backupObserver)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ package org.calyxos.backup.storage.restore
|
||||||
|
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -49,7 +50,11 @@ public abstract class RestoreService : Service() {
|
||||||
if (timestamp < 0) error("No timestamp in intent: $intent")
|
if (timestamp < 0) error("No timestamp in intent: $intent")
|
||||||
val storedSnapshot = StoredSnapshot(userId, timestamp)
|
val storedSnapshot = StoredSnapshot(userId, timestamp)
|
||||||
|
|
||||||
startForeground(NOTIFICATION_ID_RESTORE, n.getRestoreNotification())
|
startForeground(
|
||||||
|
NOTIFICATION_ID_RESTORE,
|
||||||
|
n.getRestoreNotification(),
|
||||||
|
FOREGROUND_SERVICE_TYPE_MANIFEST,
|
||||||
|
)
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
val snapshot = withContext(Dispatchers.Main) {
|
val snapshot = withContext(Dispatchers.Main) {
|
||||||
fileSelectionManager.getBackupSnapshotAndReset()
|
fileSelectionManager.getBackupSnapshotAndReset()
|
||||||
|
|
Loading…
Reference in a new issue