diff options
author | Makoto Onuki <omakoto@google.com> | 2014-07-24 18:17:57 -0700 |
---|---|---|
committer | Makoto Onuki <omakoto@google.com> | 2014-07-28 11:40:49 -0700 |
commit | 8a8ddc3d1ceee9872ace06326ebe999ba171f70b (patch) | |
tree | 423d43eb8cf510465085af32e5d14cb2d27928ec /tests | |
parent | 0fc2f46b80df2c4c14bec40055eb6b954c0c6523 (diff) | |
download | packages_providers_ContactsProvider-8a8ddc3d1ceee9872ace06326ebe999ba171f70b.zip packages_providers_ContactsProvider-8a8ddc3d1ceee9872ace06326ebe999ba171f70b.tar.gz packages_providers_ContactsProvider-8a8ddc3d1ceee9872ace06326ebe999ba171f70b.tar.bz2 |
Do not build NAME_LOOKUP from phonetic names
This prevents aggregation by phonetic name
Note: if a contact only has a phonetic name (i.e. without any non-phonetic name components), then
its display name is set from the phonetic name. This CL does *not* prevent phonetic-name-based
display names getting into NAME_LOOKUP, meaning if two contacts have no names but the same phonetic
name, then they *will* still be aggregated. But this shouldn't be an issue since what was an issue
was "aggregating two contacts with *different* names with the same phonetic name".
Bug 10957673
Change-Id: I6484128b1f7e4bbe1b08c57969a8a1ef147d5c7d
Diffstat (limited to 'tests')
3 files changed, 76 insertions, 4 deletions
diff --git a/tests/src/com/android/providers/contacts/SearchIndexManagerTest.java b/tests/src/com/android/providers/contacts/SearchIndexManagerTest.java index bfa5e30..2c1db4c 100644 --- a/tests/src/com/android/providers/contacts/SearchIndexManagerTest.java +++ b/tests/src/com/android/providers/contacts/SearchIndexManagerTest.java @@ -69,6 +69,26 @@ public class SearchIndexManagerTest extends BaseContactsProvider2Test { contactId, null, "John Doe Bob I Parr Helen I Parr PhD par helen parhelen", null); } + public void testSearchIndexForStructuredName_phoneticOnly() { + long rawContactId = RawContactUtil.createRawContact(mResolver); + long contactId = queryContactId(rawContactId); + DataUtil.insertStructuredName(mResolver, rawContactId, "John", "Doe"); + ContentValues values = new ContentValues(); + values.put(StructuredName.DISPLAY_NAME, "Bob I. Parr"); + DataUtil.insertStructuredName(mResolver, rawContactId, values); + values.clear(); + values.put(StructuredName.PREFIX, "Mrs."); + values.put(StructuredName.GIVEN_NAME, "Helen"); + values.put(StructuredName.MIDDLE_NAME, "I."); + values.put(StructuredName.FAMILY_NAME, "Parr"); + values.put(StructuredName.SUFFIX, "PhD"); + values.put(StructuredName.PHONETIC_FAMILY_NAME, "yamada"); + values.put(StructuredName.PHONETIC_GIVEN_NAME, "taro"); + DataUtil.insertStructuredName(mResolver, rawContactId, values); + + assertSearchIndex(zcontactId, null, "yamada taro", null); + } + public void testSearchIndexForChineseName() { // Only run this test when Chinese collation is supported if (!Arrays.asList(Collator.getAvailableLocales()).contains(Locale.CHINA)) { diff --git a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java index acd830f..cb0766e 100644 --- a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java +++ b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java @@ -605,6 +605,43 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test { assertNotAggregated(rawContactId1, rawContactId2); } + public void testAggregation_notAggregateByPhoneticName() { + // Different names, but have the same phonetic name. Shouldn't be aggregated. + + long rawContactId1 = RawContactUtil.createRawContact(mResolver, ACCOUNT_1); + DataUtil.insertStructuredName(mResolver, rawContactId1, "Sergey", null, "Yamada"); + + long rawContactId2 = RawContactUtil.createRawContact(mResolver, ACCOUNT_2); + DataUtil.insertStructuredName(mResolver, rawContactId2, "Lawrence", null, "Yamada"); + + assertNotAggregated(rawContactId1, rawContactId2); + } + + public void testAggregation_notAggregateByPhoneticName_2() { + // Have the same phonetic name. One has a regular name too. Shouldn't be aggregated. + + long rawContactId1 = RawContactUtil.createRawContact(mResolver, ACCOUNT_1); + DataUtil.insertStructuredName(mResolver, rawContactId1, null, null, "Yamada"); + + long rawContactId2 = RawContactUtil.createRawContact(mResolver, ACCOUNT_2); + DataUtil.insertStructuredName(mResolver, rawContactId2, "Lawrence", null, "Yamada"); + + assertNotAggregated(rawContactId1, rawContactId2); + } + + public void testAggregation_PhoneticNameOnly() { + // If a contact has no name but a phonetic name, then its display will be set from the + // phonetic name. In this case, we still aggregate by the display name. + + long rawContactId1 = RawContactUtil.createRawContact(mResolver, ACCOUNT_1); + DataUtil.insertStructuredName(mResolver, rawContactId1, null, null, "Yamada"); + + long rawContactId2 = RawContactUtil.createRawContact(mResolver, ACCOUNT_2); + DataUtil.insertStructuredName(mResolver, rawContactId2, null, null, "Yamada"); + + assertAggregated(rawContactId1, rawContactId2, "Yamada"); + } + public void testReaggregationWhenBecomesInvisible() { Account account = new Account("accountName", "accountType"); createAutoAddGroup(account); diff --git a/tests/src/com/android/providers/contacts/testutil/DataUtil.java b/tests/src/com/android/providers/contacts/testutil/DataUtil.java index 874aacf..194e67d 100644 --- a/tests/src/com/android/providers/contacts/testutil/DataUtil.java +++ b/tests/src/com/android/providers/contacts/testutil/DataUtil.java @@ -21,6 +21,7 @@ import android.content.ContentUris; import android.content.ContentValues; import android.net.Uri; import android.provider.ContactsContract; +import android.provider.ContactsContract.CommonDataKinds.StructuredName; import android.test.mock.MockContentResolver; /** @@ -43,13 +44,21 @@ public class DataUtil { public static Uri insertStructuredName(ContentResolver resolver, long rawContactId, ContentValues values) { values.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId); - values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); + values.put(ContactsContract.Data.MIMETYPE, + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); Uri resultUri = resolver.insert(ContactsContract.Data.CONTENT_URI, values); return resultUri; } public static Uri insertStructuredName(ContentResolver resolver, long rawContactId, String givenName, String familyName) { + return insertStructuredName(resolver, rawContactId, givenName, familyName, + /* phonetic given =*/ null); + } + + public static Uri insertStructuredName( + ContentResolver resolver, long rawContactId, String givenName, String familyName, + String phoneticGiven) { ContentValues values = new ContentValues(); StringBuilder sb = new StringBuilder(); if (givenName != null) { @@ -61,9 +70,15 @@ public class DataUtil { if (familyName != null) { sb.append(familyName); } - values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, sb.toString()); - values.put(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, givenName); - values.put(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, familyName); + if (sb.length() == 0 && phoneticGiven != null) { + sb.append(phoneticGiven); + } + values.put(StructuredName.DISPLAY_NAME, sb.toString()); + values.put(StructuredName.GIVEN_NAME, givenName); + values.put(StructuredName.FAMILY_NAME, familyName); + if (phoneticGiven != null) { + values.put(StructuredName.PHONETIC_GIVEN_NAME, phoneticGiven); + } return insertStructuredName(resolver, rawContactId, values); } |