Fix multiple scheduled backups due to jitter.

This commit is contained in:
Clark
2024-05-31 10:17:37 -04:00
committed by Cody Henthorne
parent 0a99b68d25
commit 1565ecdcea

View File

@@ -49,14 +49,13 @@ public class LocalBackupListener extends PersistentAlarmManagerListener {
int minute = SignalStore.settings().getBackupMinute();
LocalDateTime next = now.withHour(hour).withMinute(minute).withSecond(0);
int jitter = (new Random().nextInt(BACKUP_JITTER_WINDOW_SECONDS)) - (BACKUP_JITTER_WINDOW_SECONDS / 2);
next = next.plusSeconds(jitter);
if (now.isAfter(next)) {
next = next.plusDays(1);
}
int jitter = (new Random().nextInt(BACKUP_JITTER_WINDOW_SECONDS)) - (BACKUP_JITTER_WINDOW_SECONDS / 2);
next = next.plusSeconds(jitter);
long nextTime = JavaTimeExtensionsKt.toMillis(next);
TextSecurePreferences.setNextBackupTime(context, nextTime);