Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c8e528b8 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

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
parent 5fce2ceb
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -50,10 +50,13 @@ import android.provider.CallLog.Calls;
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 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
        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)) {
@@ -248,6 +263,26 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
        }
    }

    /**
     * @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.
     *