Remove init hack in DiscoveryService

This commit is contained in:
Cameron Gutman 2014-07-04 15:11:31 -07:00
parent 0f4e5a4585
commit 825233309d
2 changed files with 20 additions and 45 deletions

Binary file not shown.

View File

@ -1,6 +1,5 @@
package com.limelight.discovery; package com.limelight.discovery;
import java.io.IOException;
import java.util.List; import java.util.List;
import com.limelight.nvstream.mdns.MdnsComputer; import com.limelight.nvstream.mdns.MdnsComputer;
@ -47,14 +46,7 @@ public class DiscoveryService extends Service {
multicastLock = wifiMgr.createMulticastLock("Limelight mDNS"); multicastLock = wifiMgr.createMulticastLock("Limelight mDNS");
multicastLock.setReferenceCounted(false); multicastLock.setReferenceCounted(false);
// This pattern is nasty. We have to do it discoveryAgent = new MdnsDiscoveryAgent(new MdnsDiscoveryListener() {
// because we can't do network on the main thread
// even if it's non-blocking
Thread initThread = new Thread() {
@Override
public void run() {
try {
discoveryAgent = MdnsDiscoveryAgent.createDiscoveryAgent(new MdnsDiscoveryListener() {
@Override @Override
public void notifyComputerAdded(MdnsComputer computer) { public void notifyComputerAdded(MdnsComputer computer) {
if (boundListener != null) { if (boundListener != null) {
@ -76,32 +68,15 @@ public class DiscoveryService extends Service {
} }
} }
}); });
} catch (IOException e) {
e.printStackTrace();
discoveryAgent = null;
}
}
};
initThread.start();
try {
initThread.join();
} catch (InterruptedException e) {
discoveryAgent = null;
}
} }
private DiscoveryBinder binder = new DiscoveryBinder(); private DiscoveryBinder binder = new DiscoveryBinder();
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
// We should only be bindable if discovery can happen
if (discoveryAgent != null) {
return binder; return binder;
} }
return null;
}
@Override @Override
public boolean onUnbind(Intent intent) { public boolean onUnbind(Intent intent) {
// Stop any discovery session // Stop any discovery session