CallUtil.java revision ca6b31e23c5f30602fb1d4a959726a91e0e4241b
1cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng/* 2066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwell * Copyright (C) 2015 The Android Open Source Project 3cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * 4cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * Licensed under the Apache License, Version 2.0 (the "License"); 5cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * you may not use this file except in compliance with the License. 6cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * You may obtain a copy of the License at 7cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * 8cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * http://www.apache.org/licenses/LICENSE-2.0 9cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * 10cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * Unless required by applicable law or agreed to in writing, software 11cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * distributed under the License is distributed on an "AS IS" BASIS, 12cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * See the License for the specific language governing permissions and 14cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * limitations under the License 15cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng */ 16cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng 17cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Chengpackage com.android.contacts.common; 18cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng 19066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwellimport com.android.contacts.common.util.PhoneNumberHelper; 20066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwellimport com.android.phone.common.PhoneConstants; 21066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwell 227e558dcdb3af3f8a1ef57f0c445d4ef5172ee935Andrew Leeimport android.content.Context; 23cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Chengimport android.content.Intent; 24cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Chengimport android.net.Uri; 255cf7f01aa00d67edbcd9d65fbfcbc1a4c56f60c3Tyler Gunnimport android.telecom.PhoneAccount; 26ca6b31e23c5f30602fb1d4a959726a91e0e4241bVinit Deshpandeimport android.telecom.PhoneAccountHandle; 275cf7f01aa00d67edbcd9d65fbfcbc1a4c56f60c3Tyler Gunnimport android.telecom.TelecomManager; 285cf7f01aa00d67edbcd9d65fbfcbc1a4c56f60c3Tyler Gunnimport android.telecom.VideoProfile; 29066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwellimport android.text.TextUtils; 30cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng 31ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunnimport java.util.List; 32ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn 33cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng/** 34066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwell * Utilities related to calls that can be used by non system apps. These 35066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwell * use {@link Intent#ACTION_CALL} instead of ACTION_CALL_PRIVILEGED. 36066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwell * 37066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwell * The privileged version of this util exists inside Dialer. 38cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng */ 39cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Chengpublic class CallUtil { 40cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng 41cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng /** 42cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * Return an Intent for making a phone call. Scheme (e.g. tel, sip) will be determined 43cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * automatically. 44cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng */ 45cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng public static Intent getCallIntent(String number) { 46066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwell return getCallIntent(getCallUri(number)); 47cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng } 48cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng 49cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng /** 50cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * Return an Intent for making a phone call. A given Uri will be used as is (without any 51cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * sanity check). 52cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng */ 53cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng public static Intent getCallIntent(Uri uri) { 54066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwell return new Intent(Intent.ACTION_CALL, uri); 55ac51a8788f5ecf755784d00e1ef40a1a87b437c1Nancy Chen } 56ac51a8788f5ecf755784d00e1ef40a1a87b437c1Nancy Chen 57ac51a8788f5ecf755784d00e1ef40a1a87b437c1Nancy Chen /** 58066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwell * A variant of {@link #getCallIntent} for starting a video call. 59c18a7548cc07635f52575309d28a1f465748b717Andrew Lee */ 60c095aee097899239c8ec427cc640f9870edad1eeNancy Chen public static Intent getVideoCallIntent(String number, String callOrigin) { 61066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwell final Intent intent = new Intent(Intent.ACTION_CALL, getCallUri(number)); 62066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwell intent.putExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, 630a221fc115a95ebb131eb15e081e163baf9c10a2Ihab Awad VideoProfile.VideoState.BIDIRECTIONAL); 64066bd684a9c318ca9b85492dc3aa7a9384ae353eBrian Attwell if (!TextUtils.isEmpty(callOrigin)) { 65cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng intent.putExtra(PhoneConstants.EXTRA_CALL_ORIGIN, callOrigin); 66cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng } 67cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng return intent; 68cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng } 69cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng 70cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng /** 71ed1a3b2598d3aafb3f9ec8583e231cbe72ea8020Jay Shrauner * Return Uri with an appropriate scheme, accepting both SIP and usual phone call 72cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng * numbers. 73cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng */ 74cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng public static Uri getCallUri(String number) { 759e8e7cb9ec53b46ff476336e1b40f7dfa6ccb61cYorke Lee if (PhoneNumberHelper.isUriNumber(number)) { 76ed1a3b2598d3aafb3f9ec8583e231cbe72ea8020Jay Shrauner return Uri.fromParts(PhoneAccount.SCHEME_SIP, number, null); 77cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng } 78ed1a3b2598d3aafb3f9ec8583e231cbe72ea8020Jay Shrauner return Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null); 79ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn } 8056046089a707f905482ea01eac697d36fcde4556Paul Soulos 81ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn /** 82ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn * Determines if one of the call capable phone accounts defined supports video calling. 83ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn * 84ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn * @param context The context. 85ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn * @return {@code true} if one of the call capable phone accounts supports video calling, 86ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn * {@code false} otherwise. 87ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn */ 887e558dcdb3af3f8a1ef57f0c445d4ef5172ee935Andrew Lee public static boolean isVideoEnabled(Context context) { 895cf7f01aa00d67edbcd9d65fbfcbc1a4c56f60c3Tyler Gunn TelecomManager telecommMgr = (TelecomManager) 905cf7f01aa00d67edbcd9d65fbfcbc1a4c56f60c3Tyler Gunn context.getSystemService(Context.TELECOM_SERVICE); 91998492107a7907ef4bc0e992aec6196ce4db3b76Nancy Chen if (telecommMgr == null) { 927e558dcdb3af3f8a1ef57f0c445d4ef5172ee935Andrew Lee return false; 937e558dcdb3af3f8a1ef57f0c445d4ef5172ee935Andrew Lee } 947e558dcdb3af3f8a1ef57f0c445d4ef5172ee935Andrew Lee 95ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn List<PhoneAccountHandle> accountHandles = telecommMgr.getCallCapablePhoneAccounts(); 96ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn for (PhoneAccountHandle accountHandle : accountHandles) { 97ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn PhoneAccount account = telecommMgr.getPhoneAccount(accountHandle); 98ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn if (account.hasCapabilities(PhoneAccount.CAPABILITY_VIDEO_CALLING)) { 99ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn return true; 100ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn } 101ca42659ca4abe4a56cc4d85f99ec70c4c9778c44Tyler Gunn } 10256046089a707f905482ea01eac697d36fcde4556Paul Soulos return false; 10356046089a707f905482ea01eac697d36fcde4556Paul Soulos } 104cb5b270471f8cd27ba666268d11c60ffd9819b95Chiao Cheng} 105