diff --git a/OsmAnd/src/net/osmand/FileUtils.java b/OsmAnd/src/net/osmand/FileUtils.java index 426c5c10c2..65ea676356 100644 --- a/OsmAnd/src/net/osmand/FileUtils.java +++ b/OsmAnd/src/net/osmand/FileUtils.java @@ -205,10 +205,7 @@ public class FileUtils { if (!src.exists()) { return null; } - File tempDir = app.getAppPath(IndexConstants.TEMP_DIR); - if (!tempDir.exists()) { - tempDir.mkdirs(); - } + File tempDir = getTempDir(app); File dest = new File(tempDir, src.getName()); try { Algorithms.fileCopy(src, dest); @@ -218,6 +215,14 @@ public class FileUtils { return dest; } + public static File getTempDir(OsmandApplication app) { + File tempDir = app.getAppPath(IndexConstants.TEMP_DIR); + if (!tempDir.exists()) { + tempDir.mkdirs(); + } + return tempDir; + } + public interface RenameCallback { void renamedTo(File file); } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 07c545a424..58dbdd1559 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -26,6 +26,7 @@ import com.google.gson.reflect.TypeToken; import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; +import net.osmand.FileUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; @@ -2350,11 +2351,8 @@ public class OsmandAidlApi { } private int copyFileImpl(String fileName, byte[] filePartData, long startTime, boolean done, String destinationDir) { - File file = app.getAppPath(IndexConstants.TEMP_DIR + fileName); - File tempDir = app.getAppPath(IndexConstants.TEMP_DIR); - if (!tempDir.exists()) { - tempDir.mkdirs(); - } + File tempDir = FileUtils.getTempDir(app); + File file = new File(tempDir, fileName); File destFile = app.getAppPath(destinationDir + fileName); long currentTime = System.currentTimeMillis(); try { diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index c57f53a0fa..e3dcb9cd2d 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -21,6 +21,7 @@ import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; +import net.osmand.FileUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; @@ -715,17 +716,14 @@ public class ImportHelper { @Override protected String doInBackground(Void... voids) { - File tempDir = app.getAppPath(IndexConstants.TEMP_DIR); - if (!tempDir.exists()) { - tempDir.mkdirs(); - } + File tempDir = FileUtils.getTempDir(app); File dest = new File(tempDir, name); return copyFile(app, dest, uri, true); } @Override protected void onPostExecute(String error) { - File tempDir = app.getAppPath(IndexConstants.TEMP_DIR); + File tempDir = FileUtils.getTempDir(app); final File file = new File(tempDir, name); if (error == null && file.exists()) { app.getSettingsHelper().collectSettings(file, latestChanges, version, new SettingsCollectListener() { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportProfileBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportProfileBottomSheet.java index a09a8ba435..40fa4e290c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportProfileBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportProfileBottomSheet.java @@ -21,6 +21,7 @@ import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; +import net.osmand.FileUtils; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.data.LatLon; @@ -329,7 +330,7 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet { if (app != null) { exportingProfile = true; showExportProgressDialog(); - File tempDir = getTempDir(); + File tempDir = FileUtils.getTempDir(app); String fileName = profile.toHumanString(); app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), prepareSettingsItemsForExport(), true); } @@ -391,19 +392,11 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet { } private File getExportFile() { - File tempDir = getTempDir(); + File tempDir = FileUtils.getTempDir(app); String fileName = profile.toHumanString(); return new File(tempDir, fileName + IndexConstants.OSMAND_SETTINGS_FILE_EXT); } - private File getTempDir() { - File tempDir = app.getAppPath(IndexConstants.TEMP_DIR); - if (!tempDir.exists()) { - tempDir.mkdirs(); - } - return tempDir; - } - private void shareProfile(@NonNull File file, @NonNull ApplicationMode profile) { try { final Intent sendIntent = new Intent();