mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 03:23:07 +00:00
Fix thread spawning issue and remove some dead code
This commit is contained in:
parent
1a71dda243
commit
78d213d686
@ -38,7 +38,6 @@ public class ComputerManagerService extends Service {
|
|||||||
private HashMap<ComputerDetails, Thread> pollingThreads;
|
private HashMap<ComputerDetails, Thread> pollingThreads;
|
||||||
private ComputerManagerListener listener = null;
|
private ComputerManagerListener listener = null;
|
||||||
private AtomicInteger activePolls = new AtomicInteger(0);
|
private AtomicInteger activePolls = new AtomicInteger(0);
|
||||||
private boolean stopped;
|
|
||||||
|
|
||||||
private DiscoveryService.DiscoveryBinder discoveryBinder;
|
private DiscoveryService.DiscoveryBinder discoveryBinder;
|
||||||
private final ServiceConnection discoveryServiceConnection = new ServiceConnection() {
|
private final ServiceConnection discoveryServiceConnection = new ServiceConnection() {
|
||||||
@ -65,15 +64,6 @@ public class ComputerManagerService extends Service {
|
|||||||
{
|
{
|
||||||
boolean newPc = (details.name == null);
|
boolean newPc = (details.name == null);
|
||||||
|
|
||||||
// This is called from addComputerManually() where we don't
|
|
||||||
// want to block the initial poll if polling is disabled, so
|
|
||||||
// we explicitly let this through if we've never seen this
|
|
||||||
// PC before. This path won't be triggered normally when polling
|
|
||||||
// is disabled because the mDNS discovery is stopped.
|
|
||||||
if (stopped && !newPc) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!getLocalDatabaseReference()) {
|
if (!getLocalDatabaseReference()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -132,18 +122,18 @@ public class ComputerManagerService extends Service {
|
|||||||
// Wait until the next polling interval
|
// Wait until the next polling interval
|
||||||
try {
|
try {
|
||||||
Thread.sleep(POLLING_PERIOD_MS);
|
Thread.sleep(POLLING_PERIOD_MS);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
t.setName("Polling thread for "+details.localIp.getHostAddress());
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ComputerManagerBinder extends Binder {
|
public class ComputerManagerBinder extends Binder {
|
||||||
public void startPolling(ComputerManagerListener listener) {
|
public void startPolling(ComputerManagerListener listener) {
|
||||||
// Not stopped
|
|
||||||
stopped = false;
|
|
||||||
|
|
||||||
// Set the listener
|
// Set the listener
|
||||||
ComputerManagerService.this.listener = listener;
|
ComputerManagerService.this.listener = listener;
|
||||||
|
|
||||||
@ -159,11 +149,14 @@ public class ComputerManagerService extends Service {
|
|||||||
|
|
||||||
synchronized (pollingThreads) {
|
synchronized (pollingThreads) {
|
||||||
for (ComputerDetails computer : computerList) {
|
for (ComputerDetails computer : computerList) {
|
||||||
|
// This polling thread might already be there
|
||||||
|
if (!pollingThreads.containsKey(computer)) {
|
||||||
Thread t = createPollingThread(computer);
|
Thread t = createPollingThread(computer);
|
||||||
pollingThreads.put(computer, t);
|
pollingThreads.put(computer, t);
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void waitForReady() {
|
public void waitForReady() {
|
||||||
@ -210,9 +203,6 @@ public class ComputerManagerService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onUnbind(Intent intent) {
|
public boolean onUnbind(Intent intent) {
|
||||||
// Stopped now
|
|
||||||
stopped = true;
|
|
||||||
|
|
||||||
// Stop mDNS autodiscovery
|
// Stop mDNS autodiscovery
|
||||||
discoveryBinder.stopDiscovery();
|
discoveryBinder.stopDiscovery();
|
||||||
|
|
||||||
@ -221,6 +211,7 @@ public class ComputerManagerService extends Service {
|
|||||||
for (Thread t : pollingThreads.values()) {
|
for (Thread t : pollingThreads.values()) {
|
||||||
t.interrupt();
|
t.interrupt();
|
||||||
}
|
}
|
||||||
|
pollingThreads.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the listener
|
// Remove the listener
|
||||||
@ -258,11 +249,14 @@ public class ComputerManagerService extends Service {
|
|||||||
|
|
||||||
// Spawn a thread for this computer
|
// Spawn a thread for this computer
|
||||||
synchronized (pollingThreads) {
|
synchronized (pollingThreads) {
|
||||||
|
// This polling thread might already be there
|
||||||
|
if (!pollingThreads.containsKey(fakeDetails)) {
|
||||||
Thread t = createPollingThread(fakeDetails);
|
Thread t = createPollingThread(fakeDetails);
|
||||||
pollingThreads.put(fakeDetails, t);
|
pollingThreads.put(fakeDetails, t);
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean addComputerBlocking(InetAddress addr) {
|
public boolean addComputerBlocking(InetAddress addr) {
|
||||||
// Setup a placeholder
|
// Setup a placeholder
|
||||||
|
Loading…
x
Reference in New Issue
Block a user