84 lines
2.4 KiB
Java
Raw Normal View History

package org.thoughtcrime.securesms.jobs;
import androidx.annotation.NonNull;
import org.thoughtcrime.securesms.database.NoExternalStorageException;
2020-09-17 13:26:03 +10:00
import org.thoughtcrime.securesms.loki.database.BackupFileRecord;
2020-05-29 14:08:13 +10:00
import org.thoughtcrime.securesms.jobmanager.Data;
import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.service.GenericForegroundService;
import org.thoughtcrime.securesms.util.BackupUtil;
import java.io.IOException;
import java.util.Collections;
2020-05-29 14:08:13 +10:00
import network.loki.messenger.R;
2019-03-28 08:56:35 -07:00
public class LocalBackupJob extends BaseJob {
2019-03-28 08:56:35 -07:00
public static final String KEY = "LocalBackupJob";
private static final String TAG = LocalBackupJob.class.getSimpleName();
2019-03-28 08:56:35 -07:00
public LocalBackupJob() {
this(new Job.Parameters.Builder()
.setQueue("__LOCAL_BACKUP__")
.setMaxInstances(1)
.setMaxAttempts(3)
.build());
}
2019-03-28 08:56:35 -07:00
private LocalBackupJob(@NonNull Job.Parameters parameters) {
super(parameters);
}
@Override
2019-03-28 08:56:35 -07:00
public @NonNull Data serialize() {
return Data.EMPTY;
}
@Override
2019-03-28 08:56:35 -07:00
public @NonNull String getFactoryKey() {
return KEY;
}
@Override
public void onRun() throws NoExternalStorageException, IOException {
2018-08-02 09:25:33 -04:00
Log.i(TAG, "Executing backup job...");
GenericForegroundService.startForegroundTask(context,
context.getString(R.string.LocalBackupJob_creating_backup),
NotificationChannels.BACKUPS,
R.drawable.ic_launcher_foreground);
2020-05-29 14:08:13 +10:00
// TODO: Maybe create a new backup icon like ic_signal_backup?
try {
BackupFileRecord record = BackupUtil.createBackupFile(context);
BackupUtil.deleteAllBackupFiles(context, Collections.singletonList(record));
} finally {
GenericForegroundService.stopForegroundTask(context);
}
}
@Override
public boolean onShouldRetry(@NonNull Exception e) {
return false;
}
@Override
public void onCanceled() {
2019-03-28 08:56:35 -07:00
}
2019-03-28 08:56:35 -07:00
public static class Factory implements Job.Factory<LocalBackupJob> {
@Override
public @NonNull LocalBackupJob create(@NonNull Parameters parameters, @NonNull Data data) {
return new LocalBackupJob(parameters);
}
}
}