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