diff --git a/OsmAnd-api/src/net/osmand/aidlapi/copyfile/CopyFileParams.java b/OsmAnd-api/src/net/osmand/aidlapi/copyfile/CopyFileParams.java index 1118a17f5c..ad122f60c6 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/copyfile/CopyFileParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/copyfile/CopyFileParams.java @@ -9,12 +9,21 @@ import net.osmand.aidlapi.AidlParams; public class CopyFileParams extends AidlParams { + public static final String DESTINATION_DIR_KEY = "destinationDir"; + public static final String FILE_NAME_KEY = "fileName"; + public static final String FILE_PART_DATA_KEY = "filePartData"; + public static final String START_TIME_KEY = "startTime"; + public static final String DONE_KEY = "done"; + private String destinationDir; private String fileName; private byte[] filePartData; private long startTime; private boolean done; - public CopyFileParams(@NonNull String fileName, @NonNull byte[] filePartData, long startTime, boolean done) { + public CopyFileParams(@NonNull String destinationDir, @NonNull String fileName, @NonNull byte[] filePartData, + long startTime, boolean done) { + + this.destinationDir = destinationDir; this.fileName = fileName; this.filePartData = filePartData; this.startTime = startTime; @@ -37,6 +46,10 @@ public class CopyFileParams extends AidlParams { } }; + public String getDestinationDir() { + return destinationDir; + } + public String getFileName() { return fileName; } @@ -55,23 +68,26 @@ public class CopyFileParams extends AidlParams { @Override public void writeToBundle(Bundle bundle) { - bundle.putString("fileName", fileName); - bundle.putByteArray("filePartData", filePartData); - bundle.putLong("startTime", startTime); - bundle.putBoolean("done", done); + bundle.putString(DESTINATION_DIR_KEY, destinationDir); + bundle.putString(FILE_NAME_KEY, fileName); + bundle.putByteArray(FILE_PART_DATA_KEY, filePartData); + bundle.putLong(START_TIME_KEY, startTime); + bundle.putBoolean(DONE_KEY, done); } @Override protected void readFromBundle(Bundle bundle) { - fileName = bundle.getString("fileName"); - filePartData = bundle.getByteArray("filePartData"); - startTime = bundle.getLong("startTime"); - done = bundle.getBoolean("done"); + destinationDir = bundle.getString(DESTINATION_DIR_KEY); + fileName = bundle.getString(FILE_NAME_KEY); + filePartData = bundle.getByteArray(FILE_PART_DATA_KEY); + startTime = bundle.getLong(START_TIME_KEY); + done = bundle.getBoolean(DONE_KEY); } @Override public String toString() { return "CopyFileParams {" + + " destinationDir=" + destinationDir + " fileName=" + fileName + ", filePartData size=" + filePartData.length + ", startTime=" + startTime + diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index a86f48f714..6cb1dee762 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -30,6 +30,7 @@ import net.osmand.FileUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; +import net.osmand.IProgress; import net.osmand.IndexConstants; import net.osmand.Location; import net.osmand.PlatformUtil; @@ -131,6 +132,7 @@ import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_PART_SIZE_LIMIT_E import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_UNSUPPORTED_FILE_TYPE_ERROR; import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_WRITE_LOCK_ERROR; import static net.osmand.aidlapi.OsmandAidlConstants.OK_RESPONSE; +import static net.osmand.plus.FavouritesDbHelper.FILE_TO_SAVE; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_LANES; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_NAME; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_TURN; @@ -2360,7 +2362,7 @@ public class OsmandAidlApi { } } - int copyFile(String fileName, byte[] filePartData, long startTime, boolean done) { + int copyFileOld(String fileName, byte[] filePartData, long startTime, boolean done) { if (Algorithms.isEmpty(fileName) || filePartData == null) { return COPY_FILE_PARAMS_ERROR; } @@ -2374,6 +2376,31 @@ public class OsmandAidlApi { } } + int copyFile(String destinationDir, String fileName, byte[] filePartData, long startTime, boolean done) { + if (Algorithms.isEmpty(fileName) || filePartData == null) { + return COPY_FILE_PARAMS_ERROR; + } + if (filePartData.length > COPY_FILE_PART_SIZE_LIMIT) { + return COPY_FILE_PART_SIZE_LIMIT_ERROR; + } + int result = copyFileImpl(fileName, filePartData, startTime, done, destinationDir); + if (done) { + if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) && IndexConstants.MAPS_PATH.equals(destinationDir)) { + app.getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS, new ArrayList()); + app.getDownloadThread().updateLoadedFiles(); + } else if (fileName.endsWith(IndexConstants.GPX_FILE_EXT)) { + if (destinationDir.startsWith(IndexConstants.GPX_INDEX_DIR) + && !FILE_TO_SAVE.equals(fileName)) { + GPXUtilities.loadGPXFile(new File(destinationDir, fileName)); + } else if (destinationDir.isEmpty() && FILE_TO_SAVE.equals(fileName)) { + GPXUtilities.loadGPXFile(new File(destinationDir, fileName)); + app.getFavorites().loadFavorites(); + } + } + } + return result; + } + private int copyFileImpl(String fileName, byte[] filePartData, long startTime, boolean done, String destinationDir) { File tempDir = FileUtils.getTempDir(app); File file = new File(tempDir, fileName); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 17c87431e8..0d9e5d6961 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -1138,7 +1138,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { if (api == null) { return CANNOT_ACCESS_API_ERROR; } - return api.copyFile(params.getFileName(), params.getFilePartData(), params.getStartTime(), params.isDone()); + return api.copyFileOld(params.getFileName(), params.getFilePartData(), params.getStartTime(), params.isDone()); } catch (Exception e) { handleException(e); return UNKNOWN_API_ERROR; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 4cd13d12da..8f6564a957 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -1092,7 +1092,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener if (api == null) { return CANNOT_ACCESS_API_ERROR; } - return api.copyFile(params.getFileName(), params.getFilePartData(), params.getStartTime(), params.isDone()); + return api.copyFile(params.getDestinationDir(), params.getFileName(), params.getFilePartData(), + params.getStartTime(), params.isDone()); } catch (Exception e) { handleException(e); return UNKNOWN_API_ERROR;