From 8f7a29bd7acc11ff2775898b7992d51b6402ac7c Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sun, 17 Feb 2019 22:01:01 +0100 Subject: [PATCH] Only show notification after three timeouts during handshake --- .../connection_service/InsightConnectionService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/connection_service/InsightConnectionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/connection_service/InsightConnectionService.java index 06fe55bd5e..51ff6e341d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/connection_service/InsightConnectionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/connection_service/InsightConnectionService.java @@ -89,6 +89,7 @@ public class InsightConnectionService extends Service implements ConnectionEstab private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); private static final int BUFFER_SIZE = 1024; + private static final int TIMEOUT_DURING_HANDSHAKE_NOTIFICATION_THRESHOLD = 3; private static final long RESPONSE_TIMEOUT = 6000; private List stateCallbacks = new ArrayList<>(); @@ -117,6 +118,7 @@ public class InsightConnectionService extends Service implements ConnectionEstab private long lastDataTime; private long lastConnected; private long recoveryDuration = 0; + private int timeoutDuringHandshakeCounter; KeyPair getKeyPair() { if (keyPair == null) keyPair = Cryptograph.generateRSAKey(); @@ -274,6 +276,7 @@ public class InsightConnectionService extends Service implements ConnectionEstab } if (state == InsightState.DISCONNECTED && pairingDataStorage.isPaired()) { recoveryDuration = 0; + timeoutDuringHandshakeCounter = 0; connect(); } } @@ -353,8 +356,10 @@ public class InsightConnectionService extends Service implements ConnectionEstab log.info("Exception occurred: " + e.getClass().getSimpleName()); if (pairingDataStorage.isPaired()) { if (e instanceof TimeoutException && (state == InsightState.SATL_SYN_REQUEST || state == InsightState.APP_CONNECT_MESSAGE)) { - for (StateCallback stateCallback : stateCallbacks) { - stateCallback.onTimeoutDuringHandshake(); + if (++timeoutDuringHandshakeCounter == TIMEOUT_DURING_HANDSHAKE_NOTIFICATION_THRESHOLD) { + for (StateCallback stateCallback : stateCallbacks) { + stateCallback.onTimeoutDuringHandshake(); + } } } setState(connectionRequests.size() != 0 ? InsightState.RECOVERING : InsightState.DISCONNECTED);