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 | |
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
5 files changed, 84 insertions, 42 deletions
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java index bda9826..f23d245 100644 --- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java +++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java @@ -116,7 +116,7 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { * 900-999 L * </pre> */ - static final int DATABASE_VERSION = 906; + static final int DATABASE_VERSION = 907; public interface Tables { public static final String CONTACTS = "contacts"; @@ -2776,6 +2776,12 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { oldVersion = 906; } + if (oldVersion < 907) { + // Rebuild NAME_LOOKUP. + upgradeNameLookup = true; + oldVersion = 907; + } + if (upgradeViewsAndTriggers) { createContactsViews(db); createGroupsView(db); @@ -5653,25 +5659,6 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { } } - public void insertNameLookupForPhoneticName(long rawContactId, long dataId, String familyName, - String middleName, String givenName) { - mSb.setLength(0); - if (familyName != null) { - mSb.append(familyName.trim()); - } - if (middleName != null) { - mSb.append(middleName.trim()); - } - if (givenName != null) { - mSb.append(givenName.trim()); - } - - if (mSb.length() > 0) { - insertNameLookup(rawContactId, dataId, NameLookupType.NAME_COLLATION_KEY, - NameNormalizer.normalize(mSb.toString())); - } - } - /** * Performs a query and returns true if any Data item of the raw contact with the given * id and mimetype is marked as super-primary diff --git a/src/com/android/providers/contacts/DataRowHandlerForStructuredName.java b/src/com/android/providers/contacts/DataRowHandlerForStructuredName.java index 8781d2f..ba6777d 100644 --- a/src/com/android/providers/contacts/DataRowHandlerForStructuredName.java +++ b/src/com/android/providers/contacts/DataRowHandlerForStructuredName.java @@ -56,7 +56,6 @@ public class DataRowHandlerForStructuredName extends DataRowHandler { fullNameStyle != null ? mSplitter.getAdjustedFullNameStyle(fullNameStyle) : FullNameStyle.UNDEFINED); - insertNameLookupForPhoneticName(rawContactId, dataId, values); fixRawContactDisplayName(db, txContext, rawContactId); triggerAggregation(txContext, rawContactId); return dataId; @@ -76,10 +75,7 @@ public class DataRowHandlerForStructuredName extends DataRowHandler { fixStructuredNameComponents(augmented, values); super.update(db, txContext, values, c, callerIsSyncAdapter); - if (values.containsKey(StructuredName.DISPLAY_NAME) || - values.containsKey(StructuredName.PHONETIC_FAMILY_NAME) || - values.containsKey(StructuredName.PHONETIC_MIDDLE_NAME) || - values.containsKey(StructuredName.PHONETIC_GIVEN_NAME)) { + if (values.containsKey(StructuredName.DISPLAY_NAME)) { augmented.putAll(values); String name = augmented.getAsString(StructuredName.DISPLAY_NAME); mDbHelper.deleteNameLookup(dataId); @@ -88,7 +84,6 @@ public class DataRowHandlerForStructuredName extends DataRowHandler { fullNameStyle != null ? mSplitter.getAdjustedFullNameStyle(fullNameStyle) : FullNameStyle.UNDEFINED); - insertNameLookupForPhoneticName(rawContactId, dataId, augmented); } fixRawContactDisplayName(db, txContext, rawContactId); triggerAggregation(txContext, rawContactId); @@ -166,18 +161,6 @@ public class DataRowHandlerForStructuredName extends DataRowHandler { } } - public void insertNameLookupForPhoneticName(long rawContactId, long dataId, - ContentValues values) { - if (values.containsKey(StructuredName.PHONETIC_FAMILY_NAME) - || values.containsKey(StructuredName.PHONETIC_GIVEN_NAME) - || values.containsKey(StructuredName.PHONETIC_MIDDLE_NAME)) { - mDbHelper.insertNameLookupForPhoneticName(rawContactId, dataId, - values.getAsString(StructuredName.PHONETIC_FAMILY_NAME), - values.getAsString(StructuredName.PHONETIC_MIDDLE_NAME), - values.getAsString(StructuredName.PHONETIC_GIVEN_NAME)); - } - } - @Override public boolean hasSearchableData() { return true; 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); } |