blob: 783b427e4d507750f953523870e3b6b259725c98 [file] [log] [blame]
Sailesh Nepal18386a82014-03-19 10:22:40 -07001/*
2 * Copyright 2014, 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.telecomm;
18
19import android.content.ComponentName;
20import android.content.pm.PackageManager;
21import android.content.pm.ServiceInfo;
22import android.telecomm.CallServiceDescriptor;
23
24/**
25 * Utilities to deal with the system telephony services. The system telephony services are treated
26 * differently from 3rd party services in some situations (emergency calls, audio focus, etc...).
27 */
28public final class TelephonyUtil {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -070029 private static final String TAG = TelephonyUtil.class.getSimpleName();
Sailesh Nepal18386a82014-03-19 10:22:40 -070030
Sailesh Nepal4a515502014-06-26 12:58:17 -070031 private static final String TELEPHONY_PACKAGE_NAME = "com.android.phone";
Sailesh Nepal18386a82014-03-19 10:22:40 -070032
Ihab Awad55a34282014-06-18 10:31:09 -070033 private static final String PSTN_CALL_SERVICE_CLASS_NAME =
34 "com.android.services.telephony.PstnConnectionService";
Sailesh Nepal18386a82014-03-19 10:22:40 -070035
36 private TelephonyUtil() {}
37
Sailesh Nepalc92c4362014-07-04 18:33:21 -070038 static boolean isPstnConnectionService(CallServiceDescriptor descriptor) {
Sailesh Nepal4a515502014-06-26 12:58:17 -070039 final ComponentName pstnComponentName = new ComponentName(
40 TELEPHONY_PACKAGE_NAME, PSTN_CALL_SERVICE_CLASS_NAME);
41 return pstnComponentName.equals(descriptor.getServiceComponent());
Santos Cordon5b7b9b32014-03-26 14:00:22 -070042 }
43
Sailesh Nepal18386a82014-03-19 10:22:40 -070044 /**
45 * Returns whether or not the call is currently connected as a cellular call (through the
46 * device's cellular radio).
47 */
48 static boolean isCurrentlyPSTNCall(Call call) {
49 if (Log.DEBUG) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -070050 verifyConnectionServiceExists(PSTN_CALL_SERVICE_CLASS_NAME);
Sailesh Nepal18386a82014-03-19 10:22:40 -070051 }
52
Sailesh Nepalc92c4362014-07-04 18:33:21 -070053 ConnectionServiceWrapper service = call.getConnectionService();
54 if (service == null) {
Sailesh Nepal18386a82014-03-19 10:22:40 -070055 return false;
56 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -070057 return isPstnConnectionService(service.getDescriptor());
Sailesh Nepal18386a82014-03-19 10:22:40 -070058 }
59
Sailesh Nepalc92c4362014-07-04 18:33:21 -070060 private static void verifyConnectionServiceExists(String serviceName) {
Sailesh Nepal18386a82014-03-19 10:22:40 -070061 PackageManager packageManager = TelecommApp.getInstance().getPackageManager();
62 try {
63 ServiceInfo info = packageManager.getServiceInfo(
64 new ComponentName(TELEPHONY_PACKAGE_NAME, serviceName), 0);
65 if (info == null) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -070066 Log.wtf(TAG, "Error, unable to find connection service: %s", serviceName);
Sailesh Nepal18386a82014-03-19 10:22:40 -070067 }
68 } catch (PackageManager.NameNotFoundException e) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -070069 Log.wtf(TAG, e, "Error, exception while trying to find connection service: %s",
70 serviceName);
Sailesh Nepal18386a82014-03-19 10:22:40 -070071 }
72 }
73}