mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 11:33:06 +00:00
Generalize the polling grace period to all users of CMS
This commit is contained in:
parent
95ea88e932
commit
f1787c43e5
@ -55,9 +55,6 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
|
|||||||
private SpinnerDialog blockingLoadSpinner;
|
private SpinnerDialog blockingLoadSpinner;
|
||||||
private String lastRawApplist;
|
private String lastRawApplist;
|
||||||
|
|
||||||
private int consecutiveAppListFailures = 0;
|
|
||||||
private final static int CONSECUTIVE_FAILURE_LIMIT = 3;
|
|
||||||
|
|
||||||
private final static int START_OR_RESUME_ID = 1;
|
private final static int START_OR_RESUME_ID = 1;
|
||||||
private final static int QUIT_ID = 2;
|
private final static int QUIT_ID = 2;
|
||||||
private final static int CANCEL_ID = 3;
|
private final static int CANCEL_ID = 3;
|
||||||
@ -133,25 +130,19 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (details.state != ComputerDetails.State.ONLINE) {
|
if (details.state != ComputerDetails.State.ONLINE) {
|
||||||
consecutiveAppListFailures++;
|
// The PC is unreachable now
|
||||||
|
AppView.this.runOnUiThread(new Runnable() {
|
||||||
if (consecutiveAppListFailures >= CONSECUTIVE_FAILURE_LIMIT) {
|
@Override
|
||||||
// The PC is unreachable now
|
public void run() {
|
||||||
AppView.this.runOnUiThread(new Runnable() {
|
// Display a toast to the user and quit the activity
|
||||||
@Override
|
Toast.makeText(AppView.this, getResources().getText(R.string.lost_connection), Toast.LENGTH_SHORT).show();
|
||||||
public void run() {
|
finish();
|
||||||
// Display a toast to the user and quit the activity
|
}
|
||||||
Toast.makeText(AppView.this, getResources().getText(R.string.lost_connection), Toast.LENGTH_SHORT).show();
|
});
|
||||||
finish();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
consecutiveAppListFailures = 0;
|
|
||||||
|
|
||||||
// App list is the same or empty; nothing to do
|
// App list is the same or empty; nothing to do
|
||||||
if (details.rawAppList == null || details.rawAppList.equals(lastRawApplist)) {
|
if (details.rawAppList == null || details.rawAppList.equals(lastRawApplist)) {
|
||||||
return;
|
return;
|
||||||
|
@ -2,6 +2,7 @@ package com.limelight.computers;
|
|||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -34,6 +35,7 @@ public class ComputerManagerService extends Service {
|
|||||||
private static final int POLLING_PERIOD_MS = 3000;
|
private static final int POLLING_PERIOD_MS = 3000;
|
||||||
private static final int MDNS_QUERY_PERIOD_MS = 1000;
|
private static final int MDNS_QUERY_PERIOD_MS = 1000;
|
||||||
private static final int FAST_POLL_TIMEOUT = 500;
|
private static final int FAST_POLL_TIMEOUT = 500;
|
||||||
|
private static final int OFFLINE_POLL_TRIES = 3;
|
||||||
|
|
||||||
private final ComputerManagerBinder binder = new ComputerManagerBinder();
|
private final ComputerManagerBinder binder = new ComputerManagerBinder();
|
||||||
|
|
||||||
@ -67,7 +69,7 @@ public class ComputerManagerService extends Service {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Returns true if the details object was modified
|
// Returns true if the details object was modified
|
||||||
private boolean runPoll(ComputerDetails details, boolean newPc) throws InterruptedException {
|
private boolean runPoll(ComputerDetails details, boolean newPc, int offlineCount) throws InterruptedException {
|
||||||
if (!getLocalDatabaseReference()) {
|
if (!getLocalDatabaseReference()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -77,6 +79,11 @@ public class ComputerManagerService extends Service {
|
|||||||
// Poll the machine
|
// Poll the machine
|
||||||
try {
|
try {
|
||||||
if (!pollComputer(details)) {
|
if (!pollComputer(details)) {
|
||||||
|
if (!newPc && offlineCount < OFFLINE_POLL_TRIES) {
|
||||||
|
// Return without calling the listener
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
details.state = ComputerDetails.State.OFFLINE;
|
details.state = ComputerDetails.State.OFFLINE;
|
||||||
details.reachability = ComputerDetails.Reachability.OFFLINE;
|
details.reachability = ComputerDetails.Reachability.OFFLINE;
|
||||||
}
|
}
|
||||||
@ -95,7 +102,7 @@ public class ComputerManagerService extends Service {
|
|||||||
if (dbManager.getComputerByName(details.name) == null) {
|
if (dbManager.getComputerByName(details.name) == null) {
|
||||||
// It's gone
|
// It's gone
|
||||||
releaseLocalDatabaseReference();
|
releaseLocalDatabaseReference();
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,13 +122,21 @@ public class ComputerManagerService extends Service {
|
|||||||
Thread t = new Thread() {
|
Thread t = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
|
int offlineCount = 0;
|
||||||
while (!isInterrupted() && pollingActive) {
|
while (!isInterrupted() && pollingActive) {
|
||||||
try {
|
try {
|
||||||
// Check if this poll has modified the details
|
// Check if this poll has modified the details
|
||||||
runPoll(details, false);
|
if (!runPoll(details, false, offlineCount)) {
|
||||||
|
LimeLog.warning(details.name + " is offline (try " + offlineCount + ")");
|
||||||
|
offlineCount++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
offlineCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Wait until the next polling interval
|
// Wait until the next polling interval
|
||||||
Thread.sleep(POLLING_PERIOD_MS);
|
Thread.sleep(POLLING_PERIOD_MS / ((offlineCount > 0) ? 2 : 1));
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -293,7 +308,7 @@ public class ComputerManagerService extends Service {
|
|||||||
|
|
||||||
// Block while we try to fill the details
|
// Block while we try to fill the details
|
||||||
try {
|
try {
|
||||||
runPoll(fakeDetails, true);
|
runPoll(fakeDetails, true, 0);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user