Loading services/people/java/com/android/server/people/data/ContactsQueryHelper.java +3 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.annotation.Nullable; import android.annotation.WorkerThread; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteException; import android.net.Uri; import android.provider.ContactsContract; import android.provider.ContactsContract.Contacts; Loading Loading @@ -149,6 +150,8 @@ class ContactsQueryHelper { found = true; } } catch (SQLiteException exception) { Slog.w("SQLite exception when querying contacts.", exception); } if (found && lookupKey != null && hasPhoneNumber) { return queryPhoneNumber(lookupKey); Loading services/tests/servicestests/src/com/android/server/people/data/ContactsQueryHelperTest.java +20 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static org.mockito.Mockito.when; import android.database.Cursor; import android.database.MatrixCursor; import android.database.sqlite.SQLiteException; import android.net.Uri; import android.provider.ContactsContract; import android.provider.ContactsContract.Contacts; Loading Loading @@ -63,6 +64,7 @@ public final class ContactsQueryHelperTest { private MatrixCursor mContactsLookupCursor; private MatrixCursor mPhoneCursor; private ContactsQueryHelper mHelper; private ContactsContentProvider contentProvider; @Before public void setUp() { Loading @@ -73,7 +75,7 @@ public final class ContactsQueryHelperTest { mPhoneCursor = new MatrixCursor(PHONE_COLUMNS); MockContentResolver contentResolver = new MockContentResolver(); ContactsContentProvider contentProvider = new ContactsContentProvider(); contentProvider = new ContactsContentProvider(); contentProvider.registerCursor(Contacts.CONTENT_URI, mContactsCursor); contentProvider.registerCursor( ContactsContract.PhoneLookup.CONTENT_FILTER_URI, mContactsLookupCursor); Loading @@ -88,6 +90,14 @@ public final class ContactsQueryHelperTest { mHelper = new ContactsQueryHelper(mContext); } @Test public void testQueryException_returnsFalse() { contentProvider.setThrowException(true); Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, CONTACT_LOOKUP_KEY); assertFalse(mHelper.query(contactUri.toString())); } @Test public void testQueryWithUri() { mContactsCursor.addRow(new Object[] { Loading Loading @@ -168,10 +178,15 @@ public final class ContactsQueryHelperTest { private class ContactsContentProvider extends MockContentProvider { private Map<Uri, Cursor> mUriPrefixToCursorMap = new ArrayMap<>(); private boolean throwException = false; @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { if (throwException) { throw new SQLiteException(); } for (Uri prefixUri : mUriPrefixToCursorMap.keySet()) { if (uri.isPathPrefixMatch(prefixUri)) { return mUriPrefixToCursorMap.get(prefixUri); Loading @@ -180,6 +195,10 @@ public final class ContactsQueryHelperTest { return mUriPrefixToCursorMap.get(uri); } public void setThrowException(boolean throwException) { this.throwException = throwException; } private void registerCursor(Uri uriPrefix, Cursor cursor) { mUriPrefixToCursorMap.put(uriPrefix, cursor); } Loading Loading
services/people/java/com/android/server/people/data/ContactsQueryHelper.java +3 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.annotation.Nullable; import android.annotation.WorkerThread; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteException; import android.net.Uri; import android.provider.ContactsContract; import android.provider.ContactsContract.Contacts; Loading Loading @@ -149,6 +150,8 @@ class ContactsQueryHelper { found = true; } } catch (SQLiteException exception) { Slog.w("SQLite exception when querying contacts.", exception); } if (found && lookupKey != null && hasPhoneNumber) { return queryPhoneNumber(lookupKey); Loading
services/tests/servicestests/src/com/android/server/people/data/ContactsQueryHelperTest.java +20 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static org.mockito.Mockito.when; import android.database.Cursor; import android.database.MatrixCursor; import android.database.sqlite.SQLiteException; import android.net.Uri; import android.provider.ContactsContract; import android.provider.ContactsContract.Contacts; Loading Loading @@ -63,6 +64,7 @@ public final class ContactsQueryHelperTest { private MatrixCursor mContactsLookupCursor; private MatrixCursor mPhoneCursor; private ContactsQueryHelper mHelper; private ContactsContentProvider contentProvider; @Before public void setUp() { Loading @@ -73,7 +75,7 @@ public final class ContactsQueryHelperTest { mPhoneCursor = new MatrixCursor(PHONE_COLUMNS); MockContentResolver contentResolver = new MockContentResolver(); ContactsContentProvider contentProvider = new ContactsContentProvider(); contentProvider = new ContactsContentProvider(); contentProvider.registerCursor(Contacts.CONTENT_URI, mContactsCursor); contentProvider.registerCursor( ContactsContract.PhoneLookup.CONTENT_FILTER_URI, mContactsLookupCursor); Loading @@ -88,6 +90,14 @@ public final class ContactsQueryHelperTest { mHelper = new ContactsQueryHelper(mContext); } @Test public void testQueryException_returnsFalse() { contentProvider.setThrowException(true); Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, CONTACT_LOOKUP_KEY); assertFalse(mHelper.query(contactUri.toString())); } @Test public void testQueryWithUri() { mContactsCursor.addRow(new Object[] { Loading Loading @@ -168,10 +178,15 @@ public final class ContactsQueryHelperTest { private class ContactsContentProvider extends MockContentProvider { private Map<Uri, Cursor> mUriPrefixToCursorMap = new ArrayMap<>(); private boolean throwException = false; @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { if (throwException) { throw new SQLiteException(); } for (Uri prefixUri : mUriPrefixToCursorMap.keySet()) { if (uri.isPathPrefixMatch(prefixUri)) { return mUriPrefixToCursorMap.get(prefixUri); Loading @@ -180,6 +195,10 @@ public final class ContactsQueryHelperTest { return mUriPrefixToCursorMap.get(uri); } public void setThrowException(boolean throwException) { this.throwException = throwException; } private void registerCursor(Uri uriPrefix, Cursor cursor) { mUriPrefixToCursorMap.put(uriPrefix, cursor); } Loading