diff options
author | Makoto Onuki <omakoto@google.com> | 2012-08-10 14:43:54 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-08-10 14:43:54 -0700 |
commit | e8956364a9cf4ec0f463768a6116fdcda8635b13 (patch) | |
tree | b2ca4b0bf6b9dae0760b2772517fc4393ef411f7 | |
parent | 9bc20fb9de84effe8e88ccf9d526beafcea92ee9 (diff) | |
parent | 10840c6bcd8bf0ab2e5f846d345d14e5df9858a7 (diff) | |
download | packages_providers_ContactsProvider-e8956364a9cf4ec0f463768a6116fdcda8635b13.zip packages_providers_ContactsProvider-e8956364a9cf4ec0f463768a6116fdcda8635b13.tar.gz packages_providers_ContactsProvider-e8956364a9cf4ec0f463768a6116fdcda8635b13.tar.bz2 |
Merge "Don't leave stale normalized number when updating..." into jb-mr1-dev
-rw-r--r-- | src/com/android/providers/contacts/DataRowHandlerForPhoneNumber.java | 4 | ||||
-rw-r--r-- | tests/src/com/android/providers/contacts/ContactsProvider2Test.java | 53 |
2 files changed, 50 insertions, 7 deletions
diff --git a/src/com/android/providers/contacts/DataRowHandlerForPhoneNumber.java b/src/com/android/providers/contacts/DataRowHandlerForPhoneNumber.java index da7d66c..16faf2a 100644 --- a/src/com/android/providers/contacts/DataRowHandlerForPhoneNumber.java +++ b/src/com/android/providers/contacts/DataRowHandlerForPhoneNumber.java @@ -93,9 +93,7 @@ public class DataRowHandlerForPhoneNumber extends DataRowHandlerForCommonDataKin if (number != null && numberE164 == null) { final String newNumberE164 = PhoneNumberUtils.formatNumberToE164(number, mDbHelper.getCurrentCountryIso()); - if (newNumberE164 != null) { - values.put(Phone.NORMALIZED_NUMBER, newNumberE164); - } + values.put(Phone.NORMALIZED_NUMBER, newNumberE164); } } diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index 80e194d..003012e 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -1020,12 +1020,17 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { final Uri dataUri = mResolver.insert(Data.CONTENT_URI, values); - // Ensure both can be looked up + // Check the lookup table. assertEquals(1, getCount(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "1234"), null, null)); assertEquals(1, getCount(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "5678"), null, null)); + // Check the data table. + assertStoredValues(dataUri, + cv(Phone.NUMBER, "1234", Phone.NORMALIZED_NUMBER, "5678") + ); + // Replace both in an UPDATE values.clear(); values.put(Phone.NUMBER, "4321"); @@ -1040,28 +1045,68 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { assertEquals(1, getCount(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "8765"), null, null)); + assertStoredValues(dataUri, + cv(Phone.NUMBER, "4321", Phone.NORMALIZED_NUMBER, "8765") + ); + // Replace only NUMBER ==> NORMALIZED_NUMBER will be inferred (we test that by making // sure the old manual value can not be found anymore) values.clear(); - values.put(Phone.NUMBER, "1-800-466-5432"); + values.put(Phone.NUMBER, "+1-800-466-5432"); mResolver.update(dataUri, values, null, null); assertEquals( 1, - getCount(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "1-800-466-5432"), null, + getCount(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "+1-800-466-5432"), null, null)); assertEquals(0, getCount(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "8765"), null, null)); + assertStoredValues(dataUri, + cv(Phone.NUMBER, "+1-800-466-5432", Phone.NORMALIZED_NUMBER, "+18004665432") + ); + // Replace only NORMALIZED_NUMBER ==> call is ignored, things will be unchanged values.clear(); values.put(Phone.NORMALIZED_NUMBER, "8765"); mResolver.update(dataUri, values, null, null); assertEquals( 1, - getCount(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "1-800-466-5432"), null, + getCount(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "+1-800-466-5432"), null, null)); assertEquals(0, getCount(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "8765"), null, null)); + + assertStoredValues(dataUri, + cv(Phone.NUMBER, "+1-800-466-5432", Phone.NORMALIZED_NUMBER, "+18004665432") + ); + + // Replace NUMBER with an "invalid" number which can't be normalized. It should clear + // NORMALIZED_NUMBER. + + // 1. Set 999 to NORMALIZED_NUMBER explicitly. + values.clear(); + values.put(Phone.NUMBER, "888"); + values.put(Phone.NORMALIZED_NUMBER, "999"); + mResolver.update(dataUri, values, null, null); + + assertEquals(1, + getCount(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "999"), null, null)); + + assertStoredValues(dataUri, + cv(Phone.NUMBER, "888", Phone.NORMALIZED_NUMBER, "999") + ); + + // 2. Set an invalid number to NUMBER. + values.clear(); + values.put(Phone.NUMBER, "1"); + mResolver.update(dataUri, values, null, null); + + assertEquals(0, + getCount(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "999"), null, null)); + + assertStoredValues(dataUri, + cv(Phone.NUMBER, "1", Phone.NORMALIZED_NUMBER, null) + ); } public void testPhonesFilterQuery() { |