From ba028408a124bf3af2ccdb7680cb7fe5c63020bb Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 27 May 2014 18:50:34 -0400 Subject: [PATCH] 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) --- src/org/fdroid/fdroid/localrepo/LocalRepoService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/org/fdroid/fdroid/localrepo/LocalRepoService.java b/src/org/fdroid/fdroid/localrepo/LocalRepoService.java index fc182352d..590a3471d 100644 --- a/src/org/fdroid/fdroid/localrepo/LocalRepoService.java +++ b/src/org/fdroid/fdroid/localrepo/LocalRepoService.java @@ -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 values = new HashMap(); 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);