Return false in isConnected and isConnecting when connection lock is not held.

This commit is contained in:
TebbeUbben 2019-02-09 22:30:41 +01:00
parent 317f171286
commit 7a7bebc5fe
2 changed files with 9 additions and 3 deletions

View file

@ -261,13 +261,15 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
@Override @Override
public boolean isConnected() { public boolean isConnected() {
if (connectionService == null || alertService == null) return false; return connectionService != null
return connectionService.getState() == InsightState.CONNECTED; && alertService != null
&& connectionService.hasRequestedConnection(this)
&& connectionService.getState() == InsightState.CONNECTED;
} }
@Override @Override
public boolean isConnecting() { public boolean isConnecting() {
if (connectionService == null || alertService == null) return false; if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this)) return false;
InsightState state = connectionService.getState(); InsightState state = connectionService.getState();
return state == InsightState.CONNECTING return state == InsightState.CONNECTING
|| state == InsightState.APP_CONNECT_MESSAGE || state == InsightState.APP_CONNECT_MESSAGE

View file

@ -277,6 +277,10 @@ public class InsightConnectionService extends Service implements ConnectionEstab
} }
} }
public synchronized boolean hasRequestedConnection(Object lock) {
return connectionRequests.contains(lock);
}
private void cleanup() { private void cleanup() {
messageQueue.completeActiveRequest(new ConnectionLostException()); messageQueue.completeActiveRequest(new ConnectionLostException());
messageQueue.completePendingRequests(new ConnectionLostException()); messageQueue.completePendingRequests(new ConnectionLostException());