diff options
author | Zheng Fu <zhengfu@google.com> | 2014-12-08 14:55:37 -0800 |
---|---|---|
committer | Zheng Fu <zhengfu@google.com> | 2014-12-09 15:25:21 -0800 |
commit | 085a7471448168069dac091eeb8a1c5e76138ffb (patch) | |
tree | 999c031cfe7547db4f5020403f92b2959079c106 | |
parent | 098215569d35a130c883933ec76773e85356387e (diff) | |
download | ContactsProvider-085a7471448168069dac091eeb8a1c5e76138ffb.tar.gz |
Skip aggregation if candidate contact contains too many raw contacts
This is likely an error or a shared corporate data element
Bug:18641722
Change-Id: Icab78bcf621363a5b887095c043e2e1e3a2e1ca4
-rw-r--r-- | src/com/android/providers/contacts/aggregation/ContactAggregator.java | 21 | ||||
-rw-r--r-- | tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java | 19 |
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)); |