blob: 7a9ac228cfa40d066502c7c983155cc22759c0ad [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 {
29 private static final String TAG = ThreadUtil.class.getSimpleName();
30
31 private static final String TELEPHONY_PACKAGE_NAME =
32 "com.android.phone";
33
34 private static final String GSM_CALL_SERVICE_CLASS_NAME =
35 "com.android.services.telephony.GsmCallService";
36
37 private static final String CDMA_CALL_SERVICE_CLASS_NAME =
38 "com.android.services.telephony.CdmaCallService";
39
40 private TelephonyUtil() {}
41
42 static boolean isTelephonySelector(CallServiceSelectorWrapper selector) {
43 return selector.getComponentName().getPackageName().equals(TELEPHONY_PACKAGE_NAME);
44 }
45
46 /**
47 * Returns whether or not the call is currently connected as a cellular call (through the
48 * device's cellular radio).
49 */
50 static boolean isCurrentlyPSTNCall(Call call) {
51 if (Log.DEBUG) {
52 verifyCallServiceExists(GSM_CALL_SERVICE_CLASS_NAME);
53 verifyCallServiceExists(CDMA_CALL_SERVICE_CLASS_NAME);
54 }
55
56 CallServiceWrapper callService = call.getCallService();
57 if (callService == null) {
58 return false;
59 }
60 CallServiceDescriptor descriptor = callService.getDescriptor();
61 String className = descriptor.getServiceComponent().getClassName();
62 return className.equals(GSM_CALL_SERVICE_CLASS_NAME) ||
63 className.equals(CDMA_CALL_SERVICE_CLASS_NAME);
64 }
65
66 private static void verifyCallServiceExists(String serviceName) {
67 PackageManager packageManager = TelecommApp.getInstance().getPackageManager();
68 try {
69 ServiceInfo info = packageManager.getServiceInfo(
70 new ComponentName(TELEPHONY_PACKAGE_NAME, serviceName), 0);
71 if (info == null) {
72 Log.wtf(TAG, "Error, unable to find call service: %s", serviceName);
73 }
74 } catch (PackageManager.NameNotFoundException e) {
75 Log.wtf(TAG, e, "Error, exception while trying to find call service: %s", serviceName);
76 }
77 }
78}