Enable scheduled backups regardless of API version.

This commit is contained in:
Cody Henthorne
2023-03-28 09:24:11 -04:00
committed by GitHub
parent 149955e07a
commit 607a06d379
2 changed files with 9 additions and 24 deletions

View File

@@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.jobs;
import android.Manifest;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -22,10 +21,8 @@ import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider;
import org.thoughtcrime.securesms.database.NoExternalStorageException;
import org.thoughtcrime.securesms.database.SignalDatabase;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobmanager.JobManager;
import org.thoughtcrime.securesms.jobmanager.impl.ChargingConstraint;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.service.GenericForegroundService;
@@ -59,8 +56,6 @@ public final class LocalBackupJob extends BaseJob {
.setMaxAttempts(3);
if (force) {
jobManager.cancelAllInQueue(QUEUE);
} else if (Build.VERSION.SDK_INT < 31) {
parameters.addConstraint(ChargingConstraint.KEY);
}
if (BackupUtil.isUserSelectionRequired(ApplicationDependencies.getApplication())) {

View File

@@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.service;
import android.content.Context;
import android.os.Build;
import androidx.annotation.NonNull;
@@ -12,15 +11,12 @@ import org.thoughtcrime.securesms.util.JavaTimeExtensionsKt;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;
public class LocalBackupListener extends PersistentAlarmManagerListener {
private static final long INTERVAL = TimeUnit.DAYS.toMillis(1);
@Override
protected boolean shouldScheduleExact() {
return Build.VERSION.SDK_INT >= 31;
return true;
}
@Override
@@ -44,22 +40,16 @@ public class LocalBackupListener extends PersistentAlarmManagerListener {
}
public static long setNextBackupTimeToIntervalFromNow(@NonNull Context context) {
long nextTime;
if (Build.VERSION.SDK_INT < 31) {
nextTime = System.currentTimeMillis() + INTERVAL;
} else {
LocalDateTime now = LocalDateTime.now();
int hour = SignalStore.settings().getBackupHour();
int minute = SignalStore.settings().getBackupMinute();
LocalDateTime next = now.withHour(hour).withMinute(minute).withSecond(0);
if (now.isAfter(next)) {
next = next.plusDays(1);
}
nextTime = JavaTimeExtensionsKt.toMillis(next);
LocalDateTime now = LocalDateTime.now();
int hour = SignalStore.settings().getBackupHour();
int minute = SignalStore.settings().getBackupMinute();
LocalDateTime next = now.withHour(hour).withMinute(minute).withSecond(0);
if (now.isAfter(next)) {
next = next.plusDays(1);
}
long nextTime = JavaTimeExtensionsKt.toMillis(next);
TextSecurePreferences.setNextBackupTime(context, nextTime);
return nextTime;