use of com.xabber.android.data.extension.references.ReferencesProvider in project xabber-android by redsolution.
the class ConnectionThread method connectAndLogin.
@SuppressWarnings("WeakerAccess")
void connectAndLogin() {
AndroidLoggingHandler.reset(new AndroidLoggingHandler());
java.util.logging.Logger.getLogger(XMPPTCPConnection.class.getName()).setLevel(Level.FINEST);
java.util.logging.Logger.getLogger(AbstractDNSClient.class.getName()).setLevel(Level.FINEST);
java.util.logging.Logger.getLogger(AbstractXMPPConnection.class.getName()).setLevel(Level.FINEST);
java.util.logging.Logger.getLogger(DNSUtil.class.getName()).setLevel(Level.FINEST);
if (connection.getConfiguration().getPassword().isEmpty()) {
AccountErrorEvent accountErrorEvent = new AccountErrorEvent(connectionItem.getAccount(), AccountErrorEvent.Type.PASS_REQUIRED, "");
// com.xabber.android.data.account.AccountManager.getInstance().addAccountError(accountErrorEvent);
com.xabber.android.data.account.AccountManager.getInstance().setEnabled(connectionItem.getAccount(), false);
EventBus.getDefault().postSticky(accountErrorEvent);
return;
}
// switch (SettingsManager.connectionDnsResolver()) {
// case dnsJavaResolver:
// LogManager.i(this, "Use DNS Java resolver");
// ExtDNSJavaResolver.setup();
// break;
// case miniDnsResolver:
// LogManager.i(this, "Use Mini DNS resolver");
// MiniDnsResolver.setup();
// break;
// }
LogManager.i(this, "Use DNS Java resolver");
ExtDNSJavaResolver.setup();
ProviderManager.addExtensionProvider(DataForm.ELEMENT, DataForm.NAMESPACE, new CustomDataProvider());
ProviderManager.addExtensionProvider(ForwardComment.ELEMENT, ForwardComment.NAMESPACE, new ForwardCommentProvider());
ProviderManager.addExtensionProvider(ReferenceElement.ELEMENT, ReferenceElement.NAMESPACE, new ReferencesProvider());
ProviderManager.addIQProvider(XTokenIQ.ELEMENT, XTokenIQ.NAMESPACE, new XTokenProvider());
ProviderManager.addIQProvider(SessionsIQ.ELEMENT, SessionsIQ.NAMESPACE, new SessionsProvider());
try {
LogManager.i(this, "Trying to connect and login...");
if (!connection.isConnected()) {
connectionItem.updateState(ConnectionState.connecting);
connection.connect();
} else {
LogManager.i(this, "Already connected");
}
if (!connection.isAuthenticated()) {
ProviderManager.addIQProvider(HttpConfirmIq.ELEMENT, HttpConfirmIq.NAMESPACE, new HttpConfirmIqProvider());
connection.login();
} else {
LogManager.i(this, "Already authenticated");
}
} catch (SASLErrorException e) {
LogManager.exception(this, e);
if (e.getMechanism().equals(SASLXTOKENMechanism.NAME)) {
LogManager.d(this, "Authorization error with x-token: " + e.toString());
AccountManager.getInstance().removeXToken(connectionItem.getAccount());
}
AccountErrorEvent accountErrorEvent = new AccountErrorEvent(connectionItem.getAccount(), AccountErrorEvent.Type.AUTHORIZATION, e.getMessage());
// com.xabber.android.data.account.AccountManager.getInstance().addAccountError(accountErrorEvent);
com.xabber.android.data.account.AccountManager.getInstance().setEnabled(connectionItem.getAccount(), false);
EventBus.getDefault().postSticky(accountErrorEvent);
// catching RuntimeExceptions seems to be strange, but we got a lot of error coming from
// Smack or mini DSN client inside of Smack.
} catch (XMPPException | SmackException | IOException | RuntimeException e) {
LogManager.exception(this, e);
if (!((AccountItem) connectionItem).isSuccessfulConnectionHappened()) {
LogManager.i(this, "There was no successful connection, disabling account");
AccountErrorEvent accountErrorEvent = new AccountErrorEvent(connectionItem.getAccount(), AccountErrorEvent.Type.CONNECTION, Log.getStackTraceString(e));
com.xabber.android.data.account.AccountManager.getInstance().addAccountError(accountErrorEvent);
com.xabber.android.data.account.AccountManager.getInstance().setEnabled(connectionItem.getAccount(), false);
EventBus.getDefault().postSticky(accountErrorEvent);
}
} catch (InterruptedException e) {
LogManager.exception(this, e);
}
LogManager.i(this, "Connection thread finished");
}
Aggregations