From 607a06d3792849f991827acd373f7fd532090d2c Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Tue, 28 Mar 2023 09:24:11 -0400 Subject: [PATCH] Enable scheduled backups regardless of API version. --- .../securesms/jobs/LocalBackupJob.java | 5 ---- .../service/LocalBackupListener.java | 28 ++++++------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/LocalBackupJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/LocalBackupJob.java index 7405c2043bd..6b20849007d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/LocalBackupJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/LocalBackupJob.java @@ -2,7 +2,6 @@ import android.Manifest; -import android.os.Build; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -22,10 +21,8 @@ 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 static void enqueue(boolean force) { .setMaxAttempts(3); if (force) { jobManager.cancelAllInQueue(QUEUE); - } else if (Build.VERSION.SDK_INT < 31) { - parameters.addConstraint(ChargingConstraint.KEY); } if (BackupUtil.isUserSelectionRequired(ApplicationDependencies.getApplication())) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/LocalBackupListener.java b/app/src/main/java/org/thoughtcrime/securesms/service/LocalBackupListener.java index 6328a4b1600..849cf678f9a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/LocalBackupListener.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/LocalBackupListener.java @@ -2,7 +2,6 @@ import android.content.Context; -import android.os.Build; import androidx.annotation.NonNull; @@ -12,15 +11,12 @@ 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 static void schedule(Context context) { } 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;