Show work badge icon/description in InCallUI/Dialer

Add work badge icon in calllog for work contacts

To see this feature
1. Receive/Make a call from work contact
   (a contact in work profile has the phone number)
2. Drop/miss the call. See a badge icon next to phone label in calllog
BUG=26082618

Change-Id: I7371795e3c3ef925739096f39a70f03722dd430b
diff --git a/res/layout/call_log_list_item.xml b/res/layout/call_log_list_item.xml
index 95de268..469e72a 100644
--- a/res/layout/call_log_list_item.xml
+++ b/res/layout/call_log_list_item.xml
@@ -101,6 +101,14 @@
                             android:layout_marginEnd="@dimen/call_log_icon_margin"
                             android:layout_gravity="center_vertical" />
 
+                        <ImageView android:id="@+id/work_profile_icon"
+                            android:src="@drawable/ic_work_profile"
+                            android:layout_width="wrap_content"
+                            android:layout_height="wrap_content"
+                            android:layout_marginEnd="@dimen/call_log_icon_margin"
+                            android:scaleType="center"
+                            android:visibility="gone" />
+
                         <TextView
                             android:id="@+id/call_location_and_date"
                             android:layout_width="wrap_content"
diff --git a/src/com/android/dialer/PhoneCallDetails.java b/src/com/android/dialer/PhoneCallDetails.java
index 71aa26d..b332b43 100644
--- a/src/com/android/dialer/PhoneCallDetails.java
+++ b/src/com/android/dialer/PhoneCallDetails.java
@@ -16,6 +16,7 @@
 
 package com.android.dialer;
 
+import com.android.contacts.common.ContactsUtils.UserType;
 import com.android.contacts.common.preference.ContactsPreferences;
 import com.android.dialer.calllog.PhoneNumberDisplayUtil;
 
@@ -101,6 +102,9 @@
     // Whether the contact number is a voicemail number.
     public boolean isVoicemail;
 
+    /** The {@link UserType} of the contact */
+    public @UserType long contactUserType;
+
     /**
      * If this is a voicemail, whether the message is read. For other types of calls, this defaults
      * to {@code true}.
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index dac50ff..af77d86 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -41,6 +41,7 @@
 import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityEvent;
 
+import com.android.contacts.common.ContactsUtils;
 import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
 import com.android.contacts.common.preference.ContactsPreferences;
 import com.android.contacts.common.util.PermissionsUtil;
@@ -55,6 +56,7 @@
 import com.android.dialer.logging.Logger;
 import com.android.dialer.util.PhoneNumberUtil;
 import com.android.dialer.voicemail.VoicemailPlaybackPresenter;
+import com.android.incallui.CallerInfo;
 
 import java.util.HashMap;
 
@@ -400,6 +402,7 @@
      * @param viewHolder The view corresponding to this entry.
      * @param position The position of the entry.
      */
+    @Override
     public void onBindViewHolder(ViewHolder viewHolder, int position) {
         Trace.beginSection("onBindViewHolder: " + position);
 
@@ -497,6 +500,7 @@
             details.photoUri = info.photoUri;
             details.sourceType = info.sourceType;
             details.objectId = info.objectId;
+            details.contactUserType = info.userType;
         }
 
         final CallLogListItemViewHolder views = (CallLogListItemViewHolder) viewHolder;
@@ -517,6 +521,8 @@
                 details.numberLabel);
         // Default case: an item in the call log.
         views.primaryActionView.setVisibility(View.VISIBLE);
+        views.workIconView.setVisibility(
+                details.contactUserType == ContactsUtils.USER_TYPE_WORK ? View.VISIBLE : View.GONE);
 
         // Check if the day group has changed and display a header if necessary.
         int currentGroup = getDayGroupForCall(views.rowId);
diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
index 21f3213..7e14719 100644
--- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
+++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
@@ -96,6 +96,7 @@
     public View sendMessageView;
     public View detailsButtonView;
     public View callWithNoteButtonView;
+    public ImageView workIconView;
 
     /**
      * The row Id for the first call associated with the call log entry.  Used as a key for the
@@ -233,6 +234,7 @@
         this.callLogEntryView = callLogEntryView;
         this.dayGroupHeader = dayGroupHeader;
         this.primaryActionButtonView = primaryActionButtonView;
+        this.workIconView = (ImageView) rootView.findViewById(R.id.work_profile_icon);
 
         Resources resources = mContext.getResources();
         mPhotoSize = mContext.getResources().getDimensionPixelSize(R.dimen.contact_photo_size);
diff --git a/src/com/android/dialer/calllog/ContactInfo.java b/src/com/android/dialer/calllog/ContactInfo.java
index 30f60d9..1020d10 100644
--- a/src/com/android/dialer/calllog/ContactInfo.java
+++ b/src/com/android/dialer/calllog/ContactInfo.java
@@ -19,6 +19,7 @@
 import android.net.Uri;
 import android.text.TextUtils;
 
+import com.android.contacts.common.ContactsUtils.UserType;
 import com.android.contacts.common.util.UriUtils;
 import com.google.common.base.Objects;
 
@@ -46,6 +47,7 @@
     public Uri photoUri;
     public boolean isBadData;
     public String objectId;
+    public @UserType long userType;
 
     public static ContactInfo EMPTY = new ContactInfo();
 
@@ -80,6 +82,7 @@
         if (photoId != other.photoId) return false;
         if (!UriUtils.areEqual(photoUri, other.photoUri)) return false;
         if (!TextUtils.equals(objectId, other.objectId)) return false;
+        if (userType != other.userType) return false;
         return true;
     }
 
diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java
index 1fd2fad..e075b9b 100644
--- a/src/com/android/dialer/calllog/ContactInfoHelper.java
+++ b/src/com/android/dialer/calllog/ContactInfoHelper.java
@@ -32,6 +32,7 @@
 import android.util.Log;
 
 import com.android.contacts.common.ContactsUtils;
+import com.android.contacts.common.compat.ContactsCompat;
 import com.android.contacts.common.util.Constants;
 import com.android.contacts.common.util.PermissionsUtil;
 import com.android.contacts.common.util.PhoneNumberHelper;
@@ -41,6 +42,7 @@
 import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo;
 import com.android.dialer.util.TelecomUtil;
 import com.android.dialerbind.ObjectFactory;
+import com.android.incallui.CallerInfo;
 
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -200,6 +202,9 @@
         info.photoId = phoneLookupCursor.getLong(PhoneQuery.PHOTO_ID);
         info.photoUri = UriUtils.parseUriOrNull(phoneLookupCursor.getString(PhoneQuery.PHOTO_URI));
         info.formattedNumber = null;
+        info.userType = ContactsUtils.determineUserType(null,
+                phoneLookupCursor.getLong(PhoneQuery.PERSON_ID));
+
         return info;
     }
 
diff --git a/src/com/android/dialer/list/RegularSearchListAdapter.java b/src/com/android/dialer/list/RegularSearchListAdapter.java
index 748f4dc..4d8bb6d 100644
--- a/src/com/android/dialer/list/RegularSearchListAdapter.java
+++ b/src/com/android/dialer/list/RegularSearchListAdapter.java
@@ -21,6 +21,8 @@
 import android.text.TextUtils;
 
 import com.android.contacts.common.CallUtil;
+import com.android.contacts.common.ContactsUtils;
+import com.android.contacts.common.compat.DirectoryCompat;
 import com.android.contacts.common.list.DirectoryPartition;
 import com.android.contacts.common.util.PhoneNumberHelper;
 import com.android.dialer.calllog.ContactInfo;
@@ -45,19 +47,21 @@
         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();
+
             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);
+            info.userType = DirectoryCompat.isEnterpriseDirectoryId(directoryId)
+                    ? ContactsUtils.USER_TYPE_WORK : ContactsUtils.USER_TYPE_CURRENT;
 
             cacheInfo.setLookupKey(item.getString(PhoneQuery.LOOKUP_KEY));
 
-            final int partitionIndex = getPartitionForPosition(position);
-            final DirectoryPartition partition =
-                (DirectoryPartition) getPartition(partitionIndex);
-            final long directoryId = partition.getDirectoryId();
             final String sourceName = partition.getLabel();
             if (isExtendedDirectory(directoryId)) {
                 cacheInfo.setExtendedSource(sourceName, directoryId);