execute all account state managments on ping thread

This commit is contained in:
Daniel Gultsch 2024-03-03 08:02:31 +01:00
parent 86b733e159
commit 00f52226d8
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
2 changed files with 12 additions and 6 deletions

View file

@ -83,6 +83,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@ -879,7 +880,12 @@ public class XmppConnectionService extends Service {
}
return START_NOT_STICKY;
}
manageAccountConnectionStates(action, intent == null ? null : intent.getExtras());
final var extras = intent == null ? null : intent.getExtras();
try {
internalPingExecutor.execute(() -> manageAccountConnectionStates(action, extras));
} catch (final RejectedExecutionException e) {
Log.e(Config.LOGTAG, "can not schedule connection states manager");
}
if (SystemClock.elapsedRealtime() - mLastExpiryRun.get() >= Config.EXPIRY_INTERVAL) {
expireOldMessages();
}
@ -959,7 +965,7 @@ public class XmppConnectionService extends Service {
}
}
private boolean processAccountState(Account account, boolean interactive, boolean isUiAction, boolean isAccountPushed, HashSet<Account> pingCandidates) {
private boolean processAccountState(final Account account, final boolean interactive, final boolean isUiAction, final boolean isAccountPushed, final HashSet<Account> pingCandidates) {
if (!account.getStatus().isAttemptReconnect()) {
return false;
}

View file

@ -36,15 +36,15 @@ import eu.siacs.conversations.Config;
public class WakeLockHelper {
public static void acquire(PowerManager.WakeLock wakeLock) {
public static void acquire(final PowerManager.WakeLock wakeLock) {
try {
wakeLock.acquire(2000);
} catch (RuntimeException e) {
} catch (final RuntimeException e) {
Log.d(Config.LOGTAG, "unable to acquire wake lock", e);
}
}
public static void release(PowerManager.WakeLock wakeLock) {
public static void release(final PowerManager.WakeLock wakeLock) {
if (wakeLock == null) {
return;
}
@ -52,7 +52,7 @@ public class WakeLockHelper {
if (wakeLock.isHeld()) {
wakeLock.release();
}
} catch (RuntimeException e) {
} catch (final RuntimeException e) {
Log.d(Config.LOGTAG, "unable to release wake lock", e);
}
}