Sailesh Nepal | 18386a8 | 2014-03-19 10:22:40 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.telecomm; |
| 18 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.pm.PackageManager; |
| 21 | import android.content.pm.ServiceInfo; |
| 22 | import 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 | */ |
| 28 | public final class TelephonyUtil { |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 29 | private static final String TAG = TelephonyUtil.class.getSimpleName(); |
Sailesh Nepal | 18386a8 | 2014-03-19 10:22:40 -0700 | [diff] [blame] | 30 | |
| 31 | private static final String TELEPHONY_PACKAGE_NAME = |
| 32 | "com.android.phone"; |
| 33 | |
| 34 | private static final String GSM_CALL_SERVICE_CLASS_NAME = |
Ihab Awad | b2c8d51 | 2014-05-14 10:12:56 -0700 | [diff] [blame] | 35 | "com.android.services.telephony.GsmConnectionService"; |
Sailesh Nepal | 18386a8 | 2014-03-19 10:22:40 -0700 | [diff] [blame] | 36 | |
| 37 | private static final String CDMA_CALL_SERVICE_CLASS_NAME = |
Ihab Awad | b2c8d51 | 2014-05-14 10:12:56 -0700 | [diff] [blame] | 38 | "com.android.services.telephony.CdmaConnectionService"; |
Sailesh Nepal | 18386a8 | 2014-03-19 10:22:40 -0700 | [diff] [blame] | 39 | |
| 40 | private TelephonyUtil() {} |
| 41 | |
| 42 | static boolean isTelephonySelector(CallServiceSelectorWrapper selector) { |
| 43 | return selector.getComponentName().getPackageName().equals(TELEPHONY_PACKAGE_NAME); |
| 44 | } |
| 45 | |
Santos Cordon | 5b7b9b3 | 2014-03-26 14:00:22 -0700 | [diff] [blame] | 46 | static boolean isPstnCallService(CallServiceDescriptor descriptor) { |
| 47 | ComponentName componentName = descriptor.getServiceComponent(); |
| 48 | if (TELEPHONY_PACKAGE_NAME.equals(componentName.getPackageName())) { |
| 49 | String className = componentName.getClassName(); |
| 50 | return GSM_CALL_SERVICE_CLASS_NAME.equals(className) || |
| 51 | CDMA_CALL_SERVICE_CLASS_NAME.equals(className); |
| 52 | } |
| 53 | |
| 54 | return false; |
| 55 | } |
| 56 | |
Sailesh Nepal | 18386a8 | 2014-03-19 10:22:40 -0700 | [diff] [blame] | 57 | /** |
| 58 | * Returns whether or not the call is currently connected as a cellular call (through the |
| 59 | * device's cellular radio). |
| 60 | */ |
| 61 | static boolean isCurrentlyPSTNCall(Call call) { |
| 62 | if (Log.DEBUG) { |
| 63 | verifyCallServiceExists(GSM_CALL_SERVICE_CLASS_NAME); |
| 64 | verifyCallServiceExists(CDMA_CALL_SERVICE_CLASS_NAME); |
| 65 | } |
| 66 | |
| 67 | CallServiceWrapper callService = call.getCallService(); |
| 68 | if (callService == null) { |
| 69 | return false; |
| 70 | } |
Santos Cordon | 5b7b9b3 | 2014-03-26 14:00:22 -0700 | [diff] [blame] | 71 | return isPstnCallService(callService.getDescriptor()); |
Sailesh Nepal | 18386a8 | 2014-03-19 10:22:40 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | private static void verifyCallServiceExists(String serviceName) { |
| 75 | PackageManager packageManager = TelecommApp.getInstance().getPackageManager(); |
| 76 | try { |
| 77 | ServiceInfo info = packageManager.getServiceInfo( |
| 78 | new ComponentName(TELEPHONY_PACKAGE_NAME, serviceName), 0); |
| 79 | if (info == null) { |
| 80 | Log.wtf(TAG, "Error, unable to find call service: %s", serviceName); |
| 81 | } |
| 82 | } catch (PackageManager.NameNotFoundException e) { |
| 83 | Log.wtf(TAG, e, "Error, exception while trying to find call service: %s", serviceName); |
| 84 | } |
| 85 | } |
| 86 | } |