summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/providers/contacts/aggregation/ContactAggregator.java7
-rw-r--r--tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java22
-rw-r--r--tests/src/com/android/providers/contacts/testutil/DataUtil.java14
3 files changed, 37 insertions, 6 deletions
diff --git a/src/com/android/providers/contacts/aggregation/ContactAggregator.java b/src/com/android/providers/contacts/aggregation/ContactAggregator.java
index ab87c7e..5c7858e 100644
--- a/src/com/android/providers/contacts/aggregation/ContactAggregator.java
+++ b/src/com/android/providers/contacts/aggregation/ContactAggregator.java
@@ -940,11 +940,8 @@ public class ContactAggregator {
" WHERE " + RawContacts.CONTACT_ID + "=?1)" +
" OR " + Data.RAW_CONTACT_ID + "=?2)";
- if (index > 0) {
- mimeTypeCondition.append(')');
- superPrimaryUpdateSql += mimeTypeCondition.toString();
- }
-
+ mimeTypeCondition.append(')');
+ superPrimaryUpdateSql += mimeTypeCondition.toString();
db.execSQL(superPrimaryUpdateSql, args);
}
diff --git a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
index 09ee207..9aecd13 100644
--- a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
+++ b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
@@ -1615,6 +1615,28 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test {
assertSuperPrimary(ContentUris.parseId(uri_org2), false);
}
+ public void testAggregation_clearSuperPrimarySingleMimetype() {
+ // Setup: two raw contacts, each has a single name. One of the names is super primary.
+ long rawContactId1 = RawContactUtil.createRawContact(mResolver, ACCOUNT_1);
+ long rawContactId2 = RawContactUtil.createRawContact(mResolver, ACCOUNT_1);
+ final Uri uri = DataUtil.insertStructuredName(mResolver, rawContactId1, "name1",
+ null, null, /* isSuperPrimary = */ true);
+ final Uri uri2 = DataUtil.insertStructuredName(mResolver, rawContactId2, "name2",
+ null, null, /* isSuperPrimary = */ false);
+
+ // Sanity check.
+ assertStoredValue(uri, Data.IS_SUPER_PRIMARY, 1);
+ assertStoredValue(uri2, Data.IS_SUPER_PRIMARY, 0);
+
+ // Action: aggregate
+ setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1,
+ rawContactId2);
+
+ // Verify: super primary values are unchanged
+ assertStoredValue(uri, Data.IS_SUPER_PRIMARY, 1);
+ assertStoredValue(uri2, Data.IS_SUPER_PRIMARY, 0);
+ }
+
public void testNotAggregate_TooManyRawContactsInCandidate() {
long preId= 0;
for (int i = 0; i < ContactAggregator.AGGREGATION_CONTACT_SIZE_LIMIT; i++) {
diff --git a/tests/src/com/android/providers/contacts/testutil/DataUtil.java b/tests/src/com/android/providers/contacts/testutil/DataUtil.java
index 194e67d..1f4f35a 100644
--- a/tests/src/com/android/providers/contacts/testutil/DataUtil.java
+++ b/tests/src/com/android/providers/contacts/testutil/DataUtil.java
@@ -22,6 +22,7 @@ import android.content.ContentValues;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
+import android.provider.ContactsContract.Data;
import android.test.mock.MockContentResolver;
/**
@@ -59,6 +60,13 @@ public class DataUtil {
public static Uri insertStructuredName(
ContentResolver resolver, long rawContactId, String givenName, String familyName,
String phoneticGiven) {
+ return insertStructuredName(resolver, rawContactId, givenName, familyName, phoneticGiven,
+ /* isSuperPrimary = true */ false);
+ }
+
+ public static Uri insertStructuredName(
+ ContentResolver resolver, long rawContactId, String givenName, String familyName,
+ String phoneticGiven, boolean isSuperPrimary) {
ContentValues values = new ContentValues();
StringBuilder sb = new StringBuilder();
if (givenName != null) {
@@ -79,7 +87,11 @@ public class DataUtil {
if (phoneticGiven != null) {
values.put(StructuredName.PHONETIC_GIVEN_NAME, phoneticGiven);
}
+ if (isSuperPrimary) {
+ values.put(Data.IS_PRIMARY, 1);
+ values.put(Data.IS_SUPER_PRIMARY, 1);
+ }
return insertStructuredName(resolver, rawContactId, values);
}
-}
+} \ No newline at end of file