mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Remove the ability to save backups to the external SD card.
The directory we were previously saving backups to on the external SD card is actually deleted upon app uninstall and/or clearing the app's data. There's also no reliable way to write to the root of an external SD card (that isn't comically inconvenient), so for now it's safer if we just move back to getting the regular 'ol standard external storage directory (which is likely internal storage, despite its name). Fixes #7845
This commit is contained in:
parent
290b184491
commit
18756aedf6
@ -318,7 +318,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;
|
||||
|
@ -77,7 +77,7 @@ public class BackupDialog {
|
||||
.setPositiveButton(R.string.BackupDialog_delete_backups_statement, (dialog, which) -> {
|
||||
TextSecurePreferences.setBackupPassphrase(context, null);
|
||||
TextSecurePreferences.setBackupEnabled(context, false);
|
||||
BackupUtil.deleteAllBackups(context);
|
||||
BackupUtil.deleteAllBackups();
|
||||
preference.setChecked(false);
|
||||
})
|
||||
.create()
|
||||
|
@ -52,7 +52,7 @@ public class LocalBackupJob extends ContextJob {
|
||||
|
||||
try {
|
||||
String backupPassword = TextSecurePreferences.getBackupPassphrase(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("signal-%s.backup", timestamp);
|
||||
File backupFile = new File(backupDirectory, fileName);
|
||||
@ -78,7 +78,7 @@ public class LocalBackupJob extends ContextJob {
|
||||
throw new IOException("Renaming temporary backup file failed!");
|
||||
}
|
||||
|
||||
BackupUtil.deleteOldBackups(context);
|
||||
BackupUtil.deleteOldBackups();
|
||||
} finally {
|
||||
GenericForegroundService.stopForegroundTask(context);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class BackupUtil {
|
||||
|
||||
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());
|
||||
@ -32,8 +32,8 @@ public class BackupUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static @Nullable BackupInfo getLatestBackup(@NonNull 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;
|
||||
|
||||
@ -49,9 +49,9 @@ public class BackupUtil {
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public static void deleteAllBackups(@NonNull Context context) {
|
||||
public static void deleteAllBackups() {
|
||||
try {
|
||||
File backupDirectory = StorageUtil.getBackupDirectory(context);
|
||||
File backupDirectory = StorageUtil.getBackupDirectory();
|
||||
File[] backups = backupDirectory.listFiles();
|
||||
|
||||
for (File backup : backups) {
|
||||
@ -62,9 +62,9 @@ public class BackupUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteOldBackups(@NonNull 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) {
|
||||
|
@ -14,20 +14,8 @@ import java.io.File;
|
||||
|
||||
public class StorageUtil {
|
||||
|
||||
public static File getBackupDirectory(Context context) throws NoExternalStorageException {
|
||||
File storage = null;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
File[] directories = context.getExternalFilesDirs(null);
|
||||
|
||||
if (directories != null) {
|
||||
storage = getNonEmulated(directories);
|
||||
}
|
||||
}
|
||||
|
||||
if (storage == null) {
|
||||
storage = Environment.getExternalStorageDirectory();
|
||||
}
|
||||
public static File getBackupDirectory() throws NoExternalStorageException {
|
||||
File storage = Environment.getExternalStorageDirectory();
|
||||
|
||||
if (!storage.canWrite()) {
|
||||
throw new NoExternalStorageException();
|
||||
@ -46,27 +34,9 @@ public class StorageUtil {
|
||||
}
|
||||
|
||||
public static File getBackupCacheDirectory(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
File[] directories = context.getExternalCacheDirs();
|
||||
|
||||
if (directories != null) {
|
||||
File result = getNonEmulated(directories);
|
||||
if (result != null) return result;
|
||||
}
|
||||
}
|
||||
|
||||
return context.getExternalCacheDir();
|
||||
}
|
||||
|
||||
private static @Nullable File getNonEmulated(File[] directories) {
|
||||
return Stream.of(directories)
|
||||
.withoutNulls()
|
||||
.filterNot(f -> f.getAbsolutePath().contains("emulated"))
|
||||
.limit(1)
|
||||
.findSingle()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private static File getSignalStorageDir() throws NoExternalStorageException {
|
||||
final File storage = Environment.getExternalStorageDirectory();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user