Don't query contacts DB if we have nothing to query

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-08-04 09:28:20 -07:00
parent 8de9261081
commit c5a7d320f7

View File

@ -23,6 +23,7 @@ import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.PhoneLookup; import android.provider.ContactsContract.PhoneLookup;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
@ -134,7 +135,7 @@ class RecipientProvider {
Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(new Address[]{address}); Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(new Address[]{address});
MaterialColor color = preferences.isPresent() ? preferences.get().getColor() : null; MaterialColor color = preferences.isPresent() ? preferences.get().getColor() : null;
if (address.isPhone()) { if (address.isPhone() && !TextUtils.isEmpty(address.toPhoneString())) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address.toPhoneString())); Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address.toPhoneString()));
Cursor cursor = context.getContentResolver().query(uri, CALLER_ID_PROJECTION, null, null, null); Cursor cursor = context.getContentResolver().query(uri, CALLER_ID_PROJECTION, null, null, null);