blob: 8678e33f68b6b430098f548401f2d516ebed027f [file] [log] [blame]
Santos Cordon8f3fd302014-01-27 08:46:21 -08001/*
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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Santos Cordon8f3fd302014-01-27 08:46:21 -080018
Pooja Jaind34698d2017-12-28 14:15:31 +053019import android.net.Uri;
Hall Liua98f58b52017-11-07 17:59:28 -080020import android.bluetooth.BluetoothDevice;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070021import android.os.Bundle;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080022import android.os.RemoteException;
23
Tyler Gunnef9f6f92014-09-12 22:16:17 -070024import com.android.internal.telecom.IInCallAdapter;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080025
Tyler Gunndee56a82016-03-23 16:06:34 -070026import java.util.List;
27
Santos Cordon8f3fd302014-01-27 08:46:21 -080028/**
Sailesh Nepalab5d2822014-03-08 18:01:06 -080029 * Receives commands from {@link InCallService} implementations which should be executed by
Tyler Gunnef9f6f92014-09-12 22:16:17 -070030 * Telecom. When Telecom binds to a {@link InCallService}, an instance of this class is given to
Santos Cordon8f3fd302014-01-27 08:46:21 -080031 * the in-call service through which it can manipulate live (active, dialing, ringing) calls. When
Ihab Awade63fadb2014-07-09 21:52:04 -070032 * the in-call service is notified of new calls, it can use the
Santos Cordon8f3fd302014-01-27 08:46:21 -080033 * given call IDs to execute commands such as {@link #answerCall} for incoming calls or
34 * {@link #disconnectCall} for active calls the user would like to end. Some commands are only
35 * appropriate for calls in certain states; please consult each method for such limitations.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036 * <p>
37 * The adapter will stop functioning when there are no more calls.
38 *
Hall Liu95d55872017-01-25 17:12:49 -080039 * @hide
Santos Cordon8f3fd302014-01-27 08:46:21 -080040 */
Sailesh Nepalab5d2822014-03-08 18:01:06 -080041public final class InCallAdapter {
42 private final IInCallAdapter mAdapter;
43
44 /**
45 * {@hide}
46 */
47 public InCallAdapter(IInCallAdapter adapter) {
48 mAdapter = adapter;
49 }
50
Santos Cordon8f3fd302014-01-27 08:46:21 -080051 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070052 * Instructs Telecom to answer the specified call.
Santos Cordon8f3fd302014-01-27 08:46:21 -080053 *
54 * @param callId The identifier of the call to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -070055 * @param videoState The video state in which to answer the call.
Santos Cordon8f3fd302014-01-27 08:46:21 -080056 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -070057 public void answerCall(String callId, int videoState) {
Sailesh Nepalab5d2822014-03-08 18:01:06 -080058 try {
Andrew Lee8da4c3c2014-07-16 10:11:42 -070059 mAdapter.answerCall(callId, videoState);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080060 } catch (RemoteException e) {
61 }
62 }
Santos Cordon8f3fd302014-01-27 08:46:21 -080063
64 /**
Pooja Jaind34698d2017-12-28 14:15:31 +053065 * Instructs Telecom to deflect the specified call.
66 *
67 * @param callId The identifier of the call to deflect.
68 * @param address The address to deflect.
69 */
70 public void deflectCall(String callId, Uri address) {
71 try {
72 mAdapter.deflectCall(callId, address);
73 } catch (RemoteException e) {
74 }
75 }
76
77 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070078 * Instructs Telecom to reject the specified call.
Santos Cordon8f3fd302014-01-27 08:46:21 -080079 *
80 * @param callId The identifier of the call to reject.
Ihab Awadc0677542014-06-10 13:29:47 -070081 * @param rejectWithMessage Whether to reject with a text message.
82 * @param textMessage An optional text message with which to respond.
Santos Cordon8f3fd302014-01-27 08:46:21 -080083 */
Ihab Awadc0677542014-06-10 13:29:47 -070084 public void rejectCall(String callId, boolean rejectWithMessage, String textMessage) {
Sailesh Nepalab5d2822014-03-08 18:01:06 -080085 try {
Ihab Awadc0677542014-06-10 13:29:47 -070086 mAdapter.rejectCall(callId, rejectWithMessage, textMessage);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080087 } catch (RemoteException e) {
88 }
89 }
Santos Cordon8f3fd302014-01-27 08:46:21 -080090
91 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070092 * Instructs Telecom to disconnect the specified call.
Santos Cordon8f3fd302014-01-27 08:46:21 -080093 *
94 * @param callId The identifier of the call to disconnect.
95 */
Sailesh Nepalab5d2822014-03-08 18:01:06 -080096 public void disconnectCall(String callId) {
97 try {
98 mAdapter.disconnectCall(callId);
99 } catch (RemoteException e) {
100 }
101 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700102
103 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700104 * Instructs Telecom to put the specified call on hold.
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700105 *
106 * @param callId The identifier of the call to put on hold.
107 */
108 public void holdCall(String callId) {
109 try {
110 mAdapter.holdCall(callId);
111 } catch (RemoteException e) {
112 }
113 }
114
115 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700116 * Instructs Telecom to release the specified call from hold.
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700117 *
118 * @param callId The identifier of the call to release from hold.
119 */
120 public void unholdCall(String callId) {
121 try {
122 mAdapter.unholdCall(callId);
123 } catch (RemoteException e) {
124 }
125 }
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700126
127 /**
128 * Mute the microphone.
129 *
130 * @param shouldMute True if the microphone should be muted.
131 */
132 public void mute(boolean shouldMute) {
133 try {
134 mAdapter.mute(shouldMute);
135 } catch (RemoteException e) {
136 }
137 }
138
139 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700140 * Sets the audio route (speaker, bluetooth, etc...). See {@link CallAudioState}.
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700141 *
142 * @param route The audio route to use.
143 */
144 public void setAudioRoute(int route) {
145 try {
Hall Liua98f58b52017-11-07 17:59:28 -0800146 mAdapter.setAudioRoute(route, null);
147 } catch (RemoteException e) {
148 }
149 }
150
151 /**
152 * Request audio routing to a specific bluetooth device. Calling this method may result in
153 * the device routing audio to a different bluetooth device than the one specified. A list of
154 * available devices can be obtained via {@link CallAudioState#getSupportedBluetoothDevices()}
155 *
156 * @param bluetoothAddress The address of the bluetooth device to connect to, as returned by
157 * {@link BluetoothDevice#getAddress()}, or {@code null} if no device is preferred.
158 */
159 public void requestBluetoothAudio(String bluetoothAddress) {
160 try {
161 mAdapter.setAudioRoute(CallAudioState.ROUTE_BLUETOOTH, bluetoothAddress);
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700162 } catch (RemoteException e) {
163 }
164 }
Ihab Awad2f236642014-03-10 15:33:45 -0700165
166 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700167 * Instructs Telecom to play a dual-tone multi-frequency signaling (DTMF) tone in a call.
Ihab Awad2f236642014-03-10 15:33:45 -0700168 *
169 * Any other currently playing DTMF tone in the specified call is immediately stopped.
170 *
171 * @param callId The unique ID of the call in which the tone will be played.
172 * @param digit A character representing the DTMF digit for which to play the tone. This
173 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
174 */
175 public void playDtmfTone(String callId, char digit) {
176 try {
177 mAdapter.playDtmfTone(callId, digit);
178 } catch (RemoteException e) {
179 }
180 }
181
182 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700183 * Instructs Telecom to stop any dual-tone multi-frequency signaling (DTMF) tone currently
Ihab Awad2f236642014-03-10 15:33:45 -0700184 * playing.
185 *
186 * DTMF tones are played by calling {@link #playDtmfTone(String,char)}. If no DTMF tone is
187 * currently playing, this method will do nothing.
188 *
189 * @param callId The unique ID of the call in which any currently playing tone will be stopped.
190 */
191 public void stopDtmfTone(String callId) {
192 try {
193 mAdapter.stopDtmfTone(callId);
194 } catch (RemoteException e) {
195 }
196 }
197
198 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700199 * Instructs Telecom to continue playing a post-dial DTMF string.
Ihab Awad2f236642014-03-10 15:33:45 -0700200 *
201 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
202 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700203 * While these tones are playing, Telecom will notify the {@link InCallService} that the call
Ihab Awade63fadb2014-07-09 21:52:04 -0700204 * is in the post dial state.
Ihab Awad2f236642014-03-10 15:33:45 -0700205 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700206 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, Telecom
Evan Charlton8acdbb82014-04-01 13:50:07 -0700207 * will temporarily pause playing the tones for a pre-defined period of time.
Ihab Awad2f236642014-03-10 15:33:45 -0700208 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700209 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, Telecom
Evan Charlton8acdbb82014-04-01 13:50:07 -0700210 * will pause playing the tones and notify the {@link InCallService} that the call is in the
Ihab Awade63fadb2014-07-09 21:52:04 -0700211 * post dial wait state. When the user decides to continue the postdial sequence, the
212 * {@link InCallService} should invoke the {@link #postDialContinue(String,boolean)} method.
Ihab Awad2f236642014-03-10 15:33:45 -0700213 *
214 * @param callId The unique ID of the call for which postdial string playing should continue.
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700215 * @param proceed Whether or not to continue with the post-dial sequence.
Ihab Awad2f236642014-03-10 15:33:45 -0700216 */
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700217 public void postDialContinue(String callId, boolean proceed) {
Ihab Awad2f236642014-03-10 15:33:45 -0700218 try {
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700219 mAdapter.postDialContinue(callId, proceed);
Ihab Awad2f236642014-03-10 15:33:45 -0700220 } catch (RemoteException e) {
221 }
222 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700223
224 /**
Nancy Chen36c62f32014-10-21 18:36:39 -0700225 * Instructs Telecom to add a PhoneAccountHandle to the specified call.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700226 *
Nancy Chen36c62f32014-10-21 18:36:39 -0700227 * @param callId The identifier of the call.
228 * @param accountHandle The PhoneAccountHandle through which to place the call.
229 * @param setDefault {@code True} if this account should be set as the default for calls.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700230 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700231 public void phoneAccountSelected(String callId, PhoneAccountHandle accountHandle,
232 boolean setDefault) {
Nancy Chen5da0fd52014-07-08 14:16:17 -0700233 try {
Nancy Chen36c62f32014-10-21 18:36:39 -0700234 mAdapter.phoneAccountSelected(callId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700235 } catch (RemoteException e) {
236 }
237 }
238
239 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700240 * Instructs Telecom to conference the specified call.
Santos Cordon980acb92014-05-31 10:31:19 -0700241 *
242 * @param callId The unique ID of the call.
Santos Cordon980acb92014-05-31 10:31:19 -0700243 * @hide
244 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700245 public void conference(String callId, String otherCallId) {
Santos Cordon980acb92014-05-31 10:31:19 -0700246 try {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700247 mAdapter.conference(callId, otherCallId);
Santos Cordon980acb92014-05-31 10:31:19 -0700248 } catch (RemoteException ignored) {
249 }
250 }
251
252 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700253 * Instructs Telecom to split the specified call from any conference call with which it may be
Santos Cordon980acb92014-05-31 10:31:19 -0700254 * connected.
255 *
256 * @param callId The unique ID of the call.
257 * @hide
258 */
Santos Cordonb6939982014-06-04 20:20:58 -0700259 public void splitFromConference(String callId) {
Santos Cordon980acb92014-05-31 10:31:19 -0700260 try {
261 mAdapter.splitFromConference(callId);
262 } catch (RemoteException ignored) {
263 }
264 }
Sailesh Nepal61203862014-07-11 14:50:13 -0700265
266 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700267 * Instructs Telecom to merge child calls of the specified conference call.
Santos Cordona4868042014-09-04 17:39:22 -0700268 */
269 public void mergeConference(String callId) {
270 try {
271 mAdapter.mergeConference(callId);
272 } catch (RemoteException ignored) {
273 }
274 }
275
276 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700277 * Instructs Telecom to swap the child calls of the specified conference call.
Santos Cordona4868042014-09-04 17:39:22 -0700278 */
279 public void swapConference(String callId) {
280 try {
281 mAdapter.swapConference(callId);
282 } catch (RemoteException ignored) {
283 }
284 }
285
286 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700287 * Instructs Telecom to pull an external call to the local device.
288 *
289 * @param callId The callId to pull.
290 */
291 public void pullExternalCall(String callId) {
292 try {
293 mAdapter.pullExternalCall(callId);
294 } catch (RemoteException ignored) {
295 }
296 }
297
298 /**
299 * Intructs Telecom to send a call event.
300 *
301 * @param callId The callId to send the event for.
302 * @param event The event.
Sanket Padawef6a9e5b2018-01-05 14:26:16 -0800303 * @param targetSdkVer Target sdk version of the app calling this api
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700304 * @param extras Extras associated with the event.
305 */
Sanket Padawef6a9e5b2018-01-05 14:26:16 -0800306 public void sendCallEvent(String callId, String event, int targetSdkVer, Bundle extras) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700307 try {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -0800308 mAdapter.sendCallEvent(callId, event, targetSdkVer, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700309 } catch (RemoteException ignored) {
310 }
311 }
312
313 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700314 * Intructs Telecom to add extras to a call.
315 *
316 * @param callId The callId to add the extras to.
317 * @param extras The extras.
318 */
319 public void putExtras(String callId, Bundle extras) {
320 try {
321 mAdapter.putExtras(callId, extras);
322 } catch (RemoteException ignored) {
323 }
324 }
325
326 /**
327 * Intructs Telecom to add an extra to a call.
328 *
329 * @param callId The callId to add the extras to.
330 * @param key The extra key.
331 * @param value The extra value.
332 */
333 public void putExtra(String callId, String key, boolean value) {
334 try {
335 Bundle bundle = new Bundle();
336 bundle.putBoolean(key, value);
337 mAdapter.putExtras(callId, bundle);
338 } catch (RemoteException ignored) {
339 }
340 }
341
342 /**
343 * Intructs Telecom to add an extra to a call.
344 *
345 * @param callId The callId to add the extras to.
346 * @param key The extra key.
347 * @param value The extra value.
348 */
349 public void putExtra(String callId, String key, int value) {
350 try {
351 Bundle bundle = new Bundle();
352 bundle.putInt(key, value);
353 mAdapter.putExtras(callId, bundle);
354 } catch (RemoteException ignored) {
355 }
356 }
357
358 /**
359 * Intructs Telecom to add an extra to a call.
360 *
361 * @param callId The callId to add the extras to.
362 * @param key The extra key.
363 * @param value The extra value.
364 */
365 public void putExtra(String callId, String key, String value) {
366 try {
367 Bundle bundle = new Bundle();
368 bundle.putString(key, value);
369 mAdapter.putExtras(callId, bundle);
370 } catch (RemoteException ignored) {
371 }
372 }
373
374 /**
375 * Intructs Telecom to remove extras from a call.
376 * @param callId The callId to remove the extras from.
377 * @param keys The extra keys to remove.
378 */
379 public void removeExtras(String callId, List<String> keys) {
380 try {
381 mAdapter.removeExtras(callId, keys);
382 } catch (RemoteException ignored) {
383 }
384 }
385
386 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700387 * Instructs Telecom to turn the proximity sensor on.
Yorke Lee0d6ea712014-07-28 14:39:23 -0700388 */
389 public void turnProximitySensorOn() {
390 try {
391 mAdapter.turnOnProximitySensor();
392 } catch (RemoteException ignored) {
393 }
394 }
395
396 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700397 * Instructs Telecom to turn the proximity sensor off.
Yorke Lee0d6ea712014-07-28 14:39:23 -0700398 *
399 * @param screenOnImmediately If true, the screen will be turned on immediately if it was
400 * previously off. Otherwise, the screen will only be turned on after the proximity sensor
401 * is no longer triggered.
402 */
403 public void turnProximitySensorOff(boolean screenOnImmediately) {
404 try {
405 mAdapter.turnOffProximitySensor(screenOnImmediately);
406 } catch (RemoteException ignored) {
407 }
408 }
Hall Liu95d55872017-01-25 17:12:49 -0800409
410 /**
411 * Sends an RTT upgrade request to the remote end of the connection.
412 */
Hall Liu57006aa2017-02-06 10:49:48 -0800413 public void sendRttRequest(String callId) {
Hall Liu95d55872017-01-25 17:12:49 -0800414 try {
Hall Liu57006aa2017-02-06 10:49:48 -0800415 mAdapter.sendRttRequest(callId);
Hall Liu95d55872017-01-25 17:12:49 -0800416 } catch (RemoteException ignored) {
417 }
418 }
419
420 /**
421 * Responds to an RTT upgrade request initiated from the remote end.
422 *
423 * @param id the ID of the request as specified by Telecom
424 * @param accept Whether the request should be accepted.
425 */
Hall Liu57006aa2017-02-06 10:49:48 -0800426 public void respondToRttRequest(String callId, int id, boolean accept) {
Hall Liu95d55872017-01-25 17:12:49 -0800427 try {
Hall Liu57006aa2017-02-06 10:49:48 -0800428 mAdapter.respondToRttRequest(callId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -0800429 } catch (RemoteException ignored) {
430 }
431 }
432
433 /**
434 * Instructs Telecom to shut down the RTT communication channel.
435 */
Hall Liu57006aa2017-02-06 10:49:48 -0800436 public void stopRtt(String callId) {
Hall Liu95d55872017-01-25 17:12:49 -0800437 try {
Hall Liu57006aa2017-02-06 10:49:48 -0800438 mAdapter.stopRtt(callId);
Hall Liu95d55872017-01-25 17:12:49 -0800439 } catch (RemoteException ignored) {
440 }
441 }
442
443 /**
444 * Sets the RTT audio mode.
445 * @param mode the desired RTT audio mode
446 */
Hall Liu57006aa2017-02-06 10:49:48 -0800447 public void setRttMode(String callId, int mode) {
Hall Liu95d55872017-01-25 17:12:49 -0800448 try {
Hall Liu57006aa2017-02-06 10:49:48 -0800449 mAdapter.setRttMode(callId, mode);
Hall Liu95d55872017-01-25 17:12:49 -0800450 } catch (RemoteException ignored) {
451 }
452 }
Sanket Padawea8eddd42017-11-03 11:07:35 -0700453
454
455 /**
456 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
457 * by destAcct.
458 * @param callId The callId of the Call which calls this function.
459 * @param destAcct ConnectionService to which the call should be handed over.
460 * @param videoState The video state desired after the handover.
461 * @param extras Extra information to be passed to ConnectionService
462 */
463 public void handoverTo(String callId, PhoneAccountHandle destAcct, int videoState,
464 Bundle extras) {
465 try {
466 mAdapter.handoverTo(callId, destAcct, videoState, extras);
467 } catch (RemoteException ignored) {
468 }
469 }
Santos Cordon8f3fd302014-01-27 08:46:21 -0800470}