From e0998604df4ddfcd5c87ea097dcc0950a9518ed1 Mon Sep 17 00:00:00 2001 From: Daisuke Miyakawa Date: Sun, 26 Sep 2010 12:15:40 -0700 Subject: Add necessary logic removed during backport Makes importer import contcats into an appropriate group. Without this logic, all imported contacts are stored in "Other Groups". This logic is removed in my previous submit, while it shouldn't be. Bug: 3036599 Change-Id: Ic1dc7253d807fbde4352afe2082984c3b7227267 --- core/java/android/pim/vcard/VCardEntry.java | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'core/java/android') diff --git a/core/java/android/pim/vcard/VCardEntry.java b/core/java/android/pim/vcard/VCardEntry.java index 94f7c5f..02e1674 100644 --- a/core/java/android/pim/vcard/VCardEntry.java +++ b/core/java/android/pim/vcard/VCardEntry.java @@ -20,12 +20,10 @@ import android.content.ContentProviderOperation; import android.content.ContentProviderResult; import android.content.ContentResolver; import android.content.OperationApplicationException; +import android.database.Cursor; import android.net.Uri; import android.os.RemoteException; import android.provider.ContactsContract; -import android.provider.ContactsContract.Contacts; -import android.provider.ContactsContract.Data; -import android.provider.ContactsContract.RawContacts; import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.CommonDataKinds.Event; import android.provider.ContactsContract.CommonDataKinds.GroupMembership; @@ -38,6 +36,10 @@ import android.provider.ContactsContract.CommonDataKinds.Photo; import android.provider.ContactsContract.CommonDataKinds.StructuredName; import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; import android.provider.ContactsContract.CommonDataKinds.Website; +import android.provider.ContactsContract.Contacts; +import android.provider.ContactsContract.Data; +import android.provider.ContactsContract.Groups; +import android.provider.ContactsContract.RawContacts; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import android.util.Log; @@ -59,6 +61,9 @@ public class VCardEntry { private final static int DEFAULT_ORGANIZATION_TYPE = Organization.TYPE_WORK; + private static final String ACCOUNT_TYPE_GOOGLE = "com.google"; + private static final String GOOGLE_MY_CONTACTS_GROUP = "System Group: My Contacts"; + private static final Map sImMap = new HashMap(); static { @@ -1111,6 +1116,23 @@ public class VCardEntry { if (mAccount != null) { builder.withValue(RawContacts.ACCOUNT_NAME, mAccount.name); builder.withValue(RawContacts.ACCOUNT_TYPE, mAccount.type); + + // Assume that caller side creates this group if it does not exist. + if (ACCOUNT_TYPE_GOOGLE.equals(mAccount.type)) { + final Cursor cursor = resolver.query(Groups.CONTENT_URI, new String[] { + Groups.SOURCE_ID }, + Groups.TITLE + "=?", new String[] { + GOOGLE_MY_CONTACTS_GROUP }, null); + try { + if (cursor != null && cursor.moveToFirst()) { + myGroupsId = cursor.getString(0); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + } } else { builder.withValue(RawContacts.ACCOUNT_NAME, null); builder.withValue(RawContacts.ACCOUNT_TYPE, null); -- cgit v1.1