Search in sources :

Example 6 with CountryDetector

use of android.location.CountryDetector in project android_frameworks_base by DirtyUnicorns.

the class CallerInfo method getCurrentCountryIso.

/**
     * @return The ISO 3166-1 two letters country code of the country the user
     *         is in.
     */
private static String getCurrentCountryIso(Context context, Locale locale) {
    String countryIso = null;
    CountryDetector detector = (CountryDetector) context.getSystemService(Context.COUNTRY_DETECTOR);
    if (detector != null) {
        Country country = detector.detectCountry();
        if (country != null) {
            countryIso = country.getCountryIso();
        } else {
            Rlog.e(TAG, "CountryDetector.detectCountry() returned null.");
        }
    }
    if (countryIso == null) {
        countryIso = locale.getCountry();
        Rlog.w(TAG, "No CountryDetector; falling back to countryIso based on locale: " + countryIso);
    }
    return countryIso;
}
Also used : Country(android.location.Country) CountryDetector(android.location.CountryDetector)

Example 7 with CountryDetector

use of android.location.CountryDetector in project android_frameworks_base by crdroidandroid.

the class CallerInfo method getCurrentCountryIso.

/**
     * @return The ISO 3166-1 two letters country code of the country the user
     *         is in.
     */
private static String getCurrentCountryIso(Context context, Locale locale) {
    String countryIso = null;
    CountryDetector detector = (CountryDetector) context.getSystemService(Context.COUNTRY_DETECTOR);
    if (detector != null) {
        Country country = detector.detectCountry();
        if (country != null) {
            countryIso = country.getCountryIso();
        } else {
            Rlog.e(TAG, "CountryDetector.detectCountry() returned null.");
        }
    }
    if (countryIso == null) {
        countryIso = locale.getCountry();
        Rlog.w(TAG, "No CountryDetector; falling back to countryIso based on locale: " + countryIso);
    }
    return countryIso;
}
Also used : Country(android.location.Country) CountryDetector(android.location.CountryDetector)

Example 8 with CountryDetector

use of android.location.CountryDetector in project android_frameworks_base by ParanoidAndroid.

the class PhoneNumberUtils method isLocalEmergencyNumberInternal.

/**
     * Helper function for isLocalEmergencyNumber() and
     * isPotentialLocalEmergencyNumber().
     *
     * @param number the number to look up.
     * @param context the specific context which the number should be checked against
     * @param useExactMatch if true, consider a number to be an emergency
     *           number only if it *exactly* matches a number listed in
     *           the RIL / SIM.  If false, a number is considered to be an
     *           emergency number if it simply starts with the same digits
     *           as any of the emergency numbers listed in the RIL / SIM.
     *
     * @return true if the specified number is an emergency number for a
     *              local country, based on the CountryDetector.
     *
     * @see android.location.CountryDetector
     */
private static boolean isLocalEmergencyNumberInternal(String number, Context context, boolean useExactMatch) {
    String countryIso;
    CountryDetector detector = (CountryDetector) context.getSystemService(Context.COUNTRY_DETECTOR);
    if (detector != null) {
        countryIso = detector.detectCountry().getCountryIso();
    } else {
        Locale locale = context.getResources().getConfiguration().locale;
        countryIso = locale.getCountry();
        Rlog.w(LOG_TAG, "No CountryDetector; falling back to countryIso based on locale: " + countryIso);
    }
    return isEmergencyNumberInternal(number, countryIso, useExactMatch);
}
Also used : Locale(java.util.Locale) CountryDetector(android.location.CountryDetector)

Example 9 with CountryDetector

use of android.location.CountryDetector in project platform_frameworks_base by android.

the class PhoneNumberUtils method isLocalEmergencyNumberInternal.

/**
     * Helper function for isLocalEmergencyNumber() and
     * isPotentialLocalEmergencyNumber().
     *
     * @param subId the subscription id of the SIM.
     * @param number the number to look up.
     * @param context the specific context which the number should be checked against
     * @param useExactMatch if true, consider a number to be an emergency
     *           number only if it *exactly* matches a number listed in
     *           the RIL / SIM.  If false, a number is considered to be an
     *           emergency number if it simply starts with the same digits
     *           as any of the emergency numbers listed in the RIL / SIM.
     *
     * @return true if the specified number is an emergency number for a
     *              local country, based on the CountryDetector.
     * @hide
     */
private static boolean isLocalEmergencyNumberInternal(int subId, String number, Context context, boolean useExactMatch) {
    String countryIso;
    CountryDetector detector = (CountryDetector) context.getSystemService(Context.COUNTRY_DETECTOR);
    if (detector != null && detector.detectCountry() != null) {
        countryIso = detector.detectCountry().getCountryIso();
    } else {
        Locale locale = context.getResources().getConfiguration().locale;
        countryIso = locale.getCountry();
        Rlog.w(LOG_TAG, "No CountryDetector; falling back to countryIso based on locale: " + countryIso);
    }
    return isEmergencyNumberInternal(subId, number, countryIso, useExactMatch);
}
Also used : Locale(java.util.Locale) CountryDetector(android.location.CountryDetector)

Aggregations

CountryDetector (android.location.CountryDetector)9 Country (android.location.Country)4 Locale (java.util.Locale)3