mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-06-09 22:57:54 +02:00
Bangle.js: add save file to android functionality
Bangle.js:file handling LOG.warn -> info Bangle.js: sync file can't escape device directory Naïve solution. I wanted to use `Path.normalize()` but Android Studio said it could not be used from the static context. This does not attempt to normalize the path, but just remove the special names `..\` and `.\`. Bangle.js:simpler hindering of escaping device dir
This commit is contained in:
parent
cef277261a
commit
f8e15068ea
|
@ -580,6 +580,9 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||||
case "intent":
|
case "intent":
|
||||||
handleIntent(json);
|
handleIntent(json);
|
||||||
break;
|
break;
|
||||||
|
case "file":
|
||||||
|
handleFile(json);
|
||||||
|
break;
|
||||||
case "gps_power": {
|
case "gps_power": {
|
||||||
boolean status = json.getBoolean("status");
|
boolean status = json.getBoolean("status");
|
||||||
LOG.info("Got gps power status: " + status);
|
LOG.info("Got gps power status: " + status);
|
||||||
|
@ -984,6 +987,37 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleFile(JSONObject json) throws JSONException {
|
||||||
|
|
||||||
|
File dir;
|
||||||
|
try {
|
||||||
|
dir = new File(FileUtils.getExternalFilesDir() + "/" + FileUtils.makeValidFileName(getDevice().getName()));
|
||||||
|
if (!dir.isDirectory()) {
|
||||||
|
if (!dir.mkdir()) {
|
||||||
|
throw new IOException("Cannot create device specific directory for " + getDevice().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.error("Could not get directory to write to with error: " + e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String filename = json.getString("n");
|
||||||
|
String filenameThatCantEscapeDir = filename.replaceAll("/","");
|
||||||
|
|
||||||
|
LOG.debug("Compare filename and filenameThatCantEscapeDir:\n" + filename + "\n" + filenameThatCantEscapeDir);
|
||||||
|
File outputFile = new File(dir, filenameThatCantEscapeDir);
|
||||||
|
String mode = "append";
|
||||||
|
if (json.getString("m").equals("w")) {
|
||||||
|
mode = "write";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
FileUtils.copyStringToFile(json.getString("c"), outputFile, mode);
|
||||||
|
LOG.info("Writing to "+outputFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.warn("Could not write to " + outputFile + "with error: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendConfiguration(final String config) {
|
public void onSendConfiguration(final String config) {
|
||||||
switch (config) {
|
switch (config) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user