118386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal/* 218386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * Copyright 2014, The Android Open Source Project 318386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * 418386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * Licensed under the Apache License, Version 2.0 (the "License"); 518386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * you may not use this file except in compliance with the License. 618386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * You may obtain a copy of the License at 718386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * 818386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * http://www.apache.org/licenses/LICENSE-2.0 918386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * 1018386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * Unless required by applicable law or agreed to in writing, software 1118386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * distributed under the License is distributed on an "AS IS" BASIS, 1218386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1318386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * See the License for the specific language governing permissions and 1418386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * limitations under the License. 1518386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal */ 1618386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal 177cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunnpackage com.android.server.telecom; 1818386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal 1918386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepalimport android.content.ComponentName; 2069eb0f582babcedc1dc5e6613a27867be6e8d0e0Ihab Awadimport android.content.Context; 2169eb0f582babcedc1dc5e6613a27867be6e8d0e0Ihab Awadimport android.net.Uri; 22c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Leeimport android.telecom.PhoneAccount; 23c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Leeimport android.telecom.PhoneAccountHandle; 2469eb0f582babcedc1dc5e6613a27867be6e8d0e0Ihab Awadimport android.telephony.PhoneNumberUtils; 2518386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal 2618386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal/** 2718386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * Utilities to deal with the system telephony services. The system telephony services are treated 2818386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal * differently from 3rd party services in some situations (emergency calls, audio focus, etc...). 2918386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal */ 3018386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepalpublic final class TelephonyUtil { 318c85dee84fbbd8c36cf1c7b061001c6129623f92Sailesh Nepal private static final String TAG = TelephonyUtil.class.getSimpleName(); 3218386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal 334a51550686f5d2596f8e4c3b1bb6fc361b9019b4Sailesh Nepal private static final String TELEPHONY_PACKAGE_NAME = "com.android.phone"; 3418386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal 3555a3428c6b62e5a84d21f890418cfa9a8494780eIhab Awad private static final String PSTN_CALL_SERVICE_CLASS_NAME = 3669eb0f582babcedc1dc5e6613a27867be6e8d0e0Ihab Awad "com.android.services.telephony.TelephonyConnectionService"; 3718386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal 38c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee private static final PhoneAccountHandle DEFAULT_EMERGENCY_PHONE_ACCOUNT_HANDLE = 39c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee new PhoneAccountHandle( 40c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee new ComponentName(TELEPHONY_PACKAGE_NAME, PSTN_CALL_SERVICE_CLASS_NAME), "E"); 41c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee 4218386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal private TelephonyUtil() {} 4318386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal 44c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee /** 45c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee * @return fallback {@link PhoneAccount} to be used by Telecom for emergency calls in the 46c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee * rare case that Telephony has not registered any phone accounts yet. Details about this 47c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee * account are not expected to be displayed in the UI, so the description, etc are not 48c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee * populated. 49c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee */ 50c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee static PhoneAccount getDefaultEmergencyPhoneAccount() { 51c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee return PhoneAccount.builder(DEFAULT_EMERGENCY_PHONE_ACCOUNT_HANDLE, "E") 52c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee .setCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION | 53c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee PhoneAccount.CAPABILITY_CALL_PROVIDER | 54c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee PhoneAccount.CAPABILITY_PLACE_EMERGENCY_CALLS).build(); 55c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee } 56c127211ffd269bffc8a393a3c5ebfe7bdd99896bYorke Lee 57905dfba7883666f45a0c6958d8bc6c19d68972d9Sailesh Nepal static boolean isPstnComponentName(ComponentName componentName) { 584a51550686f5d2596f8e4c3b1bb6fc361b9019b4Sailesh Nepal final ComponentName pstnComponentName = new ComponentName( 594a51550686f5d2596f8e4c3b1bb6fc361b9019b4Sailesh Nepal TELEPHONY_PACKAGE_NAME, PSTN_CALL_SERVICE_CLASS_NAME); 60905dfba7883666f45a0c6958d8bc6c19d68972d9Sailesh Nepal return pstnComponentName.equals(componentName); 6118386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal } 6218386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal 6369eb0f582babcedc1dc5e6613a27867be6e8d0e0Ihab Awad static boolean shouldProcessAsEmergency(Context context, Uri handle) { 6469eb0f582babcedc1dc5e6613a27867be6e8d0e0Ihab Awad return handle != null && PhoneNumberUtils.isPotentialLocalEmergencyNumber( 6569eb0f582babcedc1dc5e6613a27867be6e8d0e0Ihab Awad context, handle.getSchemeSpecificPart()); 6618386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal } 6718386a8a98dee5cf6bb55eff7eab4109ba2b3c56Sailesh Nepal} 68