blob: d3a806026432089f7de690beec0e8767b0a4b886 [file] [log] [blame]
Daniel Lehmannf77b8e92010-07-16 18:58:36 -07001/*
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
17package com.android.contacts.util;
18
Daniel Lehmannc90c7052011-03-16 18:42:34 -070019import com.android.contacts.R;
20
Daniel Lehmannf77b8e92010-07-16 18:58:36 -070021import android.content.Context;
22import android.content.Intent;
23import android.content.pm.PackageManager;
24import android.content.pm.ResolveInfo;
25import android.net.Uri;
Daniel Lehmann7781ea12010-10-21 21:56:43 -070026import android.net.sip.SipManager;
Daniel Lehmanne9b196e2010-10-26 12:17:39 -070027import android.telephony.TelephonyManager;
Daniel Lehmannf77b8e92010-07-16 18:58:36 -070028
29import java.util.List;
30
Daniel Lehmanne9b196e2010-10-26 12:17:39 -070031/**
32 * Provides static functions to quickly test the capabilities of this device. The static
33 * members are not safe for threading
34 */
Daniel Lehmannf77b8e92010-07-16 18:58:36 -070035public final class PhoneCapabilityTester {
Daniel Lehmanne9b196e2010-10-26 12:17:39 -070036 private static boolean sIsInitialized;
37 private static boolean sIsPhone;
38 private static boolean sIsSipPhone;
39
Daniel Lehmannf77b8e92010-07-16 18:58:36 -070040 /**
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 Lehmann7779f492010-08-24 15:26:36 -070052 * Returns true if this device can be used to make phone calls
Daniel Lehmannf77b8e92010-07-16 18:58:36 -070053 */
Daniel Lehmann7779f492010-08-24 15:26:36 -070054 public static boolean isPhone(Context context) {
Daniel Lehmanne9b196e2010-10-26 12:17:39 -070055 if (!sIsInitialized) initialize(context);
Daniel Lehmann7779f492010-08-24 15:26:36 -070056 // Is the device physically capabable of making phone calls?
Daniel Lehmanne9b196e2010-10-26 12:17:39 -070057 return sIsPhone;
58 }
Daniel Lehmann7779f492010-08-24 15:26:36 -070059
Daniel Lehmanne9b196e2010-10-26 12:17:39 -070060 private static void initialize(Context context) {
61 final TelephonyManager telephonyManager = new TelephonyManager(context);
62 sIsPhone = telephonyManager.isVoiceCapable();
Dmitri Plotnikov27bfa402011-02-22 17:56:15 -080063 sIsSipPhone = sIsPhone && SipManager.isVoipSupported(context);
Daniel Lehmanne9b196e2010-10-26 12:17:39 -070064 sIsInitialized = true;
Daniel Lehmannf77b8e92010-07-16 18:58:36 -070065 }
66
67 /**
Daniel Lehmann7781ea12010-10-21 21:56:43 -070068 * Returns true if this device can be used to make sip calls
69 */
70 public static boolean isSipPhone(Context context) {
Daniel Lehmanne9b196e2010-10-26 12:17:39 -070071 if (!sIsInitialized) initialize(context);
72 return sIsSipPhone;
Daniel Lehmann7781ea12010-10-21 21:56:43 -070073 }
74
75 /**
Daniel Lehmannf77b8e92010-07-16 18:58:36 -070076 * Returns true if the device has an SMS application installed.
77 */
78 public static boolean isSmsIntentRegistered(Context context) {
Daniel Lehmanne9b196e2010-10-26 12:17:39 -070079 // Don't cache the result as the user might install third party apps to send SMS
Daniel Lehmannf77b8e92010-07-16 18:58:36 -070080 final Intent intent = new Intent(Intent.ACTION_SENDTO,
81 Uri.fromParts(Constants.SCHEME_SMSTO, "", null));
82 return isIntentRegistered(context, intent);
83 }
Daniel Lehmannc90c7052011-03-16 18:42:34 -070084
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 Lehmannf77b8e92010-07-16 18:58:36 -070092}