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 { |
| 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 | } |