mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +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
|
@Override
|
||||||
protected @Nullable BackupUtil.BackupInfo doInBackground(Void... voids) {
|
protected @Nullable BackupUtil.BackupInfo doInBackground(Void... voids) {
|
||||||
try {
|
try {
|
||||||
return BackupUtil.getLatestBackup(RegistrationActivity.this);
|
return BackupUtil.getLatestBackup();
|
||||||
} catch (NoExternalStorageException e) {
|
} catch (NoExternalStorageException e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
return null;
|
return null;
|
||||||
|
@ -4,22 +4,20 @@ package org.thoughtcrime.securesms.backup;
|
|||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import network.loki.messenger.R;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
|
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
|
||||||
import org.thoughtcrime.securesms.service.LocalBackupListener;
|
import org.thoughtcrime.securesms.service.LocalBackupListener;
|
||||||
import org.thoughtcrime.securesms.util.BackupUtil;
|
import org.thoughtcrime.securesms.util.BackupUtil;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
|
||||||
import network.loki.messenger.R;
|
|
||||||
|
|
||||||
public class BackupDialog {
|
public class BackupDialog {
|
||||||
|
|
||||||
public static void showEnableBackupDialog(@NonNull Context context, @NonNull SwitchPreferenceCompat preference) {
|
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) -> {
|
.setPositiveButton(R.string.BackupDialog_delete_backups_statement, (dialog, which) -> {
|
||||||
BackupPassphrase.set(context, null);
|
BackupPassphrase.set(context, null);
|
||||||
TextSecurePreferences.setBackupEnabled(context, false);
|
TextSecurePreferences.setBackupEnabled(context, false);
|
||||||
BackupUtil.deleteAllBackups(context);
|
BackupUtil.deleteAllBackups();
|
||||||
preference.setChecked(false);
|
preference.setChecked(false);
|
||||||
})
|
})
|
||||||
.create()
|
.create()
|
||||||
|
@ -71,7 +71,7 @@ public class LocalBackupJob extends BaseJob {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
String backupPassword = BackupPassphrase.get(context);
|
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 timestamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US).format(new Date());
|
||||||
String fileName = String.format("session-%s.backup", timestamp);
|
String fileName = String.format("session-%s.backup", timestamp);
|
||||||
File backupFile = new File(backupDirectory, fileName);
|
File backupFile = new File(backupDirectory, fileName);
|
||||||
@ -97,7 +97,7 @@ public class LocalBackupJob extends BaseJob {
|
|||||||
throw new IOException("Renaming temporary backup file failed!");
|
throw new IOException("Renaming temporary backup file failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
BackupUtil.deleteOldBackups(context);
|
BackupUtil.deleteOldBackups();
|
||||||
} finally {
|
} finally {
|
||||||
GenericForegroundService.stopForegroundTask(context);
|
GenericForegroundService.stopForegroundTask(context);
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@ package org.thoughtcrime.securesms.util;
|
|||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.database.NoExternalStorageException;
|
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
|
|
||||||
|
import network.loki.messenger.R;
|
||||||
|
import org.thoughtcrime.securesms.database.NoExternalStorageException;
|
||||||
import org.whispersystems.libsignal.util.ByteUtil;
|
import org.whispersystems.libsignal.util.ByteUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -16,15 +16,13 @@ import java.util.Arrays;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import network.loki.messenger.R;
|
|
||||||
|
|
||||||
public class BackupUtil {
|
public class BackupUtil {
|
||||||
|
|
||||||
private static final String TAG = BackupUtil.class.getSimpleName();
|
private static final String TAG = BackupUtil.class.getSimpleName();
|
||||||
|
|
||||||
public static @NonNull String getLastBackupTime(@NonNull Context context, @NonNull Locale locale) {
|
public static @NonNull String getLastBackupTime(@NonNull Context context, @NonNull Locale locale) {
|
||||||
try {
|
try {
|
||||||
BackupInfo backup = getLatestBackup(context);
|
BackupInfo backup = getLatestBackup();
|
||||||
|
|
||||||
if (backup == null) return context.getString(R.string.BackupUtil_never);
|
if (backup == null) return context.getString(R.string.BackupUtil_never);
|
||||||
else return DateUtils.getExtendedRelativeTimeSpanString(context, locale, backup.getTimestamp());
|
else return DateUtils.getExtendedRelativeTimeSpanString(context, locale, backup.getTimestamp());
|
||||||
@ -34,8 +32,8 @@ public class BackupUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @Nullable BackupInfo getLatestBackup(Context context) throws NoExternalStorageException {
|
public static @Nullable BackupInfo getLatestBackup() throws NoExternalStorageException {
|
||||||
File backupDirectory = StorageUtil.getBackupDirectory(context);
|
File backupDirectory = StorageUtil.getBackupDirectory();
|
||||||
File[] backups = backupDirectory.listFiles();
|
File[] backups = backupDirectory.listFiles();
|
||||||
BackupInfo latestBackup = null;
|
BackupInfo latestBackup = null;
|
||||||
|
|
||||||
@ -51,9 +49,9 @@ public class BackupUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public static void deleteAllBackups(Context context) {
|
public static void deleteAllBackups() {
|
||||||
try {
|
try {
|
||||||
File backupDirectory = StorageUtil.getBackupDirectory(context);
|
File backupDirectory = StorageUtil.getBackupDirectory();
|
||||||
File[] backups = backupDirectory.listFiles();
|
File[] backups = backupDirectory.listFiles();
|
||||||
|
|
||||||
for (File backup : backups) {
|
for (File backup : backups) {
|
||||||
@ -64,9 +62,9 @@ public class BackupUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteOldBackups(Context context) {
|
public static void deleteOldBackups() {
|
||||||
try {
|
try {
|
||||||
File backupDirectory = StorageUtil.getBackupDirectory(context);
|
File backupDirectory = StorageUtil.getBackupDirectory();
|
||||||
File[] backups = backupDirectory.listFiles();
|
File[] backups = backupDirectory.listFiles();
|
||||||
|
|
||||||
if (backups != null && backups.length > 2) {
|
if (backups != null && backups.length > 2) {
|
||||||
|
@ -4,14 +4,14 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.media.MediaScannerConnection;
|
import android.media.MediaScannerConnection;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import network.loki.messenger.R;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.database.NoExternalStorageException;
|
import org.thoughtcrime.securesms.database.NoExternalStorageException;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||||
@ -26,8 +26,6 @@ import java.io.OutputStream;
|
|||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
import network.loki.messenger.R;
|
|
||||||
|
|
||||||
public class SaveAttachmentTask extends ProgressDialogAsyncTask<SaveAttachmentTask.Attachment, Void, Pair<Integer, String>> {
|
public class SaveAttachmentTask extends ProgressDialogAsyncTask<SaveAttachmentTask.Attachment, Void, Pair<Integer, String>> {
|
||||||
private static final String TAG = SaveAttachmentTask.class.getSimpleName();
|
private static final String TAG = SaveAttachmentTask.class.getSimpleName();
|
||||||
|
|
||||||
@ -61,7 +59,7 @@ public class SaveAttachmentTask extends ProgressDialogAsyncTask<SaveAttachmentTa
|
|||||||
Context context = contextReference.get();
|
Context context = contextReference.get();
|
||||||
String directory = null;
|
String directory = null;
|
||||||
|
|
||||||
if (!StorageUtil.canWriteInSessionStorageDir(context)) {
|
if (!StorageUtil.canWriteInSessionStorageDir()) {
|
||||||
return new Pair<>(WRITE_ACCESS_FAILURE, null);
|
return new Pair<>(WRITE_ACCESS_FAILURE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,17 +111,16 @@ public class SaveAttachmentTask extends ProgressDialogAsyncTask<SaveAttachmentTa
|
|||||||
private File createOutputDirectoryFromContentType(@NonNull String contentType)
|
private File createOutputDirectoryFromContentType(@NonNull String contentType)
|
||||||
throws NoExternalStorageException
|
throws NoExternalStorageException
|
||||||
{
|
{
|
||||||
Context context = contextReference.get();
|
|
||||||
File outputDirectory;
|
File outputDirectory;
|
||||||
|
|
||||||
if (contentType.startsWith("video/")) {
|
if (contentType.startsWith("video/")) {
|
||||||
outputDirectory = StorageUtil.getVideoDir(context);
|
outputDirectory = StorageUtil.getVideoDir();
|
||||||
} else if (contentType.startsWith("audio/")) {
|
} else if (contentType.startsWith("audio/")) {
|
||||||
outputDirectory = StorageUtil.getAudioDir(context);
|
outputDirectory = StorageUtil.getAudioDir();
|
||||||
} else if (contentType.startsWith("image/")) {
|
} else if (contentType.startsWith("image/")) {
|
||||||
outputDirectory = StorageUtil.getImageDir(context);
|
outputDirectory = StorageUtil.getImageDir();
|
||||||
} else {
|
} else {
|
||||||
outputDirectory = StorageUtil.getDownloadDir(context);
|
outputDirectory = StorageUtil.getDownloadDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!outputDirectory.mkdirs()) Log.w(TAG, "mkdirs() returned false, attempting to continue");
|
if (!outputDirectory.mkdirs()) Log.w(TAG, "mkdirs() returned false, attempting to continue");
|
||||||
|
@ -10,8 +10,8 @@ import java.io.File;
|
|||||||
|
|
||||||
public class StorageUtil {
|
public class StorageUtil {
|
||||||
|
|
||||||
public static File getBackupDirectory(Context context) throws NoExternalStorageException {
|
public static File getBackupDirectory() throws NoExternalStorageException {
|
||||||
File storage = context.getExternalFilesDir(null);
|
File storage = Environment.getExternalStorageDirectory();
|
||||||
|
|
||||||
if (!storage.canWrite()) {
|
if (!storage.canWrite()) {
|
||||||
throw new NoExternalStorageException();
|
throw new NoExternalStorageException();
|
||||||
@ -33,8 +33,8 @@ public class StorageUtil {
|
|||||||
return context.getExternalCacheDir();
|
return context.getExternalCacheDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File getSessionStorageDir(Context context) throws NoExternalStorageException {
|
private static File getSessionStorageDir() throws NoExternalStorageException {
|
||||||
final File storage = context.getExternalFilesDir(null);
|
final File storage = Environment.getExternalStorageDirectory();
|
||||||
|
|
||||||
if (!storage.canWrite()) {
|
if (!storage.canWrite()) {
|
||||||
throw new NoExternalStorageException();
|
throw new NoExternalStorageException();
|
||||||
@ -43,11 +43,11 @@ public class StorageUtil {
|
|||||||
return storage;
|
return storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canWriteInSessionStorageDir(Context context) {
|
public static boolean canWriteInSessionStorageDir() {
|
||||||
File storage;
|
File storage;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
storage = getSessionStorageDir(context);
|
storage = getSessionStorageDir();
|
||||||
} catch (NoExternalStorageException e) {
|
} catch (NoExternalStorageException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -55,24 +55,24 @@ public class StorageUtil {
|
|||||||
return storage.canWrite();
|
return storage.canWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getLegacyBackupDirectory(Context context) throws NoExternalStorageException {
|
public static File getLegacyBackupDirectory() throws NoExternalStorageException {
|
||||||
return getSessionStorageDir(context);
|
return getSessionStorageDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getVideoDir(Context context) throws NoExternalStorageException {
|
public static File getVideoDir() throws NoExternalStorageException {
|
||||||
return new File(getSessionStorageDir(context), Environment.DIRECTORY_MOVIES);
|
return new File(getSessionStorageDir(), Environment.DIRECTORY_MOVIES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getAudioDir(Context context) throws NoExternalStorageException {
|
public static File getAudioDir() throws NoExternalStorageException {
|
||||||
return new File(getSessionStorageDir(context), Environment.DIRECTORY_MUSIC);
|
return new File(getSessionStorageDir(), Environment.DIRECTORY_MUSIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getImageDir(Context context) throws NoExternalStorageException {
|
public static File getImageDir() throws NoExternalStorageException {
|
||||||
return new File(getSessionStorageDir(context), Environment.DIRECTORY_PICTURES);
|
return new File(getSessionStorageDir(), Environment.DIRECTORY_PICTURES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getDownloadDir(Context context) throws NoExternalStorageException {
|
public static File getDownloadDir() throws NoExternalStorageException {
|
||||||
return new File(getSessionStorageDir(context), Environment.DIRECTORY_DOWNLOADS);
|
return new File(getSessionStorageDir(), Environment.DIRECTORY_DOWNLOADS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @Nullable String getCleanFileName(@Nullable String fileName) {
|
public static @Nullable String getCleanFileName(@Nullable String fileName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user