Skip to content

Commit

Permalink
Enable scheduled backups regardless of API version.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal committed Mar 28, 2023
1 parent 149955e commit 607a06d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
Expand Up @@ -2,7 +2,6 @@


import android.Manifest;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -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;
Expand Down Expand Up @@ -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())) {
Expand Down
Expand Up @@ -2,7 +2,6 @@


import android.content.Context;
import android.os.Build;

import androidx.annotation.NonNull;

Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 607a06d

Please sign in to comment.