Add icon indicating subscription in call log/call history

Display an icon in the call details showing which connection provider
(subscription) is responsible for the call.

Bug: 15473965

Change-Id: I0c6755864083799b8bafe20c3692b0d943beeee3
diff --git a/res/layout/call_log_list_item.xml b/res/layout/call_log_list_item.xml
index d925c13..d46462e 100644
--- a/res/layout/call_log_list_item.xml
+++ b/res/layout/call_log_list_item.xml
@@ -112,6 +112,14 @@
                         android:layout_marginEnd="@dimen/call_log_icon_margin"
                         android:layout_gravity="center_vertical"
                         />
+                    <ImageView
+                        android:id="@+id/call_subscription_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"
+                        />
                     <TextView
                         android:id="@+id/call_location_and_date"
                         android:layout_width="wrap_content"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 86604ed..f806c82 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -41,10 +41,12 @@
     <dimen name="call_detail_header_top_margin">24dp</dimen>
     <dimen name="call_detail_translation_z">0.5dp</dimen>
 
+    <!-- Size of call provider icon width and height -->
+    <dimen name="call_provider_small_icon_size">12dp</dimen>
+
     <!-- Match call_button_height to Phone's dimens/in_call_end_button_height -->
     <dimen name="call_button_height">74dp</dimen>
 
-
     <!-- Dimensions for speed dial tiles -->
     <dimen name="contact_tile_divider_width">1dp</dimen>
     <dimen name="contact_tile_info_button_height_and_width">36dp</dimen>
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java
index 695f8aa..d070601 100644
--- a/src/com/android/dialer/CallDetailActivity.java
+++ b/src/com/android/dialer/CallDetailActivity.java
@@ -24,6 +24,7 @@
 import android.content.Intent;
 import android.content.res.Resources;
 import android.database.Cursor;
+import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
@@ -31,6 +32,7 @@
 import android.provider.CallLog.Calls;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.provider.VoicemailContract.Voicemails;
+import android.telecomm.Subscription;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.Log;
@@ -194,6 +196,8 @@
         CallLog.Calls.COUNTRY_ISO,
         CallLog.Calls.GEOCODED_LOCATION,
         CallLog.Calls.NUMBER_PRESENTATION,
+        CallLog.Calls.SUBSCRIPTION_COMPONENT_NAME,
+        CallLog.Calls.SUBSCRIPTION_ID,
     };
 
     static final int DATE_COLUMN_INDEX = 0;
@@ -203,6 +207,8 @@
     static final int COUNTRY_ISO_COLUMN_INDEX = 4;
     static final int GEOCODED_LOCATION_COLUMN_INDEX = 5;
     static final int NUMBER_PRESENTATION_COLUMN_INDEX = 6;
+    static final int SUBSCRIPTION_COMPONENT_NAME = 7;
+    static final int SUBSCRIPTION_ID = 8;
 
     @Override
     protected void onCreate(Bundle icicle) {
@@ -328,8 +334,7 @@
                 if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
                     DialerUtils.startActivityWithErrorToast(this,
                             CallUtil.getCallIntent(Uri.fromParts(CallUtil.SCHEME_TEL, mNumber,
-                                    null)),
-                            R.string.call_not_available);
+                                    null)), R.string.call_not_available);
                     return true;
                 }
             }
@@ -482,6 +487,7 @@
             final int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
             String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
             final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX);
+            final Drawable subscriptionIcon = getSubscriptionIcon(callCursor);
 
             if (TextUtils.isEmpty(countryIso)) {
                 countryIso = mDefaultCountryIso;
@@ -523,7 +529,8 @@
             return new PhoneCallDetails(number, numberPresentation,
                     formattedNumber, countryIso, geocode,
                     new int[]{ callType }, date, duration,
-                    nameText, numberType, numberLabel, lookupUri, photoUri, sourceType);
+                    nameText, numberType, numberLabel, lookupUri, photoUri, sourceType,
+                    subscriptionIcon);
         } finally {
             if (callCursor != null) {
                 callCursor.close();
@@ -531,6 +538,17 @@
         }
     }
 
+    /**
+     * Generate subscription object from data in Telecomm database
+     */
+    private Drawable getSubscriptionIcon(Cursor c) {
+        final String component_name = c.getString(SUBSCRIPTION_COMPONENT_NAME);
+        final String subscription_id = c.getString(SUBSCRIPTION_ID);
+
+        // TODO: actually pull data from the database
+        return null;
+    }
+
     /** Load the contact photos and places them in the corresponding views. */
     private void loadContactPhotos(Uri contactUri, Uri photoUri, String displayName,
             String lookupKey, int contactType) {
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 8e873c8..da46a40 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -1108,7 +1108,9 @@
 
     @Override
     public void onCallNumberDirectly(String phoneNumber) {
-        Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
+        final Subscription subscription = mSubscriptionManager != null?
+                mSubscriptionManager.getCurrentSubscription(): null;
+        Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin(), subscription);
         DialerUtils.startActivityWithErrorToast(this, intent);
         mClearSearchOnPause = true;
     }
diff --git a/src/com/android/dialer/PhoneCallDetails.java b/src/com/android/dialer/PhoneCallDetails.java
index 4e01ab5..3562b17 100644
--- a/src/com/android/dialer/PhoneCallDetails.java
+++ b/src/com/android/dialer/PhoneCallDetails.java
@@ -16,9 +16,11 @@
 
 package com.android.dialer;
 
+import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.provider.CallLog.Calls;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.telecomm.Subscription;
 
 /**
  * The details of a phone call to be shown in the UI.
@@ -63,13 +65,17 @@
      * The source type of the contact associated with this call.
      */
     public final int sourceType;
+    /**
+     * The unique identifier for the provider associated with the call.
+     */
+    public final Drawable subscriptionIcon;
 
     /** Create the details for a call with a number not associated with a contact. */
     public PhoneCallDetails(CharSequence number, int numberPresentation,
             CharSequence formattedNumber, String countryIso, String geocode,
-            int[] callTypes, long date, long duration) {
+            int[] callTypes, long date, long duration, Drawable subscriptionIcon) {
         this(number, numberPresentation, formattedNumber, countryIso, geocode,
-                callTypes, date, duration, "", 0, "", null, null, 0);
+                callTypes, date, duration, "", 0, "", null, null, 0, subscriptionIcon);
     }
 
     /** Create the details for a call with a number associated with a contact. */
@@ -77,7 +83,7 @@
             CharSequence formattedNumber, String countryIso, String geocode,
             int[] callTypes, long date, long duration, CharSequence name,
             int numberType, CharSequence numberLabel, Uri contactUri,
-            Uri photoUri, int sourceType) {
+            Uri photoUri, int sourceType, Drawable subscriptionIcon) {
         this.number = number;
         this.numberPresentation = numberPresentation;
         this.formattedNumber = formattedNumber;
@@ -92,5 +98,6 @@
         this.contactUri = contactUri;
         this.photoUri = photoUri;
         this.sourceType = sourceType;
+        this.subscriptionIcon = subscriptionIcon;
     }
 }
diff --git a/src/com/android/dialer/PhoneCallDetailsHelper.java b/src/com/android/dialer/PhoneCallDetailsHelper.java
index f1b6f7f..0531412 100644
--- a/src/com/android/dialer/PhoneCallDetailsHelper.java
+++ b/src/com/android/dialer/PhoneCallDetailsHelper.java
@@ -17,8 +17,10 @@
 package com.android.dialer;
 
 import android.content.res.Resources;
+import android.graphics.drawable.Drawable;
 import android.graphics.Typeface;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.telecomm.Subscription;
 import android.text.SpannableString;
 import android.text.Spanned;
 import android.text.TextUtils;
@@ -27,6 +29,7 @@
 import android.text.style.StyleSpan;
 import android.view.View;
 import android.widget.TextView;
+import android.widget.ImageView;
 
 import com.android.contacts.common.testing.NeededForTesting;
 import com.android.contacts.common.util.PhoneNumberHelper;
@@ -34,6 +37,7 @@
 import com.android.dialer.calllog.ContactInfo;
 import com.android.dialer.calllog.PhoneNumberDisplayHelper;
 import com.android.dialer.calllog.PhoneNumberUtilsWrapper;
+
 import com.google.common.collect.Lists;
 
 import java.util.ArrayList;
@@ -98,6 +102,14 @@
         // Set the call count, location and date.
         setCallCountAndDate(views, callCount, callLocationAndDate);
 
+        // set the subscription icon if it exists
+        if (details.subscriptionIcon != null) {
+            views.callSubscriptionIcon.setVisibility(View.VISIBLE);
+            views.callSubscriptionIcon.setImageDrawable(details.subscriptionIcon);
+        } else {
+            views.callSubscriptionIcon.setVisibility(View.GONE);
+        }
+
         final CharSequence nameText;
         final CharSequence displayNumber =
             mPhoneNumberHelper.getDisplayNumber(details.number,
diff --git a/src/com/android/dialer/PhoneCallDetailsViews.java b/src/com/android/dialer/PhoneCallDetailsViews.java
index 30023ea..4f70137 100644
--- a/src/com/android/dialer/PhoneCallDetailsViews.java
+++ b/src/com/android/dialer/PhoneCallDetailsViews.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.view.View;
+import android.widget.ImageView;
 import android.widget.TextView;
 
 import com.android.dialer.calllog.CallTypeIconsView;
@@ -29,15 +30,17 @@
     public final TextView nameView;
     public final View callTypeView;
     public final CallTypeIconsView callTypeIcons;
+    public final ImageView callSubscriptionIcon;
     public final TextView callLocationAndDate;
     public final TextView voicemailTranscriptionView;
 
     private PhoneCallDetailsViews(TextView nameView, View callTypeView,
-            CallTypeIconsView callTypeIcons, TextView callLocationAndDate,
-            TextView voicemailTranscriptionView) {
+            CallTypeIconsView callTypeIcons, ImageView callSubscriptionIcon,
+            TextView callLocationAndDate, TextView voicemailTranscriptionView) {
         this.nameView = nameView;
         this.callTypeView = callTypeView;
         this.callTypeIcons = callTypeIcons;
+        this.callSubscriptionIcon = callSubscriptionIcon;
         this.callLocationAndDate = callLocationAndDate;
         this.voicemailTranscriptionView = voicemailTranscriptionView;
     }
@@ -53,6 +56,7 @@
         return new PhoneCallDetailsViews((TextView) view.findViewById(R.id.name),
                 view.findViewById(R.id.call_type),
                 (CallTypeIconsView) view.findViewById(R.id.call_type_icons),
+                (ImageView) view.findViewById(R.id.call_subscription_icon),
                 (TextView) view.findViewById(R.id.call_location_and_date),
                 (TextView) view.findViewById(R.id.voicemail_transcription));
     }
@@ -62,6 +66,7 @@
                 new TextView(context),
                 new View(context),
                 new CallTypeIconsView(context),
+                new ImageView(context),
                 new TextView(context),
                 new TextView(context));
     }
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index f19b924..d089330 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -21,12 +21,15 @@
 import android.content.Intent;
 import android.content.res.Resources;
 import android.database.Cursor;
+import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.Handler;
 import android.os.Message;
 import android.provider.CallLog.Calls;
 import android.provider.ContactsContract.PhoneLookup;
+import android.telecomm.Subscription;
 import android.text.TextUtils;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -51,6 +54,7 @@
 
 import java.util.HashMap;
 import java.util.LinkedList;
+import java.util.List;
 
 /**
  * Adapter class to fill in data for the Call Log.
@@ -630,6 +634,9 @@
         final long date = c.getLong(CallLogQuery.DATE);
         final long duration = c.getLong(CallLogQuery.DURATION);
         final int callType = c.getInt(CallLogQuery.CALL_TYPE);
+        final Subscription subscription = getSubscription(c);
+        final Drawable subscriptionIcon = subscription != null?
+                subscription.getIcon(mContext) : null;
         final String countryIso = c.getString(CallLogQuery.COUNTRY_ISO);
         final long rowId = c.getLong(CallLogQuery.ID);
         views.rowId = rowId;
@@ -654,6 +661,7 @@
         views.number = number;
         views.numberPresentation = numberPresentation;
         views.callType = callType;
+        views.subscription = subscription;
         views.voicemailUri = c.getString(CallLogQuery.VOICEMAIL_URI);
         // Stash away the Ids of the calls so that we can support deleting a row in the call log.
         views.callIds = getCallIds(c, count);
@@ -671,7 +679,8 @@
             // Set return call intent, otherwise null.
             if (PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)) {
                 // Sets the primary action to call the number.
-                views.primaryActionView.setTag(IntentProvider.getReturnCallIntentProvider(number));
+                views.primaryActionView.setTag(IntentProvider.getReturnCallIntentProvider(number,
+                        subscription));
             } else {
                 // Number is not callable, so hide button.
                 views.primaryActionView.setTag(null);
@@ -741,11 +750,12 @@
         if (TextUtils.isEmpty(name)) {
             details = new PhoneCallDetails(number, numberPresentation,
                     formattedNumber, countryIso, geocode, callTypes, date,
-                    duration);
+                    duration, subscriptionIcon);
         } else {
             details = new PhoneCallDetails(number, numberPresentation,
                     formattedNumber, countryIso, geocode, callTypes, date,
-                    duration, name, ntype, label, lookupUri, photoUri, sourceType);
+                    duration, name, ntype, label, lookupUri, photoUri, sourceType,
+                    subscriptionIcon);
         }
 
         mCallLogViewsHelper.setPhoneCallDetails(views, details);
@@ -929,7 +939,7 @@
         if (PhoneNumberUtilsWrapper.canPlaceCallsTo(views.number, views.numberPresentation)) {
             // Sets the primary action to call the number.
             views.callBackButtonView.setTag(
-                    IntentProvider.getReturnCallIntentProvider(views.number));
+                    IntentProvider.getReturnCallIntentProvider(views.number, views.subscription));
             views.callBackButtonView.setVisibility(View.VISIBLE);
             views.callBackButtonView.setOnClickListener(mActionListener);
         } else {
@@ -1175,6 +1185,14 @@
         return callTypes;
     }
 
+    private Subscription getSubscription(Cursor c) {
+        final String component_name = c.getString(CallLogQuery.SUBSCRIPTION_COMPONENT_NAME);
+        final String subscription_id = c.getString(CallLogQuery.SUBSCRIPTION_ID);
+
+        // TODO: actually pull data from the database
+        return null;
+    }
+
     private void setPhoto(CallLogListItemViews views, long photoId, Uri contactUri,
             String displayName, String identifier, int contactType) {
         views.quickContactView.assignContactUri(contactUri);
diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java
index 4f5c355..1d6ec79 100644
--- a/src/com/android/dialer/calllog/CallLogFragment.java
+++ b/src/com/android/dialer/calllog/CallLogFragment.java
@@ -436,47 +436,6 @@
                 getListView().getEmptyView(), R.drawable.empty_call_log, messageId, getResources());
     }
 
-    public void callSelectedEntry() {
-        int position = getListView().getSelectedItemPosition();
-        if (position < 0) {
-            // In touch mode you may often not have something selected, so
-            // just call the first entry to make sure that [send] [send] calls the
-            // most recent entry.
-            position = 0;
-        }
-        final Cursor cursor = (Cursor)mAdapter.getItem(position);
-        if (cursor != null) {
-            String number = cursor.getString(CallLogQuery.NUMBER);
-            int numberPresentation = cursor.getInt(CallLogQuery.NUMBER_PRESENTATION);
-            if (!PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)) {
-                // This number can't be called, do nothing
-                return;
-            }
-            Intent intent;
-            // If "number" is really a SIP address, construct a sip: URI.
-            if (PhoneNumberHelper.isUriNumber(number)) {
-                intent = CallUtil.getCallIntent(
-                        Uri.fromParts(CallUtil.SCHEME_SIP, number, null));
-            } else {
-                // We're calling a regular PSTN phone number.
-                // Construct a tel: URI, but do some other possible cleanup first.
-                int callType = cursor.getInt(CallLogQuery.CALL_TYPE);
-                if (!number.startsWith("+") &&
-                       (callType == Calls.INCOMING_TYPE
-                                || callType == Calls.MISSED_TYPE)) {
-                    // If the caller-id matches a contact with a better qualified number, use it
-                    String countryIso = cursor.getString(CallLogQuery.COUNTRY_ISO);
-                    number = mAdapter.getBetterNumberFromContacts(number, countryIso);
-                }
-                intent = CallUtil.getCallIntent(
-                        Uri.fromParts(CallUtil.SCHEME_TEL, number, null));
-            }
-            intent.setFlags(
-                    Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
-            startActivity(intent);
-        }
-    }
-
     CallLogAdapter getAdapter() {
         return mAdapter;
     }
diff --git a/src/com/android/dialer/calllog/CallLogGroupBuilder.java b/src/com/android/dialer/calllog/CallLogGroupBuilder.java
index 50cf054..a36ceb4 100644
--- a/src/com/android/dialer/calllog/CallLogGroupBuilder.java
+++ b/src/com/android/dialer/calllog/CallLogGroupBuilder.java
@@ -27,6 +27,8 @@
 
 import com.google.common.annotations.VisibleForTesting;
 
+import java.util.Objects;
+
 /**
  * Groups together calls in the call log.  The primary grouping attempts to group together calls
  * to and from the same number into a single row on the call log.
@@ -124,6 +126,10 @@
         // This is the type of the first call in the group.
         int firstCallType = cursor.getInt(CallLogQuery.CALL_TYPE);
 
+        // The subscription information of the first entry in the group.
+        String firstSubscriptionComponentName = cursor.getString(CallLogQuery.SUBSCRIPTION_COMPONENT_NAME);
+        String firstSubscriptionId = cursor.getString(CallLogQuery.SUBSCRIPTION_ID);
+
         // Determine the day group for the first call in the cursor.
         final long firstDate = cursor.getLong(CallLogQuery.DATE);
         final long firstRowId = cursor.getLong(CallLogQuery.ID);
@@ -134,12 +140,24 @@
             // The number of the current row in the cursor.
             final String currentNumber = cursor.getString(CallLogQuery.NUMBER);
             final int callType = cursor.getInt(CallLogQuery.CALL_TYPE);
+            final String currentSubscriptionComponentName = cursor.getString(
+                    CallLogQuery.SUBSCRIPTION_COMPONENT_NAME);
+            final String currentSubscriptionId = cursor.getString(CallLogQuery.SUBSCRIPTION_ID);
+
             final boolean sameNumber = equalNumbers(firstNumber, currentNumber);
+            final boolean sameSubscriptionComponentName = Objects.equals(
+                    firstSubscriptionComponentName,
+                    currentSubscriptionComponentName);
+            final boolean sameSubscriptionId = Objects.equals(
+                    firstSubscriptionId,
+                    currentSubscriptionId);
+            final boolean sameSubscription = sameSubscriptionComponentName && sameSubscriptionId;
+
             final boolean shouldGroup;
             final long currentCallId = cursor.getLong(CallLogQuery.ID);
             final long date = cursor.getLong(CallLogQuery.DATE);
 
-            if (!sameNumber) {
+            if (!sameNumber || !sameSubscription) {
                 // Should only group with calls from the same number.
                 shouldGroup = false;
             } else if (firstCallType == Calls.VOICEMAIL_TYPE) {
@@ -170,6 +188,8 @@
                 // The current entry is now the first in the group.
                 firstNumber = currentNumber;
                 firstCallType = callType;
+                firstSubscriptionComponentName = currentSubscriptionComponentName;
+                firstSubscriptionId = currentSubscriptionId;
             }
 
             // Save the day group associated with the current call.
diff --git a/src/com/android/dialer/calllog/CallLogListItemViews.java b/src/com/android/dialer/calllog/CallLogListItemViews.java
index ade720f..39c6e64 100644
--- a/src/com/android/dialer/calllog/CallLogListItemViews.java
+++ b/src/com/android/dialer/calllog/CallLogListItemViews.java
@@ -17,6 +17,7 @@
 package com.android.dialer.calllog;
 
 import android.content.Context;
+import android.telecomm.Subscription;
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.QuickContactBadge;
@@ -80,6 +81,12 @@
     public int callType;
 
     /**
+     * The subscription for the current call log entry.  Cached here as the call back
+     * intent is set only when the actions ViewStub is inflated.
+     */
+    public Subscription subscription;
+
+    /**
      * If the call has an associated voicemail message, the URI of the voicemail message for
      * playback.  Cached here as the voicemail intent is only set when the actions ViewStub is
      * inflated.
diff --git a/src/com/android/dialer/calllog/CallLogQuery.java b/src/com/android/dialer/calllog/CallLogQuery.java
index 4ae6afd..87b7a45 100644
--- a/src/com/android/dialer/calllog/CallLogQuery.java
+++ b/src/com/android/dialer/calllog/CallLogQuery.java
@@ -26,24 +26,26 @@
     // If you alter this, you must also alter the method that inserts a fake row to the headers
     // in the CallLogQueryHandler class called createHeaderCursorFor().
     public static final String[] _PROJECTION = new String[] {
-            Calls._ID,                       // 0
-            Calls.NUMBER,                    // 1
-            Calls.DATE,                      // 2
-            Calls.DURATION,                  // 3
-            Calls.TYPE,                      // 4
-            Calls.COUNTRY_ISO,               // 5
-            Calls.VOICEMAIL_URI,             // 6
-            Calls.GEOCODED_LOCATION,         // 7
-            Calls.CACHED_NAME,               // 8
-            Calls.CACHED_NUMBER_TYPE,        // 9
-            Calls.CACHED_NUMBER_LABEL,       // 10
-            Calls.CACHED_LOOKUP_URI,         // 11
-            Calls.CACHED_MATCHED_NUMBER,     // 12
-            Calls.CACHED_NORMALIZED_NUMBER,  // 13
-            Calls.CACHED_PHOTO_ID,           // 14
-            Calls.CACHED_FORMATTED_NUMBER,   // 15
-            Calls.IS_READ,                   // 16
-            Calls.NUMBER_PRESENTATION,       // 17
+            Calls._ID,                          // 0
+            Calls.NUMBER,                       // 1
+            Calls.DATE,                         // 2
+            Calls.DURATION,                     // 3
+            Calls.TYPE,                         // 4
+            Calls.COUNTRY_ISO,                  // 5
+            Calls.VOICEMAIL_URI,                // 6
+            Calls.GEOCODED_LOCATION,            // 7
+            Calls.CACHED_NAME,                  // 8
+            Calls.CACHED_NUMBER_TYPE,           // 9
+            Calls.CACHED_NUMBER_LABEL,          // 10
+            Calls.CACHED_LOOKUP_URI,            // 11
+            Calls.CACHED_MATCHED_NUMBER,        // 12
+            Calls.CACHED_NORMALIZED_NUMBER,     // 13
+            Calls.CACHED_PHOTO_ID,              // 14
+            Calls.CACHED_FORMATTED_NUMBER,      // 15
+            Calls.IS_READ,                      // 16
+            Calls.NUMBER_PRESENTATION,          // 17
+            Calls.SUBSCRIPTION_COMPONENT_NAME,  // 18
+            Calls.SUBSCRIPTION_ID,              // 19
     };
 
     public static final int ID = 0;
@@ -64,4 +66,6 @@
     public static final int CACHED_FORMATTED_NUMBER = 15;
     public static final int IS_READ = 16;
     public static final int NUMBER_PRESENTATION = 17;
+    public static final int SUBSCRIPTION_COMPONENT_NAME = 18;
+    public static final int SUBSCRIPTION_ID = 19;
 }
diff --git a/src/com/android/dialer/calllog/IntentProvider.java b/src/com/android/dialer/calllog/IntentProvider.java
index 96020be..6a270be 100644
--- a/src/com/android/dialer/calllog/IntentProvider.java
+++ b/src/com/android/dialer/calllog/IntentProvider.java
@@ -22,6 +22,7 @@
 import android.database.Cursor;
 import android.net.Uri;
 import android.provider.CallLog.Calls;
+import android.telecomm.Subscription;
 import android.util.Log;
 
 import com.android.contacts.common.CallUtil;
@@ -38,11 +39,12 @@
 
     public abstract Intent getIntent(Context context);
 
-    public static IntentProvider getReturnCallIntentProvider(final String number) {
+    public static IntentProvider getReturnCallIntentProvider(final String number,
+            final Subscription subscription) {
         return new IntentProvider() {
             @Override
             public Intent getIntent(Context context) {
-                return CallUtil.getCallIntent(number);
+                return CallUtil.getCallIntent(number, subscription);
             }
         };
     }
diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java
index 6e91f19..21c7d82 100644
--- a/src/com/android/dialer/dialpad/DialpadFragment.java
+++ b/src/com/android/dialer/dialpad/DialpadFragment.java
@@ -40,6 +40,7 @@
 import android.provider.Contacts.Phones;
 import android.provider.Contacts.PhonesColumns;
 import android.provider.Settings;
+import android.telecomm.Subscription;
 import android.telephony.PhoneNumberUtils;
 import android.telephony.PhoneStateListener;
 import android.telephony.TelephonyManager;
@@ -1072,9 +1073,14 @@
                 // Clear the digits just in case.
                 clearDialpad();
             } else {
+                final Subscription subscription = mSubscriptionManager != null?
+                        mSubscriptionManager.getCurrentSubscription() : null;
+
+
                 final Intent intent = CallUtil.getCallIntent(number,
                         (getActivity() instanceof DialtactsActivity ?
-                                ((DialtactsActivity) getActivity()).getCallOrigin() : null));
+                                ((DialtactsActivity) getActivity()).getCallOrigin() : null),
+                                subscription);
                 DialerUtils.startActivityWithErrorToast(getActivity(), intent);
                 hideAndClearDialpad(false);
             }
diff --git a/tests/res/layout/fill_call_log_test.xml b/tests/res/layout/fill_call_log_test.xml
index 9b89e4a..c81a679 100644
--- a/tests/res/layout/fill_call_log_test.xml
+++ b/tests/res/layout/fill_call_log_test.xml
@@ -176,6 +176,33 @@
             android:inputType="phone"
             />
     </LinearLayout>
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/call_subscription" />
+    <RadioGroup
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal">
+        <RadioButton
+            android:id="@+id/subscription0"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/subscription0"
+            android:textSize="9sp" />
+        <RadioButton
+            android:id="@+id/subscription1"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/subscription1"
+            android:textSize="9sp" />
+        <RadioButton
+            android:id="@+id/no_subscription"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/no_subscription"
+            android:textSize="9sp" />
+    </RadioGroup>
     <Button
         android:id="@+id/add_custom"
         android:layout_width="match_parent"
diff --git a/tests/res/values/donottranslate_strings.xml b/tests/res/values/donottranslate_strings.xml
index 25c3a5a..cfc70c4 100644
--- a/tests/res/values/donottranslate_strings.xml
+++ b/tests/res/values/donottranslate_strings.xml
@@ -51,4 +51,8 @@
     <string name="presentation_unknown">Unknown</string>
     <string name="presentation_payphone">Payphone</string>
     <string name="delta_after_add">Offset call time after add (min): </string>
+    <string name="call_subscription">Subscription</string>
+    <string name="subscription0">Subscription 0</string>
+    <string name="subscription1">Subscription 1</string>
+    <string name="no_subscription">No Subscription</string>
 </resources>
diff --git a/tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java b/tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java
index 679335e..ae47596 100644
--- a/tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java
+++ b/tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java
@@ -290,7 +290,7 @@
         mHelper.setPhoneCallDetails(mViews,
                 new PhoneCallDetails(number, presentation, formattedNumber,
                         TEST_COUNTRY_ISO, TEST_GEOCODE,
-                        new int[]{ Calls.VOICEMAIL_TYPE }, TEST_DATE, TEST_DURATION)
+                        new int[]{ Calls.VOICEMAIL_TYPE }, TEST_DATE, TEST_DURATION, null)
         );
     }
 
@@ -300,7 +300,7 @@
         mHelper.setPhoneCallDetails(mViews,
                 new PhoneCallDetails(number, Calls.PRESENTATION_ALLOWED,
                         formattedNumber, TEST_COUNTRY_ISO, geocodedLocation,
-                        new int[]{ Calls.VOICEMAIL_TYPE }, TEST_DATE, TEST_DURATION)
+                        new int[]{ Calls.VOICEMAIL_TYPE }, TEST_DATE, TEST_DURATION, null)
         );
     }
 
@@ -309,7 +309,7 @@
         mHelper.setPhoneCallDetails(mViews,
                 new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                         TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO, TEST_GEOCODE,
-                        new int[]{ Calls.INCOMING_TYPE }, date, TEST_DURATION)
+                        new int[]{ Calls.INCOMING_TYPE }, date, TEST_DURATION, null)
         );
     }
 
@@ -318,7 +318,7 @@
         mHelper.setPhoneCallDetails(mViews,
                 new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                         TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO, TEST_GEOCODE,
-                        callTypes, TEST_DATE, TEST_DURATION)
+                        callTypes, TEST_DATE, TEST_DURATION, null)
         );
     }
 
@@ -326,7 +326,7 @@
         mHelper.setCallDetailsHeader(mNameView,
                 new PhoneCallDetails(number, presentation,
                         TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO, TEST_GEOCODE,
-                        new int[]{ Calls.INCOMING_TYPE }, TEST_DATE, TEST_DURATION));
+                        new int[]{ Calls.INCOMING_TYPE }, TEST_DATE, TEST_DURATION, null));
     }
 
     private void setCallDetailsHeader(String name) {
@@ -334,6 +334,6 @@
                 new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                         TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO, TEST_GEOCODE,
                         new int[]{ Calls.INCOMING_TYPE }, TEST_DATE, TEST_DURATION,
-                        name, 0, "", null, null, 0));
+                        name, 0, "", null, null, 0, null));
     }
 }
diff --git a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java
index 96eefbc..ae76157 100644
--- a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java
+++ b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java
@@ -128,7 +128,7 @@
     public void testGetCallDescriptionID_UnknownAnswered() {
         PhoneCallDetails details = new PhoneCallDetails("", Calls.PRESENTATION_UNKNOWN, "",
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.INCOMING_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.INCOMING_TYPE}, TEST_DATE, TEST_DURATION, null);
         assertEquals(R.string.description_incoming_answered_call,
                 mHelper.getCallDescriptionStringID(details));
     }
@@ -140,7 +140,7 @@
     public void testGetCallDescriptionID_UnknownMissed() {
         PhoneCallDetails details = new PhoneCallDetails("", Calls.PRESENTATION_UNKNOWN, "",
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.MISSED_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.MISSED_TYPE}, TEST_DATE, TEST_DURATION, null);
         assertEquals(R.string.description_incoming_missed_call,
                 mHelper.getCallDescriptionStringID(details));
     }
@@ -152,7 +152,7 @@
     public void testGetCallDescriptionID_UnknownVoicemail() {
         PhoneCallDetails details = new PhoneCallDetails("", Calls.PRESENTATION_UNKNOWN, "",
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.VOICEMAIL_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.VOICEMAIL_TYPE}, TEST_DATE, TEST_DURATION, null);
         assertEquals(R.string.description_incoming_missed_call,
                 mHelper.getCallDescriptionStringID(details));
     }
@@ -165,7 +165,7 @@
         PhoneCallDetails details = new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                 TEST_FORMATTED_NUMBER,
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.INCOMING_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.INCOMING_TYPE}, TEST_DATE, TEST_DURATION, null);
         assertEquals(R.string.description_incoming_answered_call,
                 mHelper.getCallDescriptionStringID(details));
     }
@@ -178,7 +178,7 @@
         PhoneCallDetails details = new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                 TEST_FORMATTED_NUMBER,
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.MISSED_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.MISSED_TYPE}, TEST_DATE, TEST_DURATION, null);
         assertEquals(R.string.description_incoming_missed_call,
                 mHelper.getCallDescriptionStringID(details));
     }
@@ -191,7 +191,7 @@
         PhoneCallDetails details = new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                 TEST_FORMATTED_NUMBER,
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.VOICEMAIL_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.VOICEMAIL_TYPE}, TEST_DATE, TEST_DURATION, null);
         assertEquals(R.string.description_incoming_missed_call,
                 mHelper.getCallDescriptionStringID(details));
     }
@@ -205,7 +205,7 @@
         PhoneCallDetails details = new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                 TEST_FORMATTED_NUMBER,
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.OUTGOING_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.OUTGOING_TYPE}, TEST_DATE, TEST_DURATION, null);
         assertEquals(R.string.description_outgoing_call,
                 mHelper.getCallDescriptionStringID(details));
     }
@@ -219,7 +219,7 @@
         PhoneCallDetails details = new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                 TEST_FORMATTED_NUMBER,
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.OUTGOING_TYPE, Calls.OUTGOING_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.OUTGOING_TYPE, Calls.OUTGOING_TYPE}, TEST_DATE, TEST_DURATION, null);
         assertEquals(R.string.description_outgoing_call,
                 mHelper.getCallDescriptionStringID(details));
     }
@@ -232,7 +232,8 @@
         PhoneCallDetails details = new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                 TEST_FORMATTED_NUMBER,
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.OUTGOING_TYPE, Calls.OUTGOING_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.OUTGOING_TYPE, Calls.OUTGOING_TYPE}, TEST_DATE, TEST_DURATION,
+                null);
         CharSequence description = mHelper.getCallDescription(details);
         assertFalse(description.toString()
                 .contains(this.mResources.getString(R.string.description_new_voicemail)));
@@ -246,7 +247,8 @@
         PhoneCallDetails details = new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                 TEST_FORMATTED_NUMBER,
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.INCOMING_TYPE, Calls.OUTGOING_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.INCOMING_TYPE, Calls.OUTGOING_TYPE}, TEST_DATE, TEST_DURATION,
+                null);
         CharSequence description = mHelper.getCallDescription(details);
         assertFalse(description.toString()
                 .contains(this.mResources.getString(R.string.description_new_voicemail)));
@@ -260,7 +262,7 @@
         PhoneCallDetails details = new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                 TEST_FORMATTED_NUMBER,
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.MISSED_TYPE, Calls.OUTGOING_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.MISSED_TYPE, Calls.OUTGOING_TYPE}, TEST_DATE, TEST_DURATION, null);
         CharSequence description = mHelper.getCallDescription(details);
         assertFalse(description.toString()
                 .contains(this.mResources.getString(R.string.description_new_voicemail)));
@@ -274,7 +276,8 @@
         PhoneCallDetails details = new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                 TEST_FORMATTED_NUMBER,
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.VOICEMAIL_TYPE, Calls.OUTGOING_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.VOICEMAIL_TYPE, Calls.OUTGOING_TYPE}, TEST_DATE, TEST_DURATION,
+                null);
         CharSequence description = mHelper.getCallDescription(details);
         assertTrue(description.toString()
                 .contains(this.mResources.getString(R.string.description_new_voicemail)));
@@ -288,7 +291,7 @@
         PhoneCallDetails details = new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                 TEST_FORMATTED_NUMBER,
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.VOICEMAIL_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.VOICEMAIL_TYPE}, TEST_DATE, TEST_DURATION, null);
         CharSequence description = mHelper.getCallDescription(details);
 
         // Rather than hard coding the "X calls" string message, we'll generate it with an empty
@@ -307,7 +310,8 @@
         PhoneCallDetails details = new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                 TEST_FORMATTED_NUMBER,
                 TEST_COUNTRY_ISO, TEST_GEOCODE,
-                new int[]{Calls.VOICEMAIL_TYPE, Calls.INCOMING_TYPE}, TEST_DATE, TEST_DURATION);
+                new int[]{Calls.VOICEMAIL_TYPE, Calls.INCOMING_TYPE}, TEST_DATE, TEST_DURATION,
+                null);
         CharSequence description = mHelper.getCallDescription(details);
         assertTrue(description.toString()
                 .contains(this.mResources.getString(R.string.description_num_calls, 2)));
@@ -333,7 +337,7 @@
         mHelper.setPhoneCallDetails(mViews,
                 new PhoneCallDetails(number, presentation, formattedNumber,
                         TEST_COUNTRY_ISO, TEST_GEOCODE,
-                        new int[]{ callType }, TEST_DATE, TEST_DURATION)
+                        new int[]{ callType }, TEST_DATE, TEST_DURATION, null)
         );
     }
 
@@ -342,7 +346,7 @@
         mHelper.setPhoneCallDetails(mViews,
                 new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                         TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO, TEST_GEOCODE,
-                        types, TEST_DATE, TEST_DURATION)
+                        types, TEST_DATE, TEST_DURATION, null)
         );
     }
 
@@ -351,7 +355,7 @@
         mHelper.setPhoneCallDetails(mViews,
                 new PhoneCallDetails(TEST_NUMBER, Calls.PRESENTATION_ALLOWED,
                         TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO, TEST_GEOCODE,
-                        types, TEST_DATE, TEST_DURATION)
+                        types, TEST_DATE, TEST_DURATION, null)
         );
     }
 }
diff --git a/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java b/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java
index 1e5c257..e12a2a2 100644
--- a/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java
+++ b/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java
@@ -31,6 +31,8 @@
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.provider.CallLog.Calls;
+import android.telecomm.Subscription;
+import android.telephony.TelephonyManager;
 import android.text.format.DateFormat;
 import android.util.Log;
 import android.view.View;
@@ -47,6 +49,7 @@
 import com.android.dialer.tests.R;
 
 import java.util.Calendar;
+import java.util.List;
 import java.util.Random;
 
 /**
@@ -83,6 +86,8 @@
     private int mCallDateYear;
     private int mCallDateMonth;
     private int mCallDateDay;
+    private RadioButton mSubscription0;
+    private RadioButton mSubscription1;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -127,6 +132,8 @@
         mCallDate = (TextView) findViewById(R.id.call_date);
         mPhoneNumber = (TextView) findViewById(R.id.phone_number);
         mOffset = (EditText) findViewById(R.id.delta_after_add);
+        mSubscription0 = (RadioButton) findViewById(R.id.subscription0);
+        mSubscription1 = (RadioButton) findViewById(R.id.subscription1);
 
         // Use the current time as the default values for the picker
         final Calendar c = Calendar.getInstance();
@@ -388,6 +395,18 @@
         }
     }
 
+    private Subscription getManualSubscription() {
+        TelephonyManager telephonyManager = new TelephonyManager(this);
+        List <Subscription> subscriptions = telephonyManager.getSubscriptions();
+        if (mSubscription0.isChecked()) {
+            return subscriptions.get(0);
+        } else if (mSubscription1.isChecked()){
+            return subscriptions.get(1);
+        } else {
+            return null;
+        }
+    }
+
     /**
      * Shows a time picker dialog, storing the results in the time field.
      */
@@ -470,7 +489,8 @@
         dateTime.set(mCallDateYear, mCallDateMonth, mCallDateDay, mCallTimeHour, mCallTimeMinute);
 
         Calls.addCall(null, this, mPhoneNumber.getText().toString(), getManualPresentation(),
-                getManualCallType(), dateTime.getTimeInMillis(), RNG.nextInt(60 * 60));
+                getManualCallType(), getManualSubscription(), dateTime.getTimeInMillis(),
+                RNG.nextInt(60 * 60));
 
         // Subtract offset from the call date/time and store as new date/time
         int offset = Integer.parseInt(mOffset.getText().toString());