• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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 android.telecom;
18 
19 import android.os.Bundle;
20 import android.os.RemoteException;
21 
22 import com.android.internal.telecom.IInCallAdapter;
23 
24 import java.util.List;
25 
26 /**
27  * Receives commands from {@link InCallService} implementations which should be executed by
28  * Telecom. When Telecom binds to a {@link InCallService}, an instance of this class is given to
29  * the in-call service through which it can manipulate live (active, dialing, ringing) calls. When
30  * the in-call service is notified of new calls, it can use the
31  * given call IDs to execute commands such as {@link #answerCall} for incoming calls or
32  * {@link #disconnectCall} for active calls the user would like to end. Some commands are only
33  * appropriate for calls in certain states; please consult each method for such limitations.
34  * <p>
35  * The adapter will stop functioning when there are no more calls.
36  *
37  * @hide
38  */
39 public final class InCallAdapter {
40     private final IInCallAdapter mAdapter;
41 
42     /**
43      * {@hide}
44      */
InCallAdapter(IInCallAdapter adapter)45     public InCallAdapter(IInCallAdapter adapter) {
46         mAdapter = adapter;
47     }
48 
49     /**
50      * Instructs Telecom to answer the specified call.
51      *
52      * @param callId The identifier of the call to answer.
53      * @param videoState The video state in which to answer the call.
54      */
answerCall(String callId, int videoState)55     public void answerCall(String callId, int videoState) {
56         try {
57             mAdapter.answerCall(callId, videoState);
58         } catch (RemoteException e) {
59         }
60     }
61 
62     /**
63      * Instructs Telecom to reject the specified call.
64      *
65      * @param callId The identifier of the call to reject.
66      * @param rejectWithMessage Whether to reject with a text message.
67      * @param textMessage An optional text message with which to respond.
68      */
rejectCall(String callId, boolean rejectWithMessage, String textMessage)69     public void rejectCall(String callId, boolean rejectWithMessage, String textMessage) {
70         try {
71             mAdapter.rejectCall(callId, rejectWithMessage, textMessage);
72         } catch (RemoteException e) {
73         }
74     }
75 
76     /**
77      * Instructs Telecom to disconnect the specified call.
78      *
79      * @param callId The identifier of the call to disconnect.
80      */
disconnectCall(String callId)81     public void disconnectCall(String callId) {
82         try {
83             mAdapter.disconnectCall(callId);
84         } catch (RemoteException e) {
85         }
86     }
87 
88     /**
89      * Instructs Telecom to put the specified call on hold.
90      *
91      * @param callId The identifier of the call to put on hold.
92      */
holdCall(String callId)93     public void holdCall(String callId) {
94         try {
95             mAdapter.holdCall(callId);
96         } catch (RemoteException e) {
97         }
98     }
99 
100     /**
101      * Instructs Telecom to release the specified call from hold.
102      *
103      * @param callId The identifier of the call to release from hold.
104      */
unholdCall(String callId)105     public void unholdCall(String callId) {
106         try {
107             mAdapter.unholdCall(callId);
108         } catch (RemoteException e) {
109         }
110     }
111 
112     /**
113      * Mute the microphone.
114      *
115      * @param shouldMute True if the microphone should be muted.
116      */
mute(boolean shouldMute)117     public void mute(boolean shouldMute) {
118         try {
119             mAdapter.mute(shouldMute);
120         } catch (RemoteException e) {
121         }
122     }
123 
124     /**
125      * Sets the audio route (speaker, bluetooth, etc...). See {@link CallAudioState}.
126      *
127      * @param route The audio route to use.
128      */
setAudioRoute(int route)129     public void setAudioRoute(int route) {
130         try {
131             mAdapter.setAudioRoute(route);
132         } catch (RemoteException e) {
133         }
134     }
135 
136     /**
137      * Instructs Telecom to play a dual-tone multi-frequency signaling (DTMF) tone in a call.
138      *
139      * Any other currently playing DTMF tone in the specified call is immediately stopped.
140      *
141      * @param callId The unique ID of the call in which the tone will be played.
142      * @param digit A character representing the DTMF digit for which to play the tone. This
143      *         value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
144      */
playDtmfTone(String callId, char digit)145     public void playDtmfTone(String callId, char digit) {
146         try {
147             mAdapter.playDtmfTone(callId, digit);
148         } catch (RemoteException e) {
149         }
150     }
151 
152     /**
153      * Instructs Telecom to stop any dual-tone multi-frequency signaling (DTMF) tone currently
154      * playing.
155      *
156      * DTMF tones are played by calling {@link #playDtmfTone(String,char)}. If no DTMF tone is
157      * currently playing, this method will do nothing.
158      *
159      * @param callId The unique ID of the call in which any currently playing tone will be stopped.
160      */
stopDtmfTone(String callId)161     public void stopDtmfTone(String callId) {
162         try {
163             mAdapter.stopDtmfTone(callId);
164         } catch (RemoteException e) {
165         }
166     }
167 
168     /**
169      * Instructs Telecom to continue playing a post-dial DTMF string.
170      *
171      * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
172      * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
173      * While these tones are playing, Telecom will notify the {@link InCallService} that the call
174      * is in the post dial state.
175      *
176      * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, Telecom
177      * will temporarily pause playing the tones for a pre-defined period of time.
178      *
179      * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, Telecom
180      * will pause playing the tones and notify the {@link InCallService} that the call is in the
181      * post dial wait state. When the user decides to continue the postdial sequence, the
182      * {@link InCallService} should invoke the {@link #postDialContinue(String,boolean)} method.
183      *
184      * @param callId The unique ID of the call for which postdial string playing should continue.
185      * @param proceed Whether or not to continue with the post-dial sequence.
186      */
postDialContinue(String callId, boolean proceed)187     public void postDialContinue(String callId, boolean proceed) {
188         try {
189             mAdapter.postDialContinue(callId, proceed);
190         } catch (RemoteException e) {
191         }
192     }
193 
194     /**
195      * Instructs Telecom to add a PhoneAccountHandle to the specified call.
196      *
197      * @param callId The identifier of the call.
198      * @param accountHandle The PhoneAccountHandle through which to place the call.
199      * @param setDefault {@code True} if this account should be set as the default for calls.
200      */
phoneAccountSelected(String callId, PhoneAccountHandle accountHandle, boolean setDefault)201     public void phoneAccountSelected(String callId, PhoneAccountHandle accountHandle,
202             boolean setDefault) {
203         try {
204             mAdapter.phoneAccountSelected(callId, accountHandle, setDefault);
205         } catch (RemoteException e) {
206         }
207     }
208 
209     /**
210      * Instructs Telecom to conference the specified call.
211      *
212      * @param callId The unique ID of the call.
213      * @hide
214      */
conference(String callId, String otherCallId)215     public void conference(String callId, String otherCallId) {
216         try {
217             mAdapter.conference(callId, otherCallId);
218         } catch (RemoteException ignored) {
219         }
220     }
221 
222     /**
223      * Instructs Telecom to split the specified call from any conference call with which it may be
224      * connected.
225      *
226      * @param callId The unique ID of the call.
227      * @hide
228      */
splitFromConference(String callId)229     public void splitFromConference(String callId) {
230         try {
231             mAdapter.splitFromConference(callId);
232         } catch (RemoteException ignored) {
233         }
234     }
235 
236     /**
237      * Instructs Telecom to merge child calls of the specified conference call.
238      */
mergeConference(String callId)239     public void mergeConference(String callId) {
240         try {
241             mAdapter.mergeConference(callId);
242         } catch (RemoteException ignored) {
243         }
244     }
245 
246     /**
247      * Instructs Telecom to swap the child calls of the specified conference call.
248      */
swapConference(String callId)249     public void swapConference(String callId) {
250         try {
251             mAdapter.swapConference(callId);
252         } catch (RemoteException ignored) {
253         }
254     }
255 
256     /**
257      * Instructs Telecom to pull an external call to the local device.
258      *
259      * @param callId The callId to pull.
260      */
pullExternalCall(String callId)261     public void pullExternalCall(String callId) {
262         try {
263             mAdapter.pullExternalCall(callId);
264         } catch (RemoteException ignored) {
265         }
266     }
267 
268     /**
269      * Intructs Telecom to send a call event.
270      *
271      * @param callId The callId to send the event for.
272      * @param event The event.
273      * @param extras Extras associated with the event.
274      */
sendCallEvent(String callId, String event, Bundle extras)275     public void sendCallEvent(String callId, String event, Bundle extras) {
276         try {
277             mAdapter.sendCallEvent(callId, event, extras);
278         } catch (RemoteException ignored) {
279         }
280     }
281 
282     /**
283      * Intructs Telecom to add extras to a call.
284      *
285      * @param callId The callId to add the extras to.
286      * @param extras The extras.
287      */
putExtras(String callId, Bundle extras)288     public void putExtras(String callId, Bundle extras) {
289         try {
290             mAdapter.putExtras(callId, extras);
291         } catch (RemoteException ignored) {
292         }
293     }
294 
295     /**
296      * Intructs Telecom to add an extra to a call.
297      *
298      * @param callId The callId to add the extras to.
299      * @param key The extra key.
300      * @param value The extra value.
301      */
putExtra(String callId, String key, boolean value)302     public void putExtra(String callId, String key, boolean value) {
303         try {
304             Bundle bundle = new Bundle();
305             bundle.putBoolean(key, value);
306             mAdapter.putExtras(callId, bundle);
307         } catch (RemoteException ignored) {
308         }
309     }
310 
311     /**
312      * Intructs Telecom to add an extra to a call.
313      *
314      * @param callId The callId to add the extras to.
315      * @param key The extra key.
316      * @param value The extra value.
317      */
putExtra(String callId, String key, int value)318     public void putExtra(String callId, String key, int value) {
319         try {
320             Bundle bundle = new Bundle();
321             bundle.putInt(key, value);
322             mAdapter.putExtras(callId, bundle);
323         } catch (RemoteException ignored) {
324         }
325     }
326 
327     /**
328      * Intructs Telecom to add an extra to a call.
329      *
330      * @param callId The callId to add the extras to.
331      * @param key The extra key.
332      * @param value The extra value.
333      */
putExtra(String callId, String key, String value)334     public void putExtra(String callId, String key, String value) {
335         try {
336             Bundle bundle = new Bundle();
337             bundle.putString(key, value);
338             mAdapter.putExtras(callId, bundle);
339         } catch (RemoteException ignored) {
340         }
341     }
342 
343     /**
344      * Intructs Telecom to remove extras from a call.
345      * @param callId The callId to remove the extras from.
346      * @param keys The extra keys to remove.
347      */
removeExtras(String callId, List<String> keys)348     public void removeExtras(String callId, List<String> keys) {
349         try {
350             mAdapter.removeExtras(callId, keys);
351         } catch (RemoteException ignored) {
352         }
353     }
354 
355     /**
356      * Instructs Telecom to turn the proximity sensor on.
357      */
turnProximitySensorOn()358     public void turnProximitySensorOn() {
359         try {
360             mAdapter.turnOnProximitySensor();
361         } catch (RemoteException ignored) {
362         }
363     }
364 
365     /**
366      * Instructs Telecom to turn the proximity sensor off.
367      *
368      * @param screenOnImmediately If true, the screen will be turned on immediately if it was
369      * previously off. Otherwise, the screen will only be turned on after the proximity sensor
370      * is no longer triggered.
371      */
turnProximitySensorOff(boolean screenOnImmediately)372     public void turnProximitySensorOff(boolean screenOnImmediately) {
373         try {
374             mAdapter.turnOffProximitySensor(screenOnImmediately);
375         } catch (RemoteException ignored) {
376         }
377     }
378 
379     /**
380      * Sends an RTT upgrade request to the remote end of the connection.
381      */
sendRttRequest(String callId)382     public void sendRttRequest(String callId) {
383         try {
384             mAdapter.sendRttRequest(callId);
385         } catch (RemoteException ignored) {
386         }
387     }
388 
389     /**
390      * Responds to an RTT upgrade request initiated from the remote end.
391      *
392      * @param id the ID of the request as specified by Telecom
393      * @param accept Whether the request should be accepted.
394      */
respondToRttRequest(String callId, int id, boolean accept)395     public void respondToRttRequest(String callId, int id, boolean accept) {
396         try {
397             mAdapter.respondToRttRequest(callId, id, accept);
398         } catch (RemoteException ignored) {
399         }
400     }
401 
402     /**
403      * Instructs Telecom to shut down the RTT communication channel.
404      */
stopRtt(String callId)405     public void stopRtt(String callId) {
406         try {
407             mAdapter.stopRtt(callId);
408         } catch (RemoteException ignored) {
409         }
410     }
411 
412     /**
413      * Sets the RTT audio mode.
414      * @param mode the desired RTT audio mode
415      */
setRttMode(String callId, int mode)416     public void setRttMode(String callId, int mode) {
417         try {
418             mAdapter.setRttMode(callId, mode);
419         } catch (RemoteException ignored) {
420         }
421     }
422 }
423