1 /* 2 * Copyright (C) 2012 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.contacts.common; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.net.Uri; 22 import android.telecom.PhoneAccount; 23 import android.telecom.PhoneAccountHandle; 24 import android.telecom.TelecomManager; 25 import android.telecom.VideoProfile; 26 27 import com.android.contacts.common.util.PhoneNumberHelper; 28 import com.android.phone.common.PhoneConstants; 29 30 /** 31 * Utilities related to calls. 32 */ 33 public class CallUtil { 34 35 /** 36 * Return an Intent for making a phone call. Scheme (e.g. tel, sip) will be determined 37 * automatically. 38 */ 39 public static Intent getCallIntent(String number) { 40 return getCallIntent(number, null, null); 41 } 42 43 /** 44 * Return an Intent for making a phone call. A given Uri will be used as is (without any 45 * sanity check). 46 */ 47 public static Intent getCallIntent(Uri uri) { 48 return getCallIntent(uri, null, null); 49 } 50 51 /** 52 * A variant of {@link #getCallIntent(String)} but also accept a call origin. 53 * For more information about call origin, see comments in Phone package (PhoneApp). 54 */ 55 public static Intent getCallIntent(String number, String callOrigin) { 56 return getCallIntent(getCallUri(number), callOrigin, null); 57 } 58 59 /** 60 * A variant of {@link #getCallIntent(String)} but also include {@code Account}. 61 */ 62 public static Intent getCallIntent(String number, PhoneAccountHandle accountHandle) { 63 return getCallIntent(number, null, accountHandle); 64 } 65 66 /** 67 * A variant of {@link #getCallIntent(android.net.Uri)} but also include {@code Account}. 68 */ 69 public static Intent getCallIntent(Uri uri, PhoneAccountHandle accountHandle) { 70 return getCallIntent(uri, null, accountHandle); 71 } 72 73 /** 74 * A variant of {@link #getCallIntent(String, String)} but also include {@code Account}. 75 */ 76 public static Intent getCallIntent( 77 String number, String callOrigin, PhoneAccountHandle accountHandle) { 78 return getCallIntent(getCallUri(number), callOrigin, accountHandle); 79 } 80 81 /** 82 * A variant of {@link #getCallIntent(android.net.Uri)} but also accept a call 83 * origin and {@code Account}. 84 * For more information about call origin, see comments in Phone package (PhoneApp). 85 */ 86 public static Intent getCallIntent( 87 Uri uri, String callOrigin, PhoneAccountHandle accountHandle) { 88 return getCallIntent(uri, callOrigin, accountHandle, 89 VideoProfile.VideoState.AUDIO_ONLY); 90 } 91 92 /** 93 * A variant of {@link #getCallIntent(String, String)} for starting a video call. 94 */ 95 public static Intent getVideoCallIntent(String number, String callOrigin) { 96 return getCallIntent(getCallUri(number), callOrigin, null, 97 VideoProfile.VideoState.BIDIRECTIONAL); 98 } 99 100 /** 101 * A variant of {@link #getCallIntent(String, String, android.telecom.PhoneAccountHandle)} for 102 * starting a video call. 103 */ 104 public static Intent getVideoCallIntent( 105 String number, String callOrigin, PhoneAccountHandle accountHandle) { 106 return getCallIntent(getCallUri(number), callOrigin, accountHandle, 107 VideoProfile.VideoState.BIDIRECTIONAL); 108 } 109 110 /** 111 * A variant of {@link #getCallIntent(String, String, android.telecom.PhoneAccountHandle)} for 112 * starting a video call. 113 */ 114 public static Intent getVideoCallIntent(String number, PhoneAccountHandle accountHandle) { 115 return getVideoCallIntent(number, null, accountHandle); 116 } 117 118 /** 119 * A variant of {@link #getCallIntent(android.net.Uri)} but also accept a call 120 * origin and {@code Account} and {@code VideoCallProfile} state. 121 * For more information about call origin, see comments in Phone package (PhoneApp). 122 */ 123 public static Intent getCallIntent( 124 Uri uri, String callOrigin, PhoneAccountHandle accountHandle, int videoState) { 125 final Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, uri); 126 intent.putExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, videoState); 127 if (callOrigin != null) { 128 intent.putExtra(PhoneConstants.EXTRA_CALL_ORIGIN, callOrigin); 129 } 130 if (accountHandle != null) { 131 intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle); 132 } 133 134 return intent; 135 } 136 137 /** 138 * Return Uri with an appropriate scheme, accepting both SIP and usual phone call 139 * numbers. 140 */ 141 public static Uri getCallUri(String number) { 142 if (PhoneNumberHelper.isUriNumber(number)) { 143 return Uri.fromParts(PhoneAccount.SCHEME_SIP, number, null); 144 } 145 return Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null); 146 } 147 148 public static boolean isVideoEnabled(Context context) { 149 TelecomManager telecommMgr = (TelecomManager) 150 context.getSystemService(Context.TELECOM_SERVICE); 151 if (telecommMgr == null) { 152 return false; 153 } 154 155 // TODO: Check telecommManager for value instead. 156 // return telecommMgr.isVideoEnabled(); 157 return false; 158 } 159 } 160