1f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann/* 2f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * Copyright (C) 2010 The Android Open Source Project 3f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * 4f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * Licensed under the Apache License, Version 2.0 (the "License"); 5f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * you may not use this file except in compliance with the License. 6f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * You may obtain a copy of the License at 7f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * 8f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * http://www.apache.org/licenses/LICENSE-2.0 9f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * 10f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * Unless required by applicable law or agreed to in writing, software 11f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * distributed under the License is distributed on an "AS IS" BASIS, 12f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * See the License for the specific language governing permissions and 14f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * limitations under the License. 15f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann */ 16f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann 17f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmannpackage com.android.contacts.util; 18f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann 1976de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braunimport android.content.ComponentName; 20f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmannimport android.content.Context; 21f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmannimport android.content.Intent; 22f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmannimport android.content.pm.PackageManager; 23f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmannimport android.content.pm.ResolveInfo; 24f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmannimport android.net.Uri; 257781ea12308e5c5d7bbeab175c31cc6cf1f19188Daniel Lehmannimport android.net.sip.SipManager; 26c21751ddc1a91453a37273ace9e24907bb54cc99Yorke Leeimport android.provider.MediaStore; 2776de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braunimport android.provider.Telephony; 28e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmannimport android.telephony.TelephonyManager; 29f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann 303a8df86541c91ac5023bc46efae4ed23502512faChiao Chengimport com.android.contacts.common.CallUtil; 31e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.R; 32e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng 33f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmannimport java.util.List; 34f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann 35e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann/** 36e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann * Provides static functions to quickly test the capabilities of this device. The static 37e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann * members are not safe for threading 38e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann */ 39f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmannpublic final class PhoneCapabilityTester { 40e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann private static boolean sIsInitialized; 41e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann private static boolean sIsPhone; 42e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann private static boolean sIsSipPhone; 43e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann 44f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann /** 45f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * Tests whether the Intent has a receiver registered. This can be used to show/hide 46f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann * functionality (like Phone, SMS) 47f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann */ 48f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann public static boolean isIntentRegistered(Context context, Intent intent) { 49f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann final PackageManager packageManager = context.getPackageManager(); 50f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann final List<ResolveInfo> receiverList = packageManager.queryIntentActivities(intent, 51f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann PackageManager.MATCH_DEFAULT_ONLY); 52f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann return receiverList.size() > 0; 53f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann } 54f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann 55f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann /** 567779f490ccc2af98b5cd2cd537d1bdb36e173c94Daniel Lehmann * Returns true if this device can be used to make phone calls 57f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann */ 587779f490ccc2af98b5cd2cd537d1bdb36e173c94Daniel Lehmann public static boolean isPhone(Context context) { 59e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann if (!sIsInitialized) initialize(context); 607779f490ccc2af98b5cd2cd537d1bdb36e173c94Daniel Lehmann // Is the device physically capabable of making phone calls? 61e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann return sIsPhone; 62e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann } 637779f490ccc2af98b5cd2cd537d1bdb36e173c94Daniel Lehmann 64e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann private static void initialize(Context context) { 65e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann final TelephonyManager telephonyManager = new TelephonyManager(context); 66e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann sIsPhone = telephonyManager.isVoiceCapable(); 6727bfa40a248101925abd69cc3106897baf81cbacDmitri Plotnikov sIsSipPhone = sIsPhone && SipManager.isVoipSupported(context); 68e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann sIsInitialized = true; 69f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann } 70f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann 71f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann /** 727781ea12308e5c5d7bbeab175c31cc6cf1f19188Daniel Lehmann * Returns true if this device can be used to make sip calls 737781ea12308e5c5d7bbeab175c31cc6cf1f19188Daniel Lehmann */ 747781ea12308e5c5d7bbeab175c31cc6cf1f19188Daniel Lehmann public static boolean isSipPhone(Context context) { 75e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann if (!sIsInitialized) initialize(context); 76e9b196e446cc34f690a043c5f5d9e5a7b8b92b3fDaniel Lehmann return sIsSipPhone; 777781ea12308e5c5d7bbeab175c31cc6cf1f19188Daniel Lehmann } 787781ea12308e5c5d7bbeab175c31cc6cf1f19188Daniel Lehmann 797781ea12308e5c5d7bbeab175c31cc6cf1f19188Daniel Lehmann /** 8076de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun * Returns the component name to use for sending to sms or null. 81f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann */ 8276de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun public static ComponentName getSmsComponent(Context context) { 8376de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun String smsPackage = Telephony.Sms.getDefaultSmsPackage(context); 8476de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun if (smsPackage != null) { 8576de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun final PackageManager packageManager = context.getPackageManager(); 8676de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun final Intent intent = new Intent(Intent.ACTION_SENDTO, 8776de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun Uri.fromParts(CallUtil.SCHEME_SMSTO, "", null)); 8876de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun final List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent, 0); 8976de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun for (ResolveInfo resolveInfo : resolveInfos) { 9076de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun if (smsPackage.equals(resolveInfo.activityInfo.packageName)) { 9176de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun return new ComponentName(smsPackage, resolveInfo.activityInfo.name); 9276de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun } 9376de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun } 9476de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun } 9576de0fada634c9fa73ade154a42ba9a96730ecaeDavid Braun return null; 96f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann } 97c90c705db8b3665ba9c8d8ce4b8ab3a03e38ddc7Daniel Lehmann 98c90c705db8b3665ba9c8d8ce4b8ab3a03e38ddc7Daniel Lehmann /** 99c21751ddc1a91453a37273ace9e24907bb54cc99Yorke Lee * Returns true if there is a camera on the device 100c21751ddc1a91453a37273ace9e24907bb54cc99Yorke Lee */ 101c21751ddc1a91453a37273ace9e24907bb54cc99Yorke Lee public static boolean isCameraIntentRegistered(Context context) { 102c21751ddc1a91453a37273ace9e24907bb54cc99Yorke Lee final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 103c21751ddc1a91453a37273ace9e24907bb54cc99Yorke Lee return isIntentRegistered(context, intent); 104c21751ddc1a91453a37273ace9e24907bb54cc99Yorke Lee } 105c21751ddc1a91453a37273ace9e24907bb54cc99Yorke Lee 106c21751ddc1a91453a37273ace9e24907bb54cc99Yorke Lee /** 107c90c705db8b3665ba9c8d8ce4b8ab3a03e38ddc7Daniel Lehmann * True if we are using two-pane layouts ("tablet mode"), false if we are using single views 108c90c705db8b3665ba9c8d8ce4b8ab3a03e38ddc7Daniel Lehmann * ("phone mode") 109c90c705db8b3665ba9c8d8ce4b8ab3a03e38ddc7Daniel Lehmann */ 110c90c705db8b3665ba9c8d8ce4b8ab3a03e38ddc7Daniel Lehmann public static boolean isUsingTwoPanes(Context context) { 111c90c705db8b3665ba9c8d8ce4b8ab3a03e38ddc7Daniel Lehmann return context.getResources().getBoolean(R.bool.config_use_two_panes); 112c90c705db8b3665ba9c8d8ce4b8ab3a03e38ddc7Daniel Lehmann } 1132871d61514f014926d991e8b037828c67438e522Maurice Chu 1142871d61514f014926d991e8b037828c67438e522Maurice Chu /** 1152871d61514f014926d991e8b037828c67438e522Maurice Chu * True if the favorites tab should be shown in two-pane mode. False, otherwise. 1162871d61514f014926d991e8b037828c67438e522Maurice Chu */ 1172871d61514f014926d991e8b037828c67438e522Maurice Chu public static boolean isUsingTwoPanesInFavorites(Context context) { 1182871d61514f014926d991e8b037828c67438e522Maurice Chu return context.getResources().getBoolean(R.bool.config_use_two_panes_in_favorites); 1192871d61514f014926d991e8b037828c67438e522Maurice Chu } 120f77b8e994f512e3d75d3169198183fde482614d8Daniel Lehmann} 121