use of com.android.dialer.service.CachedNumberLookupService.CachedContactInfo in project android_packages_apps_Dialer by MoKee.
the class ContactInfoHelper method queryContactInfoForPhoneNumber.
/**
* Determines the contact information for the given phone number.
* <p>
* It returns the contact info if found.
* <p>
* If no contact corresponds to the given phone number, returns {@link ContactInfo#EMPTY}.
* <p>
* If the lookup fails for some other reason, it returns null.
*/
private ContactInfo queryContactInfoForPhoneNumber(String number, String postDialString, String countryIso, boolean isSip, boolean isConfUrlLog) {
if (TextUtils.isEmpty(number)) {
return null;
}
ContactInfo info = lookupContactFromUri(getContactInfoLookupUri(number), isSip);
if (isConfUrlLog) {
Pattern pattern = Pattern.compile("[,;]");
String[] nums = pattern.split(number);
if (nums != null && nums.length > 1) {
if (info == null || info == ContactInfo.EMPTY) {
info = new ContactInfo();
info.number = number;
info.formattedNumber = formatPhoneNumber(number, null, countryIso);
info.lookupUri = createTemporaryContactUri(info.formattedNumber);
info.normalizedNumber = PhoneNumberUtils.formatNumberToE164(number, countryIso);
}
String combName = "";
for (String num : nums) {
ContactInfo singleCi = lookupContactFromUri(getContactInfoLookupUri(num), isSip);
// If contact does not exist, need to avoid changing static empty-contact.
if (singleCi == ContactInfo.EMPTY) {
singleCi = new ContactInfo();
}
if (TextUtils.isEmpty(singleCi.name)) {
singleCi.name = formatPhoneNumber(num, null, countryIso);
}
combName += singleCi.name + ";";
}
if (!TextUtils.isEmpty(combName) && combName.length() > 1) {
info.name = combName.substring(0, combName.length() - 1);
}
}
}
if (info != null && info != ContactInfo.EMPTY) {
if (!isConfUrlLog && TextUtils.isEmpty(postDialString)) {
number += postDialString;
}
info.formattedNumber = formatPhoneNumber(number, null, countryIso);
} else if (LookupCache.hasCachedContact(mContext, number)) {
info = LookupCache.getCachedContact(mContext, number);
} else if (mCachedNumberLookupService != null) {
CachedContactInfo cacheInfo = mCachedNumberLookupService.lookupCachedContactFromNumber(mContext, number);
if (cacheInfo != null) {
info = cacheInfo.getContactInfo().isBadData ? null : cacheInfo.getContactInfo();
} else {
info = null;
}
}
return info;
}
use of com.android.dialer.service.CachedNumberLookupService.CachedContactInfo in project android_packages_apps_Dialer by MoKee.
the class CallerInfoUtils method buildCachedContactInfo.
/**
* Creates a new {@link CachedContactInfo} from a {@link CallerInfo}
*
* @param lookupService the {@link CachedNumberLookupService} used to build a
* new {@link CachedContactInfo}
* @param {@link CallerInfo} object
* @return a CachedContactInfo object created from this CallerInfo
* @throws NullPointerException if lookupService or ci are null
*/
public static CachedContactInfo buildCachedContactInfo(CachedNumberLookupService lookupService, CallerInfo ci) {
ContactInfo info = new ContactInfo();
info.name = ci.name;
info.type = ci.numberType;
info.label = ci.phoneLabel;
info.number = ci.phoneNumber;
info.normalizedNumber = ci.normalizedNumber;
info.photoUri = ci.contactDisplayPhotoUri;
info.userType = ci.userType;
CachedContactInfo cacheInfo = lookupService.buildCachedContactInfo(info);
cacheInfo.setLookupKey(ci.lookupKeyOrNull);
return cacheInfo;
}
use of com.android.dialer.service.CachedNumberLookupService.CachedContactInfo in project android_packages_apps_Dialer by MoKee.
the class ContactInfoCache method maybeInsertCnapInformationIntoCache.
public void maybeInsertCnapInformationIntoCache(Context context, final Call call, final CallerInfo info) {
if (mCachedNumberLookupService == null || TextUtils.isEmpty(info.cnapName) || mInfoMap.get(call.getId()) != null) {
return;
}
final Context applicationContext = context.getApplicationContext();
Log.i(TAG, "Found contact with CNAP name - inserting into cache");
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ContactInfo contactInfo = new ContactInfo();
CachedContactInfo cacheInfo = mCachedNumberLookupService.buildCachedContactInfo(contactInfo);
cacheInfo.setSource(CachedContactInfo.SOURCE_TYPE_CNAP, "CNAP", 0);
contactInfo.name = info.cnapName;
contactInfo.number = call.getNumber();
contactInfo.type = ContactsContract.CommonDataKinds.Phone.TYPE_MAIN;
try {
final JSONObject contactRows = new JSONObject().put(Phone.CONTENT_ITEM_TYPE, new JSONObject().put(Phone.NUMBER, contactInfo.number).put(Phone.TYPE, Phone.TYPE_MAIN));
final String jsonString = new JSONObject().put(Contacts.DISPLAY_NAME, contactInfo.name).put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.STRUCTURED_NAME).put(Contacts.CONTENT_ITEM_TYPE, contactRows).toString();
cacheInfo.setLookupKey(jsonString);
} catch (JSONException e) {
Log.w(TAG, "Creation of lookup key failed when caching CNAP information");
}
mCachedNumberLookupService.addContact(applicationContext, cacheInfo);
return null;
}
}.execute();
}
use of com.android.dialer.service.CachedNumberLookupService.CachedContactInfo in project android_packages_apps_Dialer by MoKee.
the class RegularSearchListAdapter method getContactInfo.
public CachedContactInfo getContactInfo(CachedNumberLookupService lookupService, int position) {
ContactInfo info = new ContactInfo();
CachedContactInfo cacheInfo = lookupService.buildCachedContactInfo(info);
final Cursor item = (Cursor) getItem(position);
if (item != null) {
final DirectoryPartition partition = (DirectoryPartition) getPartition(getPartitionForPosition(position));
final long directoryId = partition.getDirectoryId();
final boolean isExtendedDirectory = isExtendedDirectory(directoryId);
info.name = item.getString(PhoneQuery.DISPLAY_NAME);
info.type = item.getInt(PhoneQuery.PHONE_TYPE);
info.label = item.getString(PhoneQuery.PHONE_LABEL);
info.number = item.getString(PhoneQuery.PHONE_NUMBER);
final String photoUriStr = item.getString(PhoneQuery.PHOTO_URI);
info.photoUri = photoUriStr == null ? null : Uri.parse(photoUriStr);
/*
* An extended directory is custom directory in the app, but not a directory provided by
* framework. So it can't be USER_TYPE_WORK.
*
* When a search result is selected, RegularSearchFragment calls getContactInfo and
* cache the resulting @{link ContactInfo} into local db. Set usertype to USER_TYPE_WORK
* only if it's NOT extended directory id and is enterprise directory.
*/
info.userType = !isExtendedDirectory && DirectoryCompat.isEnterpriseDirectoryId(directoryId) ? ContactsUtils.USER_TYPE_WORK : ContactsUtils.USER_TYPE_CURRENT;
cacheInfo.setLookupKey(item.getString(PhoneQuery.LOOKUP_KEY));
final String sourceName = partition.getLabel();
if (isExtendedDirectory) {
cacheInfo.setExtendedSource(sourceName, directoryId);
} else {
cacheInfo.setDirectorySource(sourceName, directoryId);
}
}
return cacheInfo;
}
Aggregations