Show SIM indicator for multiple SIM mode

- Add icon indicator subscription in call log
- Add icon indicator icon in the incall screen

CRs-Fixed: 934258 956437

cherry-pick from I5b4d9a503b2387e48fb3efd637a0299d934f5188
cherry-pick from I375a5bceda86149edcac57ffd8420043313da8e8

Change-Id: Ifa3d88a1ba6084cc5937d7695d698a30ef28aec0
diff --git a/InCallUI/res/layout/primary_call_info.xml b/InCallUI/res/layout/primary_call_info.xml
index 2aa583c..33007bc 100644
--- a/InCallUI/res/layout/primary_call_info.xml
+++ b/InCallUI/res/layout/primary_call_info.xml
@@ -75,7 +75,6 @@
             android:layout_width="24dp"
             android:layout_height="match_parent"
             android:layout_marginEnd="10dp"
-            android:tint="@color/incall_accent_color"
             android:alpha="0.0"
             android:scaleType="fitCenter"
             android:visibility="gone" />
diff --git a/InCallUI/src/com/android/incallui/CallCardFragment.java b/InCallUI/src/com/android/incallui/CallCardFragment.java
index 39dd5ea..f46c5bf 100644
--- a/InCallUI/src/com/android/incallui/CallCardFragment.java
+++ b/InCallUI/src/com/android/incallui/CallCardFragment.java
@@ -21,12 +21,14 @@
 import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
 import android.content.Context;
+import android.content.res.ColorStateList;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.drawable.AnimationDrawable;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.GradientDrawable;
+import android.graphics.PorterDuff;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
@@ -778,6 +780,18 @@
             mCallStateIcon.setAlpha(1.0f);
             mCallStateIcon.setImageDrawable(callStateIcon);
 
+            MaterialPalette themeColors = InCallPresenter.getInstance().getThemeColors();
+            if (themeColors != null) {
+                // Change the alpha value in the 32 bit color of sim card, because the color of
+                // call background changed with the color of sim card.
+                // Set the tint mode to SCREEN to avoid the slot number in the sim icon to be
+                // covered.
+                int stateIconColor = (themeColors.mPrimaryColor & 0x00ffffff) | 0x7f000000;
+                mCallStateIcon.setImageTintMode(PorterDuff.Mode.SCREEN);
+                mCallStateIcon.setImageTintList(ColorStateList.valueOf(stateIconColor));
+                Log.d(this, "Set tint of call state icon to " + stateIconColor);
+            }
+
             if (state == Call.State.ACTIVE || state == Call.State.CONFERENCED
                     || TextUtils.isEmpty(callStateLabel.getCallStateLabel())) {
                 mCallStateIcon.clearAnimation();
diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java
index 10bf5e6..306c927 100644
--- a/InCallUI/src/com/android/incallui/CallCardPresenter.java
+++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java
@@ -909,6 +909,18 @@
     }
 
     /**
+     * Return the icon to represent the call provider
+     */
+    private Drawable getCallProviderIcon(Call call) {
+        PhoneAccount account = getAccountForCall(call);
+        TelecomManager mgr = InCallPresenter.getInstance().getTelecomManager();
+        if (account != null && mgr.getCallCapablePhoneAccounts().size() > 1) {
+            return account.getIcon().loadDrawable(mContext);
+        }
+        return null;
+    }
+
+    /**
      * Returns the label (line of text above the number/name) for any given call.
      * For example, "calling via [Account/Google Voice]" for outgoing calls.
      */
@@ -943,7 +955,7 @@
             }
         }
 
-        return null;
+        return getCallProviderIcon(mPrimary);
     }
 
     private boolean hasOutgoingGatewayCall() {
diff --git a/res/layout/call_log_list_item.xml b/res/layout/call_log_list_item.xml
index 660bca3..c8a33c5 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/call_account_icon"
+                            android:layout_width="@dimen/call_provider_small_icon_size"
+                            android:layout_height="@dimen/call_provider_small_icon_size"
+                            android:layout_marginEnd="@dimen/call_log_icon_margin"
+                            android:layout_gravity="center_vertical"
+                            android:scaleType="centerInside" />
+
                         <ImageView android:id="@+id/work_profile_icon"
                             android:src="@drawable/ic_work_profile"
                             android:layout_width="wrap_content"
diff --git a/src/com/android/dialer/PhoneCallDetails.java b/src/com/android/dialer/PhoneCallDetails.java
index 17f1c2b..103a07d 100644
--- a/src/com/android/dialer/PhoneCallDetails.java
+++ b/src/com/android/dialer/PhoneCallDetails.java
@@ -23,6 +23,7 @@
 
 import android.content.Context;
 import android.content.res.Resources;
+import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.provider.CallLog.Calls;
 import android.support.annotation.Nullable;
@@ -54,7 +55,10 @@
      * There might be multiple types if this represents a set of entries grouped together.
      */
     public int[] callTypes;
-
+    /**
+     * The icon for the account associated with the call.
+     */
+    public Drawable accountIcon;
     // The date of the call, in milliseconds since the epoch.
     public long date;
     // The duration of the call in milliseconds, or 0 for missed calls.
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index 3958611..b1c8166 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -23,6 +23,7 @@
 import android.content.SharedPreferences;
 import android.content.res.Resources;
 import android.database.Cursor;
+import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Trace;
@@ -501,6 +502,7 @@
         final PhoneAccountHandle accountHandle = PhoneAccountUtils.getAccount(
                 c.getString(CallLogQuery.ACCOUNT_COMPONENT_NAME),
                 c.getString(CallLogQuery.ACCOUNT_ID));
+        final Drawable accountIcon = PhoneAccountUtils.getAccountIcon(mContext, accountHandle);
         final ContactInfo cachedContactInfo = ContactInfoHelper.getContactInfo(c);
         final boolean isVoicemailNumber =
                 mCallLogCache.isVoicemailNumber(accountHandle, number);
@@ -522,6 +524,7 @@
                 postDialDigits, isVoicemailNumber);
         details.viaNumber = viaNumber;
         details.accountHandle = accountHandle;
+        details.accountIcon = accountIcon;
         details.countryIso = countryIso;
         details.date = c.getLong(CallLogQuery.DATE);
         details.duration = c.getLong(CallLogQuery.DURATION);
diff --git a/src/com/android/dialer/calllog/PhoneAccountUtils.java b/src/com/android/dialer/calllog/PhoneAccountUtils.java
index b3ce18b..b418934 100644
--- a/src/com/android/dialer/calllog/PhoneAccountUtils.java
+++ b/src/com/android/dialer/calllog/PhoneAccountUtils.java
@@ -18,6 +18,7 @@
 
 import android.content.ComponentName;
 import android.content.Context;
+import android.graphics.drawable.Drawable;
 import android.support.annotation.Nullable;
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
@@ -66,6 +67,17 @@
     }
 
     /**
+      *Extract account Icon from PhoneAccount object.
+      */
+    public static Drawable getAccountIcon(Context context, PhoneAccountHandle phoneAccount) {
+        final PhoneAccount account = getAccountOrNull(context, phoneAccount);
+        if (account == null) {
+            return null;
+        }
+        return account.getIcon().loadDrawable(context);
+    }
+
+    /**
      * Extract account label from PhoneAccount object.
      */
     @Nullable
diff --git a/src/com/android/dialer/calllog/PhoneCallDetailsHelper.java b/src/com/android/dialer/calllog/PhoneCallDetailsHelper.java
index 4f1c455..47b763b 100644
--- a/src/com/android/dialer/calllog/PhoneCallDetailsHelper.java
+++ b/src/com/android/dialer/calllog/PhoneCallDetailsHelper.java
@@ -21,6 +21,7 @@
 
 import android.content.Context;
 import android.content.res.Resources;
+import android.graphics.drawable.Drawable;
 import android.graphics.Typeface;
 import android.provider.CallLog.Calls;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
@@ -114,6 +115,15 @@
         // Set the call count, location, date and if voicemail, set the duration.
         setDetailText(views, callCount, details);
 
+        //set the account icon if it exists.
+        Drawable icon = details.accountIcon;
+        if (icon != null) {
+            views.callAccountIcon.setVisibility(View.VISIBLE);
+            views.callAccountIcon.setImageDrawable(icon);
+        } else {
+            views.callAccountIcon.setVisibility(View.GONE);
+        }
+
         // Set the account label if it exists.
         String accountLabel = mCallLogCache.getAccountLabel(details.accountHandle);
         if (!TextUtils.isEmpty(details.viaNumber)) {
diff --git a/src/com/android/dialer/calllog/PhoneCallDetailsViews.java b/src/com/android/dialer/calllog/PhoneCallDetailsViews.java
index 94f4411..4c0d45f 100644
--- a/src/com/android/dialer/calllog/PhoneCallDetailsViews.java
+++ b/src/com/android/dialer/calllog/PhoneCallDetailsViews.java
@@ -32,16 +32,19 @@
     public final CallTypeIconsView callTypeIcons;
     public final TextView callLocationAndDate;
     public final TextView voicemailTranscriptionView;
+    public final ImageView callAccountIcon;
     public final TextView callAccountLabel;
 
     private PhoneCallDetailsViews(TextView nameView, View callTypeView,
             CallTypeIconsView callTypeIcons, TextView callLocationAndDate,
-            TextView voicemailTranscriptionView, TextView callAccountLabel) {
+            TextView voicemailTranscriptionView,  ImageView callAccountIcon,
+            TextView callAccountLabel) {
         this.nameView = nameView;
         this.callTypeView = callTypeView;
         this.callTypeIcons = callTypeIcons;
         this.callLocationAndDate = callLocationAndDate;
         this.voicemailTranscriptionView = voicemailTranscriptionView;
+        this.callAccountIcon = callAccountIcon;
         this.callAccountLabel = callAccountLabel;
     }
 
@@ -58,6 +61,7 @@
                 (CallTypeIconsView) view.findViewById(R.id.call_type_icons),
                 (TextView) view.findViewById(R.id.call_location_and_date),
                 (TextView) view.findViewById(R.id.voicemail_transcription),
+                (ImageView) view.findViewById(R.id.call_account_icon),
                 (TextView) view.findViewById(R.id.call_account_label));
     }
 
@@ -68,6 +72,7 @@
                 new CallTypeIconsView(context),
                 new TextView(context),
                 new TextView(context),
+                new ImageView(context),
                 new TextView(context));
     }
 }