Daniel Lehmann | f77b8e9 | 2010-07-16 18:58:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| 17 | package com.android.contacts.util; |
| 18 | |
Daniel Lehmann | c90c705 | 2011-03-16 18:42:34 -0700 | [diff] [blame^] | 19 | import com.android.contacts.R; |
| 20 | |
Daniel Lehmann | f77b8e9 | 2010-07-16 18:58:36 -0700 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.pm.PackageManager; |
| 24 | import android.content.pm.ResolveInfo; |
| 25 | import android.net.Uri; |
Daniel Lehmann | 7781ea1 | 2010-10-21 21:56:43 -0700 | [diff] [blame] | 26 | import android.net.sip.SipManager; |
Daniel Lehmann | e9b196e | 2010-10-26 12:17:39 -0700 | [diff] [blame] | 27 | import android.telephony.TelephonyManager; |
Daniel Lehmann | f77b8e9 | 2010-07-16 18:58:36 -0700 | [diff] [blame] | 28 | |
| 29 | import java.util.List; |
| 30 | |
Daniel Lehmann | e9b196e | 2010-10-26 12:17:39 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Provides static functions to quickly test the capabilities of this device. The static |
| 33 | * members are not safe for threading |
| 34 | */ |
Daniel Lehmann | f77b8e9 | 2010-07-16 18:58:36 -0700 | [diff] [blame] | 35 | public final class PhoneCapabilityTester { |
Daniel Lehmann | e9b196e | 2010-10-26 12:17:39 -0700 | [diff] [blame] | 36 | private static boolean sIsInitialized; |
| 37 | private static boolean sIsPhone; |
| 38 | private static boolean sIsSipPhone; |
| 39 | |
Daniel Lehmann | f77b8e9 | 2010-07-16 18:58:36 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Tests whether the Intent has a receiver registered. This can be used to show/hide |
| 42 | * functionality (like Phone, SMS) |
| 43 | */ |
| 44 | public static boolean isIntentRegistered(Context context, Intent intent) { |
| 45 | final PackageManager packageManager = context.getPackageManager(); |
| 46 | final List<ResolveInfo> receiverList = packageManager.queryIntentActivities(intent, |
| 47 | PackageManager.MATCH_DEFAULT_ONLY); |
| 48 | return receiverList.size() > 0; |
| 49 | } |
| 50 | |
| 51 | /** |
Daniel Lehmann | 7779f49 | 2010-08-24 15:26:36 -0700 | [diff] [blame] | 52 | * Returns true if this device can be used to make phone calls |
Daniel Lehmann | f77b8e9 | 2010-07-16 18:58:36 -0700 | [diff] [blame] | 53 | */ |
Daniel Lehmann | 7779f49 | 2010-08-24 15:26:36 -0700 | [diff] [blame] | 54 | public static boolean isPhone(Context context) { |
Daniel Lehmann | e9b196e | 2010-10-26 12:17:39 -0700 | [diff] [blame] | 55 | if (!sIsInitialized) initialize(context); |
Daniel Lehmann | 7779f49 | 2010-08-24 15:26:36 -0700 | [diff] [blame] | 56 | // Is the device physically capabable of making phone calls? |
Daniel Lehmann | e9b196e | 2010-10-26 12:17:39 -0700 | [diff] [blame] | 57 | return sIsPhone; |
| 58 | } |
Daniel Lehmann | 7779f49 | 2010-08-24 15:26:36 -0700 | [diff] [blame] | 59 | |
Daniel Lehmann | e9b196e | 2010-10-26 12:17:39 -0700 | [diff] [blame] | 60 | private static void initialize(Context context) { |
| 61 | final TelephonyManager telephonyManager = new TelephonyManager(context); |
| 62 | sIsPhone = telephonyManager.isVoiceCapable(); |
Dmitri Plotnikov | 27bfa40 | 2011-02-22 17:56:15 -0800 | [diff] [blame] | 63 | sIsSipPhone = sIsPhone && SipManager.isVoipSupported(context); |
Daniel Lehmann | e9b196e | 2010-10-26 12:17:39 -0700 | [diff] [blame] | 64 | sIsInitialized = true; |
Daniel Lehmann | f77b8e9 | 2010-07-16 18:58:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
Daniel Lehmann | 7781ea1 | 2010-10-21 21:56:43 -0700 | [diff] [blame] | 68 | * Returns true if this device can be used to make sip calls |
| 69 | */ |
| 70 | public static boolean isSipPhone(Context context) { |
Daniel Lehmann | e9b196e | 2010-10-26 12:17:39 -0700 | [diff] [blame] | 71 | if (!sIsInitialized) initialize(context); |
| 72 | return sIsSipPhone; |
Daniel Lehmann | 7781ea1 | 2010-10-21 21:56:43 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /** |
Daniel Lehmann | f77b8e9 | 2010-07-16 18:58:36 -0700 | [diff] [blame] | 76 | * Returns true if the device has an SMS application installed. |
| 77 | */ |
| 78 | public static boolean isSmsIntentRegistered(Context context) { |
Daniel Lehmann | e9b196e | 2010-10-26 12:17:39 -0700 | [diff] [blame] | 79 | // Don't cache the result as the user might install third party apps to send SMS |
Daniel Lehmann | f77b8e9 | 2010-07-16 18:58:36 -0700 | [diff] [blame] | 80 | final Intent intent = new Intent(Intent.ACTION_SENDTO, |
| 81 | Uri.fromParts(Constants.SCHEME_SMSTO, "", null)); |
| 82 | return isIntentRegistered(context, intent); |
| 83 | } |
Daniel Lehmann | c90c705 | 2011-03-16 18:42:34 -0700 | [diff] [blame^] | 84 | |
| 85 | /** |
| 86 | * True if we are using two-pane layouts ("tablet mode"), false if we are using single views |
| 87 | * ("phone mode") |
| 88 | */ |
| 89 | public static boolean isUsingTwoPanes(Context context) { |
| 90 | return context.getResources().getBoolean(R.bool.config_use_two_panes); |
| 91 | } |
Daniel Lehmann | f77b8e9 | 2010-07-16 18:58:36 -0700 | [diff] [blame] | 92 | } |