Don't try to start bonjour without an IP.
Although not reproduced, it looks very much like this would be related to, and should subsequently fix #556.
This commit is contained in:
parent
3dd0589b08
commit
db120133b9
@ -1,6 +1,7 @@
|
|||||||
package org.fdroid.fdroid.localrepo.type;
|
package org.fdroid.fdroid.localrepo.type;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
@ -10,6 +11,7 @@ import org.fdroid.fdroid.localrepo.SwapService;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import javax.jmdns.JmDNS;
|
import javax.jmdns.JmDNS;
|
||||||
@ -31,10 +33,15 @@ public class BonjourBroadcast extends SwapType {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
|
|
||||||
Utils.debugLog(TAG, "Preparing to start Bonjour service.");
|
Utils.debugLog(TAG, "Preparing to start Bonjour service.");
|
||||||
sendBroadcast(SwapService.EXTRA_STARTING);
|
sendBroadcast(SwapService.EXTRA_STARTING);
|
||||||
|
|
||||||
|
InetAddress address = getDeviceAddress();
|
||||||
|
if (address == null) {
|
||||||
|
Log.e(TAG, "Starting Bonjour service, but couldn't ascertain IP address. Seems we are not connected to a network.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* a ServiceInfo can only be registered with a single instance
|
* a ServiceInfo can only be registered with a single instance
|
||||||
* of JmDNS, and there is only ever a single LocalHTTPD port to
|
* of JmDNS, and there is only ever a single LocalHTTPD port to
|
||||||
@ -43,6 +50,7 @@ public class BonjourBroadcast extends SwapType {
|
|||||||
if (pairService != null || jmdns != null) {
|
if (pairService != null || jmdns != null) {
|
||||||
clearCurrentMDNSService();
|
clearCurrentMDNSService();
|
||||||
}
|
}
|
||||||
|
|
||||||
String repoName = Preferences.get().getLocalRepoName();
|
String repoName = Preferences.get().getLocalRepoName();
|
||||||
HashMap<String, String> values = new HashMap<>();
|
HashMap<String, String> values = new HashMap<>();
|
||||||
values.put("path", "/fdroid/repo");
|
values.put("path", "/fdroid/repo");
|
||||||
@ -59,7 +67,7 @@ public class BonjourBroadcast extends SwapType {
|
|||||||
try {
|
try {
|
||||||
Utils.debugLog(TAG, "Starting bonjour service...");
|
Utils.debugLog(TAG, "Starting bonjour service...");
|
||||||
pairService = ServiceInfo.create(type, repoName, FDroidApp.port, 0, 0, values);
|
pairService = ServiceInfo.create(type, repoName, FDroidApp.port, 0, 0, values);
|
||||||
jmdns = JmDNS.create(InetAddress.getByName(FDroidApp.ipAddressString));
|
jmdns = JmDNS.create(address);
|
||||||
jmdns.registerService(pairService);
|
jmdns.registerService(pairService);
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
Utils.debugLog(TAG, "... Bounjour service started.");
|
Utils.debugLog(TAG, "... Bounjour service started.");
|
||||||
@ -90,4 +98,15 @@ public class BonjourBroadcast extends SwapType {
|
|||||||
return SwapService.BONJOUR_STATE_CHANGE;
|
return SwapService.BONJOUR_STATE_CHANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private InetAddress getDeviceAddress() {
|
||||||
|
if (FDroidApp.ipAddressString != null) {
|
||||||
|
try {
|
||||||
|
return InetAddress.getByName(FDroidApp.ipAddressString);
|
||||||
|
} catch (UnknownHostException e) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user