1/* 2 * Copyright (C) 2016 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17package com.googlecode.android_scripting.facade.telephony; 18 19import java.util.ArrayList; 20import java.util.List; 21import java.util.Set; 22 23import android.app.Service; 24import android.telecom.Call; 25import android.telecom.CallAudioState; 26import android.telecom.PhoneAccount; 27import android.telecom.PhoneAccountHandle; 28import android.telecom.VideoProfile; 29 30import com.googlecode.android_scripting.Log; 31import com.googlecode.android_scripting.facade.EventFacade; 32import com.googlecode.android_scripting.facade.FacadeManager; 33import com.googlecode.android_scripting.jsonrpc.RpcReceiver; 34import com.googlecode.android_scripting.rpc.Rpc; 35import com.googlecode.android_scripting.rpc.RpcOptional; 36import com.googlecode.android_scripting.rpc.RpcParameter; 37 38/** 39 * Exposes TelecomManager functionality. 40 */ 41public class TelecomCallFacade extends RpcReceiver { 42 43 private final Service mService; 44 45 private List<PhoneAccountHandle> mEnabledAccountHandles = null; 46 47 public TelecomCallFacade(FacadeManager manager) { 48 super(manager); 49 mService = manager.getService(); 50 51 InCallServiceImpl.setEventFacade( 52 manager.getReceiver(EventFacade.class)); 53 } 54 55 @Override 56 public void shutdown() { 57 InCallServiceImpl.setEventFacade(null); 58 } 59 60 /** 61 * Returns an identifier of the call. When a phone number is available, the number will be 62 * returned. Otherwise, the standard object toString result of the Call object. e.g. A 63 * conference call does not have a single number associated with it, thus the toString Id will 64 * be returned. 65 * 66 * @param call 67 * @return String 68 */ 69 70 @Rpc(description = "Disconnect call by callId.") 71 public void telecomCallDisconnect( 72 @RpcParameter(name = "callId") 73 String callId) { 74 InCallServiceImpl.callDisconnect(callId); 75 } 76 77 @Rpc(description = "Hold call by callId") 78 public void telecomCallHold( 79 @RpcParameter(name = "callId") 80 String callId) { 81 InCallServiceImpl.holdCall(callId); 82 } 83 84 @Rpc(description = "Merge call to conference by callId") 85 public void telecomCallMergeToConf( 86 @RpcParameter(name = "callId") 87 String callId) { 88 InCallServiceImpl.mergeCallsInConference(callId); 89 } 90 91 @Rpc(description = "Split call from conference by callId.") 92 public void telecomCallSplitFromConf( 93 @RpcParameter(name = "callId") 94 String callId) { 95 InCallServiceImpl.splitCallFromConf(callId); 96 } 97 98 @Rpc(description = "Unhold call by callId") 99 public void telecomCallUnhold( 100 @RpcParameter(name = "callId") 101 String callId) { 102 InCallServiceImpl.unholdCall(callId); 103 } 104 105 @Rpc(description = "Joins two calls into a conference call. " 106 + "Calls are identified by their " 107 + "IDs listed by telecomPhoneGetCallIds") 108 public void telecomCallJoinCallsInConf( 109 @RpcParameter(name = "callIdOne") 110 String callIdOne, 111 @RpcParameter(name = "callIdTwo") 112 String callIdTwo) { 113 InCallServiceImpl.joinCallsInConf(callIdOne, callIdTwo); 114 } 115 116 @Rpc(description = "Obtains the current call audio state of the phone.") 117 public CallAudioState telecomCallGetAudioState() { 118 return InCallServiceImpl.serviceGetCallAudioState(); 119 } 120 121 @Rpc(description = "Lists the IDs (phone numbers or hex hashes) " 122 + "of the current calls.") 123 public Set<String> telecomCallGetCallIds() { 124 return InCallServiceImpl.getCallIdList(); 125 } 126 @Rpc(description = "Get callId's children") 127 public List<String> telecomCallGetCallChildren( 128 @RpcParameter(name = "callId") String callId) { 129 return InCallServiceImpl.getCallChildren(callId); 130 } 131 @Rpc(description = "Get callId's parent") 132 public String telecomCallGetCallParent( 133 @RpcParameter(name = "callId") String callId) { 134 return InCallServiceImpl.getCallParent(callId); 135 } 136 @Rpc(description = "Swaps the calls within this conference") 137 public void telecomCallSwapCallsInConference( 138 @RpcParameter(name = "callId") String callId) { 139 InCallServiceImpl.swapCallsInConference(callId); 140 } 141 @Rpc(description = "Play a dual-tone multi-frequency signaling (DTMF) tone") 142 public void telecomCallPlayDtmfTone( 143 @RpcParameter(name = "callId") String callId, 144 @RpcParameter(name = "digit") String digitString) { 145 for(int i = 0; i < digitString.length(); i++) { 146 char c = digitString.charAt(i); 147 InCallServiceImpl.callPlayDtmfTone(callId, c); 148 } 149 } 150 @Rpc(description = "Stop any dual-tone multi-frequency signaling (DTMF) tone") 151 public void telecomCallStopDtmfTone( 152 @RpcParameter(name = "callId") String callId) { 153 InCallServiceImpl.callStopDtmfTone(callId); 154 } 155 @Rpc(description = "Obtains a list of text message, user to reject call.") 156 public List<String> telecomCallGetCannedTextResponses( 157 @RpcParameter(name = "callId") String callId) { 158 return InCallServiceImpl.callGetCannedTextResponses(callId); 159 } 160 @Rpc(description = "Reset the Call List.") 161 public void telecomCallClearCallList() { 162 InCallServiceImpl.clearCallList(); 163 } 164 165 @Rpc(description = "Get the state of a call according to call id.") 166 public String telecomCallGetCallState( 167 @RpcParameter(name = "callId") 168 String callId) { 169 170 return InCallServiceImpl.callGetState(callId); 171 } 172 173 @Rpc(description = "Sets the audio route (SPEAKER, BLUETOOTH, etc...).") 174 public void telecomCallSetAudioRoute( 175 @RpcParameter(name = "route") 176 String route) { 177 178 InCallServiceImpl.serviceSetAudioRoute(route); 179 } 180 181 @Rpc(description = "Turns the proximity sensor off. " 182 + "If screenOnImmediately is true, " 183 + "the screen will be turned on immediately") 184 public void telecomCallOverrideProximitySensor( 185 @RpcParameter(name = "screenOn") 186 Boolean screenOn) { 187 InCallServiceImpl.overrideProximitySensor(screenOn); 188 } 189 190 @Rpc(description = "Answer a call of a specified id, with video state") 191 public void telecomCallAnswer( 192 @RpcParameter(name = "call") 193 String callId, 194 @RpcParameter(name = "videoState") 195 String videoState) { 196 InCallServiceImpl.callAnswer(callId, videoState); 197 } 198 199 @Rpc(description = "Reject a call, sending the given message to the caller") 200 public void telecomCallReject( 201 @RpcParameter(name = "call") 202 String callId, 203 @RpcParameter(name = "message") 204 String message) { 205 InCallServiceImpl.callReject(callId, message); 206 } 207 208 @Rpc(description = "Start Listening for a VideoCall Event") 209 public void telecomCallStartListeningForEvent( 210 @RpcParameter(name = "call") 211 String callId, 212 @RpcParameter(name = "event") 213 String event) { 214 InCallServiceImpl.callStartListeningForEvent(callId, event); 215 } 216 217 @Rpc(description = "Stop Listening for a Call Event") 218 public void telecomCallStopListeningForEvent( 219 @RpcParameter(name = "call") 220 String callId, 221 @RpcParameter(name = "event") 222 String event) { 223 InCallServiceImpl.callStopListeningForEvent(callId, event); 224 } 225 226 @Rpc(description = "Get the detailed information about a call") 227 public Call.Details telecomCallGetDetails( 228 @RpcParameter(name = "callId") 229 String callId) { 230 return InCallServiceImpl.callGetDetails(callId); 231 } 232 233 @Rpc(description = "Return the capabilities for a call") 234 public List<String> telecomCallGetCapabilities( 235 @RpcParameter(name = "callId") 236 String callId) { 237 return InCallServiceImpl.callGetCallCapabilities(callId); 238 } 239 240 @Rpc(description = "Return the properties for a call") 241 public List<String> telecomCallGetProperties( 242 @RpcParameter(name = "callId") 243 String callId) { 244 return InCallServiceImpl.callGetCallProperties(callId); 245 } 246 247 @Rpc(description = "Start Listening for a VideoCall Event") 248 public void telecomCallVideoStartListeningForEvent( 249 @RpcParameter(name = "call") 250 String callId, 251 @RpcParameter(name = "event") 252 String event) { 253 InCallServiceImpl.videoCallStartListeningForEvent(callId, event); 254 } 255 256 @Rpc(description = "Stop Listening for a VideoCall Event") 257 public void telecomCallVideoStopListeningForEvent( 258 @RpcParameter(name = "call") 259 String callId, 260 @RpcParameter(name = "event") 261 String event) { 262 InCallServiceImpl.videoCallStopListeningForEvent(callId, event); 263 } 264 265 @Rpc(description = "Get the Video Call State") 266 public String telecomCallVideoGetState( 267 @RpcParameter(name = "call") 268 String callId) { 269 return InCallServiceImpl.videoCallGetState(callId); 270 } 271 272 @Rpc(description = "Send a request to modify the video call session parameters") 273 public void telecomCallVideoSendSessionModifyRequest( 274 @RpcParameter(name = "call") 275 String callId, 276 @RpcParameter(name = "videoState") 277 String videoState, 278 @RpcParameter(name = "videoQuality") 279 String videoQuality) { 280 InCallServiceImpl.videoCallSendSessionModifyRequest(callId, videoState, videoQuality); 281 } 282 283 @Rpc(description = "Send a response to a modify the video call session request") 284 public void telecomCallVideoSendSessionModifyResponse( 285 @RpcParameter(name = "call") 286 String callId, 287 @RpcParameter(name = "videoState") 288 String videoState, 289 @RpcParameter(name = "videoQuality") 290 String videoQuality) { 291 InCallServiceImpl.videoCallSendSessionModifyResponse(callId, videoState, videoQuality); 292 } 293} 294