registerMDNSService() overwrites any existing registration

There is only ever a single service to advertise via mDNS, so when a new
registration is requested, remove any existing ones.  This should eliminate
these stacktraces:

java.lang.IllegalStateException: A service information can only be registered with a single instamce of JmDNS.
    at javax.jmdns.impl.JmDNSImpl.registerService(JmDNSImpl.java:1005)
    at org.fdroid.fdroid.localrepo.LocalRepoService$5.run(LocalRepoService.java:239)
    at java.lang.Thread.run(Thread.java:856)
This commit is contained in:
Hans-Christoph Steiner 2014-05-27 18:50:34 -04:00
parent fdaa2ad106
commit ba028408a1

View File

@ -216,6 +216,12 @@ public class LocalRepoService extends Service {
}
private void registerMDNSService() {
/*
* a ServiceInfo can only be registered with a single instance of JmDNS,
* and there is only ever a single LocalHTTPD port to advertise anyway.
*/
if (pairService != null || jmdns != null)
clearCurrentMDNSService();
String repoName = Preferences.get().getLocalRepoName();
final HashMap<String, String> values = new HashMap<String, String>();
values.put("path", "/fdroid/repo");
@ -249,6 +255,10 @@ public class LocalRepoService extends Service {
Preferences.get().unregisterLocalRepoBonjourListeners(localRepoBonjourChangeListener);
localRepoBonjourChangeListener = null;
}
clearCurrentMDNSService();
}
private void clearCurrentMDNSService() {
if (jmdns != null) {
if (pairService != null) {
jmdns.unregisterService(pairService);