From 714ab31e5d228de6a553e3a1e712151aa106c366 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 18 Apr 2025 16:17:08 +0200 Subject: [PATCH] set fgs type on import backup worker --- .../conversations/worker/ImportBackupWorker.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/worker/ImportBackupWorker.java b/src/main/java/eu/siacs/conversations/worker/ImportBackupWorker.java index 556748a72362b2b04abe6c98f4bde5ad9035b6c9..abf2568ec148605b84bf06b82f7776c086baff48 100644 --- a/src/main/java/eu/siacs/conversations/worker/ImportBackupWorker.java +++ b/src/main/java/eu/siacs/conversations/worker/ImportBackupWorker.java @@ -8,6 +8,7 @@ import android.app.PendingIntent; import android.content.ContentValues; import android.content.Context; import android.content.Intent; +import android.content.pm.ServiceInfo; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.net.Uri; @@ -103,8 +104,7 @@ public class ImportBackupWorker extends Worker { @NonNull @Override public Result doWork() { - setForegroundAsync( - new ForegroundInfo(NOTIFICATION_ID, createImportBackupNotification(1, 0))); + setForegroundAsync(getForegroundInfo()); final Result result; try { result = importBackup(this.uri, this.password); @@ -127,6 +127,18 @@ public class ImportBackupWorker extends Worker { return result; } + @NonNull + @Override + public ForegroundInfo getForegroundInfo() { + final var notification = createImportBackupNotification(1, 0); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { + return new ForegroundInfo( + NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC); + } else { + return new ForegroundInfo(NOTIFICATION_ID, notification); + } + } + private Result importBackup(final Uri uri, final String password) throws IOException, InvalidKeySpecException { final var context = getApplicationContext();