mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Add jitter to backup scheduling.
This commit is contained in:
@@ -6,14 +6,19 @@ import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.jobs.LocalBackupJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.SettingsValues;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.util.JavaTimeExtensionsKt;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class LocalBackupListener extends PersistentAlarmManagerListener {
|
||||
|
||||
private static final int BACKUP_JITTER_WINDOW_SECONDS = Math.toIntExact(TimeUnit.MINUTES.toSeconds(10));
|
||||
|
||||
@Override
|
||||
protected boolean shouldScheduleExact() {
|
||||
return true;
|
||||
@@ -44,6 +49,11 @@ public class LocalBackupListener extends PersistentAlarmManagerListener {
|
||||
int hour = SignalStore.settings().getBackupHour();
|
||||
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.plusSeconds(jitter);
|
||||
|
||||
if (now.isAfter(next)) {
|
||||
next = next.plusDays(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user