diff options
author | Zheng Fu <zhengfu@google.com> | 2015-07-08 00:29:17 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-07-08 00:29:17 +0000 |
commit | f88d6c91f739b4c13a9d3b63734e6369bd1a9d38 (patch) | |
tree | 3060bc13a7f7741300eaadc20f39e3817b34127e | |
parent | 8a7c1d87138c02cdd823fd926d5c4a31fd39db5c (diff) | |
parent | 5ca831dc33dfa16821647e14e377c484df823c80 (diff) | |
download | packages_providers_ContactsProvider-f88d6c91f739b4c13a9d3b63734e6369bd1a9d38.tar.gz packages_providers_ContactsProvider-f88d6c91f739b4c13a9d3b63734e6369bd1a9d38.tar.bz2 packages_providers_ContactsProvider-f88d6c91f739b4c13a9d3b63734e6369bd1a9d38.zip |
am 5ca831dc: Fix bug in aggregation suggestions in new contacts aggregator.
* commit '5ca831dc33dfa16821647e14e377c484df823c80':
Fix bug in aggregation suggestions in new contacts aggregator.
-rw-r--r-- | src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java | 12 | ||||
-rw-r--r-- | tests/src/com/android/providers/contacts/aggregation/ContactAggregator2Test.java | 13 |
2 files changed, 20 insertions, 5 deletions
diff --git a/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java b/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java index 0caa861f..cfbad32b 100644 --- a/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java +++ b/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java @@ -1928,7 +1928,17 @@ public abstract class AbstractContactAggregator { db.beginTransaction(); try { List<MatchScore> bestMatches = findMatchingContacts(db, contactId, parameters); - return queryMatchingContacts(qb, db, projection, bestMatches, maxSuggestions, filter); + List<MatchScore> bestMatchesWithoutDuplicateContactIds = new ArrayList<>(); + Set<Long> contactIds = new HashSet<>(); + for (MatchScore bestMatch : bestMatches) { + long cid = bestMatch.getContactId(); + if (!contactIds.contains(cid)) { + bestMatchesWithoutDuplicateContactIds.add(bestMatch); + contactIds.add(cid); + } + } + return queryMatchingContacts(qb, db, projection, bestMatchesWithoutDuplicateContactIds, + maxSuggestions, filter); } finally { db.endTransaction(); } diff --git a/tests/src/com/android/providers/contacts/aggregation/ContactAggregator2Test.java b/tests/src/com/android/providers/contacts/aggregation/ContactAggregator2Test.java index 53e63cb0..ac64cacf 100644 --- a/tests/src/com/android/providers/contacts/aggregation/ContactAggregator2Test.java +++ b/tests/src/com/android/providers/contacts/aggregation/ContactAggregator2Test.java @@ -916,14 +916,15 @@ public class ContactAggregator2Test extends BaseContactsProvider2Test { } public void testAggregationSuggestionsBasedOnName() { + // Exact name match contact with two raw contacts long rawContactId1 = RawContactUtil.createRawContact(mResolver); DataUtil.insertStructuredName(mResolver, rawContactId1, "Duane", null); + insertPhoneNumber(rawContactId1, "(888)555-1236"); - // Exact name match + // Exact name match contact with two raw contacts long rawContactId2 = RawContactUtil.createRawContact(mResolver); DataUtil.insertStructuredName(mResolver, rawContactId2, "Duane", null); - setAggregationException(AggregationExceptions.TYPE_KEEP_SEPARATE, - rawContactId1, rawContactId2); + insertPhoneNumber(rawContactId2, "(888)555-1236"); // Edit distance == 0.84 long rawContactId3 = RawContactUtil.createRawContact(mResolver); @@ -933,11 +934,15 @@ public class ContactAggregator2Test extends BaseContactsProvider2Test { long rawContactId4 = RawContactUtil.createRawContact(mResolver); DataUtil.insertStructuredName(mResolver, rawContactId4, "Donny", null); + long rawContactId5 = RawContactUtil.createRawContact(mResolver); + DataUtil.insertStructuredName(mResolver, rawContactId5, "Duane", null); + long contactId1 = queryContactId(rawContactId1); long contactId2 = queryContactId(rawContactId2); long contactId3 = queryContactId(rawContactId3); - assertSuggestions(contactId1, contactId2, contactId3); + assertEquals(contactId1, contactId2); + assertSuggestions(queryContactId(rawContactId5), contactId1, contactId3); } public void testAggregationSuggestionsBasedOnPhoneNumber() { |