aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Attwell <brianattwell@google.com>2015-02-03 22:07:29 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-02-03 22:07:29 +0000
commit0f6927a6946350dcb3031baa9ce1c7575f48307e (patch)
treecc8181b268797a37c7174c9d755a6810fdf30d09
parentabaa423fa15f00b07b9c92c16ee186c909cac145 (diff)
parentec22e2147d07c8a6de7fabeb0c45d22e844d0e6e (diff)
downloadContactsProvider-lollipop-mr1-dev.tar.gz
Merge "Additional change to IS_SUPER_PRIMARY" into lmp-mr1-devlollipop-mr1-dev
-rw-r--r--src/com/android/providers/contacts/aggregation/ContactAggregator.java11
-rw-r--r--tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java18
-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 8dcabcad..d030687d 100644
--- a/src/com/android/providers/contacts/aggregation/ContactAggregator.java
+++ b/src/com/android/providers/contacts/aggregation/ContactAggregator.java
@@ -929,6 +929,10 @@ public class ContactAggregator {
c.close();
}
+ if (index == 0) {
+ return;
+ }
+
// Clear is_super_primary setting for all the mime-types exist in both raw contact
// of rawContactId and raw contacts of contactId
String superPrimaryUpdateSql = "UPDATE " + Tables.DATA +
@@ -938,11 +942,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 78f1b805..0e0264c0 100644
--- a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
+++ b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
@@ -1620,6 +1620,24 @@ 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);
+
+ // Sanity check.
+ assertStoredValue(uri, Data.IS_SUPER_PRIMARY, 1);
+
+ // Action: aggregate
+ setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1,
+ rawContactId2);
+
+ // Verify: name is still super primary
+ assertStoredValue(uri, Data.IS_SUPER_PRIMARY, 1);
+ }
+
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 194e67df..1f4f35a1 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