blob: 3f270d9c5829540741daf5ea4d5c0a002372e947 [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
Tyler Gunn876dbfb2016-03-14 15:18:07 -070019import android.os.Bundle;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080020import android.os.RemoteException;
21
Tyler Gunnef9f6f92014-09-12 22:16:17 -070022import com.android.internal.telecom.IInCallAdapter;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080023
Tyler Gunndee56a82016-03-23 16:06:34 -070024import java.util.List;
25
Santos Cordon8f3fd302014-01-27 08:46:21 -080026/**
Sailesh Nepalab5d2822014-03-08 18:01:06 -080027 * Receives commands from {@link InCallService} implementations which should be executed by
Tyler Gunnef9f6f92014-09-12 22:16:17 -070028 * Telecom. When Telecom binds to a {@link InCallService}, an instance of this class is given to
Santos Cordon8f3fd302014-01-27 08:46:21 -080029 * the in-call service through which it can manipulate live (active, dialing, ringing) calls. When
Ihab Awade63fadb2014-07-09 21:52:04 -070030 * the in-call service is notified of new calls, it can use the
Santos Cordon8f3fd302014-01-27 08:46:21 -080031 * 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.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070034 * <p>
35 * The adapter will stop functioning when there are no more calls.
36 *
37 * {@hide}
Santos Cordon8f3fd302014-01-27 08:46:21 -080038 */
Sailesh Nepalab5d2822014-03-08 18:01:06 -080039public final class InCallAdapter {
40 private final IInCallAdapter mAdapter;
41
42 /**
43 * {@hide}
44 */
45 public InCallAdapter(IInCallAdapter adapter) {
46 mAdapter = adapter;
47 }
48
Santos Cordon8f3fd302014-01-27 08:46:21 -080049 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070050 * Instructs Telecom to answer the specified call.
Santos Cordon8f3fd302014-01-27 08:46:21 -080051 *
52 * @param callId The identifier of the call to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -070053 * @param videoState The video state in which to answer the call.
Santos Cordon8f3fd302014-01-27 08:46:21 -080054 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -070055 public void answerCall(String callId, int videoState) {
Sailesh Nepalab5d2822014-03-08 18:01:06 -080056 try {
Andrew Lee8da4c3c2014-07-16 10:11:42 -070057 mAdapter.answerCall(callId, videoState);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080058 } catch (RemoteException e) {
59 }
60 }
Santos Cordon8f3fd302014-01-27 08:46:21 -080061
62 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070063 * Instructs Telecom to reject the specified call.
Santos Cordon8f3fd302014-01-27 08:46:21 -080064 *
65 * @param callId The identifier of the call to reject.
Ihab Awadc0677542014-06-10 13:29:47 -070066 * @param rejectWithMessage Whether to reject with a text message.
67 * @param textMessage An optional text message with which to respond.
Santos Cordon8f3fd302014-01-27 08:46:21 -080068 */
Ihab Awadc0677542014-06-10 13:29:47 -070069 public void rejectCall(String callId, boolean rejectWithMessage, String textMessage) {
Sailesh Nepalab5d2822014-03-08 18:01:06 -080070 try {
Ihab Awadc0677542014-06-10 13:29:47 -070071 mAdapter.rejectCall(callId, rejectWithMessage, textMessage);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080072 } catch (RemoteException e) {
73 }
74 }
Santos Cordon8f3fd302014-01-27 08:46:21 -080075
76 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070077 * Instructs Telecom to disconnect the specified call.
Santos Cordon8f3fd302014-01-27 08:46:21 -080078 *
79 * @param callId The identifier of the call to disconnect.
80 */
Sailesh Nepalab5d2822014-03-08 18:01:06 -080081 public void disconnectCall(String callId) {
82 try {
83 mAdapter.disconnectCall(callId);
84 } catch (RemoteException e) {
85 }
86 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -070087
88 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070089 * Instructs Telecom to put the specified call on hold.
Yorke Lee81ccaaa2014-03-12 18:33:19 -070090 *
91 * @param callId The identifier of the call to put on hold.
92 */
93 public void holdCall(String callId) {
94 try {
95 mAdapter.holdCall(callId);
96 } catch (RemoteException e) {
97 }
98 }
99
100 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700101 * Instructs Telecom to release the specified call from hold.
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700102 *
103 * @param callId The identifier of the call to release from hold.
104 */
105 public void unholdCall(String callId) {
106 try {
107 mAdapter.unholdCall(callId);
108 } catch (RemoteException e) {
109 }
110 }
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700111
112 /**
113 * Mute the microphone.
114 *
115 * @param shouldMute True if the microphone should be muted.
116 */
117 public void mute(boolean shouldMute) {
118 try {
119 mAdapter.mute(shouldMute);
120 } catch (RemoteException e) {
121 }
122 }
123
124 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700125 * Sets the audio route (speaker, bluetooth, etc...). See {@link CallAudioState}.
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700126 *
127 * @param route The audio route to use.
128 */
129 public void setAudioRoute(int route) {
130 try {
131 mAdapter.setAudioRoute(route);
132 } catch (RemoteException e) {
133 }
134 }
Ihab Awad2f236642014-03-10 15:33:45 -0700135
136 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700137 * Instructs Telecom to play a dual-tone multi-frequency signaling (DTMF) tone in a call.
Ihab Awad2f236642014-03-10 15:33:45 -0700138 *
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 */
145 public void playDtmfTone(String callId, char digit) {
146 try {
147 mAdapter.playDtmfTone(callId, digit);
148 } catch (RemoteException e) {
149 }
150 }
151
152 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700153 * Instructs Telecom to stop any dual-tone multi-frequency signaling (DTMF) tone currently
Ihab Awad2f236642014-03-10 15:33:45 -0700154 * 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 */
161 public void stopDtmfTone(String callId) {
162 try {
163 mAdapter.stopDtmfTone(callId);
164 } catch (RemoteException e) {
165 }
166 }
167
168 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700169 * Instructs Telecom to continue playing a post-dial DTMF string.
Ihab Awad2f236642014-03-10 15:33:45 -0700170 *
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.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700173 * While these tones are playing, Telecom will notify the {@link InCallService} that the call
Ihab Awade63fadb2014-07-09 21:52:04 -0700174 * is in the post dial state.
Ihab Awad2f236642014-03-10 15:33:45 -0700175 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700176 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, Telecom
Evan Charlton8acdbb82014-04-01 13:50:07 -0700177 * will temporarily pause playing the tones for a pre-defined period of time.
Ihab Awad2f236642014-03-10 15:33:45 -0700178 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700179 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, Telecom
Evan Charlton8acdbb82014-04-01 13:50:07 -0700180 * will pause playing the tones and notify the {@link InCallService} that the call is in the
Ihab Awade63fadb2014-07-09 21:52:04 -0700181 * 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.
Ihab Awad2f236642014-03-10 15:33:45 -0700183 *
184 * @param callId The unique ID of the call for which postdial string playing should continue.
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700185 * @param proceed Whether or not to continue with the post-dial sequence.
Ihab Awad2f236642014-03-10 15:33:45 -0700186 */
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700187 public void postDialContinue(String callId, boolean proceed) {
Ihab Awad2f236642014-03-10 15:33:45 -0700188 try {
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700189 mAdapter.postDialContinue(callId, proceed);
Ihab Awad2f236642014-03-10 15:33:45 -0700190 } catch (RemoteException e) {
191 }
192 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700193
194 /**
Nancy Chen36c62f32014-10-21 18:36:39 -0700195 * Instructs Telecom to add a PhoneAccountHandle to the specified call.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700196 *
Nancy Chen36c62f32014-10-21 18:36:39 -0700197 * @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.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700200 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700201 public void phoneAccountSelected(String callId, PhoneAccountHandle accountHandle,
202 boolean setDefault) {
Nancy Chen5da0fd52014-07-08 14:16:17 -0700203 try {
Nancy Chen36c62f32014-10-21 18:36:39 -0700204 mAdapter.phoneAccountSelected(callId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700205 } catch (RemoteException e) {
206 }
207 }
208
209 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700210 * Instructs Telecom to conference the specified call.
Santos Cordon980acb92014-05-31 10:31:19 -0700211 *
212 * @param callId The unique ID of the call.
Santos Cordon980acb92014-05-31 10:31:19 -0700213 * @hide
214 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700215 public void conference(String callId, String otherCallId) {
Santos Cordon980acb92014-05-31 10:31:19 -0700216 try {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700217 mAdapter.conference(callId, otherCallId);
Santos Cordon980acb92014-05-31 10:31:19 -0700218 } catch (RemoteException ignored) {
219 }
220 }
221
222 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700223 * Instructs Telecom to split the specified call from any conference call with which it may be
Santos Cordon980acb92014-05-31 10:31:19 -0700224 * connected.
225 *
226 * @param callId The unique ID of the call.
227 * @hide
228 */
Santos Cordonb6939982014-06-04 20:20:58 -0700229 public void splitFromConference(String callId) {
Santos Cordon980acb92014-05-31 10:31:19 -0700230 try {
231 mAdapter.splitFromConference(callId);
232 } catch (RemoteException ignored) {
233 }
234 }
Sailesh Nepal61203862014-07-11 14:50:13 -0700235
236 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700237 * Instructs Telecom to merge child calls of the specified conference call.
Santos Cordona4868042014-09-04 17:39:22 -0700238 */
239 public void mergeConference(String callId) {
240 try {
241 mAdapter.mergeConference(callId);
242 } catch (RemoteException ignored) {
243 }
244 }
245
246 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700247 * Instructs Telecom to swap the child calls of the specified conference call.
Santos Cordona4868042014-09-04 17:39:22 -0700248 */
249 public void swapConference(String callId) {
250 try {
251 mAdapter.swapConference(callId);
252 } catch (RemoteException ignored) {
253 }
254 }
255
256 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700257 * Instructs Telecom to pull an external call to the local device.
258 *
259 * @param callId The callId to pull.
260 */
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 */
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 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700283 * 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 */
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 */
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 */
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 */
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 */
348 public void removeExtras(String callId, List<String> keys) {
349 try {
350 mAdapter.removeExtras(callId, keys);
351 } catch (RemoteException ignored) {
352 }
353 }
354
355 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700356 * Instructs Telecom to turn the proximity sensor on.
Yorke Lee0d6ea712014-07-28 14:39:23 -0700357 */
358 public void turnProximitySensorOn() {
359 try {
360 mAdapter.turnOnProximitySensor();
361 } catch (RemoteException ignored) {
362 }
363 }
364
365 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700366 * Instructs Telecom to turn the proximity sensor off.
Yorke Lee0d6ea712014-07-28 14:39:23 -0700367 *
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 */
372 public void turnProximitySensorOff(boolean screenOnImmediately) {
373 try {
374 mAdapter.turnOffProximitySensor(screenOnImmediately);
375 } catch (RemoteException ignored) {
376 }
377 }
Santos Cordon8f3fd302014-01-27 08:46:21 -0800378}