From 1732ab5cc777e7b6195682d4716edf45c680e348 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 19 Oct 2023 14:55:28 +0200 Subject: [PATCH] add internal ping timer in case alarm manager fails --- .../conversations/services/XmppConnectionService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 3352c4c3b..6a3ac9afc 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -85,6 +85,8 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; @@ -202,6 +204,8 @@ public class XmppConnectionService extends Service { public final CountDownLatch restoredFromDatabaseLatch = new CountDownLatch(1); private final static Executor FILE_OBSERVER_EXECUTOR = Executors.newSingleThreadExecutor(); private final static Executor FILE_ATTACHMENT_EXECUTOR = Executors.newSingleThreadExecutor(); + + private final ScheduledExecutorService internalPingExecutor = Executors.newSingleThreadScheduledExecutor(); private final static SerialSingleThreadExecutor VIDEO_COMPRESSION_EXECUTOR = new SerialSingleThreadExecutor("VideoCompression"); private final SerialSingleThreadExecutor mDatabaseWriterExecutor = new SerialSingleThreadExecutor("DatabaseWriter"); private final SerialSingleThreadExecutor mDatabaseReaderExecutor = new SerialSingleThreadExecutor("DatabaseReader"); @@ -871,6 +875,10 @@ public class XmppConnectionService extends Service { return START_STICKY; } + private void manageAccountConnectionStatesInternal() { + manageAccountConnectionStates(ACTION_INTERNAL_PING, null); + } + private synchronized void manageAccountConnectionStates(final String action, final Bundle extras) { final String pushedAccountHash = extras == null ? null : extras.getString("account"); final boolean interactive = Arrays.asList(ACTION_TRY_AGAIN).contains(action); @@ -1287,6 +1295,7 @@ public class XmppConnectionService extends Service { mForceDuringOnCreate.set(false); toggleForegroundService(); setupPhoneStateListener(); + internalPingExecutor.scheduleAtFixedRate(this::manageAccountConnectionStatesInternal,10,10,TimeUnit.SECONDS); } @@ -1360,6 +1369,7 @@ public class XmppConnectionService extends Service { } destroyed = false; fileObserver.stopWatching(); + internalPingExecutor.shutdown(); super.onDestroy(); }