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.
This commit is contained in:
B. Petersen
2024-10-24 16:11:06 +02:00
committed by bjoern
parent 957a5f75dc
commit ab61246240
@@ -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) {