Some improvements around connection state.
This commit is contained in:
parent
bf179cd751
commit
e526de68ea
2 changed files with 23 additions and 19 deletions
|
@ -11,4 +11,5 @@ interface IRuffyService {
|
|||
void doRTDisconnect();
|
||||
void rtSendKey(byte keyCode, boolean changed);
|
||||
void resetPairing();
|
||||
boolean isConnected();
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ public class RuffyScripter {
|
|||
private volatile long lastCmdExecutionTime;
|
||||
private volatile Command activeCmd = null;
|
||||
|
||||
private volatile boolean connected = false;
|
||||
|
||||
public RuffyScripter(final IRuffyService ruffyService) {
|
||||
this.ruffyService = ruffyService;
|
||||
try {
|
||||
|
@ -55,8 +57,6 @@ public class RuffyScripter {
|
|||
}
|
||||
}
|
||||
|
||||
private volatile boolean connected = false;
|
||||
|
||||
private Thread idleDisconnectMonitorThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -72,6 +72,7 @@ public class RuffyScripter {
|
|||
log.debug("Disconnecting after " + (connectionTimeOutMs / 1000) + "s inactivity timeout");
|
||||
lastDisconnect = now;
|
||||
ruffyService.doRTDisconnect();
|
||||
connected = false;
|
||||
SystemClock.sleep(1000);
|
||||
}
|
||||
} catch (DeadObjectException doe) {
|
||||
|
@ -133,6 +134,8 @@ public class RuffyScripter {
|
|||
currentMenu = menu;
|
||||
menuLastUpdated = System.currentTimeMillis();
|
||||
|
||||
connected = true;
|
||||
|
||||
// note that a WARNING_OR_ERROR menu can be a valid temporary state (cancelling TBR)
|
||||
// of a running command
|
||||
if (activeCmd == null && currentMenu.getType() == MenuType.WARNING_OR_ERROR) {
|
||||
|
@ -279,6 +282,7 @@ public class RuffyScripter {
|
|||
|
||||
/** If there's an issue, this times out eventually and throws a CommandException */
|
||||
private void ensureConnected() {
|
||||
try {
|
||||
boolean menuUpdateRecentlyReceived = currentMenu != null && menuLastUpdated + 1000 > System.currentTimeMillis();
|
||||
log.debug("ensureConnect, connected: " + connected + ", receiving menu updates: " + menuUpdateRecentlyReceived);
|
||||
if (menuUpdateRecentlyReceived) {
|
||||
|
@ -286,7 +290,6 @@ public class RuffyScripter {
|
|||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
boolean connectInitSuccessful = ruffyService.doRTConnect() == 0;
|
||||
log.debug("Connect init successful: " + connectInitSuccessful);
|
||||
while (currentMenu == null) {
|
||||
|
|
Loading…
Reference in a new issue