Search in sources :

Example 6 with ImErrorInfo

use of org.awesomeapp.messenger.model.ImErrorInfo in project Zom-Android by zom.

the class XmppConnection method reconnect.

/*
     * Retry connecting
     *
     * Runs in executor thread
     */
private void reconnect() {
    if (getState() == SUSPENDED) {
        debug(TAG, "reconnect during suspend, ignoring");
        return;
    }
    if (mConnection != null) {
        // It is safe to ask mConnection whether it is connected, because either:
        // - We detected an error using ping and called force_reconnect, which did a shutdown
        // - Smack detected an error, so it knows it is not connected
        // so there are no cases where mConnection can be confused about being connected here.
        // The only left over cases are reconnect() being called too many times due to errors
        // reported multiple times or errors reported during a forced reconnect.
        // The analysis above is incorrect in the case where Smack loses connectivity
        // while trying to log in.  This case is handled in a future heartbeat
        // by checking ping responses.
        clearPing();
        if (mConnection != null && mConnection.isAuthenticated()) {
            debug(TAG, "reconnect while already connected, assuming good: " + mConnection);
            mNeedReconnect = false;
            setState(LOGGED_IN, null);
            return;
        }
        debug(TAG, "reconnect");
        try {
            if (mStreamHandler.isResumePossible()) {
                // Connect without binding, will automatically trigger a resume
                debug(TAG, "mStreamHandler resume");
                mConnection.connect();
                initServiceDiscovery();
                initPacketProcessor();
            } else {
                debug(TAG, "reconnection on network change failed: " + mUser.getAddress().getAddress());
                mConnection = null;
                mNeedReconnect = true;
                setState(LOGGING_IN, new ImErrorInfo(ImErrorInfo.NETWORK_ERROR, null));
                do_login();
            }
        } catch (Exception e) {
            if (mStreamHandler != null)
                mStreamHandler.quickShutdown();
            mConnection = null;
            debug(TAG, "reconnection attempt failed", e);
            // Smack incorrectly notified us that reconnection was successful, reset in case it fails
            mNeedReconnect = false;
            setState(LOGGING_IN, new ImErrorInfo(ImErrorInfo.NETWORK_ERROR, e.getMessage()));
            do_login();
        }
    } else {
        mNeedReconnect = false;
        mConnection = null;
        debug(TAG, "reconnection on network change failed");
        setState(LOGGING_IN, new ImErrorInfo(ImErrorInfo.NETWORK_ERROR, "reconnection on network change failed"));
        do_login();
    }
}
Also used : KeyStoreException(java.security.KeyStoreException) UndecidedOmemoIdentityException(org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException) XMPPException(org.jivesoftware.smack.XMPPException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ImException(org.awesomeapp.messenger.model.ImException) KeyManagementException(java.security.KeyManagementException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SmackException(org.jivesoftware.smack.SmackException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MultiUserChatException(org.jivesoftware.smackx.muc.MultiUserChatException) CryptoFailedException(org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException) CertificateException(java.security.cert.CertificateException) ImErrorInfo(org.awesomeapp.messenger.model.ImErrorInfo)

Example 7 with ImErrorInfo

use of org.awesomeapp.messenger.model.ImErrorInfo in project Zom-Android by zom.

the class ChatSessionManagerAdapter method createChatSession.

public IChatSession createChatSession(String contactAddress, boolean isNewSession) {
    ContactListManagerAdapter listManager = (ContactListManagerAdapter) mConnection.getContactListManager();
    Contact contact = listManager.getContactByAddress(Address.stripResource(contactAddress));
    if (contact == null) {
        try {
            contact = new Contact(new XmppAddress(contactAddress), contactAddress, Imps.Contacts.TYPE_NORMAL);
        // long contactId = listManager.queryOrInsertContact(contact);
        // String[] address = {Address.stripResource(contactAddress)};
        // contact = listManager.createTemporaryContacts(address)[0];
        } catch (IllegalArgumentException e) {
            mSessionListenerAdapter.notifyChatSessionCreateFailed(contactAddress, new ImErrorInfo(ImErrorInfo.ILLEGAL_CONTACT_ADDRESS, "Invalid contact address:" + contactAddress));
            return null;
        }
    }
    if (contact != null) {
        ChatSession session = getChatSessionManager().createChatSession(contact, isNewSession);
        return getChatSessionAdapter(session, isNewSession);
    } else
        return null;
}
Also used : XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) IChatSession(org.awesomeapp.messenger.service.IChatSession) ChatSession(org.awesomeapp.messenger.model.ChatSession) Contact(org.awesomeapp.messenger.model.Contact) ImErrorInfo(org.awesomeapp.messenger.model.ImErrorInfo)

Aggregations

ImErrorInfo (org.awesomeapp.messenger.model.ImErrorInfo)7 RemoteException (android.os.RemoteException)4 ImException (org.awesomeapp.messenger.model.ImException)4 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 KeyManagementException (java.security.KeyManagementException)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateException (java.security.cert.CertificateException)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 SmackException (org.jivesoftware.smack.SmackException)3 XMPPException (org.jivesoftware.smack.XMPPException)3 MultiUserChatException (org.jivesoftware.smackx.muc.MultiUserChatException)3 CryptoFailedException (org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException)3 UndecidedOmemoIdentityException (org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException)3 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)3 ContentResolver (android.content.ContentResolver)2 Cursor (android.database.Cursor)2 ChatSession (org.awesomeapp.messenger.model.ChatSession)2 Presence (org.awesomeapp.messenger.model.Presence)2