Add AIDL copy file
This commit is contained in:
parent
47b0bc2ff0
commit
67952bdc63
4 changed files with 56 additions and 12 deletions
|
@ -9,12 +9,21 @@ import net.osmand.aidlapi.AidlParams;
|
||||||
|
|
||||||
public class CopyFileParams extends 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 String fileName;
|
||||||
private byte[] filePartData;
|
private byte[] filePartData;
|
||||||
private long startTime;
|
private long startTime;
|
||||||
private boolean done;
|
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.fileName = fileName;
|
||||||
this.filePartData = filePartData;
|
this.filePartData = filePartData;
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
|
@ -37,6 +46,10 @@ public class CopyFileParams extends AidlParams {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public String getDestinationDir() {
|
||||||
|
return destinationDir;
|
||||||
|
}
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
@ -55,23 +68,26 @@ public class CopyFileParams extends AidlParams {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToBundle(Bundle bundle) {
|
public void writeToBundle(Bundle bundle) {
|
||||||
bundle.putString("fileName", fileName);
|
bundle.putString(DESTINATION_DIR_KEY, destinationDir);
|
||||||
bundle.putByteArray("filePartData", filePartData);
|
bundle.putString(FILE_NAME_KEY, fileName);
|
||||||
bundle.putLong("startTime", startTime);
|
bundle.putByteArray(FILE_PART_DATA_KEY, filePartData);
|
||||||
bundle.putBoolean("done", done);
|
bundle.putLong(START_TIME_KEY, startTime);
|
||||||
|
bundle.putBoolean(DONE_KEY, done);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void readFromBundle(Bundle bundle) {
|
protected void readFromBundle(Bundle bundle) {
|
||||||
fileName = bundle.getString("fileName");
|
destinationDir = bundle.getString(DESTINATION_DIR_KEY);
|
||||||
filePartData = bundle.getByteArray("filePartData");
|
fileName = bundle.getString(FILE_NAME_KEY);
|
||||||
startTime = bundle.getLong("startTime");
|
filePartData = bundle.getByteArray(FILE_PART_DATA_KEY);
|
||||||
done = bundle.getBoolean("done");
|
startTime = bundle.getLong(START_TIME_KEY);
|
||||||
|
done = bundle.getBoolean(DONE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "CopyFileParams {" +
|
return "CopyFileParams {" +
|
||||||
|
" destinationDir=" + destinationDir +
|
||||||
" fileName=" + fileName +
|
" fileName=" + fileName +
|
||||||
", filePartData size=" + filePartData.length +
|
", filePartData size=" + filePartData.length +
|
||||||
", startTime=" + startTime +
|
", startTime=" + startTime +
|
||||||
|
|
|
@ -30,6 +30,7 @@ import net.osmand.FileUtils;
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.GPXUtilities.GPXFile;
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
import net.osmand.GPXUtilities.GPXTrackAnalysis;
|
import net.osmand.GPXUtilities.GPXTrackAnalysis;
|
||||||
|
import net.osmand.IProgress;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.PlatformUtil;
|
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_UNSUPPORTED_FILE_TYPE_ERROR;
|
||||||
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_WRITE_LOCK_ERROR;
|
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_WRITE_LOCK_ERROR;
|
||||||
import static net.osmand.aidlapi.OsmandAidlConstants.OK_RESPONSE;
|
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_LANES;
|
||||||
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_NAME;
|
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_NAME;
|
||||||
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_TURN;
|
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) {
|
if (Algorithms.isEmpty(fileName) || filePartData == null) {
|
||||||
return COPY_FILE_PARAMS_ERROR;
|
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<String>());
|
||||||
|
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) {
|
private int copyFileImpl(String fileName, byte[] filePartData, long startTime, boolean done, String destinationDir) {
|
||||||
File tempDir = FileUtils.getTempDir(app);
|
File tempDir = FileUtils.getTempDir(app);
|
||||||
File file = new File(tempDir, fileName);
|
File file = new File(tempDir, fileName);
|
||||||
|
|
|
@ -1138,7 +1138,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
|
||||||
if (api == null) {
|
if (api == null) {
|
||||||
return CANNOT_ACCESS_API_ERROR;
|
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) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e);
|
||||||
return UNKNOWN_API_ERROR;
|
return UNKNOWN_API_ERROR;
|
||||||
|
|
|
@ -1092,7 +1092,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
|
||||||
if (api == null) {
|
if (api == null) {
|
||||||
return CANNOT_ACCESS_API_ERROR;
|
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) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e);
|
||||||
return UNKNOWN_API_ERROR;
|
return UNKNOWN_API_ERROR;
|
||||||
|
|
Loading…
Reference in a new issue