Format missed number in missed call notification.

This fixes an issue where missed calls in Korea are still showing the +82
prefix.  This is due to the fact that the numbers were not being formatted
in the missed call notification.

Bug: 24189507
Change-Id: I9e3041a983f2abb950ec64a2f447c18a5228bc5e
diff --git a/src/com/android/server/telecom/ui/MissedCallNotifierImpl.java b/src/com/android/server/telecom/ui/MissedCallNotifierImpl.java
index f1d1078..7eb640a 100644
--- a/src/com/android/server/telecom/ui/MissedCallNotifierImpl.java
+++ b/src/com/android/server/telecom/ui/MissedCallNotifierImpl.java
@@ -50,10 +50,13 @@
 import android.telecom.DisconnectCause;
 import android.telecom.PhoneAccount;
 import android.telephony.PhoneNumberUtils;
+import android.telephony.TelephonyManager;
 import android.text.BidiFormatter;
 import android.text.TextDirectionHeuristics;
 import android.text.TextUtils;
 
+import java.util.Locale;
+
 // TODO: Needed for move to system service: import com.android.internal.R;
 
 /**
@@ -234,6 +237,18 @@
         String handle = call.getHandle() == null ? null : call.getHandle().getSchemeSpecificPart();
         String name = call.getName();
 
+        if (!TextUtils.isEmpty(handle)) {
+            String formattedNumber = PhoneNumberUtils.formatNumber(handle,
+                    getCurrentCountryIso(mContext));
+
+            // The formatted number will be null if there was a problem formatting it, but we can
+            // default to using the unformatted number instead (e.g. a SIP URI may not be able to
+            // be formatted.
+            if (!TextUtils.isEmpty(formattedNumber)) {
+                handle = formattedNumber;
+            }
+        }
+
         if (!TextUtils.isEmpty(name) && TextUtils.isGraphic(name)) {
             return name;
         } else if (!TextUtils.isEmpty(handle)) {
@@ -249,6 +264,26 @@
     }
 
     /**
+     * @return The ISO 3166-1 two letters country code of the country the user is in based on the
+     *      network location.  If the network location does not exist, fall back to the locale
+     *      setting.
+     */
+    private String getCurrentCountryIso(Context context) {
+        // Without framework function calls, this seems to be the most accurate location service
+        // we can rely on.
+        final TelephonyManager telephonyManager =
+                (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+        String countryIso = telephonyManager.getNetworkCountryIso().toUpperCase();
+
+        if (countryIso == null) {
+            countryIso = Locale.getDefault().getCountry();
+            Log.w(this, "No CountryDetector; falling back to countryIso based on locale: "
+                    + countryIso);
+        }
+        return countryIso;
+    }
+
+    /**
      * Creates a new pending intent that sends the user to the call log.
      *
      * @return The pending intent.