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 19 import android.content.Context; 20 import android.content.Intent; 21 import android.content.pm.PackageManager; 22 import android.content.pm.ResolveInfo; 23 import android.net.Uri; 24 import android.net.sip.SipManager; 25 import android.provider.MediaStore; 26 import android.telephony.TelephonyManager; 27 28 import com.android.contacts.common.CallUtil; 29 import com.android.contacts.R; 30 31 import java.util.List; 32 33 /** 34 * Provides static functions to quickly test the capabilities of this device. The static 35 * members are not safe for threading 36 */ 37 public final class PhoneCapabilityTester { 38 private static boolean sIsInitialized; 39 private static boolean sIsPhone; 40 private static boolean sIsSipPhone; 41 42 /** 43 * Tests whether the Intent has a receiver registered. This can be used to show/hide 44 * functionality (like Phone, SMS) 45 */ 46 public static boolean isIntentRegistered(Context context, Intent intent) { 47 final PackageManager packageManager = context.getPackageManager(); 48 final List<ResolveInfo> receiverList = packageManager.queryIntentActivities(intent, 49 PackageManager.MATCH_DEFAULT_ONLY); 50 return receiverList.size() > 0; 51 } 52 53 /** 54 * Returns true if this device can be used to make phone calls 55 */ 56 public static boolean isPhone(Context context) { 57 if (!sIsInitialized) initialize(context); 58 // Is the device physically capabable of making phone calls? 59 return sIsPhone; 60 } 61 62 private static void initialize(Context context) { 63 final TelephonyManager telephonyManager = new TelephonyManager(context); 64 sIsPhone = telephonyManager.isVoiceCapable(); 65 sIsSipPhone = sIsPhone && SipManager.isVoipSupported(context); 66 sIsInitialized = true; 67 } 68 69 /** 70 * Returns true if this device can be used to make sip calls 71 */ 72 public static boolean isSipPhone(Context context) { 73 if (!sIsInitialized) initialize(context); 74 return sIsSipPhone; 75 } 76 77 /** 78 * Returns true if the device has an SMS application installed. 79 */ 80 public static boolean isSmsIntentRegistered(Context context) { 81 // Don't cache the result as the user might install third party apps to send SMS 82 final Intent intent = new Intent(Intent.ACTION_SENDTO, 83 Uri.fromParts(CallUtil.SCHEME_SMSTO, "", null)); 84 return isIntentRegistered(context, intent); 85 } 86 87 /** 88 * Returns true if there is a camera on the device 89 */ 90 public static boolean isCameraIntentRegistered(Context context) { 91 final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 92 return isIntentRegistered(context, intent); 93 } 94 95 /** 96 * True if we are using two-pane layouts ("tablet mode"), false if we are using single views 97 * ("phone mode") 98 */ 99 public static boolean isUsingTwoPanes(Context context) { 100 return context.getResources().getBoolean(R.bool.config_use_two_panes); 101 } 102 103 /** 104 * True if the favorites tab should be shown in two-pane mode. False, otherwise. 105 */ 106 public static boolean isUsingTwoPanesInFavorites(Context context) { 107 return context.getResources().getBoolean(R.bool.config_use_two_panes_in_favorites); 108 } 109 } 110