diff --git a/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java b/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java index aa598c63..de2b3c19 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java @@ -72,6 +72,7 @@ public class ConfigXml { } if (isFirstStart) { + changeLocalDeviceName(); changeDefaultFolder(); generateLoginInfo(); } @@ -174,6 +175,23 @@ public class ConfigXml { .getElementsByTagName("gui").item(0); } + /** + * Set model name as device name for Syncthing. + * + * We need to iterate through XML nodes manually, as mConfig.getDocumentElement() will also + * return nested elements inside folder element. + */ + private void changeLocalDeviceName() { + NodeList childNodes = mConfig.getDocumentElement().getChildNodes(); + for (int i = 0; i < childNodes.getLength(); i++) { + Node node = childNodes.item(i); + if (node.getNodeName().equals("device")) { + ((Element) node).setAttribute("name", Build.MODEL); + } + } + saveChanges(); + } + /** * Change default folder id to camera and path to camera folder path. */