Use cache directory on removable storage for backups if present

Fixes #7692
fork-5.53.8
Moxie Marlinspike 2018-04-23 18:39:43 -07:00 zatwierdzone przez Greyson Parrelli
rodzic 35d158cfee
commit 6c1a1fb9ad
2 zmienionych plików z 24 dodań i 7 usunięć

Wyświetl plik

@ -52,7 +52,7 @@ public class LocalBackupJob extends ContextJob {
try {
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 fileName = String.format("signal-%s.backup", timestamp);
File backupFile = new File(backupDirectory, fileName);

Wyświetl plik

@ -22,12 +22,7 @@ public class StorageUtil
File[] directories = context.getExternalFilesDirs(null);
if (directories != null) {
storage = Stream.of(directories)
.withoutNulls()
.filterNot(f -> f.getAbsolutePath().contains("emulated"))
.limit(1)
.findSingle()
.orElse(null);
storage = getNonEmulated(directories);
}
}
@ -52,6 +47,28 @@ public class StorageUtil
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 {
final File storage = Environment.getExternalStorageDirectory();