Add support for showing child number in incall ui.

Bug: 22685113
Change-Id: I4cf8f92820fcc028d26b5edcbf9bbc02a4d7a6d5
diff --git a/InCallUI/res/values/strings.xml b/InCallUI/res/values/strings.xml
index cadef73..15cba1f 100644
--- a/InCallUI/res/values/strings.xml
+++ b/InCallUI/res/values/strings.xml
@@ -456,4 +456,8 @@
     <!-- Description of the "camera off" icon displayed when the device's camera is disabled during
          a video call. [CHAR LIMIT=NONE] -->
     <string name="camera_off_description">Camera off</string>
+
+    <!-- Used to inform the user that a call was received via a number other than the primary
+        phone number associated with their device. [CHAR LIMIT=16] -->
+    <string name="child_number">via <xliff:g id="child_number" example="650-555-1212">%s</xliff:g></string>
 </resources>
diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java
index ee73db2..807d43a 100644
--- a/InCallUI/src/com/android/incallui/Call.java
+++ b/InCallUI/src/com/android/incallui/Call.java
@@ -28,6 +28,7 @@
 import android.telecom.DisconnectCause;
 import android.telecom.GatewayInfo;
 import android.telecom.InCallService.VideoCall;
+import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.VideoProfile;
 import android.text.TextUtils;
@@ -35,12 +36,20 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
+import java.util.Objects;
 
 /**
  * Describes a single call and its state.
  */
 @NeededForTesting
 public class Call {
+    /**
+     * Call extras key used to store a child number associated with the current call.
+     * Used to communicate that the connection was received via a child phone number associated with
+     * the {@link PhoneAccount}'s primary number.
+     */
+    public static final String EXTRA_CHILD_ADDRESS = "android.telecom.EXTRA_CHILD_ADDRESS";
+
     /* Defines different states of this call */
     public static class State {
         public static final int INVALID = 0;
@@ -254,6 +263,7 @@
     private int mModifyToVideoState = VideoProfile.STATE_AUDIO_ONLY;
 
     private InCallVideoCallCallback mVideoCallCallback;
+    private String mChildNumber;
 
     /**
      * Used only to create mock calls for testing
@@ -314,6 +324,14 @@
                     CallList.getInstance().getCallByTelecommCall(
                             mTelecommCall.getChildren().get(i)).getId());
         }
+
+        Bundle callExtras = mTelecommCall.getDetails().getExtras();
+        if (callExtras != null && callExtras.containsKey(EXTRA_CHILD_ADDRESS)) {
+            String childNumber = callExtras.getString(EXTRA_CHILD_ADDRESS);
+            if (!Objects.equals(childNumber, mChildNumber)) {
+                mChildNumber = childNumber;
+            }
+        }
     }
 
     private static int translateState(int state) {
@@ -393,6 +411,13 @@
         return mTelecommCall == null ? null : mTelecommCall.getDetails().getExtras();
     }
 
+    /**
+     * @return The child number for the call, or {@code null} if none specified.
+     */
+    public String getChildNumber() {
+        return mChildNumber;
+    }
+
     /** Returns call disconnect cause, defined by {@link DisconnectCause}. */
     public DisconnectCause getDisconnectCause() {
         if (mState == State.DISCONNECTED || mState == State.IDLE) {
diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java
index 3f9c567..c39d792 100644
--- a/InCallUI/src/com/android/incallui/CallCardPresenter.java
+++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java
@@ -582,13 +582,22 @@
             Log.d(TAG, "Update primary display info for " + mPrimaryContactInfo);
 
             String name = getNameForCall(mPrimaryContactInfo);
-            String number = getNumberForCall(mPrimaryContactInfo);
+            String number;
+
+            // If a child number is present, use it instead of the 2nd line.
+            boolean isChildNumberShown = !TextUtils.isEmpty(mPrimary.getChildNumber());
+            if (isChildNumberShown) {
+                number = mContext.getString(R.string.child_number, mPrimary.getChildNumber());
+            } else {
+                number = getNumberForCall(mPrimaryContactInfo);
+            }
+
             boolean nameIsNumber = name != null && name.equals(mPrimaryContactInfo.number);
             ui.setPrimary(
                     number,
                     name,
                     nameIsNumber,
-                    mPrimaryContactInfo.label,
+                    isChildNumberShown ? null : mPrimaryContactInfo.label,
                     mPrimaryContactInfo.photo,
                     mPrimaryContactInfo.isSipCall);
         } else {