summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2015-05-12 23:18:41 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-05-12 23:18:41 +0000
commit9b0faa6cc03a8e05d6ee6ba63f2abb5d4ea00a75 (patch)
tree613c14c6b2918c90abab425ad79bc812dc08aa69
parente18cf75419d439d629f598ab3ce8e1b594983a9b (diff)
parent4309a7d0dd1c08d48e703849001cc109be0e95d1 (diff)
am 57c4b61e: Merge "Save CNAP in call history" into mnc-dev
* commit '57c4b61e14bd07b05fcf75f7180efc0549e5d21a': Save CNAP in call history
-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 5d62b5cd0..8e616aefe 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;