Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a9bc7bd authored by Jeff Nainaparampil's avatar Jeff Nainaparampil Committed by Automerger Merge Worker
Browse files

Merge "[People Service] Catch potential `IllegalArgumentException` in the...

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

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



Change-Id: I5d1ff63ad7a42b99ac71b4b5a618e30c9e42be57
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 4db618cd e64cab5d
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -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);
+22 −6
Original line number Original line Diff line number Diff line
@@ -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) {