• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
16 package com.android.contacts.util;
17 
18 import android.content.Context;
19 import android.telephony.TelephonyManager;
20 import android.util.Log;
21 
22 import java.util.Locale;
23 
24 /**
25  * This class provides several TelephonyManager util functions.
26  */
27 public class TelephonyManagerUtils {
28 
29     private static final String LOG_TAG = TelephonyManagerUtils.class.getSimpleName();
30 
31     /**
32      * Gets the voicemail tag from Telephony Manager.
33      * @param context Current application context
34      * @return Voicemail tag, the alphabetic identifier associated with the voice mail number.
35      */
getVoiceMailAlphaTag(Context context)36     public static String getVoiceMailAlphaTag(Context context) {
37         final TelephonyManager telephonyManager =
38                 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
39         final String voiceMailLabel = telephonyManager.getVoiceMailAlphaTag();
40         return voiceMailLabel;
41     }
42 
43     /**
44      * @return The ISO 3166-1 two letters country code of the country the user
45      *         is in based on the network location. If the network location does not exist, fall
46      *         back to the locale setting.
47      */
getCurrentCountryIso(Context context, Locale locale)48     public static String getCurrentCountryIso(Context context, Locale locale) {
49         // Without framework function calls, this seems to be the most accurate location service
50         // we can rely on.
51         final TelephonyManager telephonyManager =
52             (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
53         String countryIso = telephonyManager.getNetworkCountryIso().toUpperCase();
54 
55         if (countryIso == null) {
56             countryIso = locale.getCountry();
57             Log.w(LOG_TAG, "No CountryDetector; falling back to countryIso based on locale: "
58                     + countryIso);
59         }
60         return countryIso;
61     }
62 
63     /**
64      * @param context Current application context.
65      * @return True if there is a subscription which supports video calls. False otherwise.
66      */
hasVideoCallSubscription(Context context)67     public static boolean hasVideoCallSubscription(Context context) {
68         // TODO: Check the telephony manager's subscriptions to see if any support video calls.
69         return true;
70     }
71 }
72