diff --git a/src/org/thoughtcrime/securesms/RegistrationActivity.java b/src/org/thoughtcrime/securesms/RegistrationActivity.java index b43c28b852..29ca7d34d9 100644 --- a/src/org/thoughtcrime/securesms/RegistrationActivity.java +++ b/src/org/thoughtcrime/securesms/RegistrationActivity.java @@ -278,7 +278,7 @@ public class RegistrationActivity extends BaseActionBarActivity implements Verif @Override protected @Nullable BackupUtil.BackupInfo doInBackground(Void... voids) { try { - return BackupUtil.getLatestBackup(RegistrationActivity.this); + return BackupUtil.getLatestBackup(); } catch (NoExternalStorageException e) { Log.w(TAG, e); return null; diff --git a/src/org/thoughtcrime/securesms/backup/BackupDialog.java b/src/org/thoughtcrime/securesms/backup/BackupDialog.java index 34eeed48ca..11ca52a688 100644 --- a/src/org/thoughtcrime/securesms/backup/BackupDialog.java +++ b/src/org/thoughtcrime/securesms/backup/BackupDialog.java @@ -4,22 +4,20 @@ package org.thoughtcrime.securesms.backup; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; import android.widget.Button; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; - +import network.loki.messenger.R; import org.thoughtcrime.securesms.components.SwitchPreferenceCompat; import org.thoughtcrime.securesms.service.LocalBackupListener; import org.thoughtcrime.securesms.util.BackupUtil; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.Util; -import network.loki.messenger.R; - public class BackupDialog { public static void showEnableBackupDialog(@NonNull Context context, @NonNull SwitchPreferenceCompat preference) { @@ -79,7 +77,7 @@ public class BackupDialog { .setPositiveButton(R.string.BackupDialog_delete_backups_statement, (dialog, which) -> { BackupPassphrase.set(context, null); TextSecurePreferences.setBackupEnabled(context, false); - BackupUtil.deleteAllBackups(context); + BackupUtil.deleteAllBackups(); preference.setChecked(false); }) .create() diff --git a/src/org/thoughtcrime/securesms/jobs/LocalBackupJob.java b/src/org/thoughtcrime/securesms/jobs/LocalBackupJob.java index 2d935c10fa..dc0d8b1f4b 100644 --- a/src/org/thoughtcrime/securesms/jobs/LocalBackupJob.java +++ b/src/org/thoughtcrime/securesms/jobs/LocalBackupJob.java @@ -71,7 +71,7 @@ public class LocalBackupJob extends BaseJob { try { String backupPassword = BackupPassphrase.get(context); - File backupDirectory = StorageUtil.getBackupDirectory(context); + File backupDirectory = StorageUtil.getBackupDirectory(); String timestamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US).format(new Date()); String fileName = String.format("session-%s.backup", timestamp); File backupFile = new File(backupDirectory, fileName); @@ -97,7 +97,7 @@ public class LocalBackupJob extends BaseJob { throw new IOException("Renaming temporary backup file failed!"); } - BackupUtil.deleteOldBackups(context); + BackupUtil.deleteOldBackups(); } finally { GenericForegroundService.stopForegroundTask(context); } diff --git a/src/org/thoughtcrime/securesms/util/BackupUtil.java b/src/org/thoughtcrime/securesms/util/BackupUtil.java index 21a983d31e..d3b4f4a112 100644 --- a/src/org/thoughtcrime/securesms/util/BackupUtil.java +++ b/src/org/thoughtcrime/securesms/util/BackupUtil.java @@ -2,12 +2,12 @@ package org.thoughtcrime.securesms.util; import android.content.Context; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; - -import org.thoughtcrime.securesms.database.NoExternalStorageException; import org.thoughtcrime.securesms.logging.Log; + +import network.loki.messenger.R; +import org.thoughtcrime.securesms.database.NoExternalStorageException; import org.whispersystems.libsignal.util.ByteUtil; import java.io.File; @@ -16,15 +16,13 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Locale; -import network.loki.messenger.R; - public class BackupUtil { private static final String TAG = BackupUtil.class.getSimpleName(); public static @NonNull String getLastBackupTime(@NonNull Context context, @NonNull Locale locale) { try { - BackupInfo backup = getLatestBackup(context); + BackupInfo backup = getLatestBackup(); if (backup == null) return context.getString(R.string.BackupUtil_never); else return DateUtils.getExtendedRelativeTimeSpanString(context, locale, backup.getTimestamp()); @@ -34,8 +32,8 @@ public class BackupUtil { } } - public static @Nullable BackupInfo getLatestBackup(Context context) throws NoExternalStorageException { - File backupDirectory = StorageUtil.getBackupDirectory(context); + public static @Nullable BackupInfo getLatestBackup() throws NoExternalStorageException { + File backupDirectory = StorageUtil.getBackupDirectory(); File[] backups = backupDirectory.listFiles(); BackupInfo latestBackup = null; @@ -51,9 +49,9 @@ public class BackupUtil { } @SuppressWarnings("ResultOfMethodCallIgnored") - public static void deleteAllBackups(Context context) { + public static void deleteAllBackups() { try { - File backupDirectory = StorageUtil.getBackupDirectory(context); + File backupDirectory = StorageUtil.getBackupDirectory(); File[] backups = backupDirectory.listFiles(); for (File backup : backups) { @@ -64,9 +62,9 @@ public class BackupUtil { } } - public static void deleteOldBackups(Context context) { + public static void deleteOldBackups() { try { - File backupDirectory = StorageUtil.getBackupDirectory(context); + File backupDirectory = StorageUtil.getBackupDirectory(); File[] backups = backupDirectory.listFiles(); if (backups != null && backups.length > 2) { diff --git a/src/org/thoughtcrime/securesms/util/SaveAttachmentTask.java b/src/org/thoughtcrime/securesms/util/SaveAttachmentTask.java index 86a2bc0d7b..f1afec8de8 100644 --- a/src/org/thoughtcrime/securesms/util/SaveAttachmentTask.java +++ b/src/org/thoughtcrime/securesms/util/SaveAttachmentTask.java @@ -4,14 +4,14 @@ import android.content.Context; import android.content.DialogInterface.OnClickListener; import android.media.MediaScannerConnection; import android.net.Uri; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; import android.text.TextUtils; import android.webkit.MimeTypeMap; import android.widget.Toast; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; - +import network.loki.messenger.R; import org.thoughtcrime.securesms.database.NoExternalStorageException; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.PartAuthority; @@ -26,8 +26,6 @@ import java.io.OutputStream; import java.lang.ref.WeakReference; import java.text.SimpleDateFormat; -import network.loki.messenger.R; - public class SaveAttachmentTask extends ProgressDialogAsyncTask> { private static final String TAG = SaveAttachmentTask.class.getSimpleName(); @@ -61,7 +59,7 @@ public class SaveAttachmentTask extends ProgressDialogAsyncTask(WRITE_ACCESS_FAILURE, null); } @@ -113,17 +111,16 @@ public class SaveAttachmentTask extends ProgressDialogAsyncTask