Search in sources :

Example 1 with ForwardCommentProvider

use of com.xabber.android.data.extension.forward.ForwardCommentProvider 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");
}
Also used : SessionsProvider(com.xabber.android.data.extension.xtoken.SessionsProvider) AndroidLoggingHandler(com.xabber.android.data.log.AndroidLoggingHandler) AccountItem(com.xabber.android.data.account.AccountItem) ReferencesProvider(com.xabber.android.data.extension.references.ReferencesProvider) SmackException(org.jivesoftware.smack.SmackException) HttpConfirmIqProvider(com.xabber.android.data.xaccount.HttpConfirmIqProvider) XTokenProvider(com.xabber.android.data.extension.xtoken.XTokenProvider) IOException(java.io.IOException) AccountErrorEvent(com.xabber.android.data.account.AccountErrorEvent) CustomDataProvider(com.xabber.android.data.extension.httpfileupload.CustomDataProvider) ForwardCommentProvider(com.xabber.android.data.extension.forward.ForwardCommentProvider) SASLErrorException(org.jivesoftware.smack.sasl.SASLErrorException) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

AccountErrorEvent (com.xabber.android.data.account.AccountErrorEvent)1 AccountItem (com.xabber.android.data.account.AccountItem)1 ForwardCommentProvider (com.xabber.android.data.extension.forward.ForwardCommentProvider)1 CustomDataProvider (com.xabber.android.data.extension.httpfileupload.CustomDataProvider)1 ReferencesProvider (com.xabber.android.data.extension.references.ReferencesProvider)1 SessionsProvider (com.xabber.android.data.extension.xtoken.SessionsProvider)1 XTokenProvider (com.xabber.android.data.extension.xtoken.XTokenProvider)1 AndroidLoggingHandler (com.xabber.android.data.log.AndroidLoggingHandler)1 HttpConfirmIqProvider (com.xabber.android.data.xaccount.HttpConfirmIqProvider)1 IOException (java.io.IOException)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 SASLErrorException (org.jivesoftware.smack.sasl.SASLErrorException)1