diff options
Diffstat (limited to 'src/com/android/dialer')
6 files changed, 53 insertions, 102 deletions
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index ae20e4943..3dccf27bb 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -16,20 +16,18 @@ package com.android.dialer.calllog; -import com.google.common.annotations.VisibleForTesting; - import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; import android.database.Cursor; import android.net.Uri; +import android.provider.ContactsContract.CommonDataKinds.Phone; +import android.support.v7.widget.RecyclerView; import android.os.Bundle; import android.os.Trace; import android.preference.PreferenceManager; import android.provider.CallLog; -import android.provider.ContactsContract.CommonDataKinds.Phone; -import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.ViewHolder; import android.telecom.PhoneAccountHandle; import android.telephony.PhoneNumberUtils; @@ -41,7 +39,6 @@ import android.view.View.AccessibilityDelegate; import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; -import com.android.contacts.common.preference.ContactsPreferences; import com.android.contacts.common.util.PermissionsUtil; import com.android.dialer.PhoneCallDetails; import com.android.dialer.R; @@ -54,6 +51,8 @@ import com.android.dialer.filterednumber.FilterNumberDialogFragment; import com.android.dialer.util.PhoneNumberUtil; import com.android.dialer.voicemail.VoicemailPlaybackPresenter; +import com.google.common.annotations.VisibleForTesting; + import java.util.HashMap; import java.util.Map; @@ -119,14 +118,12 @@ public class CallLogAdapter extends GroupingListAdapter * its day group. This hashmap provides a means of determining the previous day group without * having to reverse the cursor to the start of the previous day call log entry. */ - private HashMap<Long, Integer> mDayGroups = new HashMap<>(); + private HashMap<Long,Integer> mDayGroups = new HashMap<Long, Integer>(); private boolean mLoading = true; private SharedPreferences mPrefs; - private ContactsPreferences mContactsPreferences; - protected boolean mShowVoicemailPromoCard = false; /** Instance of helper class for managing views. */ @@ -257,7 +254,7 @@ public class CallLogAdapter extends GroupingListAdapter CallTypeHelper callTypeHelper = new CallTypeHelper(resources); mTelecomCallLogCache = new TelecomCallLogCache(mContext); - mBlockedIdCache = new HashMap<>(); + mBlockedIdCache = new HashMap<NumberWithCountryIso, Integer>(); PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper(mContext, resources, mTelecomCallLogCache); mCallLogListItemHelper = @@ -267,7 +264,6 @@ public class CallLogAdapter extends GroupingListAdapter new FilteredNumberAsyncQueryHandler(mContext.getContentResolver()); mPrefs = PreferenceManager.getDefaultSharedPreferences(context); - mContactsPreferences = new ContactsPreferences(mContext); maybeShowVoicemailPromoCard(); } @@ -315,7 +311,6 @@ public class CallLogAdapter extends GroupingListAdapter if (PermissionsUtil.hasPermission(mContext, android.Manifest.permission.READ_CONTACTS)) { mContactInfoCache.start(); } - mContactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY); } public void onPause() { @@ -465,10 +460,9 @@ public class CallLogAdapter extends GroupingListAdapter details.dataUsage = c.getLong(CallLogQuery.DATA_USAGE); } - String preferredName = getPreferredDisplayName(info); - if (!TextUtils.isEmpty(preferredName)) { + if (!TextUtils.isEmpty(info.name)) { details.contactUri = info.lookupUri; - details.name = preferredName; + details.name = info.name; details.numberType = info.type; details.numberLabel = info.label; details.photoUri = info.photoUri; @@ -538,14 +532,6 @@ public class CallLogAdapter extends GroupingListAdapter mCallLogListItemHelper.setPhoneCallDetails(views, details); } - private String getPreferredDisplayName(ContactInfo contactInfo) { - if (mContactsPreferences.getDisplayOrder() == ContactsPreferences.DISPLAY_ORDER_PRIMARY || - TextUtils.isEmpty(contactInfo.nameAlternative)) { - return contactInfo.name; - } - return contactInfo.nameAlternative; - } - @Override public int getItemCount() { return super.getItemCount() + (mShowVoicemailPromoCard ? 1 : 0) diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java index f84ffd5da..369730d96 100644 --- a/src/com/android/dialer/calllog/CallLogFragment.java +++ b/src/com/android/dialer/calllog/CallLogFragment.java @@ -33,8 +33,8 @@ import android.provider.CallLog; import android.provider.CallLog.Calls; import android.provider.ContactsContract; import android.provider.VoicemailContract.Status; -import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.LinearLayoutManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -309,6 +309,7 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis mVoicemailPlaybackPresenter, mIsCallLogActivity); mRecyclerView.setAdapter(mAdapter); + fetchCalls(); return view; } diff --git a/src/com/android/dialer/calllog/ContactInfo.java b/src/com/android/dialer/calllog/ContactInfo.java index 30f60d9d3..357c832cf 100644 --- a/src/com/android/dialer/calllog/ContactInfo.java +++ b/src/com/android/dialer/calllog/ContactInfo.java @@ -34,7 +34,6 @@ public class ContactInfo { */ public String lookupKey; public String name; - public String nameAlternative; public int type; public String label; public String number; @@ -71,7 +70,6 @@ public class ContactInfo { ContactInfo other = (ContactInfo) obj; if (!UriUtils.areEqual(lookupUri, other.lookupUri)) return false; if (!TextUtils.equals(name, other.name)) return false; - if (!TextUtils.equals(nameAlternative, other.nameAlternative)) return false; if (type != other.type) return false; if (!TextUtils.equals(label, other.label)) return false; if (!TextUtils.equals(number, other.number)) return false; @@ -85,11 +83,9 @@ public class ContactInfo { @Override public String toString() { - return Objects.toStringHelper(this).add("lookupUri", lookupUri).add("name", name) - .add("nameAlternative", nameAlternative) - .add("type", type).add("label", label) - .add("number", number).add("formattedNumber",formattedNumber) - .add("normalizedNumber", normalizedNumber).add("photoId", photoId) + return Objects.toStringHelper(this).add("lookupUri", lookupUri).add("name", name).add( + "type", type).add("label", label).add("number", number).add("formattedNumber", + formattedNumber).add("normalizedNumber", normalizedNumber).add("photoId", photoId) .add("photoUri", photoUri).add("objectId", objectId).toString(); } } diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java index 4b9d5532a..2f97bc569 100644 --- a/src/com/android/dialer/calllog/ContactInfoHelper.java +++ b/src/com/android/dialer/calllog/ContactInfoHelper.java @@ -41,6 +41,8 @@ import com.android.dialerbind.ObjectFactory; import org.json.JSONException; import org.json.JSONObject; +import java.util.List; + /** * Utility class to look up the contact information for a given number. */ @@ -149,70 +151,47 @@ public class ContactInfoHelper { * The {@link ContactInfo#formattedNumber} field is always set to {@code null} in the returned * value. */ - public ContactInfo lookupContactFromUri(Uri uri) { + private ContactInfo lookupContactFromUri(Uri uri) { if (uri == null) { return null; } if (!PermissionsUtil.hasContactsPermissions(mContext)) { return ContactInfo.EMPTY; } - - Cursor phoneLookupCursor = mContext.getContentResolver().query(uri, - PhoneQuery.PHONE_LOOKUP_PROJECTION, null, null, null); - - if (phoneLookupCursor == null) { - return null; - } - - try { - if (!phoneLookupCursor.moveToFirst()) { - return ContactInfo.EMPTY; + final ContactInfo info; + Cursor phonesCursor = + mContext.getContentResolver().query(uri, PhoneQuery._PROJECTION, null, null, null); + + if (phonesCursor != null) { + try { + if (phonesCursor.moveToFirst()) { + info = new ContactInfo(); + long contactId = phonesCursor.getLong(PhoneQuery.PERSON_ID); + String lookupKey = phonesCursor.getString(PhoneQuery.LOOKUP_KEY); + info.lookupKey = lookupKey; + info.lookupUri = Contacts.getLookupUri(contactId, lookupKey); + info.name = phonesCursor.getString(PhoneQuery.NAME); + info.type = phonesCursor.getInt(PhoneQuery.PHONE_TYPE); + info.label = phonesCursor.getString(PhoneQuery.LABEL); + info.number = phonesCursor.getString(PhoneQuery.MATCHED_NUMBER); + info.normalizedNumber = phonesCursor.getString(PhoneQuery.NORMALIZED_NUMBER); + info.photoId = phonesCursor.getLong(PhoneQuery.PHOTO_ID); + info.photoUri = + UriUtils.parseUriOrNull(phonesCursor.getString(PhoneQuery.PHOTO_URI)); + info.formattedNumber = null; + } else { + info = ContactInfo.EMPTY; + } + } finally { + phonesCursor.close(); } - String lookupKey = phoneLookupCursor.getString(PhoneQuery.LOOKUP_KEY); - ContactInfo contactInfo = createPhoneLookupContactInfo(phoneLookupCursor, lookupKey); - contactInfo.nameAlternative = lookUpDisplayNameAlternative(lookupKey); - return contactInfo; - } finally { - phoneLookupCursor.close(); + } else { + // Failed to fetch the data, ignore this request. + info = null; } - } - - private ContactInfo createPhoneLookupContactInfo(Cursor phoneLookupCursor, String lookupKey) { - ContactInfo info = new ContactInfo(); - info.lookupKey = lookupKey; - info.lookupUri = Contacts.getLookupUri(phoneLookupCursor.getLong(PhoneQuery.PERSON_ID), - lookupKey); - info.name = phoneLookupCursor.getString(PhoneQuery.NAME); - info.type = phoneLookupCursor.getInt(PhoneQuery.PHONE_TYPE); - info.label = phoneLookupCursor.getString(PhoneQuery.LABEL); - info.number = phoneLookupCursor.getString(PhoneQuery.MATCHED_NUMBER); - info.normalizedNumber = phoneLookupCursor.getString(PhoneQuery.NORMALIZED_NUMBER); - info.photoId = phoneLookupCursor.getLong(PhoneQuery.PHOTO_ID); - info.photoUri = UriUtils.parseUriOrNull(phoneLookupCursor.getString(PhoneQuery.PHOTO_URI)); - info.formattedNumber = null; return info; } - private String lookUpDisplayNameAlternative(String lookupKey) { - Uri uri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey); - - Cursor cursor = mContext.getContentResolver().query(uri, - PhoneQuery.DISPLAY_NAME_ALTERNATIVE_PROJECTION, null, null, null); - - if (cursor == null) { - return null; - } - - try { - if (!cursor.moveToFirst()) { - return null; - } - return cursor.getString(PhoneQuery.NAME_ALTERNATIVE); - } finally { - cursor.close(); - } - } - /** * Determines the contact information for the given phone number. * <p> @@ -388,6 +367,7 @@ public class ContactInfoHelper { */ public static ContactInfo getContactInfo(Cursor c) { ContactInfo info = new ContactInfo(); + info.lookupUri = UriUtils.parseUriOrNull(c.getString(CallLogQuery.CACHED_LOOKUP_URI)); info.name = c.getString(CallLogQuery.CACHED_NAME); info.type = c.getInt(CallLogQuery.CACHED_NUMBER_TYPE); @@ -426,4 +406,6 @@ public class ContactInfoHelper { return mCachedNumberLookupService != null && mCachedNumberLookupService.canReportAsInvalid(sourceType, objectId); } + + } diff --git a/src/com/android/dialer/calllog/PhoneQuery.java b/src/com/android/dialer/calllog/PhoneQuery.java index 200b5e1f4..719052204 100644 --- a/src/com/android/dialer/calllog/PhoneQuery.java +++ b/src/com/android/dialer/calllog/PhoneQuery.java @@ -16,19 +16,13 @@ package com.android.dialer.calllog; -import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.PhoneLookup; /** - * The queries to look up the {@link ContactInfo} for a given number in the Call Log. + * The query to look up the {@link ContactInfo} for a given number in the Call Log. */ final class PhoneQuery { - - /** - * Projection to look up the ContactInfo. Does not include DISPLAY_NAME_ALTERNATIVE as that - * column isn't available in ContactsCommon.PhoneLookup - */ - public static final String[] PHONE_LOOKUP_PROJECTION = new String[] { + public static final String[] _PROJECTION = new String[] { PhoneLookup._ID, PhoneLookup.DISPLAY_NAME, PhoneLookup.TYPE, @@ -48,13 +42,4 @@ final class PhoneQuery { public static final int PHOTO_ID = 6; public static final int LOOKUP_KEY = 7; public static final int PHOTO_URI = 8; - - /** - * Projection to look up a contact's DISPLAY_NAME_ALTERNATIVE - */ - public static final String[] DISPLAY_NAME_ALTERNATIVE_PROJECTION = new String[] { - Contacts.DISPLAY_NAME_ALTERNATIVE, - }; - - public static final int NAME_ALTERNATIVE = 0; } diff --git a/src/com/android/dialer/contactinfo/ContactInfoCache.java b/src/com/android/dialer/contactinfo/ContactInfoCache.java index 1e2457957..568f48886 100644 --- a/src/com/android/dialer/contactinfo/ContactInfoCache.java +++ b/src/com/android/dialer/contactinfo/ContactInfoCache.java @@ -162,7 +162,7 @@ public class ContactInfoCache { // The contact info is no longer up to date, we should request it. However, we // do not need to request them immediately. enqueueRequest(number, countryIso, cachedContactInfo, false); - } else if (!callLogInfoMatches(cachedContactInfo, info)) { + } else if (!callLogInfoMatches(cachedContactInfo, info)) { // The call log information does not match the one we have, look it up again. // We could simply update the call log directly, but that needs to be done in a // background thread, so it is easier to simply request a new lookup, which will, as @@ -309,7 +309,8 @@ public class ContactInfoCache { * Checks whether the contact info from the call log matches the one from the contacts db. */ private boolean callLogInfoMatches(ContactInfo callLogInfo, ContactInfo info) { - // The call log only contains a subset of the fields in the contacts db. Only check those. + // The call log only contains a subset of the fields in the contacts db. + // Only check those. return TextUtils.equals(callLogInfo.name, info.name) && callLogInfo.type == info.type && TextUtils.equals(callLogInfo.label, info.label); |