Display "my phone number" while in emergency callback mode

While ECM is active, display the text

  "My number is xxx-xxx-xxxx"

at the top of the in-call screen, in the same space where we display
titles like "Dialing" or "Incoming call".

This is Sprint ECM requirement ANDR-126.

Note that this change affects ECM on all CDMA devices regardless of
carrier.  (This particular requirement is from Sprint, but I don't think
it's *contrary* to any other carrier's requirements, so let's just
enabled for any device that uses ECM.)

TESTED: On crespo-s, by temporarily hacking the isPhoneInEcm() method to
return true (so I wouldn't need to actually call 911.)  Also verified
that my change to call_card.xml had no effect on normal states like
"Dialing" and "Incoming call"

Bug: 4147081
Change-Id: Iee60bd1390fc4909e77bfdfc434f15164eed0b53
diff --git a/res/layout/call_card.xml b/res/layout/call_card.xml
index 663f114..ae0dbf2 100644
--- a/res/layout/call_card.xml
+++ b/res/layout/call_card.xml
@@ -82,7 +82,7 @@
         <TextView android:id="@+id/upperTitle"
                   android:textAppearance="?android:attr/textAppearanceLarge"
                   android:textSize="28sp"
-                  android:singleLine="true"
+                  android:gravity="center_horizontal"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_marginBottom="10dip"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d2feb4f..42c65d3 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -882,6 +882,9 @@
     <string name="card_title_hanging_up">Hanging up</string>
     <!-- In-call screen: status label for a call that's in CDMA flash mode -->
     <string name="card_title_in_call">In call</string>
+    <!-- In-call screen: special status label that shows your own phone
+         number during emergency callback mode (ECM) [CHAR LIMIT=30] -->
+    <string name="card_title_my_phone_number">My number is <xliff:g id="my_phone_number">%s</xliff:g></string>
 
     <!-- Notification strings -->
     <!-- Missed call notification label, used when there's exactly one missed call -->
diff --git a/src/com/android/phone/CallCard.java b/src/com/android/phone/CallCard.java
index d49b5d1..eb5910b 100755
--- a/src/com/android/phone/CallCard.java
+++ b/src/com/android/phone/CallCard.java
@@ -22,6 +22,7 @@
 import android.net.Uri;
 import android.pim.ContactsAsyncHelper;
 import android.provider.ContactsContract.Contacts;
+import android.telephony.PhoneNumberUtils;
 import android.text.TextUtils;
 import android.text.format.DateUtils;
 import android.util.AttributeSet;
@@ -610,6 +611,7 @@
     private void updateCardTitleWidgets(Phone phone, Call call) {
         if (DBG) log("updateCardTitleWidgets(call " + call + ")...");
         Call.State state = call.getState();
+        Context context = getContext();
 
         // TODO: Still need clearer spec on exactly how title *and* status get
         // set in all states.  (Then, given that info, refactor the code
@@ -622,7 +624,7 @@
             if (!PhoneApp.getInstance().notifier.getIsCdmaRedialCall()) {
                 cardTitle = getTitleForCallCard(call);  // Normal "foreground" call card
             } else {
-                cardTitle = getContext().getString(R.string.card_title_redialing);
+                cardTitle = context.getString(R.string.card_title_redialing);
             }
         } else if ((phoneType == Phone.PHONE_TYPE_GSM)
                 || (phoneType == Phone.PHONE_TYPE_SIP)) {
@@ -643,10 +645,16 @@
                         ? mTextColorConnectedBluetooth : mTextColorConnected;
 
                 if (phoneType == Phone.PHONE_TYPE_CDMA) {
-                    // Check if the "Dialing" 3Way call needs to be displayed
-                    // as the Foreground Call state still remains ACTIVE
+                    // In normal operation we don't use an "upper title" at all,
+                    // except for a couple of special cases:
                     if (mApplication.cdmaPhoneCallState.IsThreeWayCallOrigStateDialing()) {
-                        // Use the "upper title":
+                        // Display "Dialing" while dialing a 3Way call, even
+                        // though the foreground call state is still ACTIVE.
+                        setUpperTitle(cardTitle, mTextColorDefaultPrimary, state);
+                    } else if (PhoneUtils.isPhoneInEcm(phone)) {
+                        // In emergency callback mode (ECM), use a special title
+                        // that shows your own phone number.
+                        cardTitle = getECMCardTitle(context, phone);
                         setUpperTitle(cardTitle, mTextColorDefaultPrimary, state);
                     } else {
                         // Normal "ongoing call" state; don't use any "title" at all.
@@ -748,7 +756,6 @@
         String retVal = null;
         Call.State state = call.getState();
         Context context = getContext();
-        int resId;
 
         if (DBG) log("- getTitleForCallCard(Call " + call + ")...");
 
@@ -1455,6 +1462,22 @@
     }
 
     /**
+     * Returns the special card title used in emergency callback mode (ECM),
+     * which shows your own phone number.
+     */
+    private String getECMCardTitle(Context context, Phone phone) {
+        String rawNumber = phone.getLine1Number();  // may be null or empty
+        String formattedNumber;
+        if (!TextUtils.isEmpty(rawNumber)) {
+            formattedNumber = PhoneNumberUtils.formatNumber(rawNumber);
+        } else {
+            formattedNumber = context.getString(R.string.unknown);
+        }
+        String titleFormat = context.getString(R.string.card_title_my_phone_number);
+        return String.format(titleFormat, formattedNumber);
+    }
+
+    /**
      * Updates the "Call type" label, based on the current foreground call.
      * This is a special label and/or branding we display for certain
      * kinds of calls.