blob: 60290e3b785d6bd90408031d55ada01111f20e6d [file] [log] [blame]
Ihab Awade63fadb2014-07-09 21:52:04 -07001/*
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;
Ihab Awade63fadb2014-07-09 21:52:04 -070018
Hall Liu95d55872017-01-25 17:12:49 -080019import android.annotation.IntDef;
20import android.annotation.Nullable;
Andrew Leeda80c872015-04-15 14:09:50 -070021import android.annotation.SystemApi;
Hall Liu6dfa2492019-10-01 17:20:39 -070022import android.annotation.TestApi;
Mathew Inwood42346d12018-08-01 11:33:05 +010023import android.annotation.UnsupportedAppUsage;
Ihab Awade63fadb2014-07-09 21:52:04 -070024import android.net.Uri;
Tyler Gunn6e3ecc42018-11-12 11:30:56 -080025import android.os.Build;
Nancy Chen10798dc2014-08-08 14:00:25 -070026import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070027import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080028import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070029
Hall Liu95d55872017-01-25 17:12:49 -080030import java.io.IOException;
31import java.io.InputStreamReader;
32import java.io.OutputStreamWriter;
Hall Liu95d55872017-01-25 17:12:49 -080033import java.lang.annotation.Retention;
34import java.lang.annotation.RetentionPolicy;
35import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070036import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070037import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070038import java.util.Collections;
39import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070040import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070041import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070042import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070043
44/**
45 * Represents an ongoing phone call that the in-call app should present to the user.
46 */
47public final class Call {
48 /**
49 * The state of a {@code Call} when newly created.
50 */
51 public static final int STATE_NEW = 0;
52
53 /**
54 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
55 */
56 public static final int STATE_DIALING = 1;
57
58 /**
59 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
60 */
61 public static final int STATE_RINGING = 2;
62
63 /**
64 * The state of a {@code Call} when in a holding state.
65 */
66 public static final int STATE_HOLDING = 3;
67
68 /**
69 * The state of a {@code Call} when actively supporting conversation.
70 */
71 public static final int STATE_ACTIVE = 4;
72
73 /**
74 * The state of a {@code Call} when no further voice or other communication is being
75 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
76 * is no longer active, and the local data transport has or inevitably will release resources
77 * associated with this {@code Call}.
78 */
79 public static final int STATE_DISCONNECTED = 7;
80
Nancy Chen5da0fd52014-07-08 14:16:17 -070081 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070082 * The state of an outgoing {@code Call} when waiting on user to select a
83 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070084 */
Santos Cordone3c507b2015-04-23 14:44:19 -070085 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
86
87 /**
88 * @hide
89 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
90 */
91 @Deprecated
92 @SystemApi
93 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070094
Nancy Chene20930f2014-08-07 16:17:21 -070095 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070096 * The initial state of an outgoing {@code Call}.
97 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
98 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070099 */
100 public static final int STATE_CONNECTING = 9;
101
Nancy Chen513c8922014-09-17 14:47:20 -0700102 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700103 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
104 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
105 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
106 */
107 public static final int STATE_DISCONNECTING = 10;
108
109 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700110 * The state of an external call which is in the process of being pulled from a remote device to
111 * the local device.
112 * <p>
113 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
114 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
115 * <p>
116 * An {@link InCallService} will only see this state if it has the
117 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
118 * manifest.
119 */
120 public static final int STATE_PULLING_CALL = 11;
121
122 /**
Hall Liu6dfa2492019-10-01 17:20:39 -0700123 * The state of a call that is active with the network, but the audio from the call is
124 * being intercepted by an app on the local device. Telecom does not hold audio focus in this
125 * state, and the call will be invisible to the user except for a persistent notification.
126 */
127 public static final int STATE_AUDIO_PROCESSING = 12;
128
129 /**
130 * The state of a call that is being presented to the user after being in
131 * {@link #STATE_AUDIO_PROCESSING}. The call is still active with the network in this case, and
132 * Telecom will hold audio focus and play a ringtone if appropriate.
133 */
134 public static final int STATE_SIMULATED_RINGING = 13;
135
136 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700137 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
138 * extras. Used to pass the phone accounts to display on the front end to the user in order to
139 * select phone accounts to (for example) place a call.
Hall Liu34d9e242018-11-21 17:05:58 -0800140 * @deprecated Use the list from {@link #EXTRA_SUGGESTED_PHONE_ACCOUNTS} instead.
Nancy Chen513c8922014-09-17 14:47:20 -0700141 */
Hall Liu34d9e242018-11-21 17:05:58 -0800142 @Deprecated
Nancy Chen513c8922014-09-17 14:47:20 -0700143 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
144
mike dooley4af561f2016-12-20 08:55:17 -0800145 /**
Hall Liu34d9e242018-11-21 17:05:58 -0800146 * Key for extra used to pass along a list of {@link PhoneAccountSuggestion}s to the in-call
147 * UI when a call enters the {@link #STATE_SELECT_PHONE_ACCOUNT} state. The list included here
148 * will have the same length and be in the same order as the list passed with
149 * {@link #AVAILABLE_PHONE_ACCOUNTS}.
150 */
151 public static final String EXTRA_SUGGESTED_PHONE_ACCOUNTS =
152 "android.telecom.extra.SUGGESTED_PHONE_ACCOUNTS";
153
154 /**
mike dooley91217422017-03-09 12:58:42 -0800155 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
156 * when the last outgoing emergency call was made. This is used to identify potential emergency
157 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800158 */
159 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
160 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
161
Usman Abdullahb0dc29a2019-03-06 15:54:56 -0800162
163 /**
164 * Extra key used to indicate whether a {@link CallScreeningService} has requested to silence
165 * the ringtone for a call. If the {@link InCallService} declares
166 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} in its manifest, it should not
167 * play a ringtone for an incoming call with this extra key set.
168 */
169 public static final String EXTRA_SILENT_RINGING_REQUESTED =
170 "android.telecom.extra.SILENT_RINGING_REQUESTED";
171
Tyler Gunn8bf76572017-04-06 15:30:08 -0700172 /**
173 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
174 * Telecom that the user has requested that the current {@link Call} should be handed over
175 * to another {@link ConnectionService}.
176 * <p>
177 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
178 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
179 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700180 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
181 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700182 */
183 public static final String EVENT_REQUEST_HANDOVER =
184 "android.telecom.event.REQUEST_HANDOVER";
185
186 /**
187 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
188 * {@link PhoneAccountHandle} to which a call should be handed over to.
189 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700190 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
191 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700192 */
193 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
194 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
195
196 /**
197 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
198 * video state of the call when it is handed over to the new {@link PhoneAccount}.
199 * <p>
200 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
201 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
202 * {@link VideoProfile#STATE_TX_ENABLED}.
203 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700204 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
205 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700206 */
207 public static final String EXTRA_HANDOVER_VIDEO_STATE =
208 "android.telecom.extra.HANDOVER_VIDEO_STATE";
209
210 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700211 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
212 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
213 * information to the handover {@link ConnectionService} specified by
214 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
215 * <p>
216 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
217 * {@link ConnectionService} via the request extras when
218 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
219 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700220 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700221 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
222 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700223 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700224 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700225
226 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700227 * Call event sent from Telecom to the handover {@link ConnectionService} via
228 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
229 * to the {@link ConnectionService} has completed successfully.
230 * <p>
231 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700232 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700233 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
234 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700235 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700236 public static final String EVENT_HANDOVER_COMPLETE =
237 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700238
239 /**
240 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
241 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
242 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
243 * {@code null}.
244 * <p>
245 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
246 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700247 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
248 * APIs instead.
Tyler Gunn34a2b312017-06-23 08:32:00 -0700249 */
250 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
251 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
252
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700253 /**
254 * Call event sent from Telecom to the handover {@link ConnectionService} via
255 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
256 * to the {@link ConnectionService} has failed.
257 * <p>
258 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
259 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700260 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
261 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700262 */
263 public static final String EVENT_HANDOVER_FAILED =
264 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700265
Ihab Awade63fadb2014-07-09 21:52:04 -0700266 public static class Details {
Tyler Gunn94f8f112018-12-17 09:56:11 -0800267 /** @hide */
268 @Retention(RetentionPolicy.SOURCE)
269 @IntDef(
270 prefix = { "DIRECTION_" },
271 value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
272 public @interface CallDirection {}
273
274 /**
275 * Indicates that the call is neither and incoming nor an outgoing call. This can be the
276 * case for calls reported directly by a {@link ConnectionService} in special cases such as
277 * call handovers.
278 */
279 public static final int DIRECTION_UNKNOWN = -1;
280
281 /**
282 * Indicates that the call is an incoming call.
283 */
284 public static final int DIRECTION_INCOMING = 0;
285
286 /**
287 * Indicates that the call is an outgoing call.
288 */
289 public static final int DIRECTION_OUTGOING = 1;
290
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800291
292 /** Call can currently be put on hold or unheld. */
293 public static final int CAPABILITY_HOLD = 0x00000001;
294
295 /** Call supports the hold feature. */
296 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
297
298 /**
299 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
300 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
301 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
302 * capability allows a merge button to be shown while the conference call is in the foreground
303 * of the in-call UI.
304 * <p>
305 * This is only intended for use by a {@link Conference}.
306 */
307 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
308
309 /**
310 * Calls within a conference can be swapped between foreground and background.
311 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
312 * <p>
313 * This is only intended for use by a {@link Conference}.
314 */
315 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
316
317 /**
318 * @hide
319 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700320 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800321
322 /** Call supports responding via text option. */
323 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
324
325 /** Call can be muted. */
326 public static final int CAPABILITY_MUTE = 0x00000040;
327
328 /**
329 * Call supports conference call management. This capability only applies to {@link Conference}
330 * calls which can have {@link Connection}s as children.
331 */
332 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
333
334 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700335 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800336 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700337 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800338
339 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700340 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800341 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700342 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800343
344 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700345 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800346 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700347 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700348 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800349
350 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700351 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800352 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700353 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
354
355 /**
356 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700357 */
358 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
359
360 /**
361 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700362 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700363 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700364 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800365
366 /**
367 * Call is able to be separated from its parent {@code Conference}, if any.
368 */
369 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
370
371 /**
372 * Call is able to be individually disconnected when in a {@code Conference}.
373 */
374 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
375
376 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500377 * Speed up audio setup for MT call.
378 * @hide
379 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700380 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
381
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700382 /**
383 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700384 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800385 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
386 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
387 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700388 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800389 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700390 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
391
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700392 /**
393 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700394 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700395 */
396 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
397
Bryce Lee81901682015-08-28 16:38:02 -0700398 /**
399 * Call sends responses through connection.
400 * @hide
401 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800402 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
403
404 /**
405 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
406 * <p>
407 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
408 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
409 * downgraded from a video call back to a VideoState of
410 * {@link VideoProfile#STATE_AUDIO_ONLY}.
411 * <p>
412 * Intuitively, a call which can be downgraded to audio should also have local and remote
413 * video
414 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
415 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
416 */
417 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700418
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700419 /**
420 * When set for an external call, indicates that this {@code Call} can be pulled from a
421 * remote device to the current device.
422 * <p>
423 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
424 * <p>
425 * An {@link InCallService} will only see calls with this capability if it has the
426 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
427 * in its manifest.
428 * <p>
429 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700430 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700431 */
432 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
433
Pooja Jaind34698d2017-12-28 14:15:31 +0530434 /** Call supports the deflect feature. */
435 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
436
Tyler Gunnd11a3152015-03-18 13:09:14 -0700437 //******************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530438 // Next CAPABILITY value: 0x02000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700439 //******************************************************************************************
440
441 /**
442 * Whether the call is currently a conference.
443 */
444 public static final int PROPERTY_CONFERENCE = 0x00000001;
445
446 /**
447 * Whether the call is a generic conference, where we do not know the precise state of
448 * participants in the conference (eg. on CDMA).
449 */
450 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
451
452 /**
453 * Whether the call is made while the device is in emergency callback mode.
454 */
455 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
456
457 /**
458 * Connection is using WIFI.
459 */
460 public static final int PROPERTY_WIFI = 0x00000008;
461
462 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700463 * When set, the UI should indicate to the user that a call is using high definition
464 * audio.
465 * <p>
466 * The underlying {@link ConnectionService} is responsible for reporting this
467 * property. It is important to note that this property is not intended to report the
468 * actual audio codec being used for a Call, but whether the call should be indicated
469 * to the user as high definition.
470 * <p>
471 * The Android Telephony stack reports this property for calls based on a number
472 * of factors, including which audio codec is used and whether a call is using an HD
473 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
474 * and in these cases this property will not be set for a call even if the underlying audio
475 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700476 */
477 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
478
Tony Maka68dcce2015-12-17 09:31:18 +0000479 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100480 * Whether the call is associated with the work profile.
481 */
482 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
483
484 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700485 * When set, indicates that this {@code Call} does not actually exist locally for the
486 * {@link ConnectionService}.
487 * <p>
488 * Consider, for example, a scenario where a user has two phones with the same phone number.
489 * When a user places a call on one device, the telephony stack can represent that call on
490 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700491 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700492 * <p>
493 * An {@link InCallService} will only see calls with this property if it has the
494 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
495 * in its manifest.
496 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700497 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700498 */
499 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
500
Brad Ebinger15847072016-05-18 11:08:36 -0700501 /**
502 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
503 */
504 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
505
Tyler Gunn24e18332017-02-10 09:42:49 -0800506 /**
507 * Indicates that the call is from a self-managed {@link ConnectionService}.
508 * <p>
509 * See also {@link Connection#PROPERTY_SELF_MANAGED}
510 */
511 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
512
Eric Erfanianec881872017-12-06 16:27:53 -0800513 /**
514 * Indicates the call used Assisted Dialing.
515 * See also {@link Connection#PROPERTY_ASSISTED_DIALING_USED}
516 * @hide
517 */
518 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
519
Hall Liue9041242018-02-09 16:40:03 -0800520 /**
521 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
522 * {@link RttCall} object that is used to send and receive text.
523 */
524 public static final int PROPERTY_RTT = 0x00000400;
525
Tyler Gunn5bd90852018-09-21 09:37:07 -0700526 /**
527 * Indicates that the call has been identified as the network as an emergency call. This
528 * property may be set for both incoming and outgoing calls which the network identifies as
529 * emergency calls.
530 */
531 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
532
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700533 /**
534 * Indicates that the call is using VoIP audio mode.
535 * <p>
536 * When this property is set, the {@link android.media.AudioManager} audio mode for this
537 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
538 * property is not set, the audio mode for this call will be
539 * {@link android.media.AudioManager#MODE_IN_CALL}.
540 * <p>
541 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
542 * <p>
543 * You can use this property to determine whether an un-answered incoming call or a held
544 * call will use VoIP audio mode (if the call does not currently have focus, the system
545 * audio mode may not reflect the mode the call will use).
546 */
547 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
548
Andrew Lee2378ea72015-04-29 14:38:11 -0700549 //******************************************************************************************
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700550 // Next PROPERTY value: 0x00002000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700551 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800552
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800553 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700554 private final Uri mHandle;
555 private final int mHandlePresentation;
556 private final String mCallerDisplayName;
557 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700558 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700559 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700560 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800561 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700562 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700563 private final long mConnectTimeMillis;
564 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700565 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700566 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700567 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700568 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700569 private final long mCreationTimeMillis;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800570 private final @CallDirection int mCallDirection;
Ihab Awade63fadb2014-07-09 21:52:04 -0700571
572 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800573 * Whether the supplied capabilities supports the specified capability.
574 *
575 * @param capabilities A bit field of capabilities.
576 * @param capability The capability to check capabilities for.
577 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800578 */
579 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800580 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800581 }
582
583 /**
584 * Whether the capabilities of this {@code Details} supports the specified capability.
585 *
586 * @param capability The capability to check capabilities for.
587 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800588 */
589 public boolean can(int capability) {
590 return can(mCallCapabilities, capability);
591 }
592
593 /**
594 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
595 *
596 * @param capabilities A capability bit field.
597 * @return A human readable string representation.
598 */
599 public static String capabilitiesToString(int capabilities) {
600 StringBuilder builder = new StringBuilder();
601 builder.append("[Capabilities:");
602 if (can(capabilities, CAPABILITY_HOLD)) {
603 builder.append(" CAPABILITY_HOLD");
604 }
605 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
606 builder.append(" CAPABILITY_SUPPORT_HOLD");
607 }
608 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
609 builder.append(" CAPABILITY_MERGE_CONFERENCE");
610 }
611 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
612 builder.append(" CAPABILITY_SWAP_CONFERENCE");
613 }
614 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
615 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
616 }
617 if (can(capabilities, CAPABILITY_MUTE)) {
618 builder.append(" CAPABILITY_MUTE");
619 }
620 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
621 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
622 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700623 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
624 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
625 }
626 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
627 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
628 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700629 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
630 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800631 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700632 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
633 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
634 }
635 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
636 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
637 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800638 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
639 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
640 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700641 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
642 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800643 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500644 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700645 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500646 }
Rekha Kumar07366812015-03-24 16:42:31 -0700647 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
648 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
649 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700650 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
651 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
652 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700653 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
654 builder.append(" CAPABILITY_CAN_PULL_CALL");
655 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530656 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
657 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
658 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800659 builder.append("]");
660 return builder.toString();
661 }
662
663 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700664 * Whether the supplied properties includes the specified property.
665 *
666 * @param properties A bit field of properties.
667 * @param property The property to check properties for.
668 * @return Whether the specified property is supported.
669 */
670 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800671 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700672 }
673
674 /**
675 * Whether the properties of this {@code Details} includes the specified property.
676 *
677 * @param property The property to check properties for.
678 * @return Whether the specified property is supported.
679 */
680 public boolean hasProperty(int property) {
681 return hasProperty(mCallProperties, property);
682 }
683
684 /**
685 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
686 *
687 * @param properties A property bit field.
688 * @return A human readable string representation.
689 */
690 public static String propertiesToString(int properties) {
691 StringBuilder builder = new StringBuilder();
692 builder.append("[Properties:");
693 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
694 builder.append(" PROPERTY_CONFERENCE");
695 }
696 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
697 builder.append(" PROPERTY_GENERIC_CONFERENCE");
698 }
699 if (hasProperty(properties, PROPERTY_WIFI)) {
700 builder.append(" PROPERTY_WIFI");
701 }
702 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
703 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
704 }
705 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700706 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700707 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700708 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
709 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
710 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700711 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700712 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
713 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700714 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800715 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
716 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700717 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
718 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
719 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700720 if (hasProperty(properties, PROPERTY_RTT)) {
721 builder.append(" PROPERTY_RTT");
722 }
723 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
724 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
725 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700726 builder.append("]");
727 return builder.toString();
728 }
729
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800730 /** {@hide} */
Hall Liu31de23d2019-10-11 15:38:29 -0700731 @TestApi
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800732 public String getTelecomCallId() {
733 return mTelecomCallId;
734 }
735
Andrew Lee2378ea72015-04-29 14:38:11 -0700736 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700737 * @return The handle (e.g., phone number) to which the {@code Call} is currently
738 * connected.
739 */
740 public Uri getHandle() {
741 return mHandle;
742 }
743
744 /**
745 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700746 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700747 */
748 public int getHandlePresentation() {
749 return mHandlePresentation;
750 }
751
752 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800753 * The display name for the caller.
754 * <p>
755 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800756 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700757 * @return The display name for the caller.
758 */
759 public String getCallerDisplayName() {
760 return mCallerDisplayName;
761 }
762
763 /**
764 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700765 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700766 */
767 public int getCallerDisplayNamePresentation() {
768 return mCallerDisplayNamePresentation;
769 }
770
771 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700772 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
773 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700774 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700775 public PhoneAccountHandle getAccountHandle() {
776 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700777 }
778
779 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800780 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
781 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700782 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700783 public int getCallCapabilities() {
784 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700785 }
786
787 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700788 * @return A bitmask of the properties of the {@code Call}, as defined by the various
789 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700790 */
791 public int getCallProperties() {
792 return mCallProperties;
793 }
794
795 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800796 * @return a bitmask of the audio routes available for the call.
797 *
798 * @hide
799 */
800 public int getSupportedAudioRoutes() {
801 return mSupportedAudioRoutes;
802 }
803
804 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700805 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700806 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700807 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700808 public DisconnectCause getDisconnectCause() {
809 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700810 }
811
812 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700813 * Returns the time the {@link Call} connected (i.e. became active). This information is
814 * updated periodically, but user interfaces should not rely on this to display the "call
815 * time clock". For the time when the call was first added to Telecom, see
816 * {@link #getCreationTimeMillis()}.
817 *
818 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700819 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700820 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700821 return mConnectTimeMillis;
822 }
823
824 /**
825 * @return Information about any calling gateway the {@code Call} may be using.
826 */
827 public GatewayInfo getGatewayInfo() {
828 return mGatewayInfo;
829 }
830
Andrew Lee7a341382014-07-15 17:05:08 -0700831 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700832 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700833 */
834 public int getVideoState() {
835 return mVideoState;
836 }
837
Ihab Awad5d0410f2014-07-30 10:07:40 -0700838 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700839 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700840 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700841 */
842 public StatusHints getStatusHints() {
843 return mStatusHints;
844 }
845
Nancy Chen10798dc2014-08-08 14:00:25 -0700846 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700847 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700848 */
849 public Bundle getExtras() {
850 return mExtras;
851 }
852
Santos Cordon6b7f9552015-05-27 17:21:45 -0700853 /**
854 * @return The extras used with the original intent to place this call.
855 */
856 public Bundle getIntentExtras() {
857 return mIntentExtras;
858 }
859
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700860 /**
861 * Returns the time when the call was first created and added to Telecom. This is the same
862 * time that is logged as the start time in the Call Log (see
863 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
864 * (became active), see {@link #getConnectTimeMillis()}.
865 *
866 * @return The creation time of the call, in millis since the epoch.
867 */
868 public long getCreationTimeMillis() {
869 return mCreationTimeMillis;
870 }
871
Tyler Gunnd081f042018-12-04 12:56:45 -0800872 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -0800873 * Indicates whether the call is an incoming or outgoing call.
874 * @return The call's direction.
875 */
876 public @CallDirection int getCallDirection() {
877 return mCallDirection;
878 }
879
Ihab Awade63fadb2014-07-09 21:52:04 -0700880 @Override
881 public boolean equals(Object o) {
882 if (o instanceof Details) {
883 Details d = (Details) o;
884 return
885 Objects.equals(mHandle, d.mHandle) &&
886 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
887 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
888 Objects.equals(mCallerDisplayNamePresentation,
889 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700890 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700891 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700892 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700893 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700894 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700895 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700896 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700897 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700898 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700899 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -0800900 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Tyler Gunn94f8f112018-12-17 09:56:11 -0800901 Objects.equals(mCallDirection, d.mCallDirection);
Ihab Awade63fadb2014-07-09 21:52:04 -0700902 }
903 return false;
904 }
905
906 @Override
907 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700908 return Objects.hash(mHandle,
909 mHandlePresentation,
910 mCallerDisplayName,
911 mCallerDisplayNamePresentation,
912 mAccountHandle,
913 mCallCapabilities,
914 mCallProperties,
915 mDisconnectCause,
916 mConnectTimeMillis,
917 mGatewayInfo,
918 mVideoState,
919 mStatusHints,
920 mExtras,
921 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -0800922 mCreationTimeMillis,
Tyler Gunn94f8f112018-12-17 09:56:11 -0800923 mCallDirection);
Ihab Awade63fadb2014-07-09 21:52:04 -0700924 }
925
926 /** {@hide} */
927 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800928 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700929 Uri handle,
930 int handlePresentation,
931 String callerDisplayName,
932 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700933 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700934 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700935 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700936 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700937 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700938 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700939 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700940 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700941 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700942 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -0800943 long creationTimeMillis,
Tyler Gunn94f8f112018-12-17 09:56:11 -0800944 int callDirection) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800945 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700946 mHandle = handle;
947 mHandlePresentation = handlePresentation;
948 mCallerDisplayName = callerDisplayName;
949 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700950 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700951 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700952 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700953 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700954 mConnectTimeMillis = connectTimeMillis;
955 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700956 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700957 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700958 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700959 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700960 mCreationTimeMillis = creationTimeMillis;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800961 mCallDirection = callDirection;
Ihab Awade63fadb2014-07-09 21:52:04 -0700962 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800963
964 /** {@hide} */
965 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
966 return new Details(
967 parcelableCall.getId(),
968 parcelableCall.getHandle(),
969 parcelableCall.getHandlePresentation(),
970 parcelableCall.getCallerDisplayName(),
971 parcelableCall.getCallerDisplayNamePresentation(),
972 parcelableCall.getAccountHandle(),
973 parcelableCall.getCapabilities(),
974 parcelableCall.getProperties(),
975 parcelableCall.getDisconnectCause(),
976 parcelableCall.getConnectTimeMillis(),
977 parcelableCall.getGatewayInfo(),
978 parcelableCall.getVideoState(),
979 parcelableCall.getStatusHints(),
980 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700981 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -0800982 parcelableCall.getCreationTimeMillis(),
Tyler Gunn94f8f112018-12-17 09:56:11 -0800983 parcelableCall.getCallDirection());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800984 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800985
986 @Override
987 public String toString() {
988 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -0800989 sb.append("[id: ");
990 sb.append(mTelecomCallId);
991 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -0800992 sb.append(mAccountHandle);
993 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -0800994 sb.append(Log.piiHandle(mHandle));
995 sb.append(", hdlPres: ");
996 sb.append(mHandlePresentation);
997 sb.append(", videoState: ");
998 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -0800999 sb.append(", caps: ");
1000 sb.append(capabilitiesToString(mCallCapabilities));
1001 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001002 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001003 sb.append("]");
1004 return sb.toString();
1005 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001006 }
1007
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001008 /**
1009 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1010 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1011 * implementation.
1012 * <p>
1013 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1014 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1015 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1016 * {@link Callback} implementation, if desired.
1017 * <p>
1018 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1019 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1020 * (typically in {@link InCallService#onCallRemoved(Call)}).
1021 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1022 * reach your implementation of {@link Callback}, so it is important to register your callback
1023 * as soon as your {@link InCallService} is notified of a new call via
1024 * {@link InCallService#onCallAdded(Call)}.
1025 */
Andrew Leeda80c872015-04-15 14:09:50 -07001026 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001027 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001028 * @hide
1029 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001030 @IntDef(prefix = { "HANDOVER_" },
1031 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001032 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001033 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001034 @Retention(RetentionPolicy.SOURCE)
1035 public @interface HandoverFailureErrors {}
1036
1037 /**
1038 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001039 * to handover the call to rejects the handover request.
1040 * <p>
1041 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1042 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1043 * {@code null} {@link Connection} from
1044 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1045 * ConnectionRequest)}.
1046 * <p>
1047 * For more information on call handovers, see
1048 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001049 */
1050 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1051
1052 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001053 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1054 * is initiated but the source or destination app does not support handover.
1055 * <p>
1056 * Will be returned when a handover is requested via
1057 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1058 * {@link PhoneAccountHandle} does not declare
1059 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1060 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1061 * {@link Details#getAccountHandle()}) does not declare
1062 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1063 * <p>
1064 * For more information on call handovers, see
1065 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001066 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001067 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001068
1069 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001070 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1071 * user rejects the handover request.
1072 * <p>
1073 * For more information on call handovers, see
1074 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001075 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001076 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001077
Sanket Padawe85291f62017-12-01 13:59:27 -08001078 /**
1079 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1080 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001081 * <p>
1082 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1083 * called on an emergency call, or if any other call is an emergency call.
1084 * <p>
1085 * Handovers are not permitted while there are ongoing emergency calls.
1086 * <p>
1087 * For more information on call handovers, see
1088 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001089 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001090 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001091
Tyler Gunn9d127732018-03-02 15:45:51 -08001092 /**
1093 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1094 * fails for an unknown reason.
1095 * <p>
1096 * For more information on call handovers, see
1097 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1098 */
1099 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001100
1101 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001102 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1103 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001104 * @param call The {@code Call} invoking this method.
1105 * @param state The new state of the {@code Call}.
1106 */
1107 public void onStateChanged(Call call, int state) {}
1108
1109 /**
1110 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1111 *
1112 * @param call The {@code Call} invoking this method.
1113 * @param parent The new parent of the {@code Call}.
1114 */
1115 public void onParentChanged(Call call, Call parent) {}
1116
1117 /**
1118 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1119 *
1120 * @param call The {@code Call} invoking this method.
1121 * @param children The new children of the {@code Call}.
1122 */
1123 public void onChildrenChanged(Call call, List<Call> children) {}
1124
1125 /**
1126 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1127 *
1128 * @param call The {@code Call} invoking this method.
1129 * @param details A {@code Details} object describing the {@code Call}.
1130 */
1131 public void onDetailsChanged(Call call, Details details) {}
1132
1133 /**
1134 * Invoked when the text messages that can be used as responses to the incoming
1135 * {@code Call} are loaded from the relevant database.
1136 * See {@link #getCannedTextResponses()}.
1137 *
1138 * @param call The {@code Call} invoking this method.
1139 * @param cannedTextResponses The text messages useable as responses.
1140 */
1141 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1142
1143 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001144 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1145 * character. This causes the post-dial signals to stop pending user confirmation. An
1146 * implementation should present this choice to the user and invoke
1147 * {@link #postDialContinue(boolean)} when the user makes the choice.
1148 *
1149 * @param call The {@code Call} invoking this method.
1150 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1151 */
1152 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1153
1154 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001155 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001156 *
1157 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001158 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001159 */
Andrew Lee50aca232014-07-22 16:41:54 -07001160 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001161
1162 /**
1163 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1164 * up their UI for the {@code Call} in response to state transitions. Specifically,
1165 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1166 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1167 * clients should wait for this method to be invoked.
1168 *
1169 * @param call The {@code Call} being destroyed.
1170 */
1171 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001172
1173 /**
1174 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1175 * conferenced.
1176 *
1177 * @param call The {@code Call} being updated.
1178 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1179 * conferenced.
1180 */
1181 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001182
1183 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001184 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
1185 * <p>
1186 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1187 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1188 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1189 * possible that a {@link ConnectionService} has defined its own Connection events which a
1190 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001191 * <p>
1192 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
1193 *
1194 * @param call The {@code Call} receiving the event.
1195 * @param event The event.
1196 * @param extras Extras associated with the connection event.
1197 */
1198 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001199
1200 /**
1201 * Invoked when the RTT mode changes for this call.
1202 * @param call The call whose RTT mode has changed.
1203 * @param mode the new RTT mode, one of
1204 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1205 * or {@link RttCall#RTT_MODE_VCO}
1206 */
1207 public void onRttModeChanged(Call call, int mode) {}
1208
1209 /**
1210 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1211 * @param call The call whose RTT status has changed.
1212 * @param enabled whether RTT is now enabled or disabled
1213 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1214 * on, null otherwise.
1215 */
1216 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1217
1218 /**
1219 * Invoked when the remote end of the connection has requested that an RTT communication
1220 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1221 * with the same ID that this method is invoked with.
1222 * @param call The call which the RTT request was placed on
1223 * @param id The ID of the request.
1224 */
1225 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001226
1227 /**
1228 * Invoked when the RTT session failed to initiate for some reason, including rejection
1229 * by the remote party.
1230 * @param call The call which the RTT initiation failure occurred on.
1231 * @param reason One of the status codes defined in
1232 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1233 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1234 */
1235 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001236
1237 /**
1238 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1239 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001240 * <p>
1241 * For a full discussion of the handover process and the APIs involved, see
1242 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1243 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001244 * @param call The call which had initiated handover.
1245 */
1246 public void onHandoverComplete(Call call) {}
1247
1248 /**
1249 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1250 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001251 * <p>
1252 * For a full discussion of the handover process and the APIs involved, see
1253 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1254 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001255 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001256 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001257 */
1258 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001259 }
1260
1261 /**
1262 * A class that holds the state that describes the state of the RTT channel to the remote
1263 * party, if it is active.
1264 */
1265 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001266 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001267 @Retention(RetentionPolicy.SOURCE)
1268 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1269 public @interface RttAudioMode {}
1270
1271 /**
1272 * For metrics use. Default value in the proto.
1273 * @hide
1274 */
1275 public static final int RTT_MODE_INVALID = 0;
1276
1277 /**
1278 * Indicates that there should be a bidirectional audio stream between the two parties
1279 * on the call.
1280 */
1281 public static final int RTT_MODE_FULL = 1;
1282
1283 /**
1284 * Indicates that the local user should be able to hear the audio stream from the remote
1285 * user, but not vice versa. Equivalent to muting the microphone.
1286 */
1287 public static final int RTT_MODE_HCO = 2;
1288
1289 /**
1290 * Indicates that the remote user should be able to hear the audio stream from the local
1291 * user, but not vice versa. Equivalent to setting the volume to zero.
1292 */
1293 public static final int RTT_MODE_VCO = 3;
1294
1295 private static final int READ_BUFFER_SIZE = 1000;
1296
1297 private InputStreamReader mReceiveStream;
1298 private OutputStreamWriter mTransmitStream;
1299 private int mRttMode;
1300 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001301 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001302 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1303
1304 /**
1305 * @hide
1306 */
Hall Liu57006aa2017-02-06 10:49:48 -08001307 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1308 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1309 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001310 mReceiveStream = receiveStream;
1311 mTransmitStream = transmitStream;
1312 mRttMode = mode;
1313 mInCallAdapter = inCallAdapter;
1314 }
1315
1316 /**
1317 * Returns the current RTT audio mode.
1318 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1319 * {@link #RTT_MODE_HCO}.
1320 */
1321 public int getRttAudioMode() {
1322 return mRttMode;
1323 }
1324
1325 /**
1326 * Sets the RTT audio mode. The requested mode change will be communicated through
1327 * {@link Callback#onRttModeChanged(Call, int)}.
1328 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1329 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1330 */
1331 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001332 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001333 }
1334
1335 /**
1336 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1337 * RTT transmits text in real-time, this method should be called once for each character
1338 * the user enters into the device.
1339 *
1340 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1341 * lead to interleaved text.
1342 * @param input The message to send to the remote user.
1343 */
1344 public void write(String input) throws IOException {
1345 mTransmitStream.write(input);
1346 mTransmitStream.flush();
1347 }
1348
1349 /**
1350 * Reads a string from the remote user, blocking if there is no data available. Returns
1351 * {@code null} if the RTT conversation has been terminated and there is no further data
1352 * to read.
1353 *
1354 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1355 * lead to interleaved text.
1356 * @return A string containing text sent by the remote user, or {@code null} if the
1357 * conversation has been terminated or if there was an error while reading.
1358 */
Hall Liub1c8a772017-07-17 17:04:41 -07001359 public String read() {
1360 try {
1361 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1362 if (numRead < 0) {
1363 return null;
1364 }
1365 return new String(mReadBuffer, 0, numRead);
1366 } catch (IOException e) {
1367 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001368 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001369 }
Hall Liuffa4a812017-03-02 16:11:00 -08001370 }
1371
1372 /**
1373 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1374 * be read.
1375 * @return A string containing text entered by the user, or {@code null} if the user has
1376 * not entered any new text yet.
1377 */
1378 public String readImmediately() throws IOException {
1379 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001380 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1381 if (numRead < 0) {
1382 return null;
1383 }
1384 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001385 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001386 return null;
1387 }
1388 }
Hall Liue9041242018-02-09 16:40:03 -08001389
1390 /**
1391 * Closes the underlying file descriptors
1392 * @hide
1393 */
1394 public void close() {
1395 try {
1396 mReceiveStream.close();
1397 } catch (IOException e) {
1398 // ignore
1399 }
1400 try {
1401 mTransmitStream.close();
1402 } catch (IOException e) {
1403 // ignore
1404 }
1405 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001406 }
1407
Andrew Leeda80c872015-04-15 14:09:50 -07001408 /**
1409 * @deprecated Use {@code Call.Callback} instead.
1410 * @hide
1411 */
1412 @Deprecated
1413 @SystemApi
1414 public static abstract class Listener extends Callback { }
1415
Ihab Awade63fadb2014-07-09 21:52:04 -07001416 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001417 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001418 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001419 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001420 private final List<Call> mChildren = new ArrayList<>();
1421 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001422 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001423 private final List<Call> mConferenceableCalls = new ArrayList<>();
1424 private final List<Call> mUnmodifiableConferenceableCalls =
1425 Collections.unmodifiableList(mConferenceableCalls);
1426
Santos Cordon823fd3c2014-08-07 18:35:18 -07001427 private boolean mChildrenCached;
1428 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001429 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001430 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001431 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001432 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001433 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001434 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001435 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001436 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001437 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001438
1439 /**
1440 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1441 *
1442 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1443 * remaining or this {@code Call} is not in a post-dial state.
1444 */
1445 public String getRemainingPostDialSequence() {
1446 return mRemainingPostDialSequence;
1447 }
1448
1449 /**
1450 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001451 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001452 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001453 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001454 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001455 }
1456
1457 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301458 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1459 *
1460 * @param address The address to which the call will be deflected.
1461 */
1462 public void deflect(Uri address) {
1463 mInCallAdapter.deflectCall(mTelecomCallId, address);
1464 }
1465
1466 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001467 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1468 *
1469 * @param rejectWithMessage Whether to reject with a text message.
1470 * @param textMessage An optional text message with which to respond.
1471 */
1472 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001473 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001474 }
1475
1476 /**
1477 * Instructs this {@code Call} to disconnect.
1478 */
1479 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001480 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001481 }
1482
1483 /**
1484 * Instructs this {@code Call} to go on hold.
1485 */
1486 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001487 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001488 }
1489
1490 /**
1491 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1492 */
1493 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001494 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001495 }
1496
1497 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001498 * Instructs Telecom to put the call into the background audio processing state.
1499 *
1500 * This method can be called either when the call is in {@link #STATE_RINGING} or
1501 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1502 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1503 * order to capture and play audio on the call stream.
1504 *
1505 * This method can only be called by the default dialer app.
1506 * @hide
1507 */
1508 @SystemApi
1509 @TestApi
1510 //@RequiresPermission(android.Manifest.permission.BACKGROUND_CALL_AUDIO)
1511 public void enterBackgroundAudioProcessing() {
1512 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1513 throw new IllegalStateException("Call must be active or ringing");
1514 }
1515 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1516 }
1517
1518 /**
1519 * Instructs Telecom to come out of the background audio processing state requested by
1520 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1521 *
1522 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1523 *
1524 * @param shouldRing If true, Telecom will put the call into the
1525 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1526 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1527 * immediately.
1528 * @hide
1529 */
1530 @SystemApi
1531 @TestApi
1532 //@RequiresPermission(android.Manifest.permission.BACKGROUND_CALL_AUDIO)
1533 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1534 if (mState != STATE_AUDIO_PROCESSING) {
1535 throw new IllegalStateException("Call must in the audio processing state");
1536 }
1537 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1538 }
1539
1540 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001541 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1542 *
1543 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1544 *
1545 * @param digit A character representing the DTMF digit for which to play the tone. This
1546 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1547 */
1548 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001549 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001550 }
1551
1552 /**
1553 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1554 * currently playing.
1555 *
1556 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1557 * currently playing, this method will do nothing.
1558 */
1559 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001560 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001561 }
1562
1563 /**
1564 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1565 *
1566 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1567 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001568 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001569 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001570 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1571 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001572 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001573 * {@code Call} will pause playing the tones and notify callbacks via
1574 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001575 * should display to the user an indication of this state and an affordance to continue
1576 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1577 * app should invoke the {@link #postDialContinue(boolean)} method.
1578 *
1579 * @param proceed Whether or not to continue with the post-dial sequence.
1580 */
1581 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001582 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001583 }
1584
1585 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001586 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001587 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001588 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001589 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1590 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001591
1592 }
1593
1594 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001595 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001596 *
1597 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001598 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001599 public void conference(Call callToConferenceWith) {
1600 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001601 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001602 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001603 }
1604
1605 /**
1606 * Instructs this {@code Call} to split from any conference call with which it may be
1607 * connected.
1608 */
1609 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001610 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001611 }
1612
1613 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001614 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001615 */
1616 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001617 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001618 }
1619
1620 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001621 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001622 */
1623 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001624 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001625 }
1626
1627 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001628 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1629 * device.
1630 * <p>
1631 * Calls to this method are ignored if the call does not have the
1632 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1633 * <p>
1634 * An {@link InCallService} will only see calls which support this method if it has the
1635 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1636 * in its manifest.
1637 */
1638 public void pullExternalCall() {
1639 // If this isn't an external call, ignore the request.
1640 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1641 return;
1642 }
1643
1644 mInCallAdapter.pullExternalCall(mTelecomCallId);
1645 }
1646
1647 /**
1648 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1649 * the {@link ConnectionService}.
1650 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001651 * Call events are used to communicate point in time information from an {@link InCallService}
1652 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1653 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1654 * {@link ConnectionService}.
1655 * <p>
1656 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1657 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1658 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001659 * Events are exposed to {@link ConnectionService} implementations via
1660 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1661 * <p>
1662 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001663 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1664 * ignore some events altogether.
1665 * <p>
1666 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1667 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1668 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1669 * they define their own event types in this namespace. When defining a custom event type,
1670 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1671 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1672 * <p>
1673 * When defining events and the associated extras, it is important to keep their behavior
1674 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1675 * events/extras should me maintained to ensure backwards compatibility with older
1676 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001677 *
1678 * @param event The connection event.
1679 * @param extras Bundle containing extra information associated with the event.
1680 */
1681 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001682 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001683 }
1684
1685 /**
Hall Liu95d55872017-01-25 17:12:49 -08001686 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1687 * guaranteed, and notification of success will be via the
1688 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1689 */
1690 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001691 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001692 }
1693
1694 /**
1695 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1696 * callback.
1697 * The ID used here should be the same as the ID that was received via the callback.
1698 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1699 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1700 */
1701 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001702 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001703 }
1704
1705 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001706 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1707 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1708 * handover.
1709 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001710 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1711 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1712 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1713 * is referred to as the source of the handover, and the video calling app is referred to as the
1714 * destination.
1715 * <p>
1716 * When considering a handover scenario the device this method is called on is considered the
1717 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1718 * other device is considered the <em>receiving</em> device.
1719 * <p>
1720 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1721 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1722 * and invoke
1723 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1724 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1725 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1726 * At this point the app should display UI to indicate to the user that a call
1727 * handover is in process.
1728 * <p>
1729 * The destination app is responsible for communicating the handover request from the
1730 * <em>initiating</em> device to the <em>receiving</em> device.
1731 * <p>
1732 * When the app on the <em>receiving</em> device receives the handover request, it calls
1733 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1734 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1735 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1736 * choose whether they want to continue their call in the destination app.
1737 * <p>
1738 * When the destination app on the <em>receiving</em> device calls
1739 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1740 * {@link ConnectionService} and call
1741 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1742 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1743 * {@link Connection} to represent the handover call.
1744 * <p>
1745 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1746 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1747 * original call. If the user rejects the handover, the app calls
1748 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1749 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1750 * <p>
1751 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1752 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1753 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1754 * <p>
1755 * Errors in the handover process are reported to the {@link InCallService} via
1756 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1757 * the involved {@link ConnectionService}s via
1758 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001759 *
1760 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1761 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001762 * @param videoState Indicates the video state desired after the handover (see the
1763 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001764 * @param extras Bundle containing extra information to be passed to the
1765 * {@link ConnectionService}
1766 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001767 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1768 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001769 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1770 }
1771
1772 /**
Hall Liu95d55872017-01-25 17:12:49 -08001773 * Terminate the RTT session on this call. The resulting state change will be notified via
1774 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1775 */
1776 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001777 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001778 }
1779
1780 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001781 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1782 * added.
1783 * <p>
1784 * No assumptions should be made as to how an In-Call UI or service will handle these
1785 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1786 *
1787 * @param extras The extras to add.
1788 */
1789 public final void putExtras(Bundle extras) {
1790 if (extras == null) {
1791 return;
1792 }
1793
1794 if (mExtras == null) {
1795 mExtras = new Bundle();
1796 }
1797 mExtras.putAll(extras);
1798 mInCallAdapter.putExtras(mTelecomCallId, extras);
1799 }
1800
1801 /**
1802 * Adds a boolean extra to this {@link Call}.
1803 *
1804 * @param key The extra key.
1805 * @param value The value.
1806 * @hide
1807 */
1808 public final void putExtra(String key, boolean value) {
1809 if (mExtras == null) {
1810 mExtras = new Bundle();
1811 }
1812 mExtras.putBoolean(key, value);
1813 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1814 }
1815
1816 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001817 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001818 *
1819 * @param key The extra key.
1820 * @param value The value.
1821 * @hide
1822 */
1823 public final void putExtra(String key, int value) {
1824 if (mExtras == null) {
1825 mExtras = new Bundle();
1826 }
1827 mExtras.putInt(key, value);
1828 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1829 }
1830
1831 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001832 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001833 *
1834 * @param key The extra key.
1835 * @param value The value.
1836 * @hide
1837 */
1838 public final void putExtra(String key, String value) {
1839 if (mExtras == null) {
1840 mExtras = new Bundle();
1841 }
1842 mExtras.putString(key, value);
1843 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1844 }
1845
1846 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001847 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001848 *
1849 * @param keys The keys of the extras to remove.
1850 */
1851 public final void removeExtras(List<String> keys) {
1852 if (mExtras != null) {
1853 for (String key : keys) {
1854 mExtras.remove(key);
1855 }
1856 if (mExtras.size() == 0) {
1857 mExtras = null;
1858 }
1859 }
1860 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1861 }
1862
1863 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001864 * Removes extras from this {@link Call}.
1865 *
1866 * @param keys The keys of the extras to remove.
1867 */
1868 public final void removeExtras(String ... keys) {
1869 removeExtras(Arrays.asList(keys));
1870 }
1871
1872 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001873 * Obtains the parent of this {@code Call} in a conference, if any.
1874 *
1875 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1876 * child of any conference {@code Call}s.
1877 */
1878 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001879 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001880 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001881 }
1882 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001883 }
1884
1885 /**
1886 * Obtains the children of this conference {@code Call}, if any.
1887 *
1888 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1889 * {@code List} otherwise.
1890 */
1891 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001892 if (!mChildrenCached) {
1893 mChildrenCached = true;
1894 mChildren.clear();
1895
1896 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001897 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001898 if (call == null) {
1899 // At least one child was still not found, so do not save true for "cached"
1900 mChildrenCached = false;
1901 } else {
1902 mChildren.add(call);
1903 }
1904 }
1905 }
1906
Ihab Awade63fadb2014-07-09 21:52:04 -07001907 return mUnmodifiableChildren;
1908 }
1909
1910 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001911 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1912 *
1913 * @return The list of conferenceable {@code Call}s.
1914 */
1915 public List<Call> getConferenceableCalls() {
1916 return mUnmodifiableConferenceableCalls;
1917 }
1918
1919 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001920 * Obtains the state of this {@code Call}.
1921 *
1922 * @return A state value, chosen from the {@code STATE_*} constants.
1923 */
1924 public int getState() {
1925 return mState;
1926 }
1927
1928 /**
1929 * Obtains a list of canned, pre-configured message responses to present to the user as
1930 * ways of rejecting this {@code Call} using via a text message.
1931 *
1932 * @see #reject(boolean, String)
1933 *
1934 * @return A list of canned text message responses.
1935 */
1936 public List<String> getCannedTextResponses() {
1937 return mCannedTextResponses;
1938 }
1939
1940 /**
1941 * Obtains an object that can be used to display video from this {@code Call}.
1942 *
Andrew Lee50aca232014-07-22 16:41:54 -07001943 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001944 */
Andrew Lee50aca232014-07-22 16:41:54 -07001945 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001946 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001947 }
1948
1949 /**
1950 * Obtains an object containing call details.
1951 *
1952 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1953 * result may be {@code null}.
1954 */
1955 public Details getDetails() {
1956 return mDetails;
1957 }
1958
1959 /**
Hall Liu95d55872017-01-25 17:12:49 -08001960 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1961 * receive RTT text data, as well as to change the RTT mode.
1962 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1963 */
1964 public @Nullable RttCall getRttCall() {
1965 return mRttCall;
1966 }
1967
1968 /**
1969 * Returns whether this call has an active RTT connection.
1970 * @return true if there is a connection, false otherwise.
1971 */
1972 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08001973 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08001974 }
1975
1976 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001977 * Registers a callback to this {@code Call}.
1978 *
1979 * @param callback A {@code Callback}.
1980 */
1981 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001982 registerCallback(callback, new Handler());
1983 }
1984
1985 /**
1986 * Registers a callback to this {@code Call}.
1987 *
1988 * @param callback A {@code Callback}.
1989 * @param handler A handler which command and status changes will be delivered to.
1990 */
1991 public void registerCallback(Callback callback, Handler handler) {
1992 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001993 // Don't allow new callback registration if the call is already being destroyed.
1994 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001995 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1996 }
Andrew Leeda80c872015-04-15 14:09:50 -07001997 }
1998
1999 /**
2000 * Unregisters a callback from this {@code Call}.
2001 *
2002 * @param callback A {@code Callback}.
2003 */
2004 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002005 // Don't allow callback deregistration if the call is already being destroyed.
2006 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002007 for (CallbackRecord<Callback> record : mCallbackRecords) {
2008 if (record.getCallback() == callback) {
2009 mCallbackRecords.remove(record);
2010 break;
2011 }
2012 }
Andrew Leeda80c872015-04-15 14:09:50 -07002013 }
2014 }
2015
Santos Cordon3c20d632016-02-25 16:12:35 -08002016 @Override
2017 public String toString() {
2018 return new StringBuilder().
2019 append("Call [id: ").
2020 append(mTelecomCallId).
2021 append(", state: ").
2022 append(stateToString(mState)).
2023 append(", details: ").
2024 append(mDetails).
2025 append("]").toString();
2026 }
2027
2028 /**
2029 * @param state An integer value of a {@code STATE_*} constant.
2030 * @return A string representation of the value.
2031 */
2032 private static String stateToString(int state) {
2033 switch (state) {
2034 case STATE_NEW:
2035 return "NEW";
2036 case STATE_RINGING:
2037 return "RINGING";
2038 case STATE_DIALING:
2039 return "DIALING";
2040 case STATE_ACTIVE:
2041 return "ACTIVE";
2042 case STATE_HOLDING:
2043 return "HOLDING";
2044 case STATE_DISCONNECTED:
2045 return "DISCONNECTED";
2046 case STATE_CONNECTING:
2047 return "CONNECTING";
2048 case STATE_DISCONNECTING:
2049 return "DISCONNECTING";
2050 case STATE_SELECT_PHONE_ACCOUNT:
2051 return "SELECT_PHONE_ACCOUNT";
Hall Liu4e35b642019-10-14 17:50:45 -07002052 case STATE_SIMULATED_RINGING:
2053 return "SIMULATED_RINGING";
2054 case STATE_AUDIO_PROCESSING:
2055 return "AUDIO_PROCESSING";
Santos Cordon3c20d632016-02-25 16:12:35 -08002056 default:
2057 Log.w(Call.class, "Unknown state %d", state);
2058 return "UNKNOWN";
2059 }
2060 }
2061
Andrew Leeda80c872015-04-15 14:09:50 -07002062 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002063 * Adds a listener to this {@code Call}.
2064 *
2065 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002066 * @deprecated Use {@link #registerCallback} instead.
2067 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002068 */
Andrew Leeda80c872015-04-15 14:09:50 -07002069 @Deprecated
2070 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002071 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002072 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002073 }
2074
2075 /**
2076 * Removes a listener from this {@code Call}.
2077 *
2078 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002079 * @deprecated Use {@link #unregisterCallback} instead.
2080 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002081 */
Andrew Leeda80c872015-04-15 14:09:50 -07002082 @Deprecated
2083 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002084 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002085 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002086 }
2087
2088 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002089 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2090 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002091 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002092 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002093 mInCallAdapter = inCallAdapter;
2094 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002095 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002096 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002097 }
2098
2099 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002100 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002101 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002102 mPhone = phone;
2103 mTelecomCallId = telecomCallId;
2104 mInCallAdapter = inCallAdapter;
2105 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002106 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002107 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002108 }
2109
2110 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002111 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002112 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002113 }
2114
2115 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002116 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002117
Ihab Awade63fadb2014-07-09 21:52:04 -07002118 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002119 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002120 boolean detailsChanged = !Objects.equals(mDetails, details);
2121 if (detailsChanged) {
2122 mDetails = details;
2123 }
2124
2125 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002126 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2127 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2128 mCannedTextResponses =
2129 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002130 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002131 }
2132
Tyler Gunn159f35c2017-03-02 09:28:37 -08002133 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
2134 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07002135 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002136 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07002137 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002138 mVideoCallImpl = newVideoCallImpl;
2139 }
2140 if (mVideoCallImpl != null) {
2141 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002142 }
2143
Santos Cordone3c507b2015-04-23 14:44:19 -07002144 int state = parcelableCall.getState();
Hall Liu31de23d2019-10-11 15:38:29 -07002145 if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2146 state = Call.STATE_RINGING;
2147 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002148 boolean stateChanged = mState != state;
2149 if (stateChanged) {
2150 mState = state;
2151 }
2152
Santos Cordon823fd3c2014-08-07 18:35:18 -07002153 String parentId = parcelableCall.getParentCallId();
2154 boolean parentChanged = !Objects.equals(mParentId, parentId);
2155 if (parentChanged) {
2156 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002157 }
2158
Santos Cordon823fd3c2014-08-07 18:35:18 -07002159 List<String> childCallIds = parcelableCall.getChildCallIds();
2160 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2161 if (childrenChanged) {
2162 mChildrenIds.clear();
2163 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2164 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002165 }
2166
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002167 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2168 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2169 for (String otherId : conferenceableCallIds) {
2170 if (callIdMap.containsKey(otherId)) {
2171 conferenceableCalls.add(callIdMap.get(otherId));
2172 }
2173 }
2174
2175 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2176 mConferenceableCalls.clear();
2177 mConferenceableCalls.addAll(conferenceableCalls);
2178 fireConferenceableCallsChanged();
2179 }
2180
Hall Liu95d55872017-01-25 17:12:49 -08002181 boolean isRttChanged = false;
2182 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002183 if (parcelableCall.getIsRttCallChanged()
2184 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002185 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2186 InputStreamReader receiveStream = new InputStreamReader(
2187 new ParcelFileDescriptor.AutoCloseInputStream(
2188 parcelableRttCall.getReceiveStream()),
2189 StandardCharsets.UTF_8);
2190 OutputStreamWriter transmitStream = new OutputStreamWriter(
2191 new ParcelFileDescriptor.AutoCloseOutputStream(
2192 parcelableRttCall.getTransmitStream()),
2193 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002194 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002195 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2196 if (mRttCall == null) {
2197 isRttChanged = true;
2198 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2199 rttModeChanged = true;
2200 }
2201 mRttCall = newRttCall;
2202 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2203 && parcelableCall.getIsRttCallChanged()) {
2204 isRttChanged = true;
2205 mRttCall = null;
2206 }
2207
Ihab Awade63fadb2014-07-09 21:52:04 -07002208 // Now we fire updates, ensuring that any client who listens to any of these notifications
2209 // gets the most up-to-date state.
2210
2211 if (stateChanged) {
2212 fireStateChanged(mState);
2213 }
2214 if (detailsChanged) {
2215 fireDetailsChanged(mDetails);
2216 }
2217 if (cannedTextResponsesChanged) {
2218 fireCannedTextResponsesLoaded(mCannedTextResponses);
2219 }
Andrew Lee50aca232014-07-22 16:41:54 -07002220 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002221 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002222 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002223 if (parentChanged) {
2224 fireParentChanged(getParent());
2225 }
2226 if (childrenChanged) {
2227 fireChildrenChanged(getChildren());
2228 }
Hall Liu95d55872017-01-25 17:12:49 -08002229 if (isRttChanged) {
2230 fireOnIsRttChanged(mRttCall != null, mRttCall);
2231 }
2232 if (rttModeChanged) {
2233 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2234 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002235
2236 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2237 // remove ourselves from the Phone. Note that we do this after completing all state updates
2238 // so a client can cleanly transition all their UI to the state appropriate for a
2239 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2240 if (mState == STATE_DISCONNECTED) {
2241 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002242 }
2243 }
2244
2245 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002246 final void internalSetPostDialWait(String remaining) {
2247 mRemainingPostDialSequence = remaining;
2248 firePostDialWait(mRemainingPostDialSequence);
2249 }
2250
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002251 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002252 final void internalSetDisconnected() {
2253 if (mState != Call.STATE_DISCONNECTED) {
2254 mState = Call.STATE_DISCONNECTED;
2255 fireStateChanged(mState);
2256 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002257 }
2258 }
2259
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002260 /** {@hide} */
2261 final void internalOnConnectionEvent(String event, Bundle extras) {
2262 fireOnConnectionEvent(event, extras);
2263 }
2264
Hall Liu95d55872017-01-25 17:12:49 -08002265 /** {@hide} */
2266 final void internalOnRttUpgradeRequest(final int requestId) {
2267 for (CallbackRecord<Callback> record : mCallbackRecords) {
2268 final Call call = this;
2269 final Callback callback = record.getCallback();
2270 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2271 }
2272 }
2273
Hall Liu57006aa2017-02-06 10:49:48 -08002274 /** @hide */
2275 final void internalOnRttInitiationFailure(int reason) {
2276 for (CallbackRecord<Callback> record : mCallbackRecords) {
2277 final Call call = this;
2278 final Callback callback = record.getCallback();
2279 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2280 }
2281 }
2282
Sanket Padawe85291f62017-12-01 13:59:27 -08002283 /** {@hide} */
2284 final void internalOnHandoverFailed(int error) {
2285 for (CallbackRecord<Callback> record : mCallbackRecords) {
2286 final Call call = this;
2287 final Callback callback = record.getCallback();
2288 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2289 }
2290 }
2291
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002292 /** {@hide} */
2293 final void internalOnHandoverComplete() {
2294 for (CallbackRecord<Callback> record : mCallbackRecords) {
2295 final Call call = this;
2296 final Callback callback = record.getCallback();
2297 record.getHandler().post(() -> callback.onHandoverComplete(call));
2298 }
2299 }
2300
Andrew Lee011728f2015-04-23 15:47:06 -07002301 private void fireStateChanged(final int newState) {
2302 for (CallbackRecord<Callback> record : mCallbackRecords) {
2303 final Call call = this;
2304 final Callback callback = record.getCallback();
2305 record.getHandler().post(new Runnable() {
2306 @Override
2307 public void run() {
2308 callback.onStateChanged(call, newState);
2309 }
2310 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002311 }
2312 }
2313
Andrew Lee011728f2015-04-23 15:47:06 -07002314 private void fireParentChanged(final Call newParent) {
2315 for (CallbackRecord<Callback> record : mCallbackRecords) {
2316 final Call call = this;
2317 final Callback callback = record.getCallback();
2318 record.getHandler().post(new Runnable() {
2319 @Override
2320 public void run() {
2321 callback.onParentChanged(call, newParent);
2322 }
2323 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002324 }
2325 }
2326
Andrew Lee011728f2015-04-23 15:47:06 -07002327 private void fireChildrenChanged(final List<Call> children) {
2328 for (CallbackRecord<Callback> record : mCallbackRecords) {
2329 final Call call = this;
2330 final Callback callback = record.getCallback();
2331 record.getHandler().post(new Runnable() {
2332 @Override
2333 public void run() {
2334 callback.onChildrenChanged(call, children);
2335 }
2336 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002337 }
2338 }
2339
Andrew Lee011728f2015-04-23 15:47:06 -07002340 private void fireDetailsChanged(final Details details) {
2341 for (CallbackRecord<Callback> record : mCallbackRecords) {
2342 final Call call = this;
2343 final Callback callback = record.getCallback();
2344 record.getHandler().post(new Runnable() {
2345 @Override
2346 public void run() {
2347 callback.onDetailsChanged(call, details);
2348 }
2349 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002350 }
2351 }
2352
Andrew Lee011728f2015-04-23 15:47:06 -07002353 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2354 for (CallbackRecord<Callback> record : mCallbackRecords) {
2355 final Call call = this;
2356 final Callback callback = record.getCallback();
2357 record.getHandler().post(new Runnable() {
2358 @Override
2359 public void run() {
2360 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2361 }
2362 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002363 }
2364 }
2365
Andrew Lee011728f2015-04-23 15:47:06 -07002366 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2367 for (CallbackRecord<Callback> record : mCallbackRecords) {
2368 final Call call = this;
2369 final Callback callback = record.getCallback();
2370 record.getHandler().post(new Runnable() {
2371 @Override
2372 public void run() {
2373 callback.onVideoCallChanged(call, videoCall);
2374 }
2375 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002376 }
2377 }
2378
Andrew Lee011728f2015-04-23 15:47:06 -07002379 private void firePostDialWait(final String remainingPostDialSequence) {
2380 for (CallbackRecord<Callback> record : mCallbackRecords) {
2381 final Call call = this;
2382 final Callback callback = record.getCallback();
2383 record.getHandler().post(new Runnable() {
2384 @Override
2385 public void run() {
2386 callback.onPostDialWait(call, remainingPostDialSequence);
2387 }
2388 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002389 }
2390 }
2391
2392 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002393 /**
2394 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2395 * onCallRemoved callback, we remove this call from the Phone's record
2396 * only once all of the registered onCallDestroyed callbacks are executed.
2397 * All the callbacks get removed from our records as a part of this operation
2398 * since onCallDestroyed is the final callback.
2399 */
2400 final Call call = this;
2401 if (mCallbackRecords.isEmpty()) {
2402 // No callbacks registered, remove the call from Phone's record.
2403 mPhone.internalRemoveCall(call);
2404 }
2405 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002406 final Callback callback = record.getCallback();
2407 record.getHandler().post(new Runnable() {
2408 @Override
2409 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002410 boolean isFinalRemoval = false;
2411 RuntimeException toThrow = null;
2412 try {
2413 callback.onCallDestroyed(call);
2414 } catch (RuntimeException e) {
2415 toThrow = e;
2416 }
2417 synchronized(Call.this) {
2418 mCallbackRecords.remove(record);
2419 if (mCallbackRecords.isEmpty()) {
2420 isFinalRemoval = true;
2421 }
2422 }
2423 if (isFinalRemoval) {
2424 mPhone.internalRemoveCall(call);
2425 }
2426 if (toThrow != null) {
2427 throw toThrow;
2428 }
Andrew Lee011728f2015-04-23 15:47:06 -07002429 }
2430 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002431 }
2432 }
2433
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002434 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002435 for (CallbackRecord<Callback> record : mCallbackRecords) {
2436 final Call call = this;
2437 final Callback callback = record.getCallback();
2438 record.getHandler().post(new Runnable() {
2439 @Override
2440 public void run() {
2441 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2442 }
2443 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002444 }
2445 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002446
2447 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002448 * Notifies listeners of an incoming connection event.
2449 * <p>
2450 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2451 *
2452 * @param event
2453 * @param extras
2454 */
2455 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2456 for (CallbackRecord<Callback> record : mCallbackRecords) {
2457 final Call call = this;
2458 final Callback callback = record.getCallback();
2459 record.getHandler().post(new Runnable() {
2460 @Override
2461 public void run() {
2462 callback.onConnectionEvent(call, event, extras);
2463 }
2464 });
2465 }
2466 }
2467
2468 /**
Hall Liu95d55872017-01-25 17:12:49 -08002469 * Notifies listeners of an RTT on/off change
2470 *
2471 * @param enabled True if RTT is now enabled, false otherwise
2472 */
2473 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2474 for (CallbackRecord<Callback> record : mCallbackRecords) {
2475 final Call call = this;
2476 final Callback callback = record.getCallback();
2477 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2478 }
2479 }
2480
2481 /**
2482 * Notifies listeners of a RTT mode change
2483 *
2484 * @param mode The new RTT mode
2485 */
2486 private void fireOnRttModeChanged(final int mode) {
2487 for (CallbackRecord<Callback> record : mCallbackRecords) {
2488 final Call call = this;
2489 final Callback callback = record.getCallback();
2490 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2491 }
2492 }
2493
2494 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002495 * Determines if two bundles are equal.
2496 *
2497 * @param bundle The original bundle.
2498 * @param newBundle The bundle to compare with.
2499 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2500 */
2501 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2502 if (bundle == null || newBundle == null) {
2503 return bundle == newBundle;
2504 }
2505
2506 if (bundle.size() != newBundle.size()) {
2507 return false;
2508 }
2509
2510 for(String key : bundle.keySet()) {
2511 if (key != null) {
2512 final Object value = bundle.get(key);
2513 final Object newValue = newBundle.get(key);
2514 if (!Objects.equals(value, newValue)) {
2515 return false;
2516 }
2517 }
2518 }
2519 return true;
2520 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002521}