Fix disconnect routine
This commit is contained in:
parent
cc364a0cec
commit
4d213eae7d
|
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.AppLayerMessage;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.ReadParameterBlockMessage;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.configuration.CloseConfigurationWriteSessionMessage;
|
||||
|
@ -262,16 +263,16 @@ public class InsightConnectionService extends Service implements ConnectionEstab
|
|||
if (!connectionRequests.contains(lock)) return;
|
||||
connectionRequests.remove(lock);
|
||||
if (connectionRequests.size() == 0) {
|
||||
//TODO: Make adjustable
|
||||
log.info("Last connection lock released, will disconnect in 5 seconds");
|
||||
if (recoveryTimer != null) {
|
||||
if (state == InsightState.RECOVERING) {
|
||||
recoveryTimer.interrupt();
|
||||
recoveryTimer = null;
|
||||
setState(InsightState.DISCONNECTED);
|
||||
} else {
|
||||
cleanup();
|
||||
} else if (state != InsightState.DISCONNECTED) {
|
||||
long disconnectTimeout = SP.getInt("insight_disconnect_delay", 5);
|
||||
disconnectTimeout = Math.min(disconnectTimeout, 15);
|
||||
disconnectTimeout = Math.max(disconnectTimeout, 0);
|
||||
log.info("Last connection lock released, will disconnect " + disconnectTimeout + " seconds");
|
||||
disconnectTimer = DelayedActionThread.runDelayed("Disconnect Timer", disconnectTimeout * 1000, this::disconnect);
|
||||
}
|
||||
}
|
||||
|
@ -326,10 +327,11 @@ public class InsightConnectionService extends Service implements ConnectionEstab
|
|||
}
|
||||
log.info("Exception occurred: " + e.getClass().getSimpleName());
|
||||
if (pairingDataStorage.isPaired()) {
|
||||
setState(InsightState.RECOVERING);
|
||||
setState(connectionRequests.size() != 0 ? InsightState.RECOVERING : InsightState.DISCONNECTED);
|
||||
cleanup();
|
||||
messageQueue.completeActiveRequest(e);
|
||||
messageQueue.completePendingRequests(e);
|
||||
if (connectionRequests.size() != 0) {
|
||||
if (!(e instanceof ConnectionFailedException)) {
|
||||
connect();
|
||||
} else {
|
||||
|
@ -338,9 +340,12 @@ public class InsightConnectionService extends Service implements ConnectionEstab
|
|||
recoveryDuration = Math.max(recoveryDuration, 0);
|
||||
recoveryTimer = DelayedActionThread.runDelayed("RecoveryTimer", recoveryDuration * 1000, () -> {
|
||||
recoveryTimer = null;
|
||||
connect();
|
||||
synchronized (InsightConnectionService.this) {
|
||||
if (!Thread.currentThread().isInterrupted()) connect();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setState(InsightState.NOT_PAIRED);
|
||||
cleanup();
|
||||
|
|
Loading…
Reference in a new issue