From 732961a5b936d316482f9ded6bfc5fe1c99a65c8 Mon Sep 17 00:00:00 2001 From: Dmitri Plotnikov Date: Thu, 8 Oct 2009 10:43:19 -0700 Subject: [Issue 2163519] Making ContactsProvider2 honor the super-primary flag on a photo Change-Id: I92d49bcd95922d0393eee48fc9f81f8e288247f6 --- .../providers/contacts/ContactAggregator.java | 22 +++++++++++---- .../providers/contacts/ContactsProvider2Test.java | 33 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/com/android/providers/contacts/ContactAggregator.java b/src/com/android/providers/contacts/ContactAggregator.java index afecf411..b983fe7a 100644 --- a/src/com/android/providers/contacts/ContactAggregator.java +++ b/src/com/android/providers/contacts/ContactAggregator.java @@ -1135,6 +1135,7 @@ public class ContactAggregator implements ContactAggregationScheduler.Aggregator RawContacts.IS_RESTRICTED, DataColumns.CONCRETE_ID, DataColumns.CONCRETE_MIMETYPE_ID, + Data.IS_SUPER_PRIMARY, }; int RAW_CONTACT_ID = 0; @@ -1151,6 +1152,7 @@ public class ContactAggregator implements ContactAggregationScheduler.Aggregator int IS_RESTRICTED = 11; int DATA_ID = 12; int MIMETYPE_ID = 13; + int IS_SUPER_PRIMARY = 14; } /** @@ -1170,6 +1172,7 @@ public class ContactAggregator implements ContactAggregationScheduler.Aggregator int bestDisplayNameSource = DisplayNameSources.UNDEFINED; String bestDisplayName = null; long bestPhotoId = -1; + boolean foundSuperPrimaryPhoto = false; String photoAccount = null; int totalRowCount = 0; int contactSendToVoicemail = 0; @@ -1269,18 +1272,18 @@ public class ContactAggregator implements ContactAggregationScheduler.Aggregator if (!c.isNull(RawContactsQuery.DATA_ID)) { long dataId = c.getLong(RawContactsQuery.DATA_ID); int mimetypeId = c.getInt(RawContactsQuery.MIMETYPE_ID); + boolean superprimary = c.getInt(RawContactsQuery.IS_SUPER_PRIMARY) != 0; if (mimetypeId == photoMimeType) { // For now, just choose the first photo in a list sorted by account name. String account = c.getString(RawContactsQuery.ACCOUNT_NAME); - if (photoAccount == null) { + if (!foundSuperPrimaryPhoto + && (superprimary + || photoAccount == null + || account.compareToIgnoreCase(photoAccount) < 0)) { photoAccount = account; bestPhotoId = dataId; - } else { - if (account.compareToIgnoreCase(photoAccount) < 0) { - photoAccount = account; - bestPhotoId = dataId; - } + foundSuperPrimaryPhoto |= superprimary; } } else if (mimetypeId == phoneMimeType) { hasPhoneNumber = 1; @@ -1320,10 +1323,12 @@ public class ContactAggregator implements ContactAggregationScheduler.Aggregator String[] COLUMNS = new String[] { RawContacts.ACCOUNT_NAME, DataColumns.CONCRETE_ID, + Data.IS_SUPER_PRIMARY, }; int ACCOUNT_NAME = 0; int DATA_ID = 1; + int IS_SUPER_PRIMARY = 2; } public void updatePhotoId(SQLiteDatabase db, long rawContactId) { @@ -1348,6 +1353,11 @@ public class ContactAggregator implements ContactAggregationScheduler.Aggregator try { while (c.moveToNext()) { long dataId = c.getLong(PhotoIdQuery.DATA_ID); + boolean superprimary = c.getInt(PhotoIdQuery.IS_SUPER_PRIMARY) != 0; + if (superprimary) { + bestPhotoId = dataId; + break; + } // For now, just choose the first photo in a list sorted by account name. String account = c.getString(PhotoIdQuery.ACCOUNT_NAME); diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index 8b957f13..11acf376 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -1447,6 +1447,39 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { assertEquals(ContentUris.parseId(photoUri), twigId); } + public void testSuperPrimaryPhoto() { + long rawContactId1 = createRawContact(new Account("a", "a")); + Uri photoUri1 = insertPhoto(rawContactId1); + long photoId1 = ContentUris.parseId(photoUri1); + + long rawContactId2 = createRawContact(new Account("b", "b")); + Uri photoUri2 = insertPhoto(rawContactId2); + long photoId2 = ContentUris.parseId(photoUri2); + + setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, + rawContactId1, rawContactId2); + + Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, + queryContactId(rawContactId1)); + assertStoredValue(contactUri, Contacts.PHOTO_ID, photoId1); + + setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE, + rawContactId1, rawContactId2); + + ContentValues values = new ContentValues(); + values.put(Data.IS_SUPER_PRIMARY, 1); + mResolver.update(photoUri2, values, null, null); + + setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, + rawContactId1, rawContactId2); + contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, + queryContactId(rawContactId1)); + assertStoredValue(contactUri, Contacts.PHOTO_ID, photoId2); + + mResolver.update(photoUri1, values, null, null); + assertStoredValue(contactUri, Contacts.PHOTO_ID, photoId1); + } + public void testUpdatePhoto() { ContentValues values = new ContentValues(); Uri rawContactUri = mResolver.insert(RawContacts.CONTENT_URI, values); -- cgit v1.2.3