blob: afb7d93946790b1ae2266902e5b45d9e269b8ea2 [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
Andrew Leeda80c872015-04-15 14:09:50 -070019import android.annotation.SystemApi;
Ihab Awade63fadb2014-07-09 21:52:04 -070020import android.net.Uri;
Nancy Chen10798dc2014-08-08 14:00:25 -070021import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070022import android.os.Handler;
Ihab Awade63fadb2014-07-09 21:52:04 -070023
Andrew Lee50aca232014-07-22 16:41:54 -070024import java.lang.String;
Ihab Awade63fadb2014-07-09 21:52:04 -070025import java.util.ArrayList;
26import java.util.Collections;
27import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070028import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070029import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070030import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070031
32/**
33 * Represents an ongoing phone call that the in-call app should present to the user.
34 */
35public final class Call {
36 /**
37 * The state of a {@code Call} when newly created.
38 */
39 public static final int STATE_NEW = 0;
40
41 /**
42 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
43 */
44 public static final int STATE_DIALING = 1;
45
46 /**
47 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
48 */
49 public static final int STATE_RINGING = 2;
50
51 /**
52 * The state of a {@code Call} when in a holding state.
53 */
54 public static final int STATE_HOLDING = 3;
55
56 /**
57 * The state of a {@code Call} when actively supporting conversation.
58 */
59 public static final int STATE_ACTIVE = 4;
60
61 /**
62 * The state of a {@code Call} when no further voice or other communication is being
63 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
64 * is no longer active, and the local data transport has or inevitably will release resources
65 * associated with this {@code Call}.
66 */
67 public static final int STATE_DISCONNECTED = 7;
68
Nancy Chen5da0fd52014-07-08 14:16:17 -070069 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070070 * The state of an outgoing {@code Call} when waiting on user to select a
71 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070072 */
Santos Cordone3c507b2015-04-23 14:44:19 -070073 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
74
75 /**
76 * @hide
77 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
78 */
79 @Deprecated
80 @SystemApi
81 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070082
Nancy Chene20930f2014-08-07 16:17:21 -070083 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070084 * The initial state of an outgoing {@code Call}.
85 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
86 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070087 */
88 public static final int STATE_CONNECTING = 9;
89
Nancy Chen513c8922014-09-17 14:47:20 -070090 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -070091 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
92 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
93 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
94 */
95 public static final int STATE_DISCONNECTING = 10;
96
97 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -070098 * The state of an external call which is in the process of being pulled from a remote device to
99 * the local device.
100 * <p>
101 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
102 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
103 * <p>
104 * An {@link InCallService} will only see this state if it has the
105 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
106 * manifest.
107 */
108 public static final int STATE_PULLING_CALL = 11;
109
110 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700111 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
112 * extras. Used to pass the phone accounts to display on the front end to the user in order to
113 * select phone accounts to (for example) place a call.
Nancy Chen513c8922014-09-17 14:47:20 -0700114 */
115 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
116
Ihab Awade63fadb2014-07-09 21:52:04 -0700117 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800118
119 /** Call can currently be put on hold or unheld. */
120 public static final int CAPABILITY_HOLD = 0x00000001;
121
122 /** Call supports the hold feature. */
123 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
124
125 /**
126 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
127 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
128 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
129 * capability allows a merge button to be shown while the conference call is in the foreground
130 * of the in-call UI.
131 * <p>
132 * This is only intended for use by a {@link Conference}.
133 */
134 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
135
136 /**
137 * Calls within a conference can be swapped between foreground and background.
138 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
139 * <p>
140 * This is only intended for use by a {@link Conference}.
141 */
142 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
143
144 /**
145 * @hide
146 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700147 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800148
149 /** Call supports responding via text option. */
150 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
151
152 /** Call can be muted. */
153 public static final int CAPABILITY_MUTE = 0x00000040;
154
155 /**
156 * Call supports conference call management. This capability only applies to {@link Conference}
157 * calls which can have {@link Connection}s as children.
158 */
159 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
160
161 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700162 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800163 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700164 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800165
166 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700167 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800168 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700169 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800170
171 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700172 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800173 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700174 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700175 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800176
177 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700178 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800179 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700180 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
181
182 /**
183 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700184 */
185 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
186
187 /**
188 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700189 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700190 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700191 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800192
193 /**
194 * Call is able to be separated from its parent {@code Conference}, if any.
195 */
196 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
197
198 /**
199 * Call is able to be individually disconnected when in a {@code Conference}.
200 */
201 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
202
203 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500204 * Speed up audio setup for MT call.
205 * @hide
206 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700207 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
208
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700209 /**
210 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700211 * @hide
212 */
213 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
214
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700215 /**
216 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700217 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700218 */
219 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
220
Bryce Lee81901682015-08-28 16:38:02 -0700221 /**
222 * Call sends responses through connection.
223 * @hide
224 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800225 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
226
227 /**
228 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
229 * <p>
230 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
231 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
232 * downgraded from a video call back to a VideoState of
233 * {@link VideoProfile#STATE_AUDIO_ONLY}.
234 * <p>
235 * Intuitively, a call which can be downgraded to audio should also have local and remote
236 * video
237 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
238 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
239 */
240 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700241
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700242 /**
243 * When set for an external call, indicates that this {@code Call} can be pulled from a
244 * remote device to the current device.
245 * <p>
246 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
247 * <p>
248 * An {@link InCallService} will only see calls with this capability if it has the
249 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
250 * in its manifest.
251 * <p>
252 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
253 * {@link Connection#CAPABILITY_IS_EXTERNAL_CALL}.
254 */
255 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
256
Tyler Gunnd11a3152015-03-18 13:09:14 -0700257 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700258 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700259 //******************************************************************************************
260
261 /**
262 * Whether the call is currently a conference.
263 */
264 public static final int PROPERTY_CONFERENCE = 0x00000001;
265
266 /**
267 * Whether the call is a generic conference, where we do not know the precise state of
268 * participants in the conference (eg. on CDMA).
269 */
270 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
271
272 /**
273 * Whether the call is made while the device is in emergency callback mode.
274 */
275 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
276
277 /**
278 * Connection is using WIFI.
279 */
280 public static final int PROPERTY_WIFI = 0x00000008;
281
282 /**
283 * Call is using high definition audio.
284 */
285 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
286
Tony Maka68dcce2015-12-17 09:31:18 +0000287 /**
288 * Whether the call is associated with the work profile.
289 */
290 public static final int PROPERTY_WORK_CALL = 0x00000020;
291
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700292 /**
293 * When set, indicates that this {@code Call} does not actually exist locally for the
294 * {@link ConnectionService}.
295 * <p>
296 * Consider, for example, a scenario where a user has two phones with the same phone number.
297 * When a user places a call on one device, the telephony stack can represent that call on
298 * the other device by adding it to the {@link ConnectionService} with the
299 * {@link Connection#CAPABILITY_IS_EXTERNAL_CALL} capability set.
300 * <p>
301 * An {@link InCallService} will only see calls with this property if it has the
302 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
303 * in its manifest.
304 * <p>
305 * See {@link Connection#CAPABILITY_IS_EXTERNAL_CALL}.
306 */
307 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
308
Andrew Lee2378ea72015-04-29 14:38:11 -0700309 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700310 // Next PROPERTY value: 0x00000100
Tyler Gunnd11a3152015-03-18 13:09:14 -0700311 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800312
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800313 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700314 private final Uri mHandle;
315 private final int mHandlePresentation;
316 private final String mCallerDisplayName;
317 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700318 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700319 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700320 private final int mCallProperties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700321 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700322 private final long mConnectTimeMillis;
323 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700324 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700325 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700326 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700327 private final Bundle mIntentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700328
329 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800330 * Whether the supplied capabilities supports the specified capability.
331 *
332 * @param capabilities A bit field of capabilities.
333 * @param capability The capability to check capabilities for.
334 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800335 */
336 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800337 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800338 }
339
340 /**
341 * Whether the capabilities of this {@code Details} supports the specified capability.
342 *
343 * @param capability The capability to check capabilities for.
344 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800345 */
346 public boolean can(int capability) {
347 return can(mCallCapabilities, capability);
348 }
349
350 /**
351 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
352 *
353 * @param capabilities A capability bit field.
354 * @return A human readable string representation.
355 */
356 public static String capabilitiesToString(int capabilities) {
357 StringBuilder builder = new StringBuilder();
358 builder.append("[Capabilities:");
359 if (can(capabilities, CAPABILITY_HOLD)) {
360 builder.append(" CAPABILITY_HOLD");
361 }
362 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
363 builder.append(" CAPABILITY_SUPPORT_HOLD");
364 }
365 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
366 builder.append(" CAPABILITY_MERGE_CONFERENCE");
367 }
368 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
369 builder.append(" CAPABILITY_SWAP_CONFERENCE");
370 }
371 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
372 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
373 }
374 if (can(capabilities, CAPABILITY_MUTE)) {
375 builder.append(" CAPABILITY_MUTE");
376 }
377 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
378 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
379 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700380 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
381 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
382 }
383 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
384 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
385 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700386 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
387 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800388 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700389 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
390 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
391 }
392 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
393 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
394 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800395 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
396 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
397 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700398 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
399 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800400 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500401 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700402 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500403 }
Rekha Kumar07366812015-03-24 16:42:31 -0700404 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
405 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
406 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700407 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
408 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
409 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700410 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
411 builder.append(" CAPABILITY_CAN_PULL_CALL");
412 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800413 builder.append("]");
414 return builder.toString();
415 }
416
417 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700418 * Whether the supplied properties includes the specified property.
419 *
420 * @param properties A bit field of properties.
421 * @param property The property to check properties for.
422 * @return Whether the specified property is supported.
423 */
424 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800425 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700426 }
427
428 /**
429 * Whether the properties of this {@code Details} includes the specified property.
430 *
431 * @param property The property to check properties for.
432 * @return Whether the specified property is supported.
433 */
434 public boolean hasProperty(int property) {
435 return hasProperty(mCallProperties, property);
436 }
437
438 /**
439 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
440 *
441 * @param properties A property bit field.
442 * @return A human readable string representation.
443 */
444 public static String propertiesToString(int properties) {
445 StringBuilder builder = new StringBuilder();
446 builder.append("[Properties:");
447 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
448 builder.append(" PROPERTY_CONFERENCE");
449 }
450 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
451 builder.append(" PROPERTY_GENERIC_CONFERENCE");
452 }
453 if (hasProperty(properties, PROPERTY_WIFI)) {
454 builder.append(" PROPERTY_WIFI");
455 }
456 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
457 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
458 }
459 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700460 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700461 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700462 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
463 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
464 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700465 builder.append("]");
466 return builder.toString();
467 }
468
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800469 /** {@hide} */
470 public String getTelecomCallId() {
471 return mTelecomCallId;
472 }
473
Andrew Lee2378ea72015-04-29 14:38:11 -0700474 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700475 * @return The handle (e.g., phone number) to which the {@code Call} is currently
476 * connected.
477 */
478 public Uri getHandle() {
479 return mHandle;
480 }
481
482 /**
483 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700484 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700485 */
486 public int getHandlePresentation() {
487 return mHandlePresentation;
488 }
489
490 /**
491 * @return The display name for the caller.
492 */
493 public String getCallerDisplayName() {
494 return mCallerDisplayName;
495 }
496
497 /**
498 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700499 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700500 */
501 public int getCallerDisplayNamePresentation() {
502 return mCallerDisplayNamePresentation;
503 }
504
505 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700506 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
507 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700508 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700509 public PhoneAccountHandle getAccountHandle() {
510 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700511 }
512
513 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800514 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
515 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700516 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700517 public int getCallCapabilities() {
518 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700519 }
520
521 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700522 * @return A bitmask of the properties of the {@code Call}, as defined by the various
523 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700524 */
525 public int getCallProperties() {
526 return mCallProperties;
527 }
528
529 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700530 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700531 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700532 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700533 public DisconnectCause getDisconnectCause() {
534 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700535 }
536
537 /**
538 * @return The time the {@code Call} has been connected. This information is updated
539 * periodically, but user interfaces should not rely on this to display any "call time
540 * clock".
541 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700542 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700543 return mConnectTimeMillis;
544 }
545
546 /**
547 * @return Information about any calling gateway the {@code Call} may be using.
548 */
549 public GatewayInfo getGatewayInfo() {
550 return mGatewayInfo;
551 }
552
Andrew Lee7a341382014-07-15 17:05:08 -0700553 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700554 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700555 */
556 public int getVideoState() {
557 return mVideoState;
558 }
559
Ihab Awad5d0410f2014-07-30 10:07:40 -0700560 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700561 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700562 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700563 */
564 public StatusHints getStatusHints() {
565 return mStatusHints;
566 }
567
Nancy Chen10798dc2014-08-08 14:00:25 -0700568 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700569 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700570 */
571 public Bundle getExtras() {
572 return mExtras;
573 }
574
Santos Cordon6b7f9552015-05-27 17:21:45 -0700575 /**
576 * @return The extras used with the original intent to place this call.
577 */
578 public Bundle getIntentExtras() {
579 return mIntentExtras;
580 }
581
Ihab Awade63fadb2014-07-09 21:52:04 -0700582 @Override
583 public boolean equals(Object o) {
584 if (o instanceof Details) {
585 Details d = (Details) o;
586 return
587 Objects.equals(mHandle, d.mHandle) &&
588 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
589 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
590 Objects.equals(mCallerDisplayNamePresentation,
591 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700592 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700593 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700594 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700595 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700596 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700597 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700598 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700599 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700600 areBundlesEqual(mExtras, d.mExtras) &&
601 areBundlesEqual(mIntentExtras, d.mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700602 }
603 return false;
604 }
605
606 @Override
607 public int hashCode() {
608 return
609 Objects.hashCode(mHandle) +
610 Objects.hashCode(mHandlePresentation) +
611 Objects.hashCode(mCallerDisplayName) +
612 Objects.hashCode(mCallerDisplayNamePresentation) +
Evan Charlton8c8a0622014-07-20 12:31:00 -0700613 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700614 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700615 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700616 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700617 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700618 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700619 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700620 Objects.hashCode(mStatusHints) +
Santos Cordon6b7f9552015-05-27 17:21:45 -0700621 Objects.hashCode(mExtras) +
622 Objects.hashCode(mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700623 }
624
625 /** {@hide} */
626 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800627 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700628 Uri handle,
629 int handlePresentation,
630 String callerDisplayName,
631 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700632 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700633 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700634 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700635 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700636 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700637 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700638 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700639 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700640 Bundle extras,
641 Bundle intentExtras) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800642 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700643 mHandle = handle;
644 mHandlePresentation = handlePresentation;
645 mCallerDisplayName = callerDisplayName;
646 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700647 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700648 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700649 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700650 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700651 mConnectTimeMillis = connectTimeMillis;
652 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700653 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700654 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700655 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700656 mIntentExtras = intentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700657 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800658
659 /** {@hide} */
660 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
661 return new Details(
662 parcelableCall.getId(),
663 parcelableCall.getHandle(),
664 parcelableCall.getHandlePresentation(),
665 parcelableCall.getCallerDisplayName(),
666 parcelableCall.getCallerDisplayNamePresentation(),
667 parcelableCall.getAccountHandle(),
668 parcelableCall.getCapabilities(),
669 parcelableCall.getProperties(),
670 parcelableCall.getDisconnectCause(),
671 parcelableCall.getConnectTimeMillis(),
672 parcelableCall.getGatewayInfo(),
673 parcelableCall.getVideoState(),
674 parcelableCall.getStatusHints(),
675 parcelableCall.getExtras(),
676 parcelableCall.getIntentExtras());
677 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800678
679 @Override
680 public String toString() {
681 StringBuilder sb = new StringBuilder();
682 sb.append("[pa: ");
683 sb.append(mAccountHandle);
684 sb.append(", hdl: ");
685 sb.append(Log.pii(mHandle));
686 sb.append(", caps: ");
687 sb.append(capabilitiesToString(mCallCapabilities));
688 sb.append(", props: ");
689 sb.append(mCallProperties);
690 sb.append("]");
691 return sb.toString();
692 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700693 }
694
Andrew Leeda80c872015-04-15 14:09:50 -0700695 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700696 /**
697 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
698 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700699 * @param call The {@code Call} invoking this method.
700 * @param state The new state of the {@code Call}.
701 */
702 public void onStateChanged(Call call, int state) {}
703
704 /**
705 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
706 *
707 * @param call The {@code Call} invoking this method.
708 * @param parent The new parent of the {@code Call}.
709 */
710 public void onParentChanged(Call call, Call parent) {}
711
712 /**
713 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
714 *
715 * @param call The {@code Call} invoking this method.
716 * @param children The new children of the {@code Call}.
717 */
718 public void onChildrenChanged(Call call, List<Call> children) {}
719
720 /**
721 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
722 *
723 * @param call The {@code Call} invoking this method.
724 * @param details A {@code Details} object describing the {@code Call}.
725 */
726 public void onDetailsChanged(Call call, Details details) {}
727
728 /**
729 * Invoked when the text messages that can be used as responses to the incoming
730 * {@code Call} are loaded from the relevant database.
731 * See {@link #getCannedTextResponses()}.
732 *
733 * @param call The {@code Call} invoking this method.
734 * @param cannedTextResponses The text messages useable as responses.
735 */
736 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
737
738 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700739 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
740 * character. This causes the post-dial signals to stop pending user confirmation. An
741 * implementation should present this choice to the user and invoke
742 * {@link #postDialContinue(boolean)} when the user makes the choice.
743 *
744 * @param call The {@code Call} invoking this method.
745 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
746 */
747 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
748
749 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700750 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700751 *
752 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700753 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700754 */
Andrew Lee50aca232014-07-22 16:41:54 -0700755 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700756
757 /**
758 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
759 * up their UI for the {@code Call} in response to state transitions. Specifically,
760 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
761 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
762 * clients should wait for this method to be invoked.
763 *
764 * @param call The {@code Call} being destroyed.
765 */
766 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700767
768 /**
769 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
770 * conferenced.
771 *
772 * @param call The {@code Call} being updated.
773 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
774 * conferenced.
775 */
776 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700777
778 /**
779 * Invoked when a call receives an event from its associated {@link Connection}.
780 * <p>
781 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
782 *
783 * @param call The {@code Call} receiving the event.
784 * @param event The event.
785 * @param extras Extras associated with the connection event.
786 */
787 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700788 }
789
Andrew Leeda80c872015-04-15 14:09:50 -0700790 /**
791 * @deprecated Use {@code Call.Callback} instead.
792 * @hide
793 */
794 @Deprecated
795 @SystemApi
796 public static abstract class Listener extends Callback { }
797
Ihab Awade63fadb2014-07-09 21:52:04 -0700798 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700799 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700800 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700801 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -0700802 private final List<Call> mChildren = new ArrayList<>();
803 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -0700804 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700805 private final List<Call> mConferenceableCalls = new ArrayList<>();
806 private final List<Call> mUnmodifiableConferenceableCalls =
807 Collections.unmodifiableList(mConferenceableCalls);
808
Santos Cordon823fd3c2014-08-07 18:35:18 -0700809 private boolean mChildrenCached;
810 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700811 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -0700812 private List<String> mCannedTextResponses = null;
813 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -0800814 private VideoCallImpl mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -0700815 private Details mDetails;
Ihab Awade63fadb2014-07-09 21:52:04 -0700816
817 /**
818 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
819 *
820 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
821 * remaining or this {@code Call} is not in a post-dial state.
822 */
823 public String getRemainingPostDialSequence() {
824 return mRemainingPostDialSequence;
825 }
826
827 /**
828 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700829 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -0700830 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700831 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700832 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700833 }
834
835 /**
836 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
837 *
838 * @param rejectWithMessage Whether to reject with a text message.
839 * @param textMessage An optional text message with which to respond.
840 */
841 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700842 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -0700843 }
844
845 /**
846 * Instructs this {@code Call} to disconnect.
847 */
848 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700849 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700850 }
851
852 /**
853 * Instructs this {@code Call} to go on hold.
854 */
855 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700856 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700857 }
858
859 /**
860 * Instructs this {@link #STATE_HOLDING} call to release from hold.
861 */
862 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700863 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700864 }
865
866 /**
867 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
868 *
869 * Any other currently playing DTMF tone in the specified call is immediately stopped.
870 *
871 * @param digit A character representing the DTMF digit for which to play the tone. This
872 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
873 */
874 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700875 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -0700876 }
877
878 /**
879 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
880 * currently playing.
881 *
882 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
883 * currently playing, this method will do nothing.
884 */
885 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700886 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700887 }
888
889 /**
890 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
891 *
892 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
893 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -0700894 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700895 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700896 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
897 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700898 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -0700899 * {@code Call} will pause playing the tones and notify callbacks via
900 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -0700901 * should display to the user an indication of this state and an affordance to continue
902 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
903 * app should invoke the {@link #postDialContinue(boolean)} method.
904 *
905 * @param proceed Whether or not to continue with the post-dial sequence.
906 */
907 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700908 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -0700909 }
910
911 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700912 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -0700913 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700914 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700915 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
916 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700917
918 }
919
920 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700921 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700922 *
923 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -0700924 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700925 public void conference(Call callToConferenceWith) {
926 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700927 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700928 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700929 }
930
931 /**
932 * Instructs this {@code Call} to split from any conference call with which it may be
933 * connected.
934 */
935 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700936 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700937 }
938
939 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800940 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700941 */
942 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700943 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700944 }
945
946 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800947 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700948 */
949 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700950 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700951 }
952
953 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700954 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
955 * device.
956 * <p>
957 * Calls to this method are ignored if the call does not have the
958 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
959 * <p>
960 * An {@link InCallService} will only see calls which support this method if it has the
961 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
962 * in its manifest.
963 */
964 public void pullExternalCall() {
965 // If this isn't an external call, ignore the request.
966 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
967 return;
968 }
969
970 mInCallAdapter.pullExternalCall(mTelecomCallId);
971 }
972
973 /**
974 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
975 * the {@link ConnectionService}.
976 * <p>
977 * Events are exposed to {@link ConnectionService} implementations via
978 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
979 * <p>
980 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
981 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
982 *
983 * @param event The connection event.
984 * @param extras Bundle containing extra information associated with the event.
985 */
986 public void sendCallEvent(String event, Bundle extras) {
987 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
988 }
989
990 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700991 * Obtains the parent of this {@code Call} in a conference, if any.
992 *
993 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
994 * child of any conference {@code Call}s.
995 */
996 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700997 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700998 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700999 }
1000 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001001 }
1002
1003 /**
1004 * Obtains the children of this conference {@code Call}, if any.
1005 *
1006 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1007 * {@code List} otherwise.
1008 */
1009 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001010 if (!mChildrenCached) {
1011 mChildrenCached = true;
1012 mChildren.clear();
1013
1014 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001015 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001016 if (call == null) {
1017 // At least one child was still not found, so do not save true for "cached"
1018 mChildrenCached = false;
1019 } else {
1020 mChildren.add(call);
1021 }
1022 }
1023 }
1024
Ihab Awade63fadb2014-07-09 21:52:04 -07001025 return mUnmodifiableChildren;
1026 }
1027
1028 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001029 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1030 *
1031 * @return The list of conferenceable {@code Call}s.
1032 */
1033 public List<Call> getConferenceableCalls() {
1034 return mUnmodifiableConferenceableCalls;
1035 }
1036
1037 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001038 * Obtains the state of this {@code Call}.
1039 *
1040 * @return A state value, chosen from the {@code STATE_*} constants.
1041 */
1042 public int getState() {
1043 return mState;
1044 }
1045
1046 /**
1047 * Obtains a list of canned, pre-configured message responses to present to the user as
1048 * ways of rejecting this {@code Call} using via a text message.
1049 *
1050 * @see #reject(boolean, String)
1051 *
1052 * @return A list of canned text message responses.
1053 */
1054 public List<String> getCannedTextResponses() {
1055 return mCannedTextResponses;
1056 }
1057
1058 /**
1059 * Obtains an object that can be used to display video from this {@code Call}.
1060 *
Andrew Lee50aca232014-07-22 16:41:54 -07001061 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001062 */
Andrew Lee50aca232014-07-22 16:41:54 -07001063 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001064 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001065 }
1066
1067 /**
1068 * Obtains an object containing call details.
1069 *
1070 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1071 * result may be {@code null}.
1072 */
1073 public Details getDetails() {
1074 return mDetails;
1075 }
1076
1077 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001078 * Registers a callback to this {@code Call}.
1079 *
1080 * @param callback A {@code Callback}.
1081 */
1082 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001083 registerCallback(callback, new Handler());
1084 }
1085
1086 /**
1087 * Registers a callback to this {@code Call}.
1088 *
1089 * @param callback A {@code Callback}.
1090 * @param handler A handler which command and status changes will be delivered to.
1091 */
1092 public void registerCallback(Callback callback, Handler handler) {
1093 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001094 // Don't allow new callback registration if the call is already being destroyed.
1095 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001096 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1097 }
Andrew Leeda80c872015-04-15 14:09:50 -07001098 }
1099
1100 /**
1101 * Unregisters a callback from this {@code Call}.
1102 *
1103 * @param callback A {@code Callback}.
1104 */
1105 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001106 // Don't allow callback deregistration if the call is already being destroyed.
1107 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001108 for (CallbackRecord<Callback> record : mCallbackRecords) {
1109 if (record.getCallback() == callback) {
1110 mCallbackRecords.remove(record);
1111 break;
1112 }
1113 }
Andrew Leeda80c872015-04-15 14:09:50 -07001114 }
1115 }
1116
Santos Cordon3c20d632016-02-25 16:12:35 -08001117 @Override
1118 public String toString() {
1119 return new StringBuilder().
1120 append("Call [id: ").
1121 append(mTelecomCallId).
1122 append(", state: ").
1123 append(stateToString(mState)).
1124 append(", details: ").
1125 append(mDetails).
1126 append("]").toString();
1127 }
1128
1129 /**
1130 * @param state An integer value of a {@code STATE_*} constant.
1131 * @return A string representation of the value.
1132 */
1133 private static String stateToString(int state) {
1134 switch (state) {
1135 case STATE_NEW:
1136 return "NEW";
1137 case STATE_RINGING:
1138 return "RINGING";
1139 case STATE_DIALING:
1140 return "DIALING";
1141 case STATE_ACTIVE:
1142 return "ACTIVE";
1143 case STATE_HOLDING:
1144 return "HOLDING";
1145 case STATE_DISCONNECTED:
1146 return "DISCONNECTED";
1147 case STATE_CONNECTING:
1148 return "CONNECTING";
1149 case STATE_DISCONNECTING:
1150 return "DISCONNECTING";
1151 case STATE_SELECT_PHONE_ACCOUNT:
1152 return "SELECT_PHONE_ACCOUNT";
1153 default:
1154 Log.w(Call.class, "Unknown state %d", state);
1155 return "UNKNOWN";
1156 }
1157 }
1158
Andrew Leeda80c872015-04-15 14:09:50 -07001159 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001160 * Adds a listener to this {@code Call}.
1161 *
1162 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001163 * @deprecated Use {@link #registerCallback} instead.
1164 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001165 */
Andrew Leeda80c872015-04-15 14:09:50 -07001166 @Deprecated
1167 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001168 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001169 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001170 }
1171
1172 /**
1173 * Removes a listener from this {@code Call}.
1174 *
1175 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001176 * @deprecated Use {@link #unregisterCallback} instead.
1177 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001178 */
Andrew Leeda80c872015-04-15 14:09:50 -07001179 @Deprecated
1180 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001181 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001182 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001183 }
1184
1185 /** {@hide} */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001186 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001187 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001188 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001189 mInCallAdapter = inCallAdapter;
1190 mState = STATE_NEW;
1191 }
1192
1193 /** {@hide} */
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001194 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state) {
1195 mPhone = phone;
1196 mTelecomCallId = telecomCallId;
1197 mInCallAdapter = inCallAdapter;
1198 mState = state;
1199 }
1200
1201 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001202 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001203 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001204 }
1205
1206 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001207 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001208 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001209 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001210 boolean detailsChanged = !Objects.equals(mDetails, details);
1211 if (detailsChanged) {
1212 mDetails = details;
1213 }
1214
1215 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001216 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1217 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1218 mCannedTextResponses =
1219 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001220 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001221 }
1222
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001223 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl();
Tyler Gunn75958422015-04-15 14:23:42 -07001224 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001225 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001226 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001227 mVideoCallImpl = newVideoCallImpl;
1228 }
1229 if (mVideoCallImpl != null) {
1230 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001231 }
1232
Santos Cordone3c507b2015-04-23 14:44:19 -07001233 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001234 boolean stateChanged = mState != state;
1235 if (stateChanged) {
1236 mState = state;
1237 }
1238
Santos Cordon823fd3c2014-08-07 18:35:18 -07001239 String parentId = parcelableCall.getParentCallId();
1240 boolean parentChanged = !Objects.equals(mParentId, parentId);
1241 if (parentChanged) {
1242 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001243 }
1244
Santos Cordon823fd3c2014-08-07 18:35:18 -07001245 List<String> childCallIds = parcelableCall.getChildCallIds();
1246 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1247 if (childrenChanged) {
1248 mChildrenIds.clear();
1249 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1250 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001251 }
1252
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001253 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1254 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1255 for (String otherId : conferenceableCallIds) {
1256 if (callIdMap.containsKey(otherId)) {
1257 conferenceableCalls.add(callIdMap.get(otherId));
1258 }
1259 }
1260
1261 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1262 mConferenceableCalls.clear();
1263 mConferenceableCalls.addAll(conferenceableCalls);
1264 fireConferenceableCallsChanged();
1265 }
1266
Ihab Awade63fadb2014-07-09 21:52:04 -07001267 // Now we fire updates, ensuring that any client who listens to any of these notifications
1268 // gets the most up-to-date state.
1269
1270 if (stateChanged) {
1271 fireStateChanged(mState);
1272 }
1273 if (detailsChanged) {
1274 fireDetailsChanged(mDetails);
1275 }
1276 if (cannedTextResponsesChanged) {
1277 fireCannedTextResponsesLoaded(mCannedTextResponses);
1278 }
Andrew Lee50aca232014-07-22 16:41:54 -07001279 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001280 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001281 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001282 if (parentChanged) {
1283 fireParentChanged(getParent());
1284 }
1285 if (childrenChanged) {
1286 fireChildrenChanged(getChildren());
1287 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001288
1289 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1290 // remove ourselves from the Phone. Note that we do this after completing all state updates
1291 // so a client can cleanly transition all their UI to the state appropriate for a
1292 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1293 if (mState == STATE_DISCONNECTED) {
1294 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001295 }
1296 }
1297
1298 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001299 final void internalSetPostDialWait(String remaining) {
1300 mRemainingPostDialSequence = remaining;
1301 firePostDialWait(mRemainingPostDialSequence);
1302 }
1303
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001304 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001305 final void internalSetDisconnected() {
1306 if (mState != Call.STATE_DISCONNECTED) {
1307 mState = Call.STATE_DISCONNECTED;
1308 fireStateChanged(mState);
1309 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001310 }
1311 }
1312
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001313 /** {@hide} */
1314 final void internalOnConnectionEvent(String event, Bundle extras) {
1315 fireOnConnectionEvent(event, extras);
1316 }
1317
Andrew Lee011728f2015-04-23 15:47:06 -07001318 private void fireStateChanged(final int newState) {
1319 for (CallbackRecord<Callback> record : mCallbackRecords) {
1320 final Call call = this;
1321 final Callback callback = record.getCallback();
1322 record.getHandler().post(new Runnable() {
1323 @Override
1324 public void run() {
1325 callback.onStateChanged(call, newState);
1326 }
1327 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001328 }
1329 }
1330
Andrew Lee011728f2015-04-23 15:47:06 -07001331 private void fireParentChanged(final Call newParent) {
1332 for (CallbackRecord<Callback> record : mCallbackRecords) {
1333 final Call call = this;
1334 final Callback callback = record.getCallback();
1335 record.getHandler().post(new Runnable() {
1336 @Override
1337 public void run() {
1338 callback.onParentChanged(call, newParent);
1339 }
1340 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001341 }
1342 }
1343
Andrew Lee011728f2015-04-23 15:47:06 -07001344 private void fireChildrenChanged(final List<Call> children) {
1345 for (CallbackRecord<Callback> record : mCallbackRecords) {
1346 final Call call = this;
1347 final Callback callback = record.getCallback();
1348 record.getHandler().post(new Runnable() {
1349 @Override
1350 public void run() {
1351 callback.onChildrenChanged(call, children);
1352 }
1353 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001354 }
1355 }
1356
Andrew Lee011728f2015-04-23 15:47:06 -07001357 private void fireDetailsChanged(final Details details) {
1358 for (CallbackRecord<Callback> record : mCallbackRecords) {
1359 final Call call = this;
1360 final Callback callback = record.getCallback();
1361 record.getHandler().post(new Runnable() {
1362 @Override
1363 public void run() {
1364 callback.onDetailsChanged(call, details);
1365 }
1366 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001367 }
1368 }
1369
Andrew Lee011728f2015-04-23 15:47:06 -07001370 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1371 for (CallbackRecord<Callback> record : mCallbackRecords) {
1372 final Call call = this;
1373 final Callback callback = record.getCallback();
1374 record.getHandler().post(new Runnable() {
1375 @Override
1376 public void run() {
1377 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1378 }
1379 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001380 }
1381 }
1382
Andrew Lee011728f2015-04-23 15:47:06 -07001383 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1384 for (CallbackRecord<Callback> record : mCallbackRecords) {
1385 final Call call = this;
1386 final Callback callback = record.getCallback();
1387 record.getHandler().post(new Runnable() {
1388 @Override
1389 public void run() {
1390 callback.onVideoCallChanged(call, videoCall);
1391 }
1392 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001393 }
1394 }
1395
Andrew Lee011728f2015-04-23 15:47:06 -07001396 private void firePostDialWait(final String remainingPostDialSequence) {
1397 for (CallbackRecord<Callback> record : mCallbackRecords) {
1398 final Call call = this;
1399 final Callback callback = record.getCallback();
1400 record.getHandler().post(new Runnable() {
1401 @Override
1402 public void run() {
1403 callback.onPostDialWait(call, remainingPostDialSequence);
1404 }
1405 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001406 }
1407 }
1408
1409 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001410 /**
1411 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1412 * onCallRemoved callback, we remove this call from the Phone's record
1413 * only once all of the registered onCallDestroyed callbacks are executed.
1414 * All the callbacks get removed from our records as a part of this operation
1415 * since onCallDestroyed is the final callback.
1416 */
1417 final Call call = this;
1418 if (mCallbackRecords.isEmpty()) {
1419 // No callbacks registered, remove the call from Phone's record.
1420 mPhone.internalRemoveCall(call);
1421 }
1422 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001423 final Callback callback = record.getCallback();
1424 record.getHandler().post(new Runnable() {
1425 @Override
1426 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001427 boolean isFinalRemoval = false;
1428 RuntimeException toThrow = null;
1429 try {
1430 callback.onCallDestroyed(call);
1431 } catch (RuntimeException e) {
1432 toThrow = e;
1433 }
1434 synchronized(Call.this) {
1435 mCallbackRecords.remove(record);
1436 if (mCallbackRecords.isEmpty()) {
1437 isFinalRemoval = true;
1438 }
1439 }
1440 if (isFinalRemoval) {
1441 mPhone.internalRemoveCall(call);
1442 }
1443 if (toThrow != null) {
1444 throw toThrow;
1445 }
Andrew Lee011728f2015-04-23 15:47:06 -07001446 }
1447 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001448 }
1449 }
1450
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001451 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001452 for (CallbackRecord<Callback> record : mCallbackRecords) {
1453 final Call call = this;
1454 final Callback callback = record.getCallback();
1455 record.getHandler().post(new Runnable() {
1456 @Override
1457 public void run() {
1458 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1459 }
1460 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001461 }
1462 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001463
1464 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001465 * Notifies listeners of an incoming connection event.
1466 * <p>
1467 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1468 *
1469 * @param event
1470 * @param extras
1471 */
1472 private void fireOnConnectionEvent(final String event, final Bundle extras) {
1473 for (CallbackRecord<Callback> record : mCallbackRecords) {
1474 final Call call = this;
1475 final Callback callback = record.getCallback();
1476 record.getHandler().post(new Runnable() {
1477 @Override
1478 public void run() {
1479 callback.onConnectionEvent(call, event, extras);
1480 }
1481 });
1482 }
1483 }
1484
1485 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001486 * Determines if two bundles are equal.
1487 *
1488 * @param bundle The original bundle.
1489 * @param newBundle The bundle to compare with.
1490 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1491 */
1492 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1493 if (bundle == null || newBundle == null) {
1494 return bundle == newBundle;
1495 }
1496
1497 if (bundle.size() != newBundle.size()) {
1498 return false;
1499 }
1500
1501 for(String key : bundle.keySet()) {
1502 if (key != null) {
1503 final Object value = bundle.get(key);
1504 final Object newValue = newBundle.get(key);
1505 if (!Objects.equals(value, newValue)) {
1506 return false;
1507 }
1508 }
1509 }
1510 return true;
1511 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001512}