mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-24 11:51:30 +00:00
Improve ConfigXml code
This commit is contained in:
parent
76ca22526b
commit
d8a872e592
2 changed files with 22 additions and 51 deletions
|
@ -136,6 +136,8 @@ public class SyncthingRunnable implements Runnable {
|
||||||
env.put("STGUIASSETS", externalFilesDir.getAbsolutePath() + "/gui");
|
env.put("STGUIASSETS", externalFilesDir.getAbsolutePath() + "/gui");
|
||||||
env.put("STNORESTART", "1");
|
env.put("STNORESTART", "1");
|
||||||
env.put("STNOUPGRADE", "1");
|
env.put("STNOUPGRADE", "1");
|
||||||
|
// Disable hash benchmark for faster startup.
|
||||||
|
// https://github.com/syncthing/syncthing/issues/4348
|
||||||
env.put("STHASHING", "minio");
|
env.put("STHASHING", "minio");
|
||||||
if (sp.getBoolean("use_tor", false)) {
|
if (sp.getBoolean("use_tor", false)) {
|
||||||
env.put("all_proxy", "socks5://localhost:9050");
|
env.put("all_proxy", "socks5://localhost:9050");
|
||||||
|
|
|
@ -121,31 +121,17 @@ public class ConfigXml {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (applyHashers(r)) {
|
// Set 'hashers' (see https://github.com/syncthing/syncthing-android/issues/384) on the
|
||||||
changed = true;
|
// given folder.
|
||||||
}
|
changed = setConfigElement(r, "hashers", "1") || changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enforce TLS.
|
// Enforce TLS.
|
||||||
Element gui = (Element) mConfig.getDocumentElement()
|
Element gui = getGuiElement();
|
||||||
.getElementsByTagName("gui").item(0);
|
changed = setConfigElement(gui, "tls", "true") || changed;
|
||||||
boolean tls = Boolean.parseBoolean(gui.getAttribute("tls"));
|
|
||||||
if (!tls) {
|
|
||||||
Log.i(TAG, "Enforce TLS");
|
|
||||||
gui.setAttribute("tls", Boolean.toString(true));
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set user to "syncthing"
|
// Set user to "syncthing"
|
||||||
Node user = gui.getElementsByTagName("user").item(0);
|
changed = setConfigElement(gui, "user", "syncthing") || changed;
|
||||||
if (user == null) {
|
|
||||||
user = mConfig.createElement("user");
|
|
||||||
gui.appendChild(user);
|
|
||||||
}
|
|
||||||
if (!user.getTextContent().equals("syncthing")) {
|
|
||||||
user.setTextContent("syncthing");
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set password to the API key
|
// Set password to the API key
|
||||||
Node password = gui.getElementsByTagName("password").item(0);
|
Node password = gui.getElementsByTagName("password").item(0);
|
||||||
|
@ -163,49 +149,32 @@ public class ConfigXml {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disable weak hash benchmark for faster startup.
|
||||||
|
// https://github.com/syncthing/syncthing/issues/4348
|
||||||
Element options = (Element) mConfig.getDocumentElement()
|
Element options = (Element) mConfig.getDocumentElement()
|
||||||
.getElementsByTagName("options").item(0);
|
.getElementsByTagName("options").item(0);
|
||||||
Node weakHash = options.getElementsByTagName("weakHashSelectionMethod").item(0);
|
changed = setConfigElement(options, "weakHashSelectionMethod", "never") || changed;
|
||||||
if (!weakHash.getTextContent().equals("never")) {
|
|
||||||
weakHash.setTextContent("never");
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
saveChanges();
|
saveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private boolean setConfigElement(Element parent, String tagName, String textContent) {
|
||||||
* Set 'hashers' (see https://github.com/syncthing/syncthing-android/issues/384) on the
|
Node element = parent.getElementsByTagName(tagName).item(0);
|
||||||
* given folder.
|
if (element == null) {
|
||||||
*
|
element = mConfig.createElement(tagName);
|
||||||
* @return True if the XML was changed.
|
parent.appendChild(element);
|
||||||
*/
|
}
|
||||||
private boolean applyHashers(Element folder) {
|
if (!textContent.equals(element.getTextContent())) {
|
||||||
NodeList childs = folder.getChildNodes();
|
element.setTextContent(textContent);
|
||||||
for (int i = 0; i < childs.getLength(); i++) {
|
|
||||||
Node item = childs.item(i);
|
|
||||||
if (item.getNodeName().equals("hashers")) {
|
|
||||||
if (item.getTextContent().equals(Integer.toString(0))) {
|
|
||||||
item.setTextContent(Integer.toString(1));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// XML tag does not exist, create it.
|
|
||||||
Log.i(TAG, "Set 'hashers' on folder " + folder.getAttribute("id"));
|
|
||||||
Element newElem = mConfig.createElement("hashers");
|
|
||||||
newElem.setTextContent(Integer.toString(1));
|
|
||||||
folder.appendChild(newElem);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Element getGuiElement() {
|
private Element getGuiElement() {
|
||||||
return (Element) mConfig.getDocumentElement()
|
return (Element) mConfig.getDocumentElement().getElementsByTagName("gui").item(0);
|
||||||
.getElementsByTagName("gui").item(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue