FileDocCategorySizeDatePackage
ContactListManagerAdapter.javaAPI DocAndroid 1.5 API44857Wed May 06 22:42:46 BST 2009com.android.im.service

ContactListManagerAdapter

public class ContactListManagerAdapter extends IContactListManager.Stub

Fields Summary
static final String
TAG
ImConnectionAdapter
mConn
android.content.ContentResolver
mResolver
private com.android.im.engine.ContactListManager
mAdaptee
private ContactListListenerAdapter
mContactListListenerAdapter
private SubscriptionRequestListenerAdapter
mSubscriptionListenerAdapter
final android.os.RemoteCallbackList
mRemoteContactListeners
final android.os.RemoteCallbackList
mRemoteSubscriptionListeners
HashMap
mContactLists
HashMap
mTemporaryContacts
HashSet
mValidatedContactLists
HashSet
mValidatedContacts
HashSet
mValidatedBlockedContacts
private long
mAccountId
private long
mProviderId
private android.net.Uri
mAvatarUrl
private android.net.Uri
mContactUrl
static final long
FAKE_TEMPORARY_LIST_ID
static final String[]
CONTACT_LIST_ID_PROJECTION
RemoteImService
mContext
Constructors Summary
public ContactListManagerAdapter(ImConnectionAdapter conn)


       
        mAdaptee  = conn.getAdaptee().getContactListManager();
        mConn     = conn;
        mContext  = conn.getContext();
        mResolver = mContext.getContentResolver();

        mContactListListenerAdapter = new ContactListListenerAdapter();
        mSubscriptionListenerAdapter = new SubscriptionRequestListenerAdapter();
        mContactLists = new HashMap<Address, ContactListAdapter>();
        mTemporaryContacts = new HashMap<String, Contact>();
        mValidatedContacts = new HashSet<String>();
        mValidatedContactLists = new HashSet<String>();
        mValidatedBlockedContacts = new HashSet<String>();

        mAdaptee.addContactListListener(mContactListListenerAdapter);
        mAdaptee.setSubscriptionRequestListener(mSubscriptionListenerAdapter);

        mAccountId  = mConn.getAccountId();
        mProviderId = mConn.getProviderId();

        Uri.Builder builder = Im.Avatars.CONTENT_URI_AVATARS_BY.buildUpon();
        ContentUris.appendId(builder, mProviderId);
        ContentUris.appendId(builder, mAccountId);

        mAvatarUrl = builder.build();

        builder = Im.Contacts.CONTENT_URI_CONTACTS_BY.buildUpon();
        ContentUris.appendId(builder, mProviderId);
        ContentUris.appendId(builder, mAccountId);

        mContactUrl = builder.build();
    
Methods Summary
voidaddContactListContent(com.android.im.engine.ContactList list)

        String selection = Im.ContactList.NAME + "=? AND "
                + Im.ContactList.PROVIDER + "=? AND "
                + Im.ContactList.ACCOUNT + "=?";
        String[] selectionArgs = { list.getName(),
                Long.toString(mProviderId),
                Long.toString(mAccountId) };
        Cursor cursor = mResolver.query(Im.ContactList.CONTENT_URI,
                                        CONTACT_LIST_ID_PROJECTION,
                                        selection,
                                        selectionArgs,
                                        null); // no sort order
        long listId = 0;
        Uri uri = null;
        try {
            if (cursor.moveToFirst()) {
                listId = cursor.getLong(0);
                uri = ContentUris.withAppendedId(Im.ContactList.CONTENT_URI, listId);
                //Log.d(TAG,"Found and removing ContactList with name "+list.getName());
            }
        } finally {
            cursor.close();
        }
        if (uri != null) {
            // remove existing ContactList and Contacts of that list for replacement by the newly
            // downloaded list
            mResolver.delete(mContactUrl, Im.Contacts.CONTACTLIST + "=?",
                    new String[]{Long.toString(listId)});
            mResolver.delete(uri, selection, selectionArgs);
        }

        ContentValues contactListValues = new ContentValues(3);
        contactListValues.put(Im.ContactList.NAME, list.getName());
        contactListValues.put(Im.ContactList.PROVIDER, mProviderId);
        contactListValues.put(Im.ContactList.ACCOUNT, mAccountId);

        //Log.d(TAG, "Adding ContactList name="+list.getName());
        mValidatedContactLists.add(list.getName());
        uri = mResolver.insert(Im.ContactList.CONTENT_URI, contactListValues);
        listId = ContentUris.parseId(uri);

        synchronized (mContactLists) {
            mContactLists.put(list.getAddress(),
                    new ContactListAdapter(list, listId));
        }

        Collection<Contact> contacts = list.getContacts();
        if (contacts == null || contacts.size() == 0) {
            return;
        }

        Iterator<Contact> iter = contacts.iterator();
        while(iter.hasNext()) {
            Contact c = iter.next();
            String address = c.getAddress().getFullName();
            if(isTemporary(address)) {
                moveTemporaryContactToList(address, listId);
                iter.remove();
            }
            mValidatedContacts.add(address);
        }

        ArrayList<String> usernames = new ArrayList<String>();
        ArrayList<String> nicknames = new ArrayList<String>();
        ArrayList<String> contactTypeArray = new ArrayList<String>();
        for (Contact c : contacts) {
            String username = c.getAddress().getFullName();
            String nickname = c.getName();
            int type = Im.Contacts.TYPE_NORMAL;
            if(isTemporary(username)) {
                type = Im.Contacts.TYPE_TEMPORARY;
            }
            if (isBlocked(username)) {
                type = Im.Contacts.TYPE_BLOCKED;
            }

            usernames.add(username);
            nicknames.add(nickname);
            contactTypeArray.add(String.valueOf(type));
        }
        ContentValues values = new ContentValues(6);

        values.put(Im.Contacts.PROVIDER, mProviderId);
        values.put(Im.Contacts.ACCOUNT, mAccountId);
        values.put(Im.Contacts.CONTACTLIST, listId);
        values.putStringArrayList(Im.Contacts.USERNAME, usernames);
        values.putStringArrayList(Im.Contacts.NICKNAME, nicknames);
        values.putStringArrayList(Im.Contacts.TYPE, contactTypeArray);

        mResolver.insert(Im.Contacts.BULK_CONTENT_URI, values);
    
public voidapproveSubscription(java.lang.String address)

        mAdaptee.approveSubscriptionRequest(address);
    
public intblockContact(java.lang.String address)

        try {
            mAdaptee.blockContactAsync(address);
        } catch (ImException e) {
            return e.getImError().getCode();
        }

        return ImErrorInfo.NO_ERROR;
    
voidclearHistoryMessages(java.lang.String contact)

        Uri uri = Im.Messages.getContentUriByContact(mProviderId,
            mAccountId, contact);
        mResolver.delete(uri, null, null);
    
public voidclearOnLogout()

        clearValidatedContactsAndLists();
        clearTemporaryContacts();
        clearPresence();
    
voidclearPresence()
Clears the presence of the all contacts. As contacts are persist between IM sessions, the presence need to be cleared after logout.

        StringBuilder where = new StringBuilder();
        where.append(Im.Presence.CONTACT_ID);
        where.append(" in (select _id from contacts where ");
        where.append(Im.Contacts.ACCOUNT);
        where.append("=");
        where.append(mAccountId);
        where.append(")");
        mResolver.delete(Im.Presence.CONTENT_URI, where.toString(), null);
    
private voidclearTemporaryContacts()
Clear the temporary contacts in the database. As contacts are persist between IM sessions, the temporary contacts need to be cleared after logout.

        String selection = Im.Contacts.CONTACTLIST + "=" + FAKE_TEMPORARY_LIST_ID;
        mResolver.delete(mContactUrl, selection, null);
    
private voidclearValidatedContactsAndLists()
Clears the list of validated contacts and contact lists. As contacts and contacts lists are added after login, contacts and contact lists are stored as "validated contacts". After initial download of contacts is complete, any contacts and contact lists that remain in the database, but are not in the validated list, are obsolete and should be removed. This function resets that list for use upon login.

        // clear the list of validated contacts, contact lists, and blocked contacts
        mValidatedContacts.clear();
        mValidatedContactLists.clear();
        mValidatedBlockedContacts.clear();
    
voidcloseChatSession(java.lang.String address)

        ChatSessionManagerAdapter sessionManager =
            (ChatSessionManagerAdapter) mConn.getChatSessionManager();
        ChatSessionAdapter session =
            (ChatSessionAdapter) sessionManager.getChatSession(address);
        if(session != null) {
            session.leave();
        }
    
public static intconvertPresenceStatus(com.android.im.engine.Presence presence)
Converts the presence status to the value defined for ImProvider.

param
presence The presence from the IM engine.
return
The status value defined in for ImProvider.

        switch (presence.getStatus()) {
        case Presence.AVAILABLE:
            return Im.Presence.AVAILABLE;

        case Presence.IDLE:
            return Im.Presence.IDLE;

        case Presence.AWAY:
            return Im.Presence.AWAY;

        case Presence.DO_NOT_DISTURB:
            return Im.Presence.DO_NOT_DISTURB;

        case Presence.OFFLINE:
            return Im.Presence.OFFLINE;
        }

        // impossible...
        Log.e(TAG, "Illegal presence status value " + presence.getStatus());
        return Im.Presence.AVAILABLE;
    
public intcreateContactList(java.lang.String name, java.util.List contacts)

        try {
            mAdaptee.createContactListAsync(name, contacts);
        } catch (ImException e) {
            return e.getImError().getCode();
        }

        return ImErrorInfo.NO_ERROR;
    
public com.android.im.engine.ContactcreateTemporaryContact(java.lang.String address)

        Contact c = mAdaptee.createTemporaryContact(address);
        insertTemporary(c);
        return c;
    
public voiddeclineSubscription(java.lang.String address)

        mAdaptee.declineSubscriptionRequest(address);
    
voiddeleteContactFromDataBase(com.android.im.engine.Contact contact, com.android.im.engine.ContactList list)

        String selection = Im.Contacts.USERNAME
                + "=? AND " + Im.Contacts.CONTACTLIST + "=?";
        long listId = getContactListAdapter(list.getAddress()).getDataBaseId();
        String username = contact.getAddress().getFullName();
        String[] selectionArgs = {username, Long.toString(listId)};

        mResolver.delete(mContactUrl, selection, selectionArgs);

        // clear the history message if the contact doesn't exist in any list
        // anymore.
        if(mAdaptee.getContact(contact.getAddress()) == null) {
            clearHistoryMessages(username);
        }
    
public intdeleteContactList(java.lang.String name)

        try {
            mAdaptee.deleteContactListAsync(name);
        } catch (ImException e) {
            return e.getImError().getCode();
        }

        return ImErrorInfo.NO_ERROR;
    
public com.android.im.engine.ContactgetContactByAddress(java.lang.String address)

        Contact c = mAdaptee.getContact(address);
        if(c == null) {
            synchronized (mTemporaryContacts) {
                return mTemporaryContacts.get(address);
            }
        } else {
            return c;
        }
    
private android.content.ContentValuesgetContactContentValues(com.android.im.engine.Contact contact, long listId)

        final String username = contact.getAddress().getFullName();
        final String nickname = contact.getName();
        int type = Im.Contacts.TYPE_NORMAL;
        if(isTemporary(username)) {
            type = Im.Contacts.TYPE_TEMPORARY;
        }
        if (isBlocked(username)) {
            type = Im.Contacts.TYPE_BLOCKED;
        }

        ContentValues values = new ContentValues(4);
        values.put(Im.Contacts.USERNAME, username);
        values.put(Im.Contacts.NICKNAME, nickname);
        values.put(Im.Contacts.CONTACTLIST, listId);
        values.put(Im.Contacts.TYPE, type);
        return values;
    
public com.android.im.IContactListgetContactList(java.lang.String name)

        return getContactListAdapter(name);
    
ContactListAdaptergetContactListAdapter(java.lang.String name)

        synchronized (mContactLists) {
            for (ContactListAdapter list : mContactLists.values()) {
                if (name.equals(list.getName())) {
                    return list;
                }
            }

            return null;
        }
    
ContactListAdaptergetContactListAdapter(com.android.im.engine.Address address)

        synchronized (mContactLists) {
            return mContactLists.get(address);
        }
    
public java.util.ListgetContactLists()

        synchronized (mContactLists) {
            return new ArrayList<ContactListAdapter>(mContactLists.values());
        }
    
java.lang.StringgetDisplayableAddress(java.lang.String impsAddress)

        if (impsAddress.startsWith("wv:")) {
            return impsAddress.substring(3);
        }
        return impsAddress;
    
private android.content.ContentValuesgetPresenceValues(long contactId, com.android.im.engine.Presence p)

        ContentValues values = new ContentValues(3);
        values.put(Im.Presence.CONTACT_ID, contactId);
        values.put(Im.Contacts.PRESENCE_STATUS, convertPresenceStatus(p));
        values.put(Im.Contacts.PRESENCE_CUSTOM_STATUS, p.getStatusText());
        values.put(Im.Presence.CLIENT_TYPE, translateClientType(p));
        return values;
    
public intgetState()

        return mAdaptee.getState();
    
voidinsertBlockedContactToDataBase(com.android.im.engine.Contact contact)

        // Remove the blocked contact if it already exists, to avoid duplicates and
        // handle the odd case where a blocked contact's nickname has changed
        removeBlockedContactFromDataBase(contact);

        Uri.Builder builder = Im.BlockedList.CONTENT_URI.buildUpon();
        ContentUris.appendId(builder, mProviderId);
        ContentUris.appendId(builder, mAccountId);
        Uri uri = builder.build();

        String username = contact.getAddress().getFullName();
        ContentValues values = new ContentValues(2);
        values.put(Im.BlockedList.USERNAME, username);
        values.put(Im.BlockedList.NICKNAME, contact.getName());

        mResolver.insert(uri, values);

        mValidatedBlockedContacts.add(username);
    
android.net.UriinsertContactContent(com.android.im.engine.Contact contact, long listId)

        ContentValues values = getContactContentValues(contact, listId);

        Uri uri = mResolver.insert(mContactUrl, values);

        ContentValues presenceValues = getPresenceValues(ContentUris.parseId(uri),
                contact.getPresence());

        mResolver.insert(Im.Presence.CONTENT_URI, presenceValues);

        return uri;
    
android.net.UriinsertOrUpdateSubscription(java.lang.String username, java.lang.String nickname, int subscriptionType, int subscriptionStatus)
Insert or update subscription request from user into the database.

param
username
param
nickname
param
subscriptionType
param
subscriptionStatus

        Cursor cursor = mResolver.query(mContactUrl, new String[]{ Im.Contacts._ID },
                Im.Contacts.USERNAME + "=?", new String[]{username}, null);
        if (cursor == null) {
            Log.w(TAG, "query contact " + username + " failed");
            return null;
        }

        Uri uri;
        if (cursor.moveToFirst()) {
            ContentValues values = new ContentValues(2);
            values.put(Im.Contacts.SUBSCRIPTION_TYPE, subscriptionType);
            values.put(Im.Contacts.SUBSCRIPTION_STATUS, subscriptionStatus);

            long contactId = cursor.getLong(0);
            uri = ContentUris.withAppendedId(Im.Contacts.CONTENT_URI, contactId);
            mResolver.update(uri, values, null, null);
        } else {
            ContentValues values = new ContentValues(6);
            values.put(Im.Contacts.USERNAME, username);
            values.put(Im.Contacts.NICKNAME, nickname);
            values.put(Im.Contacts.TYPE, Im.Contacts.TYPE_NORMAL);
            values.put(Im.Contacts.CONTACTLIST, FAKE_TEMPORARY_LIST_ID);
            values.put(Im.Contacts.SUBSCRIPTION_TYPE, subscriptionType);
            values.put(Im.Contacts.SUBSCRIPTION_STATUS, subscriptionStatus);

            uri = mResolver.insert(mContactUrl, values);
        }
        cursor.close();
        return uri;
    
private longinsertTemporary(com.android.im.engine.Contact c)

        synchronized (mTemporaryContacts) {
            mTemporaryContacts.put(c.getAddress().getFullName(), c);
        }
        Uri uri = insertContactContent(c, FAKE_TEMPORARY_LIST_ID);
        return ContentUris.parseId(uri);
    
public booleanisBlocked(java.lang.String address)

        try {
            return mAdaptee.isBlocked(address);
        } catch (ImException e) {
            Log.e(TAG, e.getMessage());
            return false;
        }
    
public booleanisTemporary(java.lang.String address)
Tells if a contact is a temporary one which is not in the list of contacts that we subscribe presence for. Usually created because of the user is having a chat session with this contact.

param
address the address of the contact.
return
true if it's a temporary contact; false otherwise.

        synchronized (mTemporaryContacts) {
            return mTemporaryContacts.containsKey(address);
        }
    
public voidloadContactLists()

        if(mAdaptee.getState() == ContactListManager.LISTS_NOT_LOADED){
            clearValidatedContactsAndLists();
            mAdaptee.loadContactListsAsync();
        }
    
voidmoveTemporaryContactToList(java.lang.String address, long listId)

        synchronized (mTemporaryContacts) {
            mTemporaryContacts.remove(address);
        }
        ContentValues values = new ContentValues(2);
        values.put(Im.Contacts.TYPE, Im.Contacts.TYPE_NORMAL);
        values.put(Im.Contacts.CONTACTLIST, listId);

        String selection = Im.Contacts.USERNAME + "=? AND " + Im.Contacts.TYPE + "="
                + Im.Contacts.TYPE_TEMPORARY;
        String[] selectionArgs = { address };

        mResolver.update(mContactUrl, values, selection, selectionArgs);
    
public longqueryOrInsertContact(com.android.im.engine.Contact c)

        long result;

        String username = c.getAddress().getFullName();
        String selection = Im.Contacts.USERNAME + "=?";
        String[] selectionArgs = { username };
        String[] projection = {Im.Contacts._ID};

        Cursor cursor = mResolver.query(mContactUrl, projection, selection,
                selectionArgs, null);

        if(cursor != null && cursor.moveToFirst()) {
            result = cursor.getLong(0);
        } else {
            result = insertTemporary(c);
        }

        if(cursor != null) {
            cursor.close();
        }
        return result;
    
public voidregisterContactListListener(com.android.im.IContactListListener listener)

        if (listener != null) {
            mRemoteContactListeners.register(listener);
        }
    
public voidregisterSubscriptionListener(com.android.im.ISubscriptionListener listener)

        if (listener != null) {
            mRemoteSubscriptionListeners.register(listener);
        }
    
voidremoveBlockedContactFromDataBase(com.android.im.engine.Contact contact)

        String address = contact.getAddress().getFullName();

        Uri.Builder builder = Im.BlockedList.CONTENT_URI.buildUpon();
        ContentUris.appendId(builder, mProviderId);
        ContentUris.appendId(builder, mAccountId);

        Uri uri = builder.build();
        mResolver.delete(uri, Im.BlockedList.USERNAME + "=?", new String[]{ address });

        int type = isTemporary(address) ? Im.Contacts.TYPE_TEMPORARY
                : Im.Contacts.TYPE_NORMAL;
        updateContactType(address, type);
    
public intremoveContact(java.lang.String address)

        if(isTemporary(address)) {
            // For temporary contact, just close the session and delete him in
            // database.
            closeChatSession(address);

            String selection = Im.Contacts.USERNAME + "=?";
            String[] selectionArgs = { address };
            mResolver.delete(mContactUrl, selection, selectionArgs);
            synchronized (mTemporaryContacts) {
                mTemporaryContacts.remove(address);
            }
        } else {
            synchronized (mContactLists) {
                for(ContactListAdapter list : mContactLists.values()) {
                    int resCode = list.removeContact(address);
                    if (ImErrorInfo.ILLEGAL_CONTACT_ADDRESS == resCode) {
                        // Did not find in this list, continue to remove from
                        // other list.
                        continue;
                    }
                    if (ImErrorInfo.NO_ERROR != resCode) {
                        return resCode;
                    }
                }
            }
        }

        return ImErrorInfo.NO_ERROR;
    
ContactListAdapterremoveContactListFromDataBase(java.lang.String name)

        ContactListAdapter listAdapter = getContactListAdapter(name);
        if (listAdapter == null) {
            return null;
        }
        long id = listAdapter.getDataBaseId();

        // delete contacts of this list first
        mResolver.delete(mContactUrl,
            Im.Contacts.CONTACTLIST + "=?", new String[]{Long.toString(id)});

        mResolver.delete(ContentUris.withAppendedId(Im.ContactList.CONTENT_URI, id), null, null);
        synchronized (mContactLists) {
            return mContactLists.remove(listAdapter.getAddress());
        }
    
private voidremoveObsoleteContactsAndLists()

        // remove all contacts for this provider & account which have not been
        // added since login, yet still exist in db from a prior login
        Exclusion exclusion = new Exclusion(Im.Contacts.USERNAME, mValidatedContacts);
        mResolver.delete(mContactUrl, exclusion.getSelection(), exclusion.getSelectionArgs());

        // remove all blocked contacts for this provider & account which have not been
        // added since login, yet still exist in db from a prior login
        exclusion = new Exclusion(Im.BlockedList.USERNAME, mValidatedBlockedContacts);
        Uri.Builder builder = Im.BlockedList.CONTENT_URI.buildUpon();
        ContentUris.appendId(builder, mProviderId);
        ContentUris.appendId(builder, mAccountId);
        Uri uri = builder.build();
        mResolver.delete(uri, exclusion.getSelection(), exclusion.getSelectionArgs());

        // remove all contact lists for this provider & account which have not been
        // added since login, yet still exist in db from a prior login
        exclusion = new Exclusion(Im.ContactList.NAME, mValidatedContactLists);
        builder = Im.ContactList.CONTENT_URI.buildUpon();
        ContentUris.appendId(builder, mProviderId);
        ContentUris.appendId(builder, mAccountId);
        uri = builder.build();
        mResolver.delete(uri, exclusion.getSelection(), exclusion.getSelectionArgs());

    
private inttranslateClientType(com.android.im.engine.Presence presence)

        int clientType = presence.getClientType();
        switch (clientType) {
            case Presence.CLIENT_TYPE_MOBILE:
                return Im.Presence.CLIENT_TYPE_MOBILE;
            default:
                return Im.Presence.CLIENT_TYPE_DEFAULT;
        }
    
public intunBlockContact(java.lang.String address)

        try {
            mAdaptee.unblockContactAsync(address);
        } catch (ImException e) {
            Log.e(TAG, e.getMessage());
            return e.getImError().getCode();
        }

        return ImErrorInfo.NO_ERROR;
    
public voidunregisterContactListListener(com.android.im.IContactListListener listener)

        if (listener != null) {
            mRemoteContactListeners.unregister(listener);
        }
    
public voidunregisterSubscriptionListener(com.android.im.ISubscriptionListener listener)

        if (listener != null) {
            mRemoteSubscriptionListeners.unregister(listener);
        }
    
voidupdateAvatarsContent(com.android.im.engine.Contact[] contacts)

        ArrayList<ContentValues> avatars = new ArrayList<ContentValues>();
        ArrayList<String> usernames = new ArrayList<String>();

        for (Contact contact : contacts) {
            byte[] avatarData = contact.getPresence().getAvatarData();
            if (avatarData == null) {
                continue;
            }

            String username = contact.getAddress().getFullName();

            ContentValues values = new ContentValues(2);
            values.put(Im.Avatars.CONTACT, username);
            values.put(Im.Avatars.DATA, avatarData);
            avatars.add(values);
            usernames.add(username);
        }
        if (avatars.size() > 0) {
            // ImProvider will replace the avatar content if it already exist.
            mResolver.bulkInsert(mAvatarUrl, avatars.toArray(
                    new ContentValues[avatars.size()]));

            // notify avatar changed
            Intent i = new Intent(ImServiceConstants.ACTION_AVATAR_CHANGED);
            i.putExtra(ImServiceConstants.EXTRA_INTENT_FROM_ADDRESS, usernames);
            i.putExtra(ImServiceConstants.EXTRA_INTENT_PROVIDER_ID, mProviderId);
            i.putExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, mAccountId);
            mContext.sendBroadcast(i);
        }
    
voidupdateChatPresence(java.lang.String address, java.lang.String nickname, com.android.im.engine.Presence p)

        ChatSessionManagerAdapter sessionManager =
            (ChatSessionManagerAdapter) mConn.getChatSessionManager();
        // TODO: This only find single chat sessions, we need to go through all
        // active chat sessions and find if the contact is a participant of the
        // session.
        ChatSessionAdapter session =
            (ChatSessionAdapter) sessionManager.getChatSession(address);
        if(session != null) {
            session.insertPresenceUpdatesMsg(nickname, p);
        }
    
voidupdateContact(java.lang.String username, android.content.ContentValues values)

        String selection = Im.Contacts.USERNAME + "=?";
        String[] selectionArgs = { username };
        mResolver.update(mContactUrl, values, selection, selectionArgs);
    
voidupdateContactType(java.lang.String address, int type)

        ContentValues values = new ContentValues(1);
        values.put(Im.Contacts.TYPE, type);
        updateContact(address, values);
    
voidupdateListNameInDataBase(com.android.im.engine.ContactList list)

        ContactListAdapter listAdapter = getContactListAdapter(list.getAddress());

        Uri uri = ContentUris.withAppendedId(Im.ContactList.CONTENT_URI, listAdapter.getDataBaseId());
        ContentValues values = new ContentValues(1);
        values.put(Im.ContactList.NAME, list.getName());

        mResolver.update(uri, values, null, null);
    
voidupdatePresenceContent(com.android.im.engine.Contact[] contacts)

        ArrayList<String> usernames = new ArrayList<String>();
        ArrayList<String> statusArray = new ArrayList<String>();
        ArrayList<String> customStatusArray = new ArrayList<String>();
        ArrayList<String> clientTypeArray = new ArrayList<String>();

        for(Contact c : contacts) {
            String username = c.getAddress().getFullName();
            Presence p = c.getPresence();
            int status = convertPresenceStatus(p);
            String customStatus = p.getStatusText();
            int clientType = translateClientType(p);

            usernames.add(username);
            statusArray.add(String.valueOf(status));
            customStatusArray.add(customStatus);
            clientTypeArray.add(String.valueOf(clientType));
        }

        ContentValues values = new ContentValues();
        values.put(Im.Contacts.ACCOUNT, mAccountId);
        values.putStringArrayList(Im.Contacts.USERNAME, usernames);
        values.putStringArrayList(Im.Presence.PRESENCE_STATUS, statusArray);
        values.putStringArrayList(Im.Presence.PRESENCE_CUSTOM_STATUS, customStatusArray);
        values.putStringArrayList(Im.Presence.CONTENT_TYPE, clientTypeArray);

        mResolver.update(Im.Presence.BULK_CONTENT_URI, values, null, null);