diff options
author | Victor Chang <vichang@google.com> | 2015-12-09 13:03:46 +0000 |
---|---|---|
committer | Victor Chang <vichang@google.com> | 2015-12-23 13:20:53 +0800 |
commit | afd80e27c95eb3a0fe9efdef42053071bc105e39 (patch) | |
tree | 7a615b44dc24529b1175cb27fc303a47e29244a4 | |
parent | 898b046bd6aa1ffdd5ef602f4dfdd55c74c2bbd7 (diff) |
Support Work Directory lookup for calllog in dialer
1. To follow Google Caller id behavior in call log,
only find display name in cache, but not actively querying directory
2. To following cache behavior in search bar,
cache direcetory result in ObjectFactory.newCachedNumberLookupService()
Test:
Display name of directory contact is shown in call log if any of the below
1. the directory contact has ever been selected in search bar result
2. the directory contact has ever been called
BUG=25967633,25968895
Change-Id: I6f317bfd161c9abb0b7c6ccc2df2bd27af8ef5d3
-rw-r--r-- | InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java | 49 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/CallerInfoUtils.java | 27 |
2 files changed, 68 insertions, 8 deletions
diff --git a/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java b/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java index bf254c605..9080484ed 100644 --- a/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java +++ b/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java @@ -36,6 +36,9 @@ import android.text.TextUtils; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.util.TelephonyManagerUtils; import com.android.dialer.calllog.ContactInfoHelper; +import com.android.dialer.service.CachedNumberLookupService; +import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo; +import com.android.dialerbind.ObjectFactory; import java.util.ArrayList; import java.util.Arrays; @@ -415,8 +418,8 @@ public class CallerInfoAsyncQuery { return; } - OnQueryCompleteListener intermediateListener = - new DirectoryQueryCompleteListener(size, listener); + DirectoryQueryCompleteListenerFactory listenerFactory = + new DirectoryQueryCompleteListenerFactory(context, size, listener); // The current implementation of multiple async query runs in single handler thread // in AsyncQueryHandler. @@ -428,6 +431,8 @@ public class CallerInfoAsyncQuery { if (DBG) { Log.d(LOG_TAG, "directoryId: " + directoryId + " uri: " + uri); } + OnQueryCompleteListener intermediateListener = + listenerFactory.newListener(directoryId); startQueryInternal(token, context, info, intermediateListener, cookie, uri); } } @@ -465,19 +470,44 @@ public class CallerInfoAsyncQuery { } } - private static final class DirectoryQueryCompleteListener implements OnQueryCompleteListener { + private static final class DirectoryQueryCompleteListenerFactory { + // Make sure listener to be called once and only once int mCount; boolean mIsListenerCalled; OnQueryCompleteListener mListener; + Context mContext; + CachedNumberLookupService mCachedNumberLookupService = + ObjectFactory.newCachedNumberLookupService(); - DirectoryQueryCompleteListener(int size, OnQueryCompleteListener listener) { + private class DirectoryQueryCompleteListener implements OnQueryCompleteListener { + long mDirectoryId; + + DirectoryQueryCompleteListener(long directoryId) { + mDirectoryId = directoryId; + } + + @Override + public void onQueryComplete(int token, Object cookie, CallerInfo ci) { + if (ci.contactExists && mCachedNumberLookupService != null) { + CachedContactInfo cachedContactInfo = + CallerInfoUtils.buildCachedContactInfo(mCachedNumberLookupService, ci); + String directoryLabel = mContext.getString(R.string.directory_search_label); + cachedContactInfo.setDirectorySource(directoryLabel, mDirectoryId); + mCachedNumberLookupService.addContact(mContext, cachedContactInfo); + } + + callListenerIfNecessary(token, cookie, ci); + } + } + + DirectoryQueryCompleteListenerFactory(Context context, int size, OnQueryCompleteListener listener) { mCount = size; mListener = listener; mIsListenerCalled = false; + mContext = context; } - @Override - public void onQueryComplete(int token, Object cookie, CallerInfo ci) { + private void callListenerIfNecessary(int token, Object cookie, CallerInfo ci) { boolean shouldCallListener = false; synchronized (this) { mCount = mCount - 1; @@ -486,11 +516,14 @@ public class CallerInfoAsyncQuery { shouldCallListener = true; } } - - if (shouldCallListener) { + if (shouldCallListener && mListener != null) { mListener.onQueryComplete(token, cookie, ci); } } + + public OnQueryCompleteListener newListener(long directoryId) { + return new DirectoryQueryCompleteListener(directoryId); + } } /* Directory lookup related code - END */ diff --git a/InCallUI/src/com/android/incallui/CallerInfoUtils.java b/InCallUI/src/com/android/incallui/CallerInfoUtils.java index 095f995ca..434164ec2 100644 --- a/InCallUI/src/com/android/incallui/CallerInfoUtils.java +++ b/InCallUI/src/com/android/incallui/CallerInfoUtils.java @@ -11,7 +11,10 @@ import android.util.Log; import com.android.contacts.common.model.Contact; import com.android.contacts.common.model.ContactLoader; +import com.android.dialer.calllog.ContactInfo; import com.android.dialer.compat.telecom.TelecomManagerCompat; +import com.android.dialer.service.CachedNumberLookupService; +import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo; import java.util.Arrays; @@ -87,6 +90,30 @@ public class CallerInfoUtils { return info; } + /** + * 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; + + CachedContactInfo cacheInfo = lookupService.buildCachedContactInfo(info); + cacheInfo.setLookupKey(ci.lookupKeyOrNull); + return cacheInfo; + } + public static boolean isVoiceMailNumber(Context context, Call call) { return TelecomManagerCompat.isVoiceMailNumber( (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE), |