aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZheng Fu <zhengfu@google.com>2014-12-09 23:34:35 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-12-09 23:34:36 +0000
commitbecda5cc4e265ab2cc3fc958e39de08380abd6c3 (patch)
tree142a81052b0f2eb122fbbc9c20fcd2ad925cf5b8
parenteb10c527fcd100d485f2d27a8a1ffea585960802 (diff)
parent085a7471448168069dac091eeb8a1c5e76138ffb (diff)
downloadContactsProvider-becda5cc4e265ab2cc3fc958e39de08380abd6c3.tar.gz
Merge "Skip aggregation if candidate contact contains too many raw contacts" into lmp-mr1-dev
-rw-r--r--src/com/android/providers/contacts/aggregation/ContactAggregator.java21
-rw-r--r--tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java19
2 files changed, 38 insertions, 2 deletions
diff --git a/src/com/android/providers/contacts/aggregation/ContactAggregator.java b/src/com/android/providers/contacts/aggregation/ContactAggregator.java
index ce2c50af..8dcabcad 100644
--- a/src/com/android/providers/contacts/aggregation/ContactAggregator.java
+++ b/src/com/android/providers/contacts/aggregation/ContactAggregator.java
@@ -136,6 +136,12 @@ public class ContactAggregator {
private static final int SECONDARY_HIT_LIMIT = 20;
private static final String SECONDARY_HIT_LIMIT_STRING = String.valueOf(SECONDARY_HIT_LIMIT);
+ // If we encounter no less than this many raw contacts in the best matching contact during
+ // aggregation, don't attempt to aggregate - this is likely an error or a shared corporate
+ // data element.
+ @VisibleForTesting
+ static final int AGGREGATION_CONTACT_SIZE_LIMIT = 50;
+
// If we encounter more than this many contacts with matching name during aggregation
// suggestion lookup, ignore the remaining results.
private static final int FIRST_LETTER_SUGGESTION_HIT_LIMIT = 100;
@@ -789,8 +795,19 @@ public class ContactAggregator {
} finally {
rawContactsToAccountsCursor.close();
}
- final int actionCode = canJoinIntoContact(db, rawContactId,
- rawContactIdsInSameAccount, rawContactIdsInOtherAccount);
+ final int actionCode;
+ final int totalNumOfRawContactsInCandidate = rawContactIdsInSameAccount.size()
+ + rawContactIdsInOtherAccount.size();
+ if (totalNumOfRawContactsInCandidate >= AGGREGATION_CONTACT_SIZE_LIMIT) {
+ if (VERBOSE_LOGGING) {
+ Log.v(TAG, "Too many raw contacts (" + totalNumOfRawContactsInCandidate
+ + ") in the best matching contact, so skip aggregation");
+ }
+ actionCode = KEEP_SEPARATE;
+ } else {
+ actionCode = canJoinIntoContact(db, rawContactId,
+ rawContactIdsInSameAccount, rawContactIdsInOtherAccount);
+ }
if (actionCode == KEEP_SEPARATE) {
contactId = -1;
} else if (actionCode == RE_AGGREGATE) {
diff --git a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
index 63d5f3bb..78f1b805 100644
--- a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
+++ b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
@@ -1620,6 +1620,25 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test {
assertSuperPrimary(ContentUris.parseId(uri_org2), false);
}
+ public void testNotAggregate_TooManyRawContactsInCandidate() {
+ long preId= 0;
+ for (int i = 0; i < ContactAggregator.AGGREGATION_CONTACT_SIZE_LIMIT; i++) {
+ long id = RawContactUtil.createRawContactWithName(mResolver, "John", "Doe");
+ if (i > 0) {
+ setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, preId, id);
+ }
+ preId = id;
+ }
+ // Although the newly added raw contact matches the names with other raw contacts,
+ // but the best matching contact has already meets the size limit, so keep the new raw
+ // contact separate from other raw contacts.
+ long newId = RawContactUtil.createRawContact(mResolver,
+ new Account("account_new", "new account type"));
+ DataUtil.insertStructuredName(mResolver, newId, "John", "Doe");
+ assertNotAggregated(preId, newId);
+ assertTrue(queryContactId(newId) > 0);
+ }
+
public void testFindConnectedRawContacts() {
Set<Long> rawContactIdSet = new HashSet<Long>();
rawContactIdSet.addAll(Arrays.asList(1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l, 9l));