blob: a8cfb3e1b9208ef0cd038b3d158ceb1c4b9979b8 [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
31 private static final String TELEPHONY_PACKAGE_NAME =
32 "com.android.phone";
33
Ihab Awad55a34282014-06-18 10:31:09 -070034 private static final String PSTN_CALL_SERVICE_CLASS_NAME =
35 "com.android.services.telephony.PstnConnectionService";
Sailesh Nepal18386a82014-03-19 10:22:40 -070036
37 private TelephonyUtil() {}
38
Santos Cordon5b7b9b32014-03-26 14:00:22 -070039 static boolean isPstnCallService(CallServiceDescriptor descriptor) {
40 ComponentName componentName = descriptor.getServiceComponent();
41 if (TELEPHONY_PACKAGE_NAME.equals(componentName.getPackageName())) {
42 String className = componentName.getClassName();
Ihab Awad55a34282014-06-18 10:31:09 -070043 return PSTN_CALL_SERVICE_CLASS_NAME.equals(className);
Santos Cordon5b7b9b32014-03-26 14:00:22 -070044 }
45
46 return false;
47 }
48
Sailesh Nepal18386a82014-03-19 10:22:40 -070049 /**
50 * Returns whether or not the call is currently connected as a cellular call (through the
51 * device's cellular radio).
52 */
53 static boolean isCurrentlyPSTNCall(Call call) {
54 if (Log.DEBUG) {
Ihab Awad55a34282014-06-18 10:31:09 -070055 verifyCallServiceExists(PSTN_CALL_SERVICE_CLASS_NAME);
Sailesh Nepal18386a82014-03-19 10:22:40 -070056 }
57
58 CallServiceWrapper callService = call.getCallService();
59 if (callService == null) {
60 return false;
61 }
Santos Cordon5b7b9b32014-03-26 14:00:22 -070062 return isPstnCallService(callService.getDescriptor());
Sailesh Nepal18386a82014-03-19 10:22:40 -070063 }
64
65 private static void verifyCallServiceExists(String serviceName) {
66 PackageManager packageManager = TelecommApp.getInstance().getPackageManager();
67 try {
68 ServiceInfo info = packageManager.getServiceInfo(
69 new ComponentName(TELEPHONY_PACKAGE_NAME, serviceName), 0);
70 if (info == null) {
71 Log.wtf(TAG, "Error, unable to find call service: %s", serviceName);
72 }
73 } catch (PackageManager.NameNotFoundException e) {
74 Log.wtf(TAG, e, "Error, exception while trying to find call service: %s", serviceName);
75 }
76 }
77}