Applies promoted emergency numbers.

- Shows promoted emergency numbers provided by Telephony framework.
- Removes the fallback emergency number "112" since it may confuse users.
- Dials promoted emergency numbers with specified phone.
- Dials other emergency numbers with default phone.

Bug: 114163622
Test: Manually
Change-Id: I26edaabd26dd06ae96018ff1d5c0177d33316a72
diff --git a/src/com/android/phone/EccShortcutAdapter.java b/src/com/android/phone/EccShortcutAdapter.java
index e14b90a..19b1fec 100644
--- a/src/com/android/phone/EccShortcutAdapter.java
+++ b/src/com/android/phone/EccShortcutAdapter.java
@@ -17,6 +17,7 @@
 package com.android.phone;
 
 import android.content.Context;
+import android.telephony.emergency.EmergencyNumber;
 import android.text.TextUtils;
 import android.view.View;
 import android.view.ViewGroup;
@@ -25,9 +26,6 @@
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
-import com.android.phone.ecc.CountryEccInfo;
-import com.android.phone.ecc.EccInfo;
-
 import com.google.common.collect.LinkedListMultimap;
 
 import java.util.ArrayList;
@@ -35,15 +33,11 @@
 
 /**
  * An abstract adapter between ECC data and the view contains ECC shortcuts.
- * This adapter will convert given {@link CountryEccInfo} to number string, description string and
- * icon resource id for each {@link EccInfo}.
+ * This adapter prepares description and icon for every promoted emergency number.
  * The subclass should implements {@link #inflateView} to provide the view for an ECC data, when the
  * view container calls {@link #getView}.
  */
 public abstract class EccShortcutAdapter extends BaseAdapter {
-    // GSM default emergency number, used when country's fallback ECC(112 or 911) not available.
-    private static final String FALLBACK_EMERGENCY_NUMBER = "112";
-
     private List<EccDisplayMaterial> mEccDisplayMaterialList;
 
     private CharSequence mPoliceDescription;
@@ -90,16 +84,16 @@
      * Get a View that display the given ECC data: number, description and iconRes.
      *
      * @param convertView The old view to reuse, if possible. Note: You should check that this view
-     *                   is non-null and of an appropriate type before using. If it is not possible
-     *                   to convert this view to display the correct data, this method can create a
-     *                   new view. Heterogeneous lists can specify their number of view types, so
-     *                   that this View is always of the right type (see {@link
-     *                   BaseAdapter#getViewTypeCount()} and {@link
-     *                   BaseAdapter#getItemViewType(int)}).
-     * @param parent The parent that this view will eventually be attached to.
-     * @param number The number of the ECC shortcut to display in the view.
+     *                    is non-null and of an appropriate type before using. If it is not possible
+     *                    to convert this view to display the correct data, this method can create a
+     *                    new view. Heterogeneous lists can specify their number of view types, so
+     *                    that this View is always of the right type (see {@link
+     *                    BaseAdapter#getViewTypeCount()} and {@link
+     *                    BaseAdapter#getItemViewType(int)}).
+     * @param parent      The parent that this view will eventually be attached to.
+     * @param number      The number of the ECC shortcut to display in the view.
      * @param description The description of the ECC shortcut to display in the view.
-     * @param iconRes The icon resource ID represent for the ECC shortcut.
+     * @param iconRes     The icon resource ID represent for the ECC shortcut.
      * @return A View corresponding to the data at the specified position.
      */
     public abstract View inflateView(View convertView, ViewGroup parent, CharSequence number,
@@ -110,89 +104,68 @@
      * be display by the short container View.
      *
      * @param context The context used to access resources.
-     * @param countryEccInfo Updated country ECC info.
+     * @param phoneInfo Information of the phone to make an emergency call.
      */
-    public void updateCountryEccInfo(@NonNull Context context, CountryEccInfo countryEccInfo) {
+    public void updateCountryEccInfo(@NonNull Context context,
+            @Nullable ShortcutViewUtils.PhoneInfo phoneInfo) {
         List<EccDisplayMaterial> displayMaterials = new ArrayList<>();
 
-        final EccInfo.Type[] orderedMustHaveTypes =
-                { EccInfo.Type.POLICE, EccInfo.Type.AMBULANCE, EccInfo.Type.FIRE };
-
-        String fallback = null;
-        EccInfo[] eccInfoList = null;
-        if (countryEccInfo != null) {
-            fallback = countryEccInfo.getFallbackEcc();
-            eccInfoList = countryEccInfo.getEccInfoList();
-        }
-        if (TextUtils.isEmpty(fallback)) {
-            fallback = FALLBACK_EMERGENCY_NUMBER;
-        }
-
-        // Finding matched ECC for each must have types.
-        // Using LinkedListMultimap to prevent duplicated keys.
-        // LinkedListMultimap also preserve the insertion order of keys (ECC number) and values
-        // (matched types of the ECC number), which follows the order in orderedMustHaveTypes.
-        LinkedListMultimap<String, EccInfo.Type> eccList = LinkedListMultimap.create();
-        for (EccInfo.Type type : orderedMustHaveTypes) {
-            String number = null;
-            if (eccInfoList != null) {
-                number = pickEccNumberForType(type, eccInfoList);
+        try {
+            if (phoneInfo == null) {
+                return;
             }
-            if (number == null) {
-                number = fallback;
-            }
-            // append type for exist number, otherwise insert a new entry.
-            eccList.put(number, type);
-        }
 
-        // prepare display material for picked ECC
-        for (String number : eccList.keySet()) {
-            EccDisplayMaterial material = prepareDisplayMaterialForEccInfo(context,
-                    new EccInfo(number, eccList.asMap().get(number)));
-            if (material != null) {
-                displayMaterials.add(material);
-            }
-        }
-
-        mEccDisplayMaterialList = displayMaterials;
-        notifyDataSetChanged();
-    }
-
-    private @Nullable String pickEccNumberForType(@NonNull EccInfo.Type targetType,
-            @NonNull EccInfo[] eccInfoList) {
-        EccInfo pickedEccInfo = null;
-        for (EccInfo eccInfo : eccInfoList) {
-            if (eccInfo.containsType(targetType)) {
-                // An ECC is more suitable for a type if the ECC has fewer other types.
-                if (pickedEccInfo == null
-                        || eccInfo.getTypesCount() < pickedEccInfo.getTypesCount()) {
-                    pickedEccInfo = eccInfo;
+            LinkedListMultimap<String, Integer> emergencyNumbers = LinkedListMultimap.create();
+            for (int category : ShortcutViewUtils.PROMOTED_CATEGORIES) {
+                String number = pickEmergencyNumberForCategory(category,
+                        phoneInfo.getPromotedEmergencyNumbers());
+                if (number != null) {
+                    emergencyNumbers.put(number, category);
                 }
             }
+
+            // prepare display material for picked ECC
+            for (String number : emergencyNumbers.keySet()) {
+                EccDisplayMaterial material = prepareEccMaterial(context, number,
+                        emergencyNumbers.get(number));
+                if (material != null) {
+                    displayMaterials.add(material);
+                }
+            }
+        } finally {
+            mEccDisplayMaterialList = displayMaterials;
+            notifyDataSetChanged();
         }
-        if (pickedEccInfo != null) {
-            return pickedEccInfo.getNumber();
+    }
+
+    @Nullable
+    private String pickEmergencyNumberForCategory(int category,
+            @NonNull List<EmergencyNumber> emergencyNumbers) {
+        for (EmergencyNumber number : emergencyNumbers) {
+            if ((number.getEmergencyServiceCategoryBitmask() & category) != 0) {
+                return number.getNumber();
+            }
         }
         return null;
     }
 
-    private @Nullable EccDisplayMaterial prepareDisplayMaterialForEccInfo(@NonNull Context context,
-            @NonNull EccInfo eccInfo) {
+    @Nullable
+    private EccDisplayMaterial prepareEccMaterial(@NonNull Context context, @NonNull String number,
+            @NonNull List<Integer> categories) {
         EccDisplayMaterial material = new EccDisplayMaterial();
-        material.number = eccInfo.getNumber();
-        EccInfo.Type[] types = eccInfo.getTypes();
-        for (EccInfo.Type type : types) {
+        material.number = number;
+        for (int category : categories) {
             CharSequence description;
-            switch (type) {
-                case POLICE:
+            switch (category) {
+                case EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_POLICE:
                     description = mPoliceDescription;
                     material.iconRes = R.drawable.ic_local_police_gm2_24px;
                     break;
-                case AMBULANCE:
+                case EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_AMBULANCE:
                     description = mAmbulanceDescription;
                     material.iconRes = R.drawable.ic_local_hospital_gm2_24px;
                     break;
-                case FIRE:
+                case EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_FIRE_BRIGADE:
                     description = mFireDescription;
                     material.iconRes = R.drawable.ic_local_fire_department_gm2_24px;
                     break;
@@ -200,6 +173,7 @@
                     // ignore unknown types
                     continue;
             }
+
             if (TextUtils.isEmpty(material.description)) {
                 material.description = description;
             } else {
@@ -209,10 +183,10 @@
                         material.description, description);
             }
         }
+
         if (TextUtils.isEmpty(material.description) || material.iconRes == 0) {
             return null;
         }
         return material;
     }
-
 }
diff --git a/src/com/android/phone/EmergencyDialer.java b/src/com/android/phone/EmergencyDialer.java
index c89ddc6..80b4632 100644
--- a/src/com/android/phone/EmergencyDialer.java
+++ b/src/com/android/phone/EmergencyDialer.java
@@ -83,9 +83,6 @@
 import com.android.phone.common.dialpad.DialpadKeyButton;
 import com.android.phone.common.util.ViewUtil;
 import com.android.phone.common.widget.ResizingTextEditText;
-import com.android.phone.ecc.CountryEccInfo;
-import com.android.phone.ecc.EccInfoHelper;
-import com.android.phone.ecc.IsoToEccProtobufRepository;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -235,7 +232,7 @@
     private View mEmergencyShortcutView;
     private View mDialpadView;
 
-    private EccInfoHelper mEccInfoHelper;
+    private ShortcutViewUtils.PhoneInfo mPhoneInfo;
 
     private List<EmergencyShortcutButton> mEmergencyShortcutButtonList;
     private EccShortcutAdapter mShortcutAdapter;
@@ -363,14 +360,10 @@
                 configMgr.getConfigForSubId(SubscriptionManager.getDefaultVoiceSubscriptionId());
 
         mIsShortcutViewEnabled = false;
+        mPhoneInfo = null;
         if (canEnableShortcutView(carrierConfig)) {
-            TelephonyManager tm = getSystemService(TelephonyManager.class);
-            String countryIso = tm.getNetworkCountryIso();
-            if (TextUtils.isEmpty(countryIso)) {
-                Log.d(LOG_TAG, "Unable to determine the country of current network.");
-            } else if (!EccInfoHelper.isCountryEccInfoAvailable(this, countryIso)) {
-                Log.d(LOG_TAG, "ECC info is unavailable.");
-            } else {
+            mPhoneInfo = ShortcutViewUtils.pickPreferredPhone(this);
+            if (mPhoneInfo != null) {
                 mIsShortcutViewEnabled = true;
             }
         }
@@ -469,7 +462,6 @@
         mEmergencyInfoGroup = (EmergencyInfoGroup) findViewById(R.id.emergency_info_button);
 
         if (mIsShortcutViewEnabled) {
-            mEccInfoHelper = new EccInfoHelper(IsoToEccProtobufRepository.getInstance());
             setupEmergencyShortcutsView();
         }
     }
@@ -611,11 +603,8 @@
 
         if (!TextUtils.isEmpty(phoneNumber)) {
             if (DBG) Log.d(LOG_TAG, "dial emergency number: " + Rlog.pii(LOG_TAG, phoneNumber));
-            Bundle extras = new Bundle();
-            extras.putInt(TelecomManager.EXTRA_CALL_SOURCE,
-                    ParcelableCallAnalytics.CALL_SOURCE_EMERGENCY_SHORTCUT);
-            TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
-            tm.placeCall(Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null), extras);
+            placeCall(phoneNumber, ParcelableCallAnalytics.CALL_SOURCE_EMERGENCY_SHORTCUT,
+                    mPhoneInfo);
         } else {
             Log.d(LOG_TAG, "emergency number is empty");
         }
@@ -769,30 +758,9 @@
             updateTheme(lockScreenColors.supportsDarkText());
         }
 
-        if (mIsShortcutViewEnabled && mEccInfoHelper != null) {
-            final Context context = this;
-            mEccInfoHelper.getCountryEccInfoAsync(context,
-                    new EccInfoHelper.CountryEccInfoResultCallback() {
-                        @Override
-                        public void onSuccess(String iso, CountryEccInfo countryEccInfo) {
-                            Log.d(LOG_TAG, "Retrieve ECC info success, country ISO: "
-                                    + Rlog.pii(LOG_TAG, iso));
-                            updateLocationAndEccInfo(iso, countryEccInfo);
-                        }
-
-                        @Override
-                        public void onDetectCountryFailed() {
-                            Log.w(LOG_TAG, "Cannot detect current country.");
-                            updateLocationAndEccInfo(null, null);
-                        }
-
-                        @Override
-                        public void onRetrieveCountryEccInfoFailed(String iso) {
-                            Log.w(LOG_TAG, "Retrieve ECC info failed, country ISO: "
-                                    + Rlog.pii(LOG_TAG, iso));
-                            updateLocationAndEccInfo(iso, null);
-                        }
-                    });
+        if (mIsShortcutViewEnabled) {
+            mPhoneInfo = ShortcutViewUtils.pickPreferredPhone(this);
+            updateLocationAndEccInfo();
         }
     }
 
@@ -897,7 +865,20 @@
         // nothing and just returns input number.
         mLastNumber = PhoneNumberUtils.convertToEmergencyNumber(this, mLastNumber);
 
-        if (PhoneNumberUtils.isLocalEmergencyNumber(this, mLastNumber)) {
+        boolean isEmergencyNumber = false;
+        ShortcutViewUtils.PhoneInfo phoneToMakeCall = null;
+        if (mPhoneInfo != null) {
+            isEmergencyNumber = mPhoneInfo.hasPromotedEmergencyNumber(mLastNumber);
+            if (isEmergencyNumber) {
+                phoneToMakeCall = mPhoneInfo;
+            }
+        }
+        if (!isEmergencyNumber) {
+            TelephonyManager tm = getSystemService(TelephonyManager.class);
+            isEmergencyNumber = tm.isCurrentEmergencyNumber(mLastNumber);
+        }
+
+        if (isEmergencyNumber) {
             if (DBG) Log.d(LOG_TAG, "placing call to " + mLastNumber);
 
             // place the call if it is a valid number
@@ -910,11 +891,8 @@
             mMetricsWriter.writeMetricsForMakingCall(MetricsWriter.CALL_SOURCE_DIALPAD,
                     MetricsWriter.PHONE_NUMBER_TYPE_EMERGENCY, isShortcutNumber(mLastNumber));
 
-            Bundle extras = new Bundle();
-            extras.putInt(TelecomManager.EXTRA_CALL_SOURCE,
-                    ParcelableCallAnalytics.CALL_SOURCE_EMERGENCY_DIALPAD);
-            TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
-            tm.placeCall(Uri.fromParts(PhoneAccount.SCHEME_TEL, mLastNumber, null), extras);
+            placeCall(mLastNumber, ParcelableCallAnalytics.CALL_SOURCE_EMERGENCY_DIALPAD,
+                    phoneToMakeCall);
         } else {
             if (DBG) Log.d(LOG_TAG, "rejecting bad requested number " + mLastNumber);
 
@@ -928,6 +906,20 @@
         mDigits.getText().delete(0, mDigits.getText().length());
     }
 
+    private void placeCall(String number, int callSource, ShortcutViewUtils.PhoneInfo phone) {
+        Bundle extras = new Bundle();
+        extras.putInt(TelecomManager.EXTRA_CALL_SOURCE, callSource);
+
+        if (phone != null && phone.getPhoneAccountHandle() != null) {
+            // Requests to dial through the specified phone.
+            extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,
+                    phone.getPhoneAccountHandle());
+        }
+
+        TelecomManager tm = this.getSystemService(TelecomManager.class);
+        tm.placeCall(Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null), extras);
+    }
+
     /**
      * Plays the specified tone for TONE_LENGTH_MS milliseconds.
      *
@@ -1071,7 +1063,7 @@
         AsyncTask<Void, Void, Boolean> showWfcWarningTask = new AsyncTask<Void, Void, Boolean>() {
             @Override
             protected Boolean doInBackground(Void... voids) {
-                TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
+                TelephonyManager tm = getSystemService(TelephonyManager.class);
                 boolean isWfcAvailable = tm.isWifiCallingAvailable();
                 ServiceState ss = tm.getServiceState();
                 boolean isCellAvailable =
@@ -1143,14 +1135,15 @@
         mEmergencyShortcutButtonList = new ArrayList<>();
         setupEmergencyCallShortcutButton();
 
-        updateLocationAndEccInfo(null, null);
+        updateLocationAndEccInfo();
 
         switchView(mEmergencyShortcutView, mDialpadView, false);
     }
 
-    private void setLocationInfo(String countryIso) {
+    private void setLocationInfo() {
         final View locationInfo = findViewById(R.id.location_info);
 
+        String countryIso = mPhoneInfo != null ? mPhoneInfo.getCountryIso() : null;
         String countryName = null;
         if (!TextUtils.isEmpty(countryIso)) {
             Locale locale = Locale.getDefault();
@@ -1227,11 +1220,11 @@
         mShortcutAdapter.registerDataSetObserver(mShortcutDataSetObserver);
     }
 
-    private void updateLocationAndEccInfo(String iso, CountryEccInfo countryEccInfo) {
+    private void updateLocationAndEccInfo() {
         if (!isFinishing() && !isDestroyed()) {
-            setLocationInfo(iso);
+            setLocationInfo();
             if (mShortcutAdapter != null) {
-                mShortcutAdapter.updateCountryEccInfo(this, countryEccInfo);
+                mShortcutAdapter.updateCountryEccInfo(this, mPhoneInfo);
             }
         }
     }
diff --git a/src/com/android/phone/ecc/EccInfoHelper.java b/src/com/android/phone/ecc/EccInfoHelper.java
deleted file mode 100644
index c471c4b..0000000
--- a/src/com/android/phone/ecc/EccInfoHelper.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.phone.ecc;
-
-import android.content.Context;
-import android.os.AsyncTask;
-import android.provider.Settings;
-import android.telephony.CellIdentityGsm;
-import android.telephony.CellIdentityLte;
-import android.telephony.CellIdentityWcdma;
-import android.telephony.CellInfo;
-import android.telephony.CellInfoGsm;
-import android.telephony.CellInfoLte;
-import android.telephony.CellInfoWcdma;
-import android.telephony.PhoneNumberUtils;
-import android.telephony.Rlog;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-import android.util.Log;
-import android.util.Pair;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import com.android.internal.telephony.MccTable;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Helper for retrieve ECC info for current country.
- */
-public class EccInfoHelper {
-    // Debug constants.
-    private static final boolean DBG = false;
-    private static final String LOG_TAG = "EccInfoHelper";
-
-    /**
-     * Check if current CountryEccInfo is available for current environment.
-     */
-    public static boolean isCountryEccInfoAvailable(Context context, String countryIso) {
-        CountryEccInfo countryEccInfo;
-        try {
-            countryEccInfo = IsoToEccProtobufRepository.getInstance()
-                    .getCountryEccInfo(context, countryIso);
-        } catch (IOException e) {
-            Log.e(LOG_TAG, "Failed to retrieve ECC: ", e);
-            return false;
-        }
-
-        if (countryEccInfo == null) {
-            return false;
-        }
-        for (EccInfo entry : countryEccInfo.getEccInfoList()) {
-            if (!PhoneNumberUtils.isEmergencyNumber(entry.getNumber())) {
-                // The CountryEccInfo is unavailable if any ecc number in the local table was
-                // declined.
-                return false;
-            }
-        }
-        return true;
-    }
-
-    // country ISO to ECC list data source
-    private IsoToEccRepository mEccRepo;
-
-    /**
-     * Callback for {@link #getCountryEccInfoAsync}.
-     */
-    public interface CountryEccInfoResultCallback {
-        /**
-         * Called if successfully get country ECC info.
-         *
-         * @param iso Detected current country ISO.
-         * @param countryEccInfo The EccInfo of current country.
-         */
-        void onSuccess(@NonNull String iso, @NonNull CountryEccInfo countryEccInfo);
-
-        /**
-         * Called if failed to get country ISO.
-         */
-        void onDetectCountryFailed();
-
-        /**
-         * Called if failed to get ECC info for given country ISO.
-         *
-         * @param iso Detected current country ISO.
-         */
-        void onRetrieveCountryEccInfoFailed(@NonNull String iso);
-    }
-
-    /**
-     * Constructor of EccInfoHelper
-     *
-     * @param eccRepository A repository for ECC info, indexed by country ISO.
-     */
-    public EccInfoHelper(@NonNull IsoToEccRepository eccRepository) {
-        mEccRepo = eccRepository;
-    }
-
-    /**
-     * Get ECC info for current location, base on detected country ISO.
-     * It's possible we cannot detect current country, ex. device is in airplane mode,
-     * or there's no available base station near by.
-     *
-     * @param context The context used to access resources.
-     * @param callback Callback for result.
-     */
-    public void getCountryEccInfoAsync(final @NonNull Context context,
-            final CountryEccInfoResultCallback callback) {
-        new AsyncTask<Void, Void, Pair<String, CountryEccInfo>>() {
-            @Override
-            protected Pair<String, CountryEccInfo> doInBackground(Void... voids) {
-                String iso = getCurrentCountryIso(context);
-                if (TextUtils.isEmpty(iso)) {
-                    return null;
-                }
-
-                CountryEccInfo dialableCountryEccInfo;
-                try {
-                    // access data source in background thread to avoid possible file IO caused ANR.
-                    CountryEccInfo rawEccInfo = mEccRepo.getCountryEccInfo(context, iso);
-                    dialableCountryEccInfo = getDialableCountryEccInfo(rawEccInfo);
-                } catch (IOException e) {
-                    Log.e(LOG_TAG, "Failed to retrieve ECC: " + e.getMessage());
-                    dialableCountryEccInfo = null;
-                }
-                return new Pair<>(iso, dialableCountryEccInfo);
-            }
-
-            @Override
-            protected void onPostExecute(Pair<String, CountryEccInfo> result) {
-                if (callback != null) {
-                    if (result == null) {
-                        callback.onDetectCountryFailed();
-                    } else {
-                        String iso = result.first;
-                        CountryEccInfo countryEccInfo = result.second;
-                        if (countryEccInfo == null) {
-                            callback.onRetrieveCountryEccInfoFailed(iso);
-                        } else {
-                            callback.onSuccess(iso, countryEccInfo);
-                        }
-                    }
-                }
-            }
-        }.execute();
-    }
-
-    @NonNull
-    private CountryEccInfo getDialableCountryEccInfo(CountryEccInfo countryEccInfo) {
-        ArrayList<EccInfo> dialableECCList = new ArrayList<>();
-        String dialableFallback = null;
-
-        // filter out non-dialable ECC
-        if (countryEccInfo != null) {
-            for (EccInfo entry : countryEccInfo.getEccInfoList()) {
-                if (PhoneNumberUtils.isEmergencyNumber(entry.getNumber())) {
-                    dialableECCList.add(entry);
-                }
-            }
-            String defaultFallback = countryEccInfo.getFallbackEcc();
-            if (PhoneNumberUtils.isEmergencyNumber(defaultFallback)) {
-                dialableFallback = defaultFallback;
-            }
-        }
-        return new CountryEccInfo(dialableFallback, dialableECCList);
-    }
-
-    @Nullable
-    private String getCurrentCountryIso(@NonNull Context context) {
-        // Do not detect country ISO if airplane mode is on
-        int airplaneMode = Settings.System.getInt(context.getContentResolver(),
-                Settings.Global.AIRPLANE_MODE_ON, 0);
-        if (airplaneMode != 0) {
-            Log.d(LOG_TAG, "Airplane mode is on, do not get country ISO.");
-            return null;
-        }
-
-        TelephonyManager tm = (TelephonyManager) context.getSystemService(
-                Context.TELEPHONY_SERVICE);
-        String iso = tm.getNetworkCountryIso();
-        if (DBG) Log.d(LOG_TAG, "Current country ISO is " + Rlog.pii(LOG_TAG, iso));
-
-        if (TextUtils.isEmpty(iso)) {
-            // XXX: according to ServiceStateTracker's implementation, retrieve cell info in a
-            // thread other than TelephonyManager's main thread.
-            String mcc = getCurrentMccFromCellInfo(context);
-            iso = MccTable.countryCodeForMcc(mcc);
-            if (DBG) {
-                Log.d(LOG_TAG, "Current mcc is " + Rlog.pii(LOG_TAG, mcc) + ", mapping to ISO: "
-                        + Rlog.pii(LOG_TAG, iso));
-            }
-        }
-        return iso;
-    }
-
-    // XXX: According to ServiceStateTracker implementation, to actually get current cell info,
-    // this method must be called in a separate thread from ServiceStateTracker, which is the
-    // main thread of Telephony service.
-    @Nullable
-    private String getCurrentMccFromCellInfo(@NonNull Context context) {
-        // retrieve mcc info from base station even no SIM present.
-        TelephonyManager tm = (TelephonyManager) context.getSystemService(
-                Context.TELEPHONY_SERVICE);
-        List<CellInfo> cellInfos = tm.getAllCellInfo();
-        String mcc = null;
-        if (cellInfos != null) {
-            for (CellInfo ci : cellInfos) {
-                if (ci instanceof CellInfoGsm) {
-                    CellInfoGsm cellInfoGsm = (CellInfoGsm) ci;
-                    CellIdentityGsm cellIdentityGsm = cellInfoGsm.getCellIdentity();
-                    mcc = cellIdentityGsm.getMccString();
-                    break;
-                } else if (ci instanceof CellInfoWcdma) {
-                    CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) ci;
-                    CellIdentityWcdma cellIdentityWcdma = cellInfoWcdma.getCellIdentity();
-                    mcc = cellIdentityWcdma.getMccString();
-                    break;
-                } else if (ci instanceof CellInfoLte) {
-                    CellInfoLte cellInfoLte = (CellInfoLte) ci;
-                    CellIdentityLte cellIdentityLte = cellInfoLte.getCellIdentity();
-                    mcc = cellIdentityLte.getMccString();
-                    break;
-                }
-            }
-            if (DBG) Log.d(LOG_TAG, "Retrieve MCC from cell info list: " + Rlog.pii(LOG_TAG, mcc));
-        } else {
-            Log.w(LOG_TAG, "Cannot get cell info list.");
-        }
-        return mcc;
-    }
-}