summaryrefslogtreecommitdiff
path: root/InCallUI/src/com/android
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2015-05-11 10:05:02 -0700
committerYorke Lee <yorkelee@google.com>2015-05-11 17:46:02 -0700
commit5795518d822b644c4e0c9efdba512ff1f7c04aed (patch)
tree9411edd28ce632fbec64f9016719e61356c275e7 /InCallUI/src/com/android
parent23d95f348445a4091fba5f466e21438efe67f2c1 (diff)
Save CNAP in call history
If the call contains necessary CNAP information, try to save it into the CachedNumberLookupService. Bug: 10121624 Change-Id: I2e842b3145e00618b1afd3ed661d7c40764d0536
Diffstat (limited to 'InCallUI/src/com/android')
-rw-r--r--InCallUI/src/com/android/incallui/CallCardPresenter.java3
-rw-r--r--InCallUI/src/com/android/incallui/CallerInfoUtils.java4
-rw-r--r--InCallUI/src/com/android/incallui/ContactInfoCache.java50
3 files changed, 53 insertions, 4 deletions
diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java
index b233ad56b..583173fc0 100644
--- a/InCallUI/src/com/android/incallui/CallCardPresenter.java
+++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java
@@ -34,10 +34,8 @@ import android.telecom.StatusHints;
import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
import android.telephony.PhoneNumberUtils;
-import android.telephony.TelephonyManager;
import android.text.TextUtils;
-import com.android.incallui.CircularRevealFragment.OnCircularRevealCompleteListener;
import com.android.incallui.ContactInfoCache.ContactCacheEntry;
import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback;
import com.android.incallui.InCallPresenter.InCallDetailsListener;
@@ -48,7 +46,6 @@ import com.android.incallui.InCallPresenter.IncomingCallListener;
import com.android.incalluibind.ObjectFactory;
import java.lang.ref.WeakReference;
-import java.util.Objects;
import com.google.common.base.Preconditions;
diff --git a/InCallUI/src/com/android/incallui/CallerInfoUtils.java b/InCallUI/src/com/android/incallui/CallerInfoUtils.java
index 5693db092..21e492b7f 100644
--- a/InCallUI/src/com/android/incallui/CallerInfoUtils.java
+++ b/InCallUI/src/com/android/incallui/CallerInfoUtils.java
@@ -6,7 +6,6 @@ import android.content.Loader.OnLoadCompleteListener;
import android.net.Uri;
import android.telecom.PhoneAccount;
import android.telecom.TelecomManager;
-import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.util.Log;
@@ -81,6 +80,9 @@ public class CallerInfoUtils {
info.markAsVoiceMail(context);
}
+ ContactInfoCache.getInstance(context).maybeInsertCnapInformationIntoCache(context, call,
+ info);
+
return info;
}
diff --git a/InCallUI/src/com/android/incallui/ContactInfoCache.java b/InCallUI/src/com/android/incallui/ContactInfoCache.java
index 27bf5a8f6..73209742b 100644
--- a/InCallUI/src/com/android/incallui/ContactInfoCache.java
+++ b/InCallUI/src/com/android/incallui/ContactInfoCache.java
@@ -21,16 +21,26 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Looper;
+import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
+import android.provider.ContactsContract.DisplayNameSources;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.telecom.TelecomManager;
import android.text.TextUtils;
import com.android.contacts.common.util.PhoneNumberHelper;
+import com.android.dialer.calllog.ContactInfo;
+import com.android.dialer.service.CachedNumberLookupService;
+import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo;
import com.android.incallui.service.PhoneNumberService;
import com.android.incalluibind.ObjectFactory;
import com.android.services.telephony.common.MoreStrings;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.base.Objects;
@@ -52,6 +62,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
private final Context mContext;
private final PhoneNumberService mPhoneNumberService;
+ private final CachedNumberLookupService mCachedNumberLookupService;
private final HashMap<String, ContactCacheEntry> mInfoMap = Maps.newHashMap();
private final HashMap<String, Set<ContactInfoCacheCallback>> mCallBacks = Maps.newHashMap();
@@ -70,6 +81,8 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
private ContactInfoCache(Context context) {
mContext = context;
mPhoneNumberService = ObjectFactory.newPhoneNumberService(context);
+ mCachedNumberLookupService =
+ com.android.dialerbind.ObjectFactory.newCachedNumberLookupService();
}
public ContactCacheEntry getInfo(String callId) {
@@ -87,6 +100,43 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
return entry;
}
+ 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();
+ }
+
private class FindInfoCallback implements CallerInfoAsyncQuery.OnQueryCompleteListener {
private final boolean mIsIncoming;