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 e13894ecd3..8db8d112e1 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 @@ -261,13 +261,15 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con @Override public boolean isConnected() { - if (connectionService == null || alertService == null) return false; - return connectionService.getState() == InsightState.CONNECTED; + return connectionService != null + && alertService != null + && connectionService.hasRequestedConnection(this) + && connectionService.getState() == InsightState.CONNECTED; } @Override public boolean isConnecting() { - if (connectionService == null || alertService == null) return false; + if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this)) return false; InsightState state = connectionService.getState(); return state == InsightState.CONNECTING || state == InsightState.APP_CONNECT_MESSAGE 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 bb086a541e..ce046420a2 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 @@ -277,6 +277,10 @@ public class InsightConnectionService extends Service implements ConnectionEstab } } + public synchronized boolean hasRequestedConnection(Object lock) { + return connectionRequests.contains(lock); + } + private void cleanup() { messageQueue.completeActiveRequest(new ConnectionLostException()); messageQueue.completePendingRequests(new ConnectionLostException());