mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 14:21:16 +00:00
Fixed crash on first start after install.
This commit is contained in:
parent
d6025a5e6b
commit
ce7773bac7
1 changed files with 79 additions and 81 deletions
|
@ -106,17 +106,11 @@ public class SyncthingService extends Service {
|
||||||
return super.getMessage() + "\n" + mLog;
|
return super.getMessage() + "\n" + mLog;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Runs the syncthing binary from command line, and prints its output to logcat.
|
|
||||||
*/
|
|
||||||
private class NativeSyncthingRunnable implements Runnable {
|
|
||||||
@Override
|
|
||||||
public void run() throws NativeExecutionException {
|
|
||||||
if (isFirstStart(SyncthingService.this)) {
|
|
||||||
copyDefaultConfig();
|
|
||||||
}
|
|
||||||
updateConfig();
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the syncthing binary from command line, and prints its output to logcat (on exit).
|
||||||
|
*/
|
||||||
|
private void runNative() {
|
||||||
DataOutputStream dos = null;
|
DataOutputStream dos = null;
|
||||||
InputStreamReader isr = null;
|
InputStreamReader isr = null;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
@ -172,7 +166,6 @@ public class SyncthingService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Polls SYNCTHING_URL until it returns HTTP status OK, then calls all listeners
|
* Polls SYNCTHING_URL until it returns HTTP status OK, then calls all listeners
|
||||||
|
@ -232,6 +225,14 @@ public class SyncthingService extends Service {
|
||||||
n.flags |= Notification.FLAG_ONGOING_EVENT;
|
n.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||||
startForeground(NOTIFICATION_ID, n);
|
startForeground(NOTIFICATION_ID, n);
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (isFirstStart(SyncthingService.this)) {
|
||||||
|
copyDefaultConfig();
|
||||||
|
}
|
||||||
|
updateConfig();
|
||||||
|
|
||||||
String syncthingUrl = null;
|
String syncthingUrl = null;
|
||||||
try {
|
try {
|
||||||
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
|
@ -239,23 +240,20 @@ public class SyncthingService extends Service {
|
||||||
Element options = (Element)
|
Element options = (Element)
|
||||||
d.getDocumentElement().getElementsByTagName("gui").item(0);
|
d.getDocumentElement().getElementsByTagName("gui").item(0);
|
||||||
syncthingUrl = options.getElementsByTagName("address").item(0).getTextContent();
|
syncthingUrl = options.getElementsByTagName("address").item(0).getTextContent();
|
||||||
}
|
} catch (SAXException e) {
|
||||||
catch (SAXException e) {
|
|
||||||
throw new RuntimeException("Failed to read gui url, aborting", e);
|
throw new RuntimeException("Failed to read gui url, aborting", e);
|
||||||
}
|
} catch (ParserConfigurationException e) {
|
||||||
catch (ParserConfigurationException e) {
|
|
||||||
throw new RuntimeException("Failed to read gui url, aborting", e);
|
throw new RuntimeException("Failed to read gui url, aborting", e);
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
throw new RuntimeException("Failed to read gui url, aborting", e);
|
throw new RuntimeException("Failed to read gui url, aborting", e);
|
||||||
}
|
} finally {
|
||||||
finally {
|
mApi = new RestApi(SyncthingService.this, "http://" + syncthingUrl);
|
||||||
mApi = new RestApi(this, "http://" + syncthingUrl);
|
|
||||||
registerOnWebGuiAvailableListener(mApi);
|
registerOnWebGuiAvailableListener(mApi);
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread(new NativeSyncthingRunnable()).start();
|
|
||||||
new PollWebGuiAvailableTask().execute();
|
new PollWebGuiAvailableTask().execute();
|
||||||
|
runNative();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -347,7 +345,7 @@ public class SyncthingService extends Service {
|
||||||
Log.w(TAG, "Failed to parse config", e);
|
Log.w(TAG, "Failed to parse config", e);
|
||||||
}
|
}
|
||||||
catch (TransformerException e) {
|
catch (TransformerException e) {
|
||||||
Log.d(TAG, "Failed to save updated config", e);
|
Log.w(TAG, "Failed to save updated config", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue