diff --git a/src/org/thoughtcrime/securesms/jobs/LocalBackupJob.java b/src/org/thoughtcrime/securesms/jobs/LocalBackupJob.java index 9d556a2a22..f436cdde8c 100644 --- a/src/org/thoughtcrime/securesms/jobs/LocalBackupJob.java +++ b/src/org/thoughtcrime/securesms/jobs/LocalBackupJob.java @@ -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); diff --git a/src/org/thoughtcrime/securesms/util/StorageUtil.java b/src/org/thoughtcrime/securesms/util/StorageUtil.java index 6a7b160f9b..2bcd34f0fe 100644 --- a/src/org/thoughtcrime/securesms/util/StorageUtil.java +++ b/src/org/thoughtcrime/securesms/util/StorageUtil.java @@ -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();