Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void connect(MqttConnectOptions options, String invocationContext,
service.messageStore.clearArrivedMessages(clientHandle);
}

service.traceDebug(TAG, "Connecting {" + serverURI + "} as {"+ clientId + "}");
service.traceDebug(TAG, "Connecting {" + serverURI + "} as {" + clientId + "}");
final Bundle resultBundle = new Bundle();
resultBundle.putString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN,
activityToken);
Expand Down Expand Up @@ -314,7 +314,7 @@ private void doAfterConnectFail(final Bundle resultBundle){
acquireWakeLock();
disconnected = true;
setConnectingState(false);
service.callbackToActivity(clientHandle, Status.ERROR,resultBundle);
service.callbackToActivity(clientHandle, Status.ERROR, resultBundle);
releaseWakeLock();
}

Expand Down Expand Up @@ -1018,9 +1018,22 @@ public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
Thread.sleep(delay);
} catch(InterruptedException e) {
}
reconnect();

if(isNotAuthenticationFailed(exception))
{
reconnect();
}

}

private boolean isNotAuthenticationFailed(Throwable throwable) {
int reasonCode = -1;
if(throwable instanceof MqttException) {
reasonCode = ((MqttException) throwable).getReasonCode();
}

return reasonCode != MqttException.REASON_CODE_FAILED_AUTHENTICATION;
}
};

myClient.connect(connectOptions, null, listener);
Expand Down