Skip to content

Commit

Permalink
Closes #870
Browse files Browse the repository at this point in the history
  • Loading branch information
jberkel committed Apr 9, 2018
1 parent fdb917e commit 9d23fa8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
18 changes: 12 additions & 6 deletions app/src/main/java/com/zegoggles/smssync/mail/PersonLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,19 @@ public PersonLookup(ContentResolver resolver) {
if (TextUtils.isEmpty(address)) {
return new PersonRecord(0, null, null, "-1");
} else if (!mPeopleCache.containsKey(address)) {
Uri personUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address));
final Uri personUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address));

Cursor c = null;
try {
c = mResolver.query(personUri, new String[] {
PhoneLookup._ID,
PhoneLookup.DISPLAY_NAME
}, null, null, null);
} catch (IllegalArgumentException e) {
// https://github.com/jberkel/sms-backup-plus/issues/870
Log.wtf(TAG, "avoided a crash with address: " + address, e);
}

Cursor c = mResolver.query(personUri, new String[] {
PhoneLookup._ID,
PhoneLookup.DISPLAY_NAME
}, null, null, null);
final PersonRecord record;
if (c != null && c.moveToFirst()) {
final long id = c.getLong(0);
Expand All @@ -58,7 +65,6 @@ record = new PersonRecord(
getPrimaryEmail(id),
address
);

} else {
if (LOCAL_LOGV) Log.v(TAG, "Looked up unknown address: " + address);
record = new PersonRecord(0, null, null, address);
Expand Down
10 changes: 10 additions & 0 deletions app/src/test/java/com/zegoggles/smssync/mail/PersonLookupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ public void shouldLookupExistingPersonUsingGmailAsPrimaryEmail() throws Exceptio
assertThat(record.getEmail()).isEqualTo("foo@gmail.com");
}

@Test
public void shouldIgnoreIllegalArgumentException() {
// https://github.com/jberkel/sms-backup-plus/issues/870
when(resolver.query(any(Uri.class), any(String[].class), (String) isNull(), (String[]) isNull(), (String) isNull()))
.thenThrow(new IllegalArgumentException("column 'data1' does not exist"));

PersonRecord record = lookup.lookupPerson("1234");
assertThat(record.isUnknown()).isTrue();
}

private Cursor name(String... names) {
MatrixCursor cursor = new MatrixCursor(new String[] {
ContactsContract.Contacts._ID,
Expand Down

0 comments on commit 9d23fa8

Please sign in to comment.