diff options
author | Tony Mak <tonymak@google.com> | 2016-02-17 19:40:30 +0000 |
---|---|---|
committer | Tony Mak <tonymak@google.com> | 2016-02-17 21:42:31 +0000 |
commit | b716ac69042174eb9b5a00d132a27e32b5693caa (patch) | |
tree | 0f3e0fa2ab9e6cb0ec6aa2fb0c0c5b03944b7224 /tests | |
parent | 19c239fb39136e41231c5ed1d446d33ef2fa1973 (diff) | |
download | ContactsProvider-b716ac69042174eb9b5a00d132a27e32b5693caa.tar.gz |
[CP2] Add new API PhoneLookup.CONTACT_ID
It is a mistake that we put contact id in PhoneLookup._ID.
But for SIP query, the contact id is put in Data.CONTACT_ID instead.
For backward-compability issue, we can't revert the change, but to
save developer from having logic like below, PhoneLookup.CONTACT_ID is
introduced.
if (sip) {
get contact id in Data.CONTACT_ID column
} else {
get contact id in PhoneLookup._ID column
}
So for sip query, we put contact id in PhoneLookup.CONTACT_ID.
For other phone lookup query, we put contact id in both PhoneLookup.ID
and PhoneLookup.CONTACT_ID.
BUG:27149017
Change-Id: I4155da29bbacdda0d43164b0ce11c7224a4eee67
Diffstat (limited to 'tests')
3 files changed, 140 insertions, 45 deletions
diff --git a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java index ea924906..86dff66a 100644 --- a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java @@ -71,6 +71,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.Comparator; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; @@ -1331,6 +1332,16 @@ public abstract class BaseContactsProvider2Test extends PhotoLoadingTestCase { cursor.close(); } + protected void assertContainProjection(Uri uri, String[] mustHaveProjection) { + Cursor cursor = mResolver.query(uri, null, "0", null, null); + String[] actualProjection = cursor.getColumnNames(); + Set<String> actualProjectionSet = Sets.newHashSet(actualProjection); + Set<String> mustHaveProjectionSet = Sets.newHashSet(mustHaveProjection); + actualProjectionSet.retainAll(mustHaveProjectionSet); + MoreAsserts.assertEquals(mustHaveProjectionSet, actualProjectionSet); + cursor.close(); + } + protected void assertRowCount(int expectedCount, Uri uri, String selection, String[] args) { Cursor cursor = mResolver.query(uri, null, selection, args, null); diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index e6b8b86f..50a107a6 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -708,6 +708,8 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { assertProjection(PhoneLookup.CONTENT_FILTER_URI.buildUpon().appendPath("123").build(), new String[]{ PhoneLookup._ID, + PhoneLookup.CONTACT_ID, + PhoneLookup.DATA_ID, PhoneLookup.LOOKUP_KEY, PhoneLookup.DISPLAY_NAME, PhoneLookup.LAST_TIME_CONTACTED, @@ -734,6 +736,68 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { .buildUpon().appendPath("123").build(), new String[]{ PhoneLookup._ID, + PhoneLookup.CONTACT_ID, + PhoneLookup.DATA_ID, + PhoneLookup.LOOKUP_KEY, + PhoneLookup.DISPLAY_NAME, + PhoneLookup.LAST_TIME_CONTACTED, + PhoneLookup.TIMES_CONTACTED, + PhoneLookup.STARRED, + PhoneLookup.IN_DEFAULT_DIRECTORY, + PhoneLookup.IN_VISIBLE_GROUP, + PhoneLookup.PHOTO_FILE_ID, + PhoneLookup.PHOTO_ID, + PhoneLookup.PHOTO_URI, + PhoneLookup.PHOTO_THUMBNAIL_URI, + PhoneLookup.CUSTOM_RINGTONE, + PhoneLookup.HAS_PHONE_NUMBER, + PhoneLookup.SEND_TO_VOICEMAIL, + PhoneLookup.NUMBER, + PhoneLookup.TYPE, + PhoneLookup.LABEL, + PhoneLookup.NORMALIZED_NUMBER, + }); + } + + public void testSipPhoneLookupProjection() { + assertContainProjection(PhoneLookup.CONTENT_FILTER_URI.buildUpon().appendPath("123") + .appendQueryParameter(PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS, "1") + .build(), + new String[] { + PhoneLookup._ID, + PhoneLookup.CONTACT_ID, + PhoneLookup.DATA_ID, + PhoneLookup.LOOKUP_KEY, + PhoneLookup.DISPLAY_NAME, + PhoneLookup.LAST_TIME_CONTACTED, + PhoneLookup.TIMES_CONTACTED, + PhoneLookup.STARRED, + PhoneLookup.IN_DEFAULT_DIRECTORY, + PhoneLookup.IN_VISIBLE_GROUP, + PhoneLookup.PHOTO_FILE_ID, + PhoneLookup.PHOTO_ID, + PhoneLookup.PHOTO_URI, + PhoneLookup.PHOTO_THUMBNAIL_URI, + PhoneLookup.CUSTOM_RINGTONE, + PhoneLookup.HAS_PHONE_NUMBER, + PhoneLookup.SEND_TO_VOICEMAIL, + PhoneLookup.NUMBER, + PhoneLookup.TYPE, + PhoneLookup.LABEL, + PhoneLookup.NORMALIZED_NUMBER, + }); + } + + public void testSipPhoneLookupEnterpriseProjection() { + assertContainProjection(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI + .buildUpon() + .appendPath("123") + .appendQueryParameter(PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS, "1") + .build(), + new String[] { + PhoneLookup._ID, + PhoneLookup.CONTACT_ID, + PhoneLookup.DATA_ID, PhoneLookup.LOOKUP_KEY, PhoneLookup.DISPLAY_NAME, PhoneLookup.LAST_TIME_CONTACTED, @@ -1540,7 +1604,8 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { long rawContactId = ContentUris.parseId(rawContactUri); DataUtil.insertStructuredName(mResolver, rawContactId, "Hot", "Tamale"); - insertPhoneNumber(rawContactId, "18004664411"); + long dataId = + Long.parseLong(insertPhoneNumber(rawContactId, "18004664411").getLastPathSegment()); // We'll create two lookup records, 18004664411 and +18004664411, and the below lookup // will match both. @@ -1549,6 +1614,8 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { values.clear(); values.put(PhoneLookup._ID, queryContactId(rawContactId)); + values.put(PhoneLookup.CONTACT_ID, queryContactId(rawContactId)); + values.put(PhoneLookup.DATA_ID, dataId); values.put(PhoneLookup.DISPLAY_NAME, "Hot Tamale"); values.put(PhoneLookup.NUMBER, "18004664411"); values.put(PhoneLookup.TYPE, Phone.TYPE_HOME); @@ -1567,6 +1634,35 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { assertEquals(0, getCount(lookupUri2, null, null)); } + public void testSipPhoneLookup() { + ContentValues values = new ContentValues(); + + Uri rawContactUri = mResolver.insert(RawContacts.CONTENT_URI, values); + long rawContactId = ContentUris.parseId(rawContactUri); + + DataUtil.insertStructuredName(mResolver, rawContactId, "Hot", "Tamale"); + long dataId = + Long.parseLong(insertSipAddress(rawContactId, "abc@sip").getLastPathSegment()); + + Uri lookupUri1 = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, "abc@sip") + .buildUpon() + .appendQueryParameter(PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS, "1") + .build(); + + values.clear(); + values.put(PhoneLookup._ID, dataId); + values.put(PhoneLookup.CONTACT_ID, queryContactId(rawContactId)); + values.put(PhoneLookup.DATA_ID, dataId); + values.put(PhoneLookup.DISPLAY_NAME, "Hot Tamale"); + values.put(PhoneLookup.NUMBER, "abc@sip"); + values.putNull(PhoneLookup.LABEL); + assertStoredValues(lookupUri1, null, null, new ContentValues[] {values}); + + // A wrong sip address should not be matched + Uri lookupUri2 = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, "wrong@sip"); + assertEquals(0, getCount(lookupUri2, null, null)); + } + public void testPhoneLookupStarUseCases() { // Create two raw contacts with numbers "*123" and "12 3". This is a real life example // from b/13195334. diff --git a/tests/src/com/android/providers/contacts/EnterpriseContactsCursorWrapperTest.java b/tests/src/com/android/providers/contacts/EnterpriseContactsCursorWrapperTest.java index 74a74a36..5bf5397b 100644 --- a/tests/src/com/android/providers/contacts/EnterpriseContactsCursorWrapperTest.java +++ b/tests/src/com/android/providers/contacts/EnterpriseContactsCursorWrapperTest.java @@ -30,38 +30,40 @@ import com.android.providers.contacts.enterprise.EnterpriseContactsCursorWrapper public class EnterpriseContactsCursorWrapperTest extends AndroidTestCase { public void testWrappedResults() { - // 19 columns final String[] projection = new String[] { /* column 0 */ PhoneLookup._ID, - /* column 1 */ PhoneLookup.LOOKUP_KEY, - /* column 2 */ PhoneLookup.DISPLAY_NAME, - /* column 3 */ PhoneLookup.LAST_TIME_CONTACTED, - /* column 4 */ PhoneLookup.TIMES_CONTACTED, - /* column 5 */ PhoneLookup.STARRED, - /* column 6 */ PhoneLookup.IN_DEFAULT_DIRECTORY, - /* column 7 */ PhoneLookup.IN_VISIBLE_GROUP, - /* column 8 */ PhoneLookup.PHOTO_FILE_ID, - /* column 9 */ PhoneLookup.PHOTO_ID, - /* column 10 */ PhoneLookup.PHOTO_URI, - /* column 11 */ PhoneLookup.PHOTO_THUMBNAIL_URI, - /* column 12 */ PhoneLookup.CUSTOM_RINGTONE, - /* column 13 */ PhoneLookup.HAS_PHONE_NUMBER, - /* column 14 */ PhoneLookup.SEND_TO_VOICEMAIL, - /* column 15 */ PhoneLookup.NUMBER, - /* column 16 */ PhoneLookup.TYPE, - /* column 17 */ PhoneLookup.LABEL, - /* column 18 */ PhoneLookup.NORMALIZED_NUMBER + /* column 1 */ PhoneLookup.CONTACT_ID, + /* column 2 */ PhoneLookup.LOOKUP_KEY, + /* column 3 */ PhoneLookup.DISPLAY_NAME, + /* column 4 */ PhoneLookup.LAST_TIME_CONTACTED, + /* column 5 */ PhoneLookup.TIMES_CONTACTED, + /* column 6 */ PhoneLookup.STARRED, + /* column 7 */ PhoneLookup.IN_DEFAULT_DIRECTORY, + /* column 8 */ PhoneLookup.IN_VISIBLE_GROUP, + /* column 9 */ PhoneLookup.PHOTO_FILE_ID, + /* column 10 */ PhoneLookup.PHOTO_ID, + /* column 11 */ PhoneLookup.PHOTO_URI, + /* column 12 */ PhoneLookup.PHOTO_THUMBNAIL_URI, + /* column 13 */ PhoneLookup.CUSTOM_RINGTONE, + /* column 14 */ PhoneLookup.HAS_PHONE_NUMBER, + /* column 15 */ PhoneLookup.SEND_TO_VOICEMAIL, + /* column 16 */ PhoneLookup.NUMBER, + /* column 17 */ PhoneLookup.TYPE, + /* column 18 */ PhoneLookup.LABEL, + /* column 19 */ PhoneLookup.NORMALIZED_NUMBER }; final MatrixCursor c = new MatrixCursor(projection); // First, convert and make sure it returns an empty cursor. - Cursor rewritten = new EnterpriseContactsCursorWrapper(c, projection, 0, false, null); + Cursor rewritten = new EnterpriseContactsCursorWrapper(c, projection, + new int[] {0, 1}, null); assertEquals(0, rewritten.getCount()); - assertEquals(19, rewritten.getColumnCount()); + assertEquals(projection.length, rewritten.getColumnCount()); c.addRow(new Object[] { 1L, // PhoneLookup._ID, + 1L, // PhoneLookup.CONTACT_ID, null, // PhoneLookup.LOOKUP_KEY, null, // PhoneLookup.DISPLAY_NAME, null, // PhoneLookup.LAST_TIME_CONTACTED, @@ -84,6 +86,7 @@ public class EnterpriseContactsCursorWrapperTest extends AndroidTestCase { c.addRow(new Object[] { 10L, // PhoneLookup._ID, + 10L, // PhoneLookup.CONTACT_ID, "key", // PhoneLookup.LOOKUP_KEY, "name", // PhoneLookup.DISPLAY_NAME, 123, // PhoneLookup.LAST_TIME_CONTACTED, @@ -103,13 +106,16 @@ public class EnterpriseContactsCursorWrapperTest extends AndroidTestCase { "label", // PhoneLookup.LABEL, "+1234", // PhoneLookup.NORMALIZED_NUMBER }); - rewritten = new EnterpriseContactsCursorWrapper(c, projection, 0, false, null); + rewritten = new EnterpriseContactsCursorWrapper(c, projection, new int[] {0, 1}, null); assertEquals(2, rewritten.getCount()); - assertEquals(19, rewritten.getColumnCount()); + assertEquals(projection.length, rewritten.getColumnCount()); - rewritten.moveToPosition(0); + rewritten.moveToFirst(); + + // Verify the first row. int column = 0; assertEquals(1000000001L, rewritten.getLong(column++)); // We offset ID for corp contacts. + assertEquals(1000000001L, rewritten.getLong(column++)); // We offset ID for corp contacts. assertEquals(null, rewritten.getString(column++)); assertEquals(null, rewritten.getString(column++)); assertEquals(null, rewritten.getString(column++)); @@ -130,9 +136,11 @@ public class EnterpriseContactsCursorWrapperTest extends AndroidTestCase { assertEquals(null, rewritten.getString(column++)); + // Verify the second row. rewritten.moveToNext(); column = 0; assertEquals(1000000010L, rewritten.getLong(column++)); // With offset. + assertEquals(1000000010L, rewritten.getLong(column++)); // With offset. assertEquals("c-key", rewritten.getString(column++)); assertEquals("name", rewritten.getString(column++)); assertEquals(123, rewritten.getInt(column++)); @@ -153,25 +161,5 @@ public class EnterpriseContactsCursorWrapperTest extends AndroidTestCase { assertEquals(1, rewritten.getInt(column++)); assertEquals("label", rewritten.getString(column++)); assertEquals("+1234", rewritten.getString(column++)); - - - rewritten = new EnterpriseContactsCursorWrapper(c, projection, 0, false, null); - - assertEquals(2, rewritten.getCount()); - assertEquals(19, rewritten.getColumnCount()); - - rewritten.moveToPosition(0); - - assertEquals(null, rewritten.getString(10)); - assertEquals(null, rewritten.getString(11)); - - - rewritten.moveToNext(); - column = 0; - assertEquals("content://com.android.contacts/contacts_corp/10/display_photo", - rewritten.getString(10)); - assertEquals("content://com.android.contacts/contacts_corp/10/photo", - rewritten.getString(11)); } } - |