• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TelecomCallFacade(FacadeManager manager)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
shutdown()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")
telecomCallGetCallById(String callId)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.")
telecomCallDisconnect( @pcParametername = "callId") String 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")
telecomCallHold( @pcParametername = "callId") String 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")
telecomCallMergeToConf( @pcParametername = "callId") String 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.")
telecomCallSplitFromConf( @pcParametername = "callId") String 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")
telecomCallUnhold( @pcParametername = "callId") String callId)102     public void telecomCallUnhold(
103                         @RpcParameter(name = "callId")
104             String callId) {
105         InCallServiceImpl.unholdCall(callId);
106     }
107 
108     @Rpc(description = "Joins two calls into a conference call. "
109             + "Calls are identified by their "
110             + "IDs listed by telecomPhoneGetCallIds")
telecomCallJoinCallsInConf( @pcParametername = "callIdOne") String callIdOne, @RpcParameter(name = "callIdTwo") String callIdTwo)111     public void telecomCallJoinCallsInConf(
112                         @RpcParameter(name = "callIdOne")
113             String callIdOne,
114                         @RpcParameter(name = "callIdTwo")
115             String callIdTwo) {
116         InCallServiceImpl.joinCallsInConf(callIdOne, callIdTwo);
117     }
118 
119     @Rpc(description = "Obtains the current call audio state of the phone.")
telecomCallGetAudioState()120     public CallAudioState telecomCallGetAudioState() {
121         return InCallServiceImpl.serviceGetCallAudioState();
122     }
123 
124     @Rpc(description = "Lists the IDs (phone numbers or hex hashes) "
125             + "of the current calls.")
telecomCallGetCallIds()126     public Set<String> telecomCallGetCallIds() {
127         return InCallServiceImpl.getCallIdList();
128     }
129     @Rpc(description = "Get callId's children")
telecomCallGetCallChildren( @pcParametername = "callId") String callId)130     public List<String> telecomCallGetCallChildren(
131                         @RpcParameter(name = "callId") String callId) {
132         return InCallServiceImpl.getCallChildren(callId);
133     }
134     @Rpc(description = "Get callId's parent")
telecomCallGetCallParent( @pcParametername = "callId") String callId)135     public String telecomCallGetCallParent(
136                         @RpcParameter(name = "callId") String callId) {
137         return InCallServiceImpl.getCallParent(callId);
138     }
139     @Rpc(description = "Swaps the calls within this conference")
telecomCallSwapCallsInConference( @pcParametername = "callId") String callId)140     public void telecomCallSwapCallsInConference(
141                         @RpcParameter(name = "callId") String callId) {
142         InCallServiceImpl.swapCallsInConference(callId);
143     }
144     @Rpc(description = "Play a dual-tone multi-frequency signaling (DTMF) tone")
telecomCallPlayDtmfTone( @pcParametername = "callId") String callId, @RpcParameter(name = "digit") String digitString)145     public void telecomCallPlayDtmfTone(
146                         @RpcParameter(name = "callId") String callId,
147                         @RpcParameter(name = "digit") String digitString) {
148         for(int i = 0; i < digitString.length(); i++) {
149             char c = digitString.charAt(i);
150             InCallServiceImpl.callPlayDtmfTone(callId, c);
151         }
152     }
153     @Rpc(description = "Stop any dual-tone multi-frequency signaling (DTMF) tone")
telecomCallStopDtmfTone( @pcParametername = "callId") String callId)154     public void telecomCallStopDtmfTone(
155                         @RpcParameter(name = "callId") String callId) {
156         InCallServiceImpl.callStopDtmfTone(callId);
157     }
158     @Rpc(description = "Obtains a list of text message, user to reject call.")
telecomCallGetCannedTextResponses( @pcParametername = "callId") String callId)159     public List<String> telecomCallGetCannedTextResponses(
160                         @RpcParameter(name = "callId") String callId) {
161         return InCallServiceImpl.callGetCannedTextResponses(callId);
162     }
163     @Rpc(description = "Reset the Call List.")
telecomCallClearCallList()164     public void telecomCallClearCallList() {
165         InCallServiceImpl.clearCallList();
166     }
167 
168     @Rpc(description = "Get the state of a call according to call id.")
telecomCallGetCallState( @pcParametername = "callId") String callId)169     public String telecomCallGetCallState(
170                         @RpcParameter(name = "callId")
171             String callId) {
172 
173         return InCallServiceImpl.callGetState(callId);
174     }
175 
176     @Rpc(description = "Sets the audio route (SPEAKER, BLUETOOTH, etc...).")
telecomCallSetAudioRoute( @pcParametername = "route") String route)177     public void telecomCallSetAudioRoute(
178                         @RpcParameter(name = "route")
179             String route) {
180 
181         InCallServiceImpl.serviceSetAudioRoute(route);
182     }
183 
184     @Rpc(description = "Turns the proximity sensor off. "
185             + "If screenOnImmediately is true, "
186             + "the screen will be turned on immediately")
telecomCallOverrideProximitySensor( @pcParametername = "screenOn") Boolean screenOn)187     public void telecomCallOverrideProximitySensor(
188                         @RpcParameter(name = "screenOn")
189             Boolean screenOn) {
190         InCallServiceImpl.overrideProximitySensor(screenOn);
191     }
192 
193     @Rpc(description = "Answer a call of a specified id, with video state")
telecomCallAnswer( @pcParametername = "call") String callId, @RpcParameter(name = "videoState") String videoState)194     public void telecomCallAnswer(
195                         @RpcParameter(name = "call")
196             String callId,
197                         @RpcParameter(name = "videoState")
198             String videoState) {
199         InCallServiceImpl.callAnswer(callId, videoState);
200     }
201 
202     @Rpc(description = "Reject a call, sending the given message to the caller")
telecomCallReject( @pcParametername = "call") String callId, @RpcParameter(name = "message") String message)203     public void telecomCallReject(
204                         @RpcParameter(name = "call")
205             String callId,
206                         @RpcParameter(name = "message")
207             String message) {
208         InCallServiceImpl.callReject(callId, message);
209     }
210 
211     @Rpc(description = "Start Listening for a VideoCall Event")
telecomCallStartListeningForEvent( @pcParametername = "call") String callId, @RpcParameter(name = "event") String event)212     public void telecomCallStartListeningForEvent(
213                         @RpcParameter(name = "call")
214             String callId,
215                         @RpcParameter(name = "event")
216             String event) {
217         InCallServiceImpl.callStartListeningForEvent(callId, event);
218     }
219 
220     @Rpc(description = "Stop Listening for a Call Event")
telecomCallStopListeningForEvent( @pcParametername = "call") String callId, @RpcParameter(name = "event") String event)221     public void telecomCallStopListeningForEvent(
222                         @RpcParameter(name = "call")
223             String callId,
224                         @RpcParameter(name = "event")
225             String event) {
226         InCallServiceImpl.callStopListeningForEvent(callId, event);
227     }
228 
229     @Rpc(description = "Get the detailed information about a call")
telecomCallGetDetails( @pcParametername = "callId") String callId)230     public Call.Details telecomCallGetDetails(
231                         @RpcParameter(name = "callId")
232             String callId) {
233         return InCallServiceImpl.callGetDetails(callId);
234     }
235 
236     @Rpc(description = "Return the capabilities for a call")
telecomCallGetCapabilities( @pcParametername = "callId") String callId)237     public  List<String> telecomCallGetCapabilities(
238                         @RpcParameter(name = "callId")
239             String callId) {
240         return InCallServiceImpl.callGetCallCapabilities(callId);
241     }
242 
243     @Rpc(description = "Return the properties for a call")
telecomCallGetProperties( @pcParametername = "callId") String callId)244     public  List<String> telecomCallGetProperties(
245                         @RpcParameter(name = "callId")
246             String callId) {
247         return InCallServiceImpl.callGetCallProperties(callId);
248     }
249 
250     @Rpc(description = "Start Listening for a VideoCall Event")
telecomCallVideoStartListeningForEvent( @pcParametername = "call") String callId, @RpcParameter(name = "event") String event)251     public void telecomCallVideoStartListeningForEvent(
252                         @RpcParameter(name = "call")
253             String callId,
254                         @RpcParameter(name = "event")
255             String event) {
256         InCallServiceImpl.videoCallStartListeningForEvent(callId, event);
257     }
258 
259     @Rpc(description = "Stop Listening for a VideoCall Event")
telecomCallVideoStopListeningForEvent( @pcParametername = "call") String callId, @RpcParameter(name = "event") String event)260     public void telecomCallVideoStopListeningForEvent(
261                         @RpcParameter(name = "call")
262             String callId,
263                         @RpcParameter(name = "event")
264             String event) {
265         InCallServiceImpl.videoCallStopListeningForEvent(callId, event);
266     }
267 
268     @Rpc(description = "Get the Video Call State")
telecomCallVideoGetState( @pcParametername = "call") String callId)269     public String telecomCallVideoGetState(
270                         @RpcParameter(name = "call")
271             String callId) {
272         return InCallServiceImpl.videoCallGetState(callId);
273     }
274 
275     @Rpc(description = "Send a request to modify the video call session parameters")
telecomCallVideoSendSessionModifyRequest( @pcParametername = "call") String callId, @RpcParameter(name = "videoState") String videoState, @RpcParameter(name = "videoQuality") String videoQuality)276     public void telecomCallVideoSendSessionModifyRequest(
277                         @RpcParameter(name = "call")
278             String callId,
279                         @RpcParameter(name = "videoState")
280             String videoState,
281                         @RpcParameter(name = "videoQuality")
282             String videoQuality) {
283         InCallServiceImpl.videoCallSendSessionModifyRequest(callId, videoState, videoQuality);
284     }
285 
286     @Rpc(description = "Send a response to a modify the video call session request")
telecomCallVideoSendSessionModifyResponse( @pcParametername = "call") String callId, @RpcParameter(name = "videoState") String videoState, @RpcParameter(name = "videoQuality") String videoQuality)287     public void telecomCallVideoSendSessionModifyResponse(
288                         @RpcParameter(name = "call")
289             String callId,
290                         @RpcParameter(name = "videoState")
291             String videoState,
292                         @RpcParameter(name = "videoQuality")
293             String videoQuality) {
294         InCallServiceImpl.videoCallSendSessionModifyResponse(callId, videoState, videoQuality);
295     }
296 }
297