Merge "[People Service] Catch potential IllegalArgumentException in the event of a malformed contacts URI" into tm-qpr-dev am: a4845f10cf

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21893943

Change-Id: I431121c6336adeedbe52a68ad031267bef9d7414
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jeff Nainaparampil
2023-03-08 18:17:14 +00:00
committed by Automerger Merge Worker
2 changed files with 24 additions and 6 deletions

View File

@@ -152,6 +152,8 @@ class ContactsQueryHelper {
} }
} catch (SQLiteException exception) { } catch (SQLiteException exception) {
Slog.w("SQLite exception when querying contacts.", exception); Slog.w("SQLite exception when querying contacts.", exception);
} catch (IllegalArgumentException exception) {
Slog.w("Illegal Argument exception when querying contacts.", exception);
} }
if (found && lookupKey != null && hasPhoneNumber) { if (found && lookupKey != null && hasPhoneNumber) {
return queryPhoneNumber(lookupKey); return queryPhoneNumber(lookupKey);

View File

@@ -91,8 +91,16 @@ public final class ContactsQueryHelperTest {
} }
@Test @Test
public void testQueryException_returnsFalse() { public void testQuerySQLiteException_returnsFalse() {
contentProvider.setThrowException(true); contentProvider.setThrowSQLiteException(true);
Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, CONTACT_LOOKUP_KEY);
assertFalse(mHelper.query(contactUri.toString()));
}
@Test
public void testQueryIllegalArgumentException_returnsFalse() {
contentProvider.setThrowIllegalArgumentException(true);
Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, CONTACT_LOOKUP_KEY); Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, CONTACT_LOOKUP_KEY);
assertFalse(mHelper.query(contactUri.toString())); assertFalse(mHelper.query(contactUri.toString()));
@@ -178,14 +186,18 @@ public final class ContactsQueryHelperTest {
private class ContactsContentProvider extends MockContentProvider { private class ContactsContentProvider extends MockContentProvider {
private Map<Uri, Cursor> mUriPrefixToCursorMap = new ArrayMap<>(); private Map<Uri, Cursor> mUriPrefixToCursorMap = new ArrayMap<>();
private boolean throwException = false; private boolean mThrowSQLiteException = false;
private boolean mThrowIllegalArgumentException = false;
@Override @Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) { String sortOrder) {
if (throwException) { if (mThrowSQLiteException) {
throw new SQLiteException(); throw new SQLiteException();
} }
if (mThrowIllegalArgumentException) {
throw new IllegalArgumentException();
}
for (Uri prefixUri : mUriPrefixToCursorMap.keySet()) { for (Uri prefixUri : mUriPrefixToCursorMap.keySet()) {
if (uri.isPathPrefixMatch(prefixUri)) { if (uri.isPathPrefixMatch(prefixUri)) {
@@ -195,8 +207,12 @@ public final class ContactsQueryHelperTest {
return mUriPrefixToCursorMap.get(uri); return mUriPrefixToCursorMap.get(uri);
} }
public void setThrowException(boolean throwException) { public void setThrowSQLiteException(boolean throwException) {
this.throwException = throwException; this.mThrowSQLiteException = throwException;
}
public void setThrowIllegalArgumentException(boolean throwException) {
this.mThrowIllegalArgumentException = throwException;
} }
private void registerCursor(Uri uriPrefix, Cursor cursor) { private void registerCursor(Uri uriPrefix, Cursor cursor) {