1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.contacts.common.util;
17
18import android.content.Context;
19import android.telephony.PhoneNumberUtils;
20import android.telephony.TelephonyManager;
21import android.text.TextUtils;
22import android.util.Log;
23
24import java.util.Locale;
25
26/**
27 * This class provides several TelephonyManager util functions.
28 */
29public class TelephonyManagerUtils {
30
31    private static final String LOG_TAG = TelephonyManagerUtils.class.getSimpleName();
32
33    /**
34     * Gets the voicemail tag from Telephony Manager.
35     * @param context Current application context
36     * @return Voicemail tag, the alphabetic identifier associated with the voice mail number.
37     */
38    public static String getVoiceMailAlphaTag(Context context) {
39        final TelephonyManager telephonyManager =
40                (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
41        final String voiceMailLabel = telephonyManager.getVoiceMailAlphaTag();
42        return voiceMailLabel;
43    }
44
45    /**
46     * @return The ISO 3166-1 two letters country code of the country the user
47     *         is in based on the network location. If the network location does not exist, fall
48     *         back to the locale setting.
49     */
50    public static String getCurrentCountryIso(Context context, Locale locale) {
51        // Without framework function calls, this seems to be the most accurate location service
52        // we can rely on.
53        final TelephonyManager telephonyManager =
54            (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
55        String countryIso = telephonyManager.getNetworkCountryIso().toUpperCase();
56
57        if (countryIso == null) {
58            countryIso = locale.getCountry();
59            Log.w(LOG_TAG, "No CountryDetector; falling back to countryIso based on locale: "
60                    + countryIso);
61        }
62        return countryIso;
63    }
64
65    /**
66     * @param context Current application context.
67     * @return True if there is a subscription which supports video calls. False otherwise.
68     */
69    public static boolean hasVideoCallSubscription(Context context) {
70        // TODO: Check the telephony manager's subscriptions to see if any support video calls.
71        return true;
72    }
73}
74