blob: 9bf04675613d79e9a1b29da3c765452db03a376d [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
Hall Liua98f58b52017-11-07 17:59:28 -080019import android.bluetooth.BluetoothDevice;
Tyler Gunn876dbfb2016-03-14 15:18:07 -070020import android.os.Bundle;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080021import android.os.RemoteException;
22
Tyler Gunnef9f6f92014-09-12 22:16:17 -070023import com.android.internal.telecom.IInCallAdapter;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080024
Tyler Gunndee56a82016-03-23 16:06:34 -070025import java.util.List;
26
Santos Cordon8f3fd302014-01-27 08:46:21 -080027/**
Sailesh Nepalab5d2822014-03-08 18:01:06 -080028 * Receives commands from {@link InCallService} implementations which should be executed by
Tyler Gunnef9f6f92014-09-12 22:16:17 -070029 * Telecom. When Telecom binds to a {@link InCallService}, an instance of this class is given to
Santos Cordon8f3fd302014-01-27 08:46:21 -080030 * the in-call service through which it can manipulate live (active, dialing, ringing) calls. When
Ihab Awade63fadb2014-07-09 21:52:04 -070031 * the in-call service is notified of new calls, it can use the
Santos Cordon8f3fd302014-01-27 08:46:21 -080032 * given call IDs to execute commands such as {@link #answerCall} for incoming calls or
33 * {@link #disconnectCall} for active calls the user would like to end. Some commands are only
34 * appropriate for calls in certain states; please consult each method for such limitations.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035 * <p>
36 * The adapter will stop functioning when there are no more calls.
37 *
Hall Liu95d55872017-01-25 17:12:49 -080038 * @hide
Santos Cordon8f3fd302014-01-27 08:46:21 -080039 */
Sailesh Nepalab5d2822014-03-08 18:01:06 -080040public final class InCallAdapter {
41 private final IInCallAdapter mAdapter;
42
43 /**
44 * {@hide}
45 */
46 public InCallAdapter(IInCallAdapter adapter) {
47 mAdapter = adapter;
48 }
49
Santos Cordon8f3fd302014-01-27 08:46:21 -080050 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070051 * Instructs Telecom to answer the specified call.
Santos Cordon8f3fd302014-01-27 08:46:21 -080052 *
53 * @param callId The identifier of the call to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -070054 * @param videoState The video state in which to answer the call.
Santos Cordon8f3fd302014-01-27 08:46:21 -080055 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -070056 public void answerCall(String callId, int videoState) {
Sailesh Nepalab5d2822014-03-08 18:01:06 -080057 try {
Andrew Lee8da4c3c2014-07-16 10:11:42 -070058 mAdapter.answerCall(callId, videoState);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080059 } catch (RemoteException e) {
60 }
61 }
Santos Cordon8f3fd302014-01-27 08:46:21 -080062
63 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070064 * Instructs Telecom to reject the specified call.
Santos Cordon8f3fd302014-01-27 08:46:21 -080065 *
66 * @param callId The identifier of the call to reject.
Ihab Awadc0677542014-06-10 13:29:47 -070067 * @param rejectWithMessage Whether to reject with a text message.
68 * @param textMessage An optional text message with which to respond.
Santos Cordon8f3fd302014-01-27 08:46:21 -080069 */
Ihab Awadc0677542014-06-10 13:29:47 -070070 public void rejectCall(String callId, boolean rejectWithMessage, String textMessage) {
Sailesh Nepalab5d2822014-03-08 18:01:06 -080071 try {
Ihab Awadc0677542014-06-10 13:29:47 -070072 mAdapter.rejectCall(callId, rejectWithMessage, textMessage);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080073 } catch (RemoteException e) {
74 }
75 }
Santos Cordon8f3fd302014-01-27 08:46:21 -080076
77 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070078 * Instructs Telecom to disconnect the specified call.
Santos Cordon8f3fd302014-01-27 08:46:21 -080079 *
80 * @param callId The identifier of the call to disconnect.
81 */
Sailesh Nepalab5d2822014-03-08 18:01:06 -080082 public void disconnectCall(String callId) {
83 try {
84 mAdapter.disconnectCall(callId);
85 } catch (RemoteException e) {
86 }
87 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -070088
89 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070090 * Instructs Telecom to put the specified call on hold.
Yorke Lee81ccaaa2014-03-12 18:33:19 -070091 *
92 * @param callId The identifier of the call to put on hold.
93 */
94 public void holdCall(String callId) {
95 try {
96 mAdapter.holdCall(callId);
97 } catch (RemoteException e) {
98 }
99 }
100
101 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700102 * Instructs Telecom to release the specified call from hold.
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700103 *
104 * @param callId The identifier of the call to release from hold.
105 */
106 public void unholdCall(String callId) {
107 try {
108 mAdapter.unholdCall(callId);
109 } catch (RemoteException e) {
110 }
111 }
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700112
113 /**
114 * Mute the microphone.
115 *
116 * @param shouldMute True if the microphone should be muted.
117 */
118 public void mute(boolean shouldMute) {
119 try {
120 mAdapter.mute(shouldMute);
121 } catch (RemoteException e) {
122 }
123 }
124
125 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700126 * Sets the audio route (speaker, bluetooth, etc...). See {@link CallAudioState}.
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700127 *
128 * @param route The audio route to use.
129 */
130 public void setAudioRoute(int route) {
131 try {
Hall Liua98f58b52017-11-07 17:59:28 -0800132 mAdapter.setAudioRoute(route, null);
133 } catch (RemoteException e) {
134 }
135 }
136
137 /**
138 * Request audio routing to a specific bluetooth device. Calling this method may result in
139 * the device routing audio to a different bluetooth device than the one specified. A list of
140 * available devices can be obtained via {@link CallAudioState#getSupportedBluetoothDevices()}
141 *
142 * @param bluetoothAddress The address of the bluetooth device to connect to, as returned by
143 * {@link BluetoothDevice#getAddress()}, or {@code null} if no device is preferred.
144 */
145 public void requestBluetoothAudio(String bluetoothAddress) {
146 try {
147 mAdapter.setAudioRoute(CallAudioState.ROUTE_BLUETOOTH, bluetoothAddress);
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700148 } catch (RemoteException e) {
149 }
150 }
Ihab Awad2f236642014-03-10 15:33:45 -0700151
152 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700153 * Instructs Telecom to play a dual-tone multi-frequency signaling (DTMF) tone in a call.
Ihab Awad2f236642014-03-10 15:33:45 -0700154 *
155 * Any other currently playing DTMF tone in the specified call is immediately stopped.
156 *
157 * @param callId The unique ID of the call in which the tone will be played.
158 * @param digit A character representing the DTMF digit for which to play the tone. This
159 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
160 */
161 public void playDtmfTone(String callId, char digit) {
162 try {
163 mAdapter.playDtmfTone(callId, digit);
164 } catch (RemoteException e) {
165 }
166 }
167
168 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700169 * Instructs Telecom to stop any dual-tone multi-frequency signaling (DTMF) tone currently
Ihab Awad2f236642014-03-10 15:33:45 -0700170 * playing.
171 *
172 * DTMF tones are played by calling {@link #playDtmfTone(String,char)}. If no DTMF tone is
173 * currently playing, this method will do nothing.
174 *
175 * @param callId The unique ID of the call in which any currently playing tone will be stopped.
176 */
177 public void stopDtmfTone(String callId) {
178 try {
179 mAdapter.stopDtmfTone(callId);
180 } catch (RemoteException e) {
181 }
182 }
183
184 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700185 * Instructs Telecom to continue playing a post-dial DTMF string.
Ihab Awad2f236642014-03-10 15:33:45 -0700186 *
187 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
188 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700189 * While these tones are playing, Telecom will notify the {@link InCallService} that the call
Ihab Awade63fadb2014-07-09 21:52:04 -0700190 * is in the post dial state.
Ihab Awad2f236642014-03-10 15:33:45 -0700191 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700192 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, Telecom
Evan Charlton8acdbb82014-04-01 13:50:07 -0700193 * will temporarily pause playing the tones for a pre-defined period of time.
Ihab Awad2f236642014-03-10 15:33:45 -0700194 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700195 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, Telecom
Evan Charlton8acdbb82014-04-01 13:50:07 -0700196 * will pause playing the tones and notify the {@link InCallService} that the call is in the
Ihab Awade63fadb2014-07-09 21:52:04 -0700197 * post dial wait state. When the user decides to continue the postdial sequence, the
198 * {@link InCallService} should invoke the {@link #postDialContinue(String,boolean)} method.
Ihab Awad2f236642014-03-10 15:33:45 -0700199 *
200 * @param callId The unique ID of the call for which postdial string playing should continue.
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700201 * @param proceed Whether or not to continue with the post-dial sequence.
Ihab Awad2f236642014-03-10 15:33:45 -0700202 */
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700203 public void postDialContinue(String callId, boolean proceed) {
Ihab Awad2f236642014-03-10 15:33:45 -0700204 try {
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700205 mAdapter.postDialContinue(callId, proceed);
Ihab Awad2f236642014-03-10 15:33:45 -0700206 } catch (RemoteException e) {
207 }
208 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700209
210 /**
Nancy Chen36c62f32014-10-21 18:36:39 -0700211 * Instructs Telecom to add a PhoneAccountHandle to the specified call.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700212 *
Nancy Chen36c62f32014-10-21 18:36:39 -0700213 * @param callId The identifier of the call.
214 * @param accountHandle The PhoneAccountHandle through which to place the call.
215 * @param setDefault {@code True} if this account should be set as the default for calls.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700216 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700217 public void phoneAccountSelected(String callId, PhoneAccountHandle accountHandle,
218 boolean setDefault) {
Nancy Chen5da0fd52014-07-08 14:16:17 -0700219 try {
Nancy Chen36c62f32014-10-21 18:36:39 -0700220 mAdapter.phoneAccountSelected(callId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700221 } catch (RemoteException e) {
222 }
223 }
224
225 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700226 * Instructs Telecom to conference the specified call.
Santos Cordon980acb92014-05-31 10:31:19 -0700227 *
228 * @param callId The unique ID of the call.
Santos Cordon980acb92014-05-31 10:31:19 -0700229 * @hide
230 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700231 public void conference(String callId, String otherCallId) {
Santos Cordon980acb92014-05-31 10:31:19 -0700232 try {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700233 mAdapter.conference(callId, otherCallId);
Santos Cordon980acb92014-05-31 10:31:19 -0700234 } catch (RemoteException ignored) {
235 }
236 }
237
238 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700239 * Instructs Telecom to split the specified call from any conference call with which it may be
Santos Cordon980acb92014-05-31 10:31:19 -0700240 * connected.
241 *
242 * @param callId The unique ID of the call.
243 * @hide
244 */
Santos Cordonb6939982014-06-04 20:20:58 -0700245 public void splitFromConference(String callId) {
Santos Cordon980acb92014-05-31 10:31:19 -0700246 try {
247 mAdapter.splitFromConference(callId);
248 } catch (RemoteException ignored) {
249 }
250 }
Sailesh Nepal61203862014-07-11 14:50:13 -0700251
252 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700253 * Instructs Telecom to merge child calls of the specified conference call.
Santos Cordona4868042014-09-04 17:39:22 -0700254 */
255 public void mergeConference(String callId) {
256 try {
257 mAdapter.mergeConference(callId);
258 } catch (RemoteException ignored) {
259 }
260 }
261
262 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700263 * Instructs Telecom to swap the child calls of the specified conference call.
Santos Cordona4868042014-09-04 17:39:22 -0700264 */
265 public void swapConference(String callId) {
266 try {
267 mAdapter.swapConference(callId);
268 } catch (RemoteException ignored) {
269 }
270 }
271
272 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700273 * Instructs Telecom to pull an external call to the local device.
274 *
275 * @param callId The callId to pull.
276 */
277 public void pullExternalCall(String callId) {
278 try {
279 mAdapter.pullExternalCall(callId);
280 } catch (RemoteException ignored) {
281 }
282 }
283
284 /**
285 * Intructs Telecom to send a call event.
286 *
287 * @param callId The callId to send the event for.
288 * @param event The event.
289 * @param extras Extras associated with the event.
290 */
291 public void sendCallEvent(String callId, String event, Bundle extras) {
292 try {
293 mAdapter.sendCallEvent(callId, event, extras);
294 } catch (RemoteException ignored) {
295 }
296 }
297
298 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700299 * Intructs Telecom to add extras to a call.
300 *
301 * @param callId The callId to add the extras to.
302 * @param extras The extras.
303 */
304 public void putExtras(String callId, Bundle extras) {
305 try {
306 mAdapter.putExtras(callId, extras);
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 */
318 public void putExtra(String callId, String key, boolean value) {
319 try {
320 Bundle bundle = new Bundle();
321 bundle.putBoolean(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 */
334 public void putExtra(String callId, String key, int value) {
335 try {
336 Bundle bundle = new Bundle();
337 bundle.putInt(key, value);
338 mAdapter.putExtras(callId, bundle);
339 } catch (RemoteException ignored) {
340 }
341 }
342
343 /**
344 * Intructs Telecom to add an extra to a call.
345 *
346 * @param callId The callId to add the extras to.
347 * @param key The extra key.
348 * @param value The extra value.
349 */
350 public void putExtra(String callId, String key, String value) {
351 try {
352 Bundle bundle = new Bundle();
353 bundle.putString(key, value);
354 mAdapter.putExtras(callId, bundle);
355 } catch (RemoteException ignored) {
356 }
357 }
358
359 /**
360 * Intructs Telecom to remove extras from a call.
361 * @param callId The callId to remove the extras from.
362 * @param keys The extra keys to remove.
363 */
364 public void removeExtras(String callId, List<String> keys) {
365 try {
366 mAdapter.removeExtras(callId, keys);
367 } catch (RemoteException ignored) {
368 }
369 }
370
371 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700372 * Instructs Telecom to turn the proximity sensor on.
Yorke Lee0d6ea712014-07-28 14:39:23 -0700373 */
374 public void turnProximitySensorOn() {
375 try {
376 mAdapter.turnOnProximitySensor();
377 } catch (RemoteException ignored) {
378 }
379 }
380
381 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700382 * Instructs Telecom to turn the proximity sensor off.
Yorke Lee0d6ea712014-07-28 14:39:23 -0700383 *
384 * @param screenOnImmediately If true, the screen will be turned on immediately if it was
385 * previously off. Otherwise, the screen will only be turned on after the proximity sensor
386 * is no longer triggered.
387 */
388 public void turnProximitySensorOff(boolean screenOnImmediately) {
389 try {
390 mAdapter.turnOffProximitySensor(screenOnImmediately);
391 } catch (RemoteException ignored) {
392 }
393 }
Hall Liu95d55872017-01-25 17:12:49 -0800394
395 /**
396 * Sends an RTT upgrade request to the remote end of the connection.
397 */
Hall Liu57006aa2017-02-06 10:49:48 -0800398 public void sendRttRequest(String callId) {
Hall Liu95d55872017-01-25 17:12:49 -0800399 try {
Hall Liu57006aa2017-02-06 10:49:48 -0800400 mAdapter.sendRttRequest(callId);
Hall Liu95d55872017-01-25 17:12:49 -0800401 } catch (RemoteException ignored) {
402 }
403 }
404
405 /**
406 * Responds to an RTT upgrade request initiated from the remote end.
407 *
408 * @param id the ID of the request as specified by Telecom
409 * @param accept Whether the request should be accepted.
410 */
Hall Liu57006aa2017-02-06 10:49:48 -0800411 public void respondToRttRequest(String callId, int id, boolean accept) {
Hall Liu95d55872017-01-25 17:12:49 -0800412 try {
Hall Liu57006aa2017-02-06 10:49:48 -0800413 mAdapter.respondToRttRequest(callId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -0800414 } catch (RemoteException ignored) {
415 }
416 }
417
418 /**
419 * Instructs Telecom to shut down the RTT communication channel.
420 */
Hall Liu57006aa2017-02-06 10:49:48 -0800421 public void stopRtt(String callId) {
Hall Liu95d55872017-01-25 17:12:49 -0800422 try {
Hall Liu57006aa2017-02-06 10:49:48 -0800423 mAdapter.stopRtt(callId);
Hall Liu95d55872017-01-25 17:12:49 -0800424 } catch (RemoteException ignored) {
425 }
426 }
427
428 /**
429 * Sets the RTT audio mode.
430 * @param mode the desired RTT audio mode
431 */
Hall Liu57006aa2017-02-06 10:49:48 -0800432 public void setRttMode(String callId, int mode) {
Hall Liu95d55872017-01-25 17:12:49 -0800433 try {
Hall Liu57006aa2017-02-06 10:49:48 -0800434 mAdapter.setRttMode(callId, mode);
Hall Liu95d55872017-01-25 17:12:49 -0800435 } catch (RemoteException ignored) {
436 }
437 }
Santos Cordon8f3fd302014-01-27 08:46:21 -0800438}