mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Use cache directory on removable storage for backups if present
Fixes #7692
This commit is contained in:
parent
35d158cfee
commit
6c1a1fb9ad
@ -52,7 +52,7 @@ public class LocalBackupJob extends ContextJob {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
String backupPassword = TextSecurePreferences.getBackupPassphrase(context);
|
String backupPassword = TextSecurePreferences.getBackupPassphrase(context);
|
||||||
File backupDirectory = StorageUtil.getBackupDirectory(context);
|
File backupDirectory = StorageUtil.getBackupCacheDirectory(context);
|
||||||
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("signal-%s.backup", timestamp);
|
String fileName = String.format("signal-%s.backup", timestamp);
|
||||||
File backupFile = new File(backupDirectory, fileName);
|
File backupFile = new File(backupDirectory, fileName);
|
||||||
|
@ -22,12 +22,7 @@ public class StorageUtil
|
|||||||
File[] directories = context.getExternalFilesDirs(null);
|
File[] directories = context.getExternalFilesDirs(null);
|
||||||
|
|
||||||
if (directories != null) {
|
if (directories != null) {
|
||||||
storage = Stream.of(directories)
|
storage = getNonEmulated(directories);
|
||||||
.withoutNulls()
|
|
||||||
.filterNot(f -> f.getAbsolutePath().contains("emulated"))
|
|
||||||
.limit(1)
|
|
||||||
.findSingle()
|
|
||||||
.orElse(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +47,28 @@ public class StorageUtil
|
|||||||
return backups;
|
return backups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
private static File getSignalStorageDir() throws NoExternalStorageException {
|
||||||
final File storage = Environment.getExternalStorageDirectory();
|
final File storage = Environment.getExternalStorageDirectory();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user