Search in sources :

Example 1 with ImException

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

the class XmppConnection method initUser.

public void initUser(long providerId, long accountId) throws ImException {
    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(providerId) }, null);
    if (cursor == null)
        throw new ImException("unable to query settings");
    Imps.ProviderSettings.QueryMap providerSettings = new Imps.ProviderSettings.QueryMap(cursor, contentResolver, providerId, false, null);
    mProviderId = providerId;
    mAccountId = accountId;
    mUser = makeUser(providerSettings, contentResolver);
    try {
        mUserJid = JidCreate.bareFrom(mUser.getAddress().getAddress());
    } catch (Exception e) {
    }
    providerSettings.close();
}
Also used : ImException(org.awesomeapp.messenger.model.ImException) Imps(org.awesomeapp.messenger.provider.Imps) Cursor(android.database.Cursor) 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)

Example 2 with ImException

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

the class LoopbackConnection method doUpdateUserPresenceAsync.

@Override
protected void doUpdateUserPresenceAsync(Presence presence) {
    // mimic presence
    ContactList cl;
    try {
        cl = mContactListManager.getDefaultContactList();
    } catch (ImException e) {
        throw new RuntimeException(e);
    }
    if (cl == null)
        return;
    Collection<Contact> contacts = cl.getContacts();
    for (Iterator<Contact> iter = contacts.iterator(); iter.hasNext(); ) {
        Contact contact = iter.next();
        contact.setPresence(presence);
    }
    Contact[] contacts_array = new Contact[contacts.size()];
    contacts.toArray(contacts_array);
    mContactListManager.doPresence(contacts_array);
}
Also used : ImException(org.awesomeapp.messenger.model.ImException) ContactList(org.awesomeapp.messenger.model.ContactList) Contact(org.awesomeapp.messenger.model.Contact)

Example 3 with ImException

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

the class RemoteImService method do_createConnection.

private IImConnection do_createConnection(long providerId, long accountId) {
    if (providerId == -1)
        return null;
    Map<String, String> settings = loadProviderSettings(providerId);
    // make sure OTR is init'd before you create your first connection
    initOtrChatManager();
    ConnectionFactory factory = ConnectionFactory.getInstance();
    try {
        ImConnection conn = factory.createConnection(settings, this);
        conn.initUser(providerId, accountId);
        ImConnectionAdapter imConnectionAdapter = new ImConnectionAdapter(providerId, accountId, conn, this);
        conn.addConnectionListener(new ConnectionListener() {

            @Override
            public void onStateChanged(int state, ImErrorInfo error) {
            }

            @Override
            public void onUserPresenceUpdated() {
            }

            @Override
            public void onUpdatePresenceError(ImErrorInfo error) {
            }
        });
        ContentResolver contentResolver = getContentResolver();
        Cursor cursor = contentResolver.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(providerId) }, null);
        if (cursor == null)
            throw new ImException("unable to query the provider settings");
        Imps.ProviderSettings.QueryMap providerSettings = new Imps.ProviderSettings.QueryMap(cursor, contentResolver, providerId, false, null);
        String userName = Imps.Account.getUserName(contentResolver, accountId);
        String domain = providerSettings.getDomain();
        providerSettings.close();
        mConnections.put(providerId + "." + accountId, imConnectionAdapter);
        mConnectionsByUser.put(imConnectionAdapter.getLoginUser().getAddress().getBareAddress(), imConnectionAdapter);
        Debug.recordTrail(this, CONNECTIONS_TRAIL_TAG, "" + mConnections.size());
        synchronized (mRemoteListeners) {
            try {
                final int N = mRemoteListeners.beginBroadcast();
                for (int i = 0; i < N; i++) {
                    IConnectionCreationListener listener = mRemoteListeners.getBroadcastItem(i);
                    try {
                        listener.onConnectionCreated(imConnectionAdapter);
                    } catch (RemoteException e) {
                    // The RemoteCallbackList will take care of removing the
                    // dead listeners.
                    }
                }
            } finally {
                mRemoteListeners.finishBroadcast();
            }
        }
        return imConnectionAdapter;
    } catch (ImException e) {
        debug("Error creating connection", e);
        return null;
    }
}
Also used : Imps(org.awesomeapp.messenger.provider.Imps) ConnectionListener(org.awesomeapp.messenger.model.ConnectionListener) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver) ConnectionFactory(org.awesomeapp.messenger.model.ConnectionFactory) ImException(org.awesomeapp.messenger.model.ImException) ImConnection(org.awesomeapp.messenger.model.ImConnection) RemoteException(android.os.RemoteException) ImConnectionAdapter(org.awesomeapp.messenger.service.adapters.ImConnectionAdapter) ImErrorInfo(org.awesomeapp.messenger.model.ImErrorInfo)

Example 4 with ImException

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

the class ContactListManagerAdapter method setContactName.

public int setContactName(String address, String name) {
    // update the server
    try {
        mAdaptee.setContactName(address, name);
    } catch (ImException e) {
        return e.getImError().getCode();
    }
    // update locally
    String selection = Imps.Contacts.USERNAME + "=?";
    String[] selectionArgs = { address };
    ContentValues values = new ContentValues(1);
    values.put(Imps.Contacts.NICKNAME, name);
    int updated = mResolver.update(mContactUrl, values, selection, selectionArgs);
    if (updated != 1) {
        return ImErrorInfo.ILLEGAL_CONTACT_ADDRESS;
    }
    return ImErrorInfo.NO_ERROR;
}
Also used : ContentValues(android.content.ContentValues) ImException(org.awesomeapp.messenger.model.ImException)

Example 5 with ImException

use of org.awesomeapp.messenger.model.ImException 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)

Aggregations

ImException (org.awesomeapp.messenger.model.ImException)5 ContentResolver (android.content.ContentResolver)3 Cursor (android.database.Cursor)2 RemoteException (android.os.RemoteException)2 Imps (org.awesomeapp.messenger.provider.Imps)2 ContentValues (android.content.ContentValues)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ConnectionFactory (org.awesomeapp.messenger.model.ConnectionFactory)1 ConnectionListener (org.awesomeapp.messenger.model.ConnectionListener)1 Contact (org.awesomeapp.messenger.model.Contact)1 ContactList (org.awesomeapp.messenger.model.ContactList)1 ImConnection (org.awesomeapp.messenger.model.ImConnection)1 ImErrorInfo (org.awesomeapp.messenger.model.ImErrorInfo)1 Presence (org.awesomeapp.messenger.model.Presence)1