Merge pull request #1637 from TebbeUbben/insight-dev
Improvement for timeout during handshake notification
This commit is contained in:
commit
58f4012323
|
@ -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;
|
||||
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;
|
||||
profileBlocks = null;
|
||||
|
|
|
@ -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<StateCallback> 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,10 +356,12 @@ 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)) {
|
||||
if (++timeoutDuringHandshakeCounter == TIMEOUT_DURING_HANDSHAKE_NOTIFICATION_THRESHOLD) {
|
||||
for (StateCallback stateCallback : stateCallbacks) {
|
||||
stateCallback.onTimeoutDuringHandshake();
|
||||
}
|
||||
}
|
||||
}
|
||||
setState(connectionRequests.size() != 0 ? InsightState.RECOVERING : InsightState.DISCONNECTED);
|
||||
if (e instanceof ConnectionFailedException) {
|
||||
cleanup(((ConnectionFailedException) e).getDurationOfConnectionAttempt() <= 1000);
|
||||
|
|
Loading…
Reference in a new issue