Search in sources :

Example 6 with Presence

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

the class XmppConnection method do_login_async.

private void do_login_async() {
    if (getState() == LOGGED_IN || getState() == SUSPENDED || getState() == SUSPENDING) {
        mNeedReconnect = false;
        return;
    }
    /*
        if (mConnection != null) {
            setState(getState(), new ImErrorInfo(ImErrorInfo.CANT_CONNECT_TO_SERVER,
                    "still trying..."));
            return;
        }*/
    ContentResolver contentResolver = mContext.getContentResolver();
    Cursor cursor = contentResolver.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(mProviderId) }, null);
    if (cursor == null)
        // not going to work
        return;
    Imps.ProviderSettings.QueryMap providerSettings = new Imps.ProviderSettings.QueryMap(cursor, contentResolver, mProviderId, false, null);
    // providerSettings is closed in initConnection();
    mUsername = Imps.Account.getUserName(contentResolver, mAccountId);
    String defaultStatus = null;
    mNeedReconnect = true;
    setState(LOGGING_IN, null);
    mUserPresence = new Presence(Presence.AVAILABLE, defaultStatus, Presence.CLIENT_TYPE_MOBILE);
    try {
        if (mUsername == null || mUsername.length() == 0)
            throw new Exception("empty username not allowed");
        initConnectionAndLogin(providerSettings, mUsername);
        setState(LOGGED_IN, null);
        debug(TAG, "logged in");
        mNeedReconnect = false;
    } catch (XMPPException e) {
        debug(TAG, "exception thrown on connection", e);
        ImErrorInfo info = new ImErrorInfo(ImErrorInfo.CANT_CONNECT_TO_SERVER, e.getMessage());
        // our default behavior is to retry
        mRetryLogin = true;
        if (mConnection != null && mConnection.isConnected()) {
            if (!mConnection.isAuthenticated()) {
                debug(TAG, "not authorized - will not retry");
                info = new ImErrorInfo(ImErrorInfo.INVALID_USERNAME, "invalid user/password");
                setState(SUSPENDED, info);
                mRetryLogin = false;
                mNeedReconnect = false;
            }
        }
        if (mRetryLogin && getState() != SUSPENDED) {
            debug(TAG, "will retry");
            setState(LOGGING_IN, info);
            maybe_reconnect();
        } else {
            // debug(TAG, "will not retry"); //WE MUST ALWAYS RETRY!
            disconnect();
            disconnected(info);
        }
    } catch (Exception e) {
        debug(TAG, "login failed: " + e.getMessage(), e);
        if (getState() != SUSPENDED || getState() != SUSPENDING) {
            mRetryLogin = true;
            mNeedReconnect = true;
            debug(TAG, "will retry");
            ImErrorInfo info = new ImErrorInfo(ImErrorInfo.UNKNOWN_ERROR, "keymanagement exception");
            setState(LOGGING_IN, info);
        } else {
            mRetryLogin = false;
            mNeedReconnect = true;
        }
    } finally {
        providerSettings.close();
        if (!cursor.isClosed())
            cursor.close();
    }
}
Also used : Imps(org.awesomeapp.messenger.provider.Imps) Presence(org.awesomeapp.messenger.model.Presence) Cursor(android.database.Cursor) XMPPException(org.jivesoftware.smack.XMPPException) 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) ContentResolver(android.content.ContentResolver) ImErrorInfo(org.awesomeapp.messenger.model.ImErrorInfo)

Example 7 with Presence

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

the class ImConnectionAdapter method loadSavedPresence.

private void loadSavedPresence() {
    ContentResolver cr = mService.getContentResolver();
    // Imps.ProviderSettings.setPresence(cr, mProviderId, status, statusText);
    int presenceState = Imps.ProviderSettings.getIntValue(cr, mProviderId, Imps.ProviderSettings.PRESENCE_STATE);
    String presenceStatusMessage = Imps.ProviderSettings.getStringValue(cr, mProviderId, Imps.ProviderSettings.PRESENCE_STATUS_MESSAGE);
    if (presenceState != -1) {
        Presence presence = new Presence();
        presence.setStatus(presenceState);
        presence.setStatusText(presenceStatusMessage);
        try {
            mConnection.updateUserPresenceAsync(presence);
        } catch (ImException e) {
            Log.e(ImApp.LOG_TAG, "unable able to update presence", e);
        }
    }
}
Also used : ImException(org.awesomeapp.messenger.model.ImException) Presence(org.awesomeapp.messenger.model.Presence) ContentResolver(android.content.ContentResolver)

Example 8 with Presence

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

the class ContactListManagerAdapter method updatePresenceContent.

void updatePresenceContent(Contact[] contacts) {
    if (mAdaptee == null)
        return;
    ArrayList<String> usernames = new ArrayList<String>();
    ArrayList<String> nicknames = new ArrayList<String>();
    ArrayList<String> statusArray = new ArrayList<String>();
    ArrayList<String> customStatusArray = new ArrayList<String>();
    ArrayList<String> clientTypeArray = new ArrayList<String>();
    ArrayList<String> resourceArray = new ArrayList<String>();
    for (Contact c : contacts) {
        String username = mAdaptee.normalizeAddress(c.getAddress().getAddress());
        Presence p = c.getPresence();
        int status = convertPresenceStatus(p);
        String customStatus = p.getStatusText();
        int clientType = translateClientType(p);
        usernames.add(username);
        nicknames.add(c.getName());
        statusArray.add(String.valueOf(status));
        customStatusArray.add(customStatus);
        clientTypeArray.add(String.valueOf(clientType));
        if (!TextUtils.isEmpty(p.getResource()))
            resourceArray.add(p.getResource());
        else
            resourceArray.add("");
    }
    ContentValues values = new ContentValues();
    values.put(Imps.Contacts.ACCOUNT, mConn.getAccountId());
    values.put(Imps.Contacts.PROVIDER, mConn.getProviderId());
    putStringArrayList(values, Imps.Contacts.USERNAME, usernames);
    putStringArrayList(values, Imps.Contacts.NICKNAME, nicknames);
    mResolver.update(Imps.Contacts.BULK_CONTENT_URI, values, null, null);
    values = new ContentValues();
    values.put(Imps.Contacts.ACCOUNT, mConn.getAccountId());
    values.put(Imps.Contacts.PROVIDER, mConn.getProviderId());
    putStringArrayList(values, Imps.Contacts.USERNAME, usernames);
    putStringArrayList(values, Imps.Presence.PRESENCE_STATUS, statusArray);
    putStringArrayList(values, Imps.Presence.PRESENCE_CUSTOM_STATUS, customStatusArray);
    putStringArrayList(values, Imps.Presence.CONTENT_TYPE, clientTypeArray);
    putStringArrayList(values, Imps.Presence.JID_RESOURCE, resourceArray);
    mResolver.update(Imps.Presence.BULK_CONTENT_URI, values, null, null);
}
Also used : ContentValues(android.content.ContentValues) ArrayList(java.util.ArrayList) Presence(org.awesomeapp.messenger.model.Presence) Contact(org.awesomeapp.messenger.model.Contact)

Example 9 with Presence

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

the class ContactListManagerAdapter method getPresenceValues.

private ContentValues getPresenceValues(Contact c) {
    Presence p = c.getPresence();
    ContentValues values = new ContentValues(3);
    values.put(Imps.Contacts.PRESENCE_STATUS, convertPresenceStatus(p));
    values.put(Imps.Contacts.PRESENCE_CUSTOM_STATUS, p.getStatusText());
    values.put(Imps.Presence.CLIENT_TYPE, translateClientType(p));
    return values;
}
Also used : ContentValues(android.content.ContentValues) Presence(org.awesomeapp.messenger.model.Presence)

Example 10 with Presence

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

the class ImConnectionAdapter method updateAccountStatusInDb.

void updateAccountStatusInDb() {
    Presence p = getUserPresence();
    int presenceStatus = Imps.Presence.OFFLINE;
    int connectionStatus = convertConnStateForDb(mConnectionState);
    if (p != null) {
        presenceStatus = ContactListManagerAdapter.convertPresenceStatus(p);
    }
    ContentResolver cr = mService.getContentResolver();
    Uri uri = Imps.AccountStatus.CONTENT_URI;
    ContentValues values = new ContentValues();
    values.put(Imps.AccountStatus.ACCOUNT, mAccountId);
    values.put(Imps.AccountStatus.PRESENCE_STATUS, presenceStatus);
    values.put(Imps.AccountStatus.CONNECTION_STATUS, connectionStatus);
    cr.insert(uri, values);
}
Also used : ContentValues(android.content.ContentValues) Presence(org.awesomeapp.messenger.model.Presence) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Aggregations

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