From ab612462403c7745ff48b962a1282f806e88bce8 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 24 Oct 2024 16:11:06 +0200 Subject: [PATCH] do not start foreground service in foreground the foreground service was introduced unconditionally in #3312, however turns out to be annoying and flickering if the app is actually in foreground. the service _might_ be needed in this case only if the app is about going to background during fetch, but in this case, we assume, that we have some 10 seconds time still. in any case, this is still an improvement to the released apps, that _never_ show a foreground service. --- .../securesms/service/FetchForegroundService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java b/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java index 71967f559..b748921b4 100644 --- a/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java +++ b/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java @@ -13,6 +13,7 @@ import androidx.core.content.ContextCompat; import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.R; +import org.thoughtcrime.securesms.connect.ForegroundDetector; import org.thoughtcrime.securesms.notifications.FcmReceiveService; import org.thoughtcrime.securesms.notifications.NotificationCenter; import org.thoughtcrime.securesms.util.Util; @@ -23,6 +24,11 @@ public final class FetchForegroundService extends Service { private static Intent service; public static void start(Context context) { + ForegroundDetector foregroundDetector = ForegroundDetector.getInstance(); + if (foregroundDetector != null && foregroundDetector.isForeground()) { + return; + } + GenericForegroundService.createFgNotificationChannel(context); synchronized (SERVICE_LOCK) { if (service == null) {