mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 00:37:47 +00:00
Revert "Fix file storage"
This reverts commit c9e686551f1558ae1c8ac87905260958cadd2ad3.
This commit is contained in:
parent
499f1ebe50
commit
d6f780eb79
@ -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;
|
||||
|
@ -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()
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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<SaveAttachmentTask.Attachment, Void, Pair<Integer, String>> {
|
||||
private static final String TAG = SaveAttachmentTask.class.getSimpleName();
|
||||
|
||||
@ -61,7 +59,7 @@ public class SaveAttachmentTask extends ProgressDialogAsyncTask<SaveAttachmentTa
|
||||
Context context = contextReference.get();
|
||||
String directory = null;
|
||||
|
||||
if (!StorageUtil.canWriteInSessionStorageDir(context)) {
|
||||
if (!StorageUtil.canWriteInSessionStorageDir()) {
|
||||
return new Pair<>(WRITE_ACCESS_FAILURE, null);
|
||||
}
|
||||
|
||||
@ -113,17 +111,16 @@ public class SaveAttachmentTask extends ProgressDialogAsyncTask<SaveAttachmentTa
|
||||
private File createOutputDirectoryFromContentType(@NonNull String contentType)
|
||||
throws NoExternalStorageException
|
||||
{
|
||||
Context context = contextReference.get();
|
||||
File outputDirectory;
|
||||
|
||||
if (contentType.startsWith("video/")) {
|
||||
outputDirectory = StorageUtil.getVideoDir(context);
|
||||
outputDirectory = StorageUtil.getVideoDir();
|
||||
} else if (contentType.startsWith("audio/")) {
|
||||
outputDirectory = StorageUtil.getAudioDir(context);
|
||||
outputDirectory = StorageUtil.getAudioDir();
|
||||
} else if (contentType.startsWith("image/")) {
|
||||
outputDirectory = StorageUtil.getImageDir(context);
|
||||
outputDirectory = StorageUtil.getImageDir();
|
||||
} else {
|
||||
outputDirectory = StorageUtil.getDownloadDir(context);
|
||||
outputDirectory = StorageUtil.getDownloadDir();
|
||||
}
|
||||
|
||||
if (!outputDirectory.mkdirs()) Log.w(TAG, "mkdirs() returned false, attempting to continue");
|
||||
|
@ -10,8 +10,8 @@ import java.io.File;
|
||||
|
||||
public class StorageUtil {
|
||||
|
||||
public static File getBackupDirectory(Context context) throws NoExternalStorageException {
|
||||
File storage = context.getExternalFilesDir(null);
|
||||
public static File getBackupDirectory() throws NoExternalStorageException {
|
||||
File storage = Environment.getExternalStorageDirectory();
|
||||
|
||||
if (!storage.canWrite()) {
|
||||
throw new NoExternalStorageException();
|
||||
@ -33,8 +33,8 @@ public class StorageUtil {
|
||||
return context.getExternalCacheDir();
|
||||
}
|
||||
|
||||
private static File getSessionStorageDir(Context context) throws NoExternalStorageException {
|
||||
final File storage = context.getExternalFilesDir(null);
|
||||
private static File getSessionStorageDir() throws NoExternalStorageException {
|
||||
final File storage = Environment.getExternalStorageDirectory();
|
||||
|
||||
if (!storage.canWrite()) {
|
||||
throw new NoExternalStorageException();
|
||||
@ -43,11 +43,11 @@ public class StorageUtil {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public static boolean canWriteInSessionStorageDir(Context context) {
|
||||
public static boolean canWriteInSessionStorageDir() {
|
||||
File storage;
|
||||
|
||||
try {
|
||||
storage = getSessionStorageDir(context);
|
||||
storage = getSessionStorageDir();
|
||||
} catch (NoExternalStorageException e) {
|
||||
return false;
|
||||
}
|
||||
@ -55,24 +55,24 @@ public class StorageUtil {
|
||||
return storage.canWrite();
|
||||
}
|
||||
|
||||
public static File getLegacyBackupDirectory(Context context) throws NoExternalStorageException {
|
||||
return getSessionStorageDir(context);
|
||||
public static File getLegacyBackupDirectory() throws NoExternalStorageException {
|
||||
return getSessionStorageDir();
|
||||
}
|
||||
|
||||
public static File getVideoDir(Context context) throws NoExternalStorageException {
|
||||
return new File(getSessionStorageDir(context), Environment.DIRECTORY_MOVIES);
|
||||
public static File getVideoDir() throws NoExternalStorageException {
|
||||
return new File(getSessionStorageDir(), Environment.DIRECTORY_MOVIES);
|
||||
}
|
||||
|
||||
public static File getAudioDir(Context context) throws NoExternalStorageException {
|
||||
return new File(getSessionStorageDir(context), Environment.DIRECTORY_MUSIC);
|
||||
public static File getAudioDir() throws NoExternalStorageException {
|
||||
return new File(getSessionStorageDir(), Environment.DIRECTORY_MUSIC);
|
||||
}
|
||||
|
||||
public static File getImageDir(Context context) throws NoExternalStorageException {
|
||||
return new File(getSessionStorageDir(context), Environment.DIRECTORY_PICTURES);
|
||||
public static File getImageDir() throws NoExternalStorageException {
|
||||
return new File(getSessionStorageDir(), Environment.DIRECTORY_PICTURES);
|
||||
}
|
||||
|
||||
public static File getDownloadDir(Context context) throws NoExternalStorageException {
|
||||
return new File(getSessionStorageDir(context), Environment.DIRECTORY_DOWNLOADS);
|
||||
public static File getDownloadDir() throws NoExternalStorageException {
|
||||
return new File(getSessionStorageDir(), Environment.DIRECTORY_DOWNLOADS);
|
||||
}
|
||||
|
||||
public static @Nullable String getCleanFileName(@Nullable String fileName) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user