From 5fb0fe62f49c1da050c724c1a566b0167fff0e45 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sun, 17 Feb 2019 21:58:17 +0100 Subject: [PATCH 1/3] Remove timeout during handshake notification when connection was successful --- .../plugins/PumpInsightLocal/LocalInsightPlugin.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index ece7113877..5365ca7601 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -1535,8 +1535,10 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con @Override public void onStateChanged(InsightState state) { - if (state == InsightState.CONNECTED) statusLoaded = false; - else if (state == InsightState.NOT_PAIRED) { + if (state == InsightState.CONNECTED) { + statusLoaded = false; + MainApp.bus().post(new EventDismissNotification(Notification.INSIGHT_TIMEOUT_DURING_HANDSHAKE)); + } else if (state == InsightState.NOT_PAIRED) { connectionService.withdrawConnectionRequest(this); statusLoaded = false; profileBlocks = null; From 8f7a29bd7acc11ff2775898b7992d51b6402ac7c Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sun, 17 Feb 2019 22:01:01 +0100 Subject: [PATCH 2/3] 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); From 71f73210c99102c23cfd81fe06332a7c3bcf3abb Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sun, 17 Feb 2019 22:02:51 +0100 Subject: [PATCH 3/3] Send dismiss event in main thread --- .../androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index 5365ca7601..c6b721aa8a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -1537,7 +1537,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con public void onStateChanged(InsightState state) { if (state == InsightState.CONNECTED) { statusLoaded = false; - MainApp.bus().post(new EventDismissNotification(Notification.INSIGHT_TIMEOUT_DURING_HANDSHAKE)); + new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventDismissNotification(Notification.INSIGHT_TIMEOUT_DURING_HANDSHAKE))); } else if (state == InsightState.NOT_PAIRED) { connectionService.withdrawConnectionRequest(this); statusLoaded = false;