blob: 7c322ca0e48e8a87818fd800413ffae9911ebf94 [file] [log] [blame]
Christine Chen03741c62013-10-23 16:17:03 -07001/*
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
Christine Chen03741c62013-10-23 16:17:03 -070045 /**
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);
Yorke Leeba3c8392014-04-11 14:34:40 -070055 String countryIso = telephonyManager.getNetworkCountryIso().toUpperCase();
Christine Chen03741c62013-10-23 16:17:03 -070056
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 }
Andrew Leebf8600e2014-07-01 16:07:59 -070064
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 }
Christine Chen03741c62013-10-23 16:17:03 -070073}