blob: 43f8739f74fdf4f4d78fcb35ad9192020d3133c3 [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.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700107 * @hide
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700108 */
109 public static final int STATE_PULLING_CALL = 11;
110
111 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700112 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
113 * extras. Used to pass the phone accounts to display on the front end to the user in order to
114 * select phone accounts to (for example) place a call.
Nancy Chen513c8922014-09-17 14:47:20 -0700115 */
116 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
117
Ihab Awade63fadb2014-07-09 21:52:04 -0700118 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800119
120 /** Call can currently be put on hold or unheld. */
121 public static final int CAPABILITY_HOLD = 0x00000001;
122
123 /** Call supports the hold feature. */
124 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
125
126 /**
127 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
128 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
129 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
130 * capability allows a merge button to be shown while the conference call is in the foreground
131 * of the in-call UI.
132 * <p>
133 * This is only intended for use by a {@link Conference}.
134 */
135 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
136
137 /**
138 * Calls within a conference can be swapped between foreground and background.
139 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
140 * <p>
141 * This is only intended for use by a {@link Conference}.
142 */
143 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
144
145 /**
146 * @hide
147 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700148 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800149
150 /** Call supports responding via text option. */
151 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
152
153 /** Call can be muted. */
154 public static final int CAPABILITY_MUTE = 0x00000040;
155
156 /**
157 * Call supports conference call management. This capability only applies to {@link Conference}
158 * calls which can have {@link Connection}s as children.
159 */
160 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
161
162 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700163 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800164 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700165 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800166
167 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700168 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800169 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700170 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800171
172 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700173 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800174 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700175 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700176 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800177
178 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700179 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800180 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700181 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
182
183 /**
184 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700185 */
186 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
187
188 /**
189 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700190 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700191 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700192 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800193
194 /**
195 * Call is able to be separated from its parent {@code Conference}, if any.
196 */
197 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
198
199 /**
200 * Call is able to be individually disconnected when in a {@code Conference}.
201 */
202 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
203
204 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500205 * Speed up audio setup for MT call.
206 * @hide
207 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700208 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
209
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700210 /**
211 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700212 * @hide
213 */
214 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
215
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700216 /**
217 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700218 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700219 */
220 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
221
Bryce Lee81901682015-08-28 16:38:02 -0700222 /**
223 * Call sends responses through connection.
224 * @hide
225 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800226 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
227
228 /**
229 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
230 * <p>
231 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
232 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
233 * downgraded from a video call back to a VideoState of
234 * {@link VideoProfile#STATE_AUDIO_ONLY}.
235 * <p>
236 * Intuitively, a call which can be downgraded to audio should also have local and remote
237 * video
238 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
239 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
240 */
241 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700242
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700243 /**
244 * When set for an external call, indicates that this {@code Call} can be pulled from a
245 * remote device to the current device.
246 * <p>
247 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
248 * <p>
249 * An {@link InCallService} will only see calls with this capability if it has the
250 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
251 * in its manifest.
252 * <p>
253 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700254 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700255 * @hide
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700256 */
257 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
258
Tyler Gunnd11a3152015-03-18 13:09:14 -0700259 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700260 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700261 //******************************************************************************************
262
263 /**
264 * Whether the call is currently a conference.
265 */
266 public static final int PROPERTY_CONFERENCE = 0x00000001;
267
268 /**
269 * Whether the call is a generic conference, where we do not know the precise state of
270 * participants in the conference (eg. on CDMA).
271 */
272 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
273
274 /**
275 * Whether the call is made while the device is in emergency callback mode.
276 */
277 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
278
279 /**
280 * Connection is using WIFI.
281 */
282 public static final int PROPERTY_WIFI = 0x00000008;
283
284 /**
285 * Call is using high definition audio.
286 */
287 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
288
Tony Maka68dcce2015-12-17 09:31:18 +0000289 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100290 * @deprecated Use {@link #PROPERTY_ENTERPRISE_CALL} instead.
Tony Maka68dcce2015-12-17 09:31:18 +0000291 */
292 public static final int PROPERTY_WORK_CALL = 0x00000020;
293
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700294 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100295 * Whether the call is associated with the work profile.
296 */
297 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
298
299 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700300 * When set, indicates that this {@code Call} does not actually exist locally for the
301 * {@link ConnectionService}.
302 * <p>
303 * Consider, for example, a scenario where a user has two phones with the same phone number.
304 * When a user places a call on one device, the telephony stack can represent that call on
305 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700306 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700307 * <p>
308 * An {@link InCallService} will only see calls with this property if it has the
309 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
310 * in its manifest.
311 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700312 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700313 * @hide
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700314 */
315 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
316
Andrew Lee2378ea72015-04-29 14:38:11 -0700317 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700318 // Next PROPERTY value: 0x00000100
Tyler Gunnd11a3152015-03-18 13:09:14 -0700319 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800320
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800321 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700322 private final Uri mHandle;
323 private final int mHandlePresentation;
324 private final String mCallerDisplayName;
325 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700326 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700327 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700328 private final int mCallProperties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700329 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700330 private final long mConnectTimeMillis;
331 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700332 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700333 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700334 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700335 private final Bundle mIntentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700336
337 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800338 * Whether the supplied capabilities supports the specified capability.
339 *
340 * @param capabilities A bit field of capabilities.
341 * @param capability The capability to check capabilities for.
342 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800343 */
344 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800345 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800346 }
347
348 /**
349 * Whether the capabilities of this {@code Details} supports the specified capability.
350 *
351 * @param capability The capability to check capabilities for.
352 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800353 */
354 public boolean can(int capability) {
355 return can(mCallCapabilities, capability);
356 }
357
358 /**
359 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
360 *
361 * @param capabilities A capability bit field.
362 * @return A human readable string representation.
363 */
364 public static String capabilitiesToString(int capabilities) {
365 StringBuilder builder = new StringBuilder();
366 builder.append("[Capabilities:");
367 if (can(capabilities, CAPABILITY_HOLD)) {
368 builder.append(" CAPABILITY_HOLD");
369 }
370 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
371 builder.append(" CAPABILITY_SUPPORT_HOLD");
372 }
373 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
374 builder.append(" CAPABILITY_MERGE_CONFERENCE");
375 }
376 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
377 builder.append(" CAPABILITY_SWAP_CONFERENCE");
378 }
379 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
380 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
381 }
382 if (can(capabilities, CAPABILITY_MUTE)) {
383 builder.append(" CAPABILITY_MUTE");
384 }
385 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
386 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
387 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700388 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
389 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
390 }
391 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
392 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
393 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700394 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
395 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800396 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700397 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
398 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
399 }
400 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
401 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
402 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800403 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
404 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
405 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700406 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
407 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800408 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500409 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700410 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500411 }
Rekha Kumar07366812015-03-24 16:42:31 -0700412 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
413 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
414 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700415 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
416 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
417 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700418 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
419 builder.append(" CAPABILITY_CAN_PULL_CALL");
420 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800421 builder.append("]");
422 return builder.toString();
423 }
424
425 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700426 * Whether the supplied properties includes the specified property.
427 *
428 * @param properties A bit field of properties.
429 * @param property The property to check properties for.
430 * @return Whether the specified property is supported.
431 */
432 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800433 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700434 }
435
436 /**
437 * Whether the properties of this {@code Details} includes the specified property.
438 *
439 * @param property The property to check properties for.
440 * @return Whether the specified property is supported.
441 */
442 public boolean hasProperty(int property) {
443 return hasProperty(mCallProperties, property);
444 }
445
446 /**
447 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
448 *
449 * @param properties A property bit field.
450 * @return A human readable string representation.
451 */
452 public static String propertiesToString(int properties) {
453 StringBuilder builder = new StringBuilder();
454 builder.append("[Properties:");
455 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
456 builder.append(" PROPERTY_CONFERENCE");
457 }
458 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
459 builder.append(" PROPERTY_GENERIC_CONFERENCE");
460 }
461 if (hasProperty(properties, PROPERTY_WIFI)) {
462 builder.append(" PROPERTY_WIFI");
463 }
464 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
465 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
466 }
467 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700468 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700469 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700470 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
471 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
472 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700473 builder.append("]");
474 return builder.toString();
475 }
476
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800477 /** {@hide} */
478 public String getTelecomCallId() {
479 return mTelecomCallId;
480 }
481
Andrew Lee2378ea72015-04-29 14:38:11 -0700482 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700483 * @return The handle (e.g., phone number) to which the {@code Call} is currently
484 * connected.
485 */
486 public Uri getHandle() {
487 return mHandle;
488 }
489
490 /**
491 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700492 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700493 */
494 public int getHandlePresentation() {
495 return mHandlePresentation;
496 }
497
498 /**
499 * @return The display name for the caller.
500 */
501 public String getCallerDisplayName() {
502 return mCallerDisplayName;
503 }
504
505 /**
506 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700507 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700508 */
509 public int getCallerDisplayNamePresentation() {
510 return mCallerDisplayNamePresentation;
511 }
512
513 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700514 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
515 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700516 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700517 public PhoneAccountHandle getAccountHandle() {
518 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700519 }
520
521 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800522 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
523 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700524 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700525 public int getCallCapabilities() {
526 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700527 }
528
529 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700530 * @return A bitmask of the properties of the {@code Call}, as defined by the various
531 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700532 */
533 public int getCallProperties() {
534 return mCallProperties;
535 }
536
537 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700538 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700539 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700540 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700541 public DisconnectCause getDisconnectCause() {
542 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700543 }
544
545 /**
546 * @return The time the {@code Call} has been connected. This information is updated
547 * periodically, but user interfaces should not rely on this to display any "call time
548 * clock".
549 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700550 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700551 return mConnectTimeMillis;
552 }
553
554 /**
555 * @return Information about any calling gateway the {@code Call} may be using.
556 */
557 public GatewayInfo getGatewayInfo() {
558 return mGatewayInfo;
559 }
560
Andrew Lee7a341382014-07-15 17:05:08 -0700561 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700562 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700563 */
564 public int getVideoState() {
565 return mVideoState;
566 }
567
Ihab Awad5d0410f2014-07-30 10:07:40 -0700568 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700569 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700570 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700571 */
572 public StatusHints getStatusHints() {
573 return mStatusHints;
574 }
575
Nancy Chen10798dc2014-08-08 14:00:25 -0700576 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700577 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700578 */
579 public Bundle getExtras() {
580 return mExtras;
581 }
582
Santos Cordon6b7f9552015-05-27 17:21:45 -0700583 /**
584 * @return The extras used with the original intent to place this call.
585 */
586 public Bundle getIntentExtras() {
587 return mIntentExtras;
588 }
589
Ihab Awade63fadb2014-07-09 21:52:04 -0700590 @Override
591 public boolean equals(Object o) {
592 if (o instanceof Details) {
593 Details d = (Details) o;
594 return
595 Objects.equals(mHandle, d.mHandle) &&
596 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
597 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
598 Objects.equals(mCallerDisplayNamePresentation,
599 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700600 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700601 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700602 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700603 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700604 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700605 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700606 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700607 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700608 areBundlesEqual(mExtras, d.mExtras) &&
609 areBundlesEqual(mIntentExtras, d.mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700610 }
611 return false;
612 }
613
614 @Override
615 public int hashCode() {
616 return
617 Objects.hashCode(mHandle) +
618 Objects.hashCode(mHandlePresentation) +
619 Objects.hashCode(mCallerDisplayName) +
620 Objects.hashCode(mCallerDisplayNamePresentation) +
Evan Charlton8c8a0622014-07-20 12:31:00 -0700621 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700622 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700623 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700624 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700625 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700626 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700627 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700628 Objects.hashCode(mStatusHints) +
Santos Cordon6b7f9552015-05-27 17:21:45 -0700629 Objects.hashCode(mExtras) +
630 Objects.hashCode(mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700631 }
632
633 /** {@hide} */
634 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800635 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700636 Uri handle,
637 int handlePresentation,
638 String callerDisplayName,
639 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700640 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700641 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700642 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700643 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700644 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700645 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700646 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700647 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700648 Bundle extras,
649 Bundle intentExtras) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800650 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700651 mHandle = handle;
652 mHandlePresentation = handlePresentation;
653 mCallerDisplayName = callerDisplayName;
654 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700655 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700656 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700657 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700658 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700659 mConnectTimeMillis = connectTimeMillis;
660 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700661 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700662 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700663 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700664 mIntentExtras = intentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700665 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800666
667 /** {@hide} */
668 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
669 return new Details(
670 parcelableCall.getId(),
671 parcelableCall.getHandle(),
672 parcelableCall.getHandlePresentation(),
673 parcelableCall.getCallerDisplayName(),
674 parcelableCall.getCallerDisplayNamePresentation(),
675 parcelableCall.getAccountHandle(),
676 parcelableCall.getCapabilities(),
677 parcelableCall.getProperties(),
678 parcelableCall.getDisconnectCause(),
679 parcelableCall.getConnectTimeMillis(),
680 parcelableCall.getGatewayInfo(),
681 parcelableCall.getVideoState(),
682 parcelableCall.getStatusHints(),
683 parcelableCall.getExtras(),
684 parcelableCall.getIntentExtras());
685 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800686
687 @Override
688 public String toString() {
689 StringBuilder sb = new StringBuilder();
690 sb.append("[pa: ");
691 sb.append(mAccountHandle);
692 sb.append(", hdl: ");
693 sb.append(Log.pii(mHandle));
694 sb.append(", caps: ");
695 sb.append(capabilitiesToString(mCallCapabilities));
696 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700697 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800698 sb.append("]");
699 return sb.toString();
700 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700701 }
702
Andrew Leeda80c872015-04-15 14:09:50 -0700703 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700704 /**
705 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
706 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700707 * @param call The {@code Call} invoking this method.
708 * @param state The new state of the {@code Call}.
709 */
710 public void onStateChanged(Call call, int state) {}
711
712 /**
713 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
714 *
715 * @param call The {@code Call} invoking this method.
716 * @param parent The new parent of the {@code Call}.
717 */
718 public void onParentChanged(Call call, Call parent) {}
719
720 /**
721 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
722 *
723 * @param call The {@code Call} invoking this method.
724 * @param children The new children of the {@code Call}.
725 */
726 public void onChildrenChanged(Call call, List<Call> children) {}
727
728 /**
729 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
730 *
731 * @param call The {@code Call} invoking this method.
732 * @param details A {@code Details} object describing the {@code Call}.
733 */
734 public void onDetailsChanged(Call call, Details details) {}
735
736 /**
737 * Invoked when the text messages that can be used as responses to the incoming
738 * {@code Call} are loaded from the relevant database.
739 * See {@link #getCannedTextResponses()}.
740 *
741 * @param call The {@code Call} invoking this method.
742 * @param cannedTextResponses The text messages useable as responses.
743 */
744 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
745
746 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700747 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
748 * character. This causes the post-dial signals to stop pending user confirmation. An
749 * implementation should present this choice to the user and invoke
750 * {@link #postDialContinue(boolean)} when the user makes the choice.
751 *
752 * @param call The {@code Call} invoking this method.
753 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
754 */
755 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
756
757 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700758 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700759 *
760 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700761 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700762 */
Andrew Lee50aca232014-07-22 16:41:54 -0700763 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700764
765 /**
766 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
767 * up their UI for the {@code Call} in response to state transitions. Specifically,
768 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
769 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
770 * clients should wait for this method to be invoked.
771 *
772 * @param call The {@code Call} being destroyed.
773 */
774 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700775
776 /**
777 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
778 * conferenced.
779 *
780 * @param call The {@code Call} being updated.
781 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
782 * conferenced.
783 */
784 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700785
786 /**
787 * Invoked when a call receives an event from its associated {@link Connection}.
788 * <p>
789 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
790 *
791 * @param call The {@code Call} receiving the event.
792 * @param event The event.
793 * @param extras Extras associated with the connection event.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700794 * @hide
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700795 */
796 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700797 }
798
Andrew Leeda80c872015-04-15 14:09:50 -0700799 /**
800 * @deprecated Use {@code Call.Callback} instead.
801 * @hide
802 */
803 @Deprecated
804 @SystemApi
805 public static abstract class Listener extends Callback { }
806
Ihab Awade63fadb2014-07-09 21:52:04 -0700807 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700808 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700809 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700810 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -0700811 private final List<Call> mChildren = new ArrayList<>();
812 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -0700813 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700814 private final List<Call> mConferenceableCalls = new ArrayList<>();
815 private final List<Call> mUnmodifiableConferenceableCalls =
816 Collections.unmodifiableList(mConferenceableCalls);
817
Santos Cordon823fd3c2014-08-07 18:35:18 -0700818 private boolean mChildrenCached;
819 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700820 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -0700821 private List<String> mCannedTextResponses = null;
822 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -0800823 private VideoCallImpl mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -0700824 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -0700825 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700826
827 /**
828 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
829 *
830 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
831 * remaining or this {@code Call} is not in a post-dial state.
832 */
833 public String getRemainingPostDialSequence() {
834 return mRemainingPostDialSequence;
835 }
836
837 /**
838 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700839 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -0700840 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700841 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700842 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700843 }
844
845 /**
846 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
847 *
848 * @param rejectWithMessage Whether to reject with a text message.
849 * @param textMessage An optional text message with which to respond.
850 */
851 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700852 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -0700853 }
854
855 /**
856 * Instructs this {@code Call} to disconnect.
857 */
858 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700859 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700860 }
861
862 /**
863 * Instructs this {@code Call} to go on hold.
864 */
865 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700866 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700867 }
868
869 /**
870 * Instructs this {@link #STATE_HOLDING} call to release from hold.
871 */
872 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700873 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700874 }
875
876 /**
877 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
878 *
879 * Any other currently playing DTMF tone in the specified call is immediately stopped.
880 *
881 * @param digit A character representing the DTMF digit for which to play the tone. This
882 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
883 */
884 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700885 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -0700886 }
887
888 /**
889 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
890 * currently playing.
891 *
892 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
893 * currently playing, this method will do nothing.
894 */
895 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700896 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700897 }
898
899 /**
900 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
901 *
902 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
903 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -0700904 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700905 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700906 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
907 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700908 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -0700909 * {@code Call} will pause playing the tones and notify callbacks via
910 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -0700911 * should display to the user an indication of this state and an affordance to continue
912 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
913 * app should invoke the {@link #postDialContinue(boolean)} method.
914 *
915 * @param proceed Whether or not to continue with the post-dial sequence.
916 */
917 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700918 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -0700919 }
920
921 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700922 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -0700923 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700924 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700925 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
926 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700927
928 }
929
930 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700931 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700932 *
933 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -0700934 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700935 public void conference(Call callToConferenceWith) {
936 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700937 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700938 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700939 }
940
941 /**
942 * Instructs this {@code Call} to split from any conference call with which it may be
943 * connected.
944 */
945 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700946 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700947 }
948
949 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800950 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700951 */
952 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700953 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700954 }
955
956 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800957 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700958 */
959 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700960 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700961 }
962
963 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700964 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
965 * device.
966 * <p>
967 * Calls to this method are ignored if the call does not have the
968 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
969 * <p>
970 * An {@link InCallService} will only see calls which support this method if it has the
971 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
972 * in its manifest.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700973 * @hide
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700974 */
975 public void pullExternalCall() {
976 // If this isn't an external call, ignore the request.
977 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
978 return;
979 }
980
981 mInCallAdapter.pullExternalCall(mTelecomCallId);
982 }
983
984 /**
985 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
986 * the {@link ConnectionService}.
987 * <p>
988 * Events are exposed to {@link ConnectionService} implementations via
989 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
990 * <p>
991 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
992 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
993 *
994 * @param event The connection event.
995 * @param extras Bundle containing extra information associated with the event.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700996 * @hide
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700997 */
998 public void sendCallEvent(String event, Bundle extras) {
999 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1000 }
1001
1002 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001003 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1004 * added.
1005 * <p>
1006 * No assumptions should be made as to how an In-Call UI or service will handle these
1007 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1008 *
1009 * @param extras The extras to add.
Tyler Gunn1bf206b2016-04-15 11:28:44 -07001010 * @hide
Tyler Gunndee56a82016-03-23 16:06:34 -07001011 */
1012 public final void putExtras(Bundle extras) {
1013 if (extras == null) {
1014 return;
1015 }
1016
1017 if (mExtras == null) {
1018 mExtras = new Bundle();
1019 }
1020 mExtras.putAll(extras);
1021 mInCallAdapter.putExtras(mTelecomCallId, extras);
1022 }
1023
1024 /**
1025 * Adds a boolean extra to this {@link Call}.
1026 *
1027 * @param key The extra key.
1028 * @param value The value.
1029 * @hide
1030 */
1031 public final void putExtra(String key, boolean value) {
1032 if (mExtras == null) {
1033 mExtras = new Bundle();
1034 }
1035 mExtras.putBoolean(key, value);
1036 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1037 }
1038
1039 /**
1040 * Adds an integer extra to this {@code Connection}.
1041 *
1042 * @param key The extra key.
1043 * @param value The value.
1044 * @hide
1045 */
1046 public final void putExtra(String key, int value) {
1047 if (mExtras == null) {
1048 mExtras = new Bundle();
1049 }
1050 mExtras.putInt(key, value);
1051 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1052 }
1053
1054 /**
1055 * Adds a string extra to this {@code Connection}.
1056 *
1057 * @param key The extra key.
1058 * @param value The value.
1059 * @hide
1060 */
1061 public final void putExtra(String key, String value) {
1062 if (mExtras == null) {
1063 mExtras = new Bundle();
1064 }
1065 mExtras.putString(key, value);
1066 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1067 }
1068
1069 /**
1070 * Removes extras from this {@code Connection}.
1071 *
1072 * @param keys The keys of the extras to remove.
Tyler Gunn1bf206b2016-04-15 11:28:44 -07001073 * @hide
Tyler Gunndee56a82016-03-23 16:06:34 -07001074 */
1075 public final void removeExtras(List<String> keys) {
1076 if (mExtras != null) {
1077 for (String key : keys) {
1078 mExtras.remove(key);
1079 }
1080 if (mExtras.size() == 0) {
1081 mExtras = null;
1082 }
1083 }
1084 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1085 }
1086
1087 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001088 * Obtains the parent of this {@code Call} in a conference, if any.
1089 *
1090 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1091 * child of any conference {@code Call}s.
1092 */
1093 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001094 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001095 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001096 }
1097 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001098 }
1099
1100 /**
1101 * Obtains the children of this conference {@code Call}, if any.
1102 *
1103 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1104 * {@code List} otherwise.
1105 */
1106 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001107 if (!mChildrenCached) {
1108 mChildrenCached = true;
1109 mChildren.clear();
1110
1111 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001112 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001113 if (call == null) {
1114 // At least one child was still not found, so do not save true for "cached"
1115 mChildrenCached = false;
1116 } else {
1117 mChildren.add(call);
1118 }
1119 }
1120 }
1121
Ihab Awade63fadb2014-07-09 21:52:04 -07001122 return mUnmodifiableChildren;
1123 }
1124
1125 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001126 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1127 *
1128 * @return The list of conferenceable {@code Call}s.
1129 */
1130 public List<Call> getConferenceableCalls() {
1131 return mUnmodifiableConferenceableCalls;
1132 }
1133
1134 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001135 * Obtains the state of this {@code Call}.
1136 *
1137 * @return A state value, chosen from the {@code STATE_*} constants.
1138 */
1139 public int getState() {
1140 return mState;
1141 }
1142
1143 /**
1144 * Obtains a list of canned, pre-configured message responses to present to the user as
1145 * ways of rejecting this {@code Call} using via a text message.
1146 *
1147 * @see #reject(boolean, String)
1148 *
1149 * @return A list of canned text message responses.
1150 */
1151 public List<String> getCannedTextResponses() {
1152 return mCannedTextResponses;
1153 }
1154
1155 /**
1156 * Obtains an object that can be used to display video from this {@code Call}.
1157 *
Andrew Lee50aca232014-07-22 16:41:54 -07001158 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001159 */
Andrew Lee50aca232014-07-22 16:41:54 -07001160 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001161 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001162 }
1163
1164 /**
1165 * Obtains an object containing call details.
1166 *
1167 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1168 * result may be {@code null}.
1169 */
1170 public Details getDetails() {
1171 return mDetails;
1172 }
1173
1174 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001175 * Registers a callback to this {@code Call}.
1176 *
1177 * @param callback A {@code Callback}.
1178 */
1179 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001180 registerCallback(callback, new Handler());
1181 }
1182
1183 /**
1184 * Registers a callback to this {@code Call}.
1185 *
1186 * @param callback A {@code Callback}.
1187 * @param handler A handler which command and status changes will be delivered to.
1188 */
1189 public void registerCallback(Callback callback, Handler handler) {
1190 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001191 // Don't allow new callback registration if the call is already being destroyed.
1192 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001193 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1194 }
Andrew Leeda80c872015-04-15 14:09:50 -07001195 }
1196
1197 /**
1198 * Unregisters a callback from this {@code Call}.
1199 *
1200 * @param callback A {@code Callback}.
1201 */
1202 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001203 // Don't allow callback deregistration if the call is already being destroyed.
1204 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001205 for (CallbackRecord<Callback> record : mCallbackRecords) {
1206 if (record.getCallback() == callback) {
1207 mCallbackRecords.remove(record);
1208 break;
1209 }
1210 }
Andrew Leeda80c872015-04-15 14:09:50 -07001211 }
1212 }
1213
Santos Cordon3c20d632016-02-25 16:12:35 -08001214 @Override
1215 public String toString() {
1216 return new StringBuilder().
1217 append("Call [id: ").
1218 append(mTelecomCallId).
1219 append(", state: ").
1220 append(stateToString(mState)).
1221 append(", details: ").
1222 append(mDetails).
1223 append("]").toString();
1224 }
1225
1226 /**
1227 * @param state An integer value of a {@code STATE_*} constant.
1228 * @return A string representation of the value.
1229 */
1230 private static String stateToString(int state) {
1231 switch (state) {
1232 case STATE_NEW:
1233 return "NEW";
1234 case STATE_RINGING:
1235 return "RINGING";
1236 case STATE_DIALING:
1237 return "DIALING";
1238 case STATE_ACTIVE:
1239 return "ACTIVE";
1240 case STATE_HOLDING:
1241 return "HOLDING";
1242 case STATE_DISCONNECTED:
1243 return "DISCONNECTED";
1244 case STATE_CONNECTING:
1245 return "CONNECTING";
1246 case STATE_DISCONNECTING:
1247 return "DISCONNECTING";
1248 case STATE_SELECT_PHONE_ACCOUNT:
1249 return "SELECT_PHONE_ACCOUNT";
1250 default:
1251 Log.w(Call.class, "Unknown state %d", state);
1252 return "UNKNOWN";
1253 }
1254 }
1255
Andrew Leeda80c872015-04-15 14:09:50 -07001256 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001257 * Adds a listener to this {@code Call}.
1258 *
1259 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001260 * @deprecated Use {@link #registerCallback} instead.
1261 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001262 */
Andrew Leeda80c872015-04-15 14:09:50 -07001263 @Deprecated
1264 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001265 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001266 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001267 }
1268
1269 /**
1270 * Removes a listener from this {@code Call}.
1271 *
1272 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001273 * @deprecated Use {@link #unregisterCallback} instead.
1274 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001275 */
Andrew Leeda80c872015-04-15 14:09:50 -07001276 @Deprecated
1277 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001278 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001279 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001280 }
1281
1282 /** {@hide} */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001283 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001284 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001285 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001286 mInCallAdapter = inCallAdapter;
1287 mState = STATE_NEW;
1288 }
1289
1290 /** {@hide} */
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001291 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state) {
1292 mPhone = phone;
1293 mTelecomCallId = telecomCallId;
1294 mInCallAdapter = inCallAdapter;
1295 mState = state;
1296 }
1297
1298 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001299 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001300 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001301 }
1302
1303 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001304 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001305 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001306 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001307 boolean detailsChanged = !Objects.equals(mDetails, details);
1308 if (detailsChanged) {
1309 mDetails = details;
1310 }
1311
1312 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001313 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1314 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1315 mCannedTextResponses =
1316 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001317 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001318 }
1319
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001320 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl();
Tyler Gunn75958422015-04-15 14:23:42 -07001321 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001322 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001323 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001324 mVideoCallImpl = newVideoCallImpl;
1325 }
1326 if (mVideoCallImpl != null) {
1327 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001328 }
1329
Santos Cordone3c507b2015-04-23 14:44:19 -07001330 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001331 boolean stateChanged = mState != state;
1332 if (stateChanged) {
1333 mState = state;
1334 }
1335
Santos Cordon823fd3c2014-08-07 18:35:18 -07001336 String parentId = parcelableCall.getParentCallId();
1337 boolean parentChanged = !Objects.equals(mParentId, parentId);
1338 if (parentChanged) {
1339 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001340 }
1341
Santos Cordon823fd3c2014-08-07 18:35:18 -07001342 List<String> childCallIds = parcelableCall.getChildCallIds();
1343 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1344 if (childrenChanged) {
1345 mChildrenIds.clear();
1346 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1347 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001348 }
1349
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001350 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1351 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1352 for (String otherId : conferenceableCallIds) {
1353 if (callIdMap.containsKey(otherId)) {
1354 conferenceableCalls.add(callIdMap.get(otherId));
1355 }
1356 }
1357
1358 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1359 mConferenceableCalls.clear();
1360 mConferenceableCalls.addAll(conferenceableCalls);
1361 fireConferenceableCallsChanged();
1362 }
1363
Ihab Awade63fadb2014-07-09 21:52:04 -07001364 // Now we fire updates, ensuring that any client who listens to any of these notifications
1365 // gets the most up-to-date state.
1366
1367 if (stateChanged) {
1368 fireStateChanged(mState);
1369 }
1370 if (detailsChanged) {
1371 fireDetailsChanged(mDetails);
1372 }
1373 if (cannedTextResponsesChanged) {
1374 fireCannedTextResponsesLoaded(mCannedTextResponses);
1375 }
Andrew Lee50aca232014-07-22 16:41:54 -07001376 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001377 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001378 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001379 if (parentChanged) {
1380 fireParentChanged(getParent());
1381 }
1382 if (childrenChanged) {
1383 fireChildrenChanged(getChildren());
1384 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001385
1386 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1387 // remove ourselves from the Phone. Note that we do this after completing all state updates
1388 // so a client can cleanly transition all their UI to the state appropriate for a
1389 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1390 if (mState == STATE_DISCONNECTED) {
1391 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001392 }
1393 }
1394
1395 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001396 final void internalSetPostDialWait(String remaining) {
1397 mRemainingPostDialSequence = remaining;
1398 firePostDialWait(mRemainingPostDialSequence);
1399 }
1400
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001401 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001402 final void internalSetDisconnected() {
1403 if (mState != Call.STATE_DISCONNECTED) {
1404 mState = Call.STATE_DISCONNECTED;
1405 fireStateChanged(mState);
1406 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001407 }
1408 }
1409
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001410 /** {@hide} */
1411 final void internalOnConnectionEvent(String event, Bundle extras) {
1412 fireOnConnectionEvent(event, extras);
1413 }
1414
Andrew Lee011728f2015-04-23 15:47:06 -07001415 private void fireStateChanged(final int newState) {
1416 for (CallbackRecord<Callback> record : mCallbackRecords) {
1417 final Call call = this;
1418 final Callback callback = record.getCallback();
1419 record.getHandler().post(new Runnable() {
1420 @Override
1421 public void run() {
1422 callback.onStateChanged(call, newState);
1423 }
1424 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001425 }
1426 }
1427
Andrew Lee011728f2015-04-23 15:47:06 -07001428 private void fireParentChanged(final Call newParent) {
1429 for (CallbackRecord<Callback> record : mCallbackRecords) {
1430 final Call call = this;
1431 final Callback callback = record.getCallback();
1432 record.getHandler().post(new Runnable() {
1433 @Override
1434 public void run() {
1435 callback.onParentChanged(call, newParent);
1436 }
1437 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001438 }
1439 }
1440
Andrew Lee011728f2015-04-23 15:47:06 -07001441 private void fireChildrenChanged(final List<Call> children) {
1442 for (CallbackRecord<Callback> record : mCallbackRecords) {
1443 final Call call = this;
1444 final Callback callback = record.getCallback();
1445 record.getHandler().post(new Runnable() {
1446 @Override
1447 public void run() {
1448 callback.onChildrenChanged(call, children);
1449 }
1450 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001451 }
1452 }
1453
Andrew Lee011728f2015-04-23 15:47:06 -07001454 private void fireDetailsChanged(final Details details) {
1455 for (CallbackRecord<Callback> record : mCallbackRecords) {
1456 final Call call = this;
1457 final Callback callback = record.getCallback();
1458 record.getHandler().post(new Runnable() {
1459 @Override
1460 public void run() {
1461 callback.onDetailsChanged(call, details);
1462 }
1463 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001464 }
1465 }
1466
Andrew Lee011728f2015-04-23 15:47:06 -07001467 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1468 for (CallbackRecord<Callback> record : mCallbackRecords) {
1469 final Call call = this;
1470 final Callback callback = record.getCallback();
1471 record.getHandler().post(new Runnable() {
1472 @Override
1473 public void run() {
1474 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1475 }
1476 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001477 }
1478 }
1479
Andrew Lee011728f2015-04-23 15:47:06 -07001480 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1481 for (CallbackRecord<Callback> record : mCallbackRecords) {
1482 final Call call = this;
1483 final Callback callback = record.getCallback();
1484 record.getHandler().post(new Runnable() {
1485 @Override
1486 public void run() {
1487 callback.onVideoCallChanged(call, videoCall);
1488 }
1489 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001490 }
1491 }
1492
Andrew Lee011728f2015-04-23 15:47:06 -07001493 private void firePostDialWait(final String remainingPostDialSequence) {
1494 for (CallbackRecord<Callback> record : mCallbackRecords) {
1495 final Call call = this;
1496 final Callback callback = record.getCallback();
1497 record.getHandler().post(new Runnable() {
1498 @Override
1499 public void run() {
1500 callback.onPostDialWait(call, remainingPostDialSequence);
1501 }
1502 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001503 }
1504 }
1505
1506 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001507 /**
1508 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1509 * onCallRemoved callback, we remove this call from the Phone's record
1510 * only once all of the registered onCallDestroyed callbacks are executed.
1511 * All the callbacks get removed from our records as a part of this operation
1512 * since onCallDestroyed is the final callback.
1513 */
1514 final Call call = this;
1515 if (mCallbackRecords.isEmpty()) {
1516 // No callbacks registered, remove the call from Phone's record.
1517 mPhone.internalRemoveCall(call);
1518 }
1519 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001520 final Callback callback = record.getCallback();
1521 record.getHandler().post(new Runnable() {
1522 @Override
1523 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001524 boolean isFinalRemoval = false;
1525 RuntimeException toThrow = null;
1526 try {
1527 callback.onCallDestroyed(call);
1528 } catch (RuntimeException e) {
1529 toThrow = e;
1530 }
1531 synchronized(Call.this) {
1532 mCallbackRecords.remove(record);
1533 if (mCallbackRecords.isEmpty()) {
1534 isFinalRemoval = true;
1535 }
1536 }
1537 if (isFinalRemoval) {
1538 mPhone.internalRemoveCall(call);
1539 }
1540 if (toThrow != null) {
1541 throw toThrow;
1542 }
Andrew Lee011728f2015-04-23 15:47:06 -07001543 }
1544 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001545 }
1546 }
1547
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001548 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001549 for (CallbackRecord<Callback> record : mCallbackRecords) {
1550 final Call call = this;
1551 final Callback callback = record.getCallback();
1552 record.getHandler().post(new Runnable() {
1553 @Override
1554 public void run() {
1555 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1556 }
1557 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001558 }
1559 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001560
1561 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001562 * Notifies listeners of an incoming connection event.
1563 * <p>
1564 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1565 *
1566 * @param event
1567 * @param extras
1568 */
1569 private void fireOnConnectionEvent(final String event, final Bundle extras) {
1570 for (CallbackRecord<Callback> record : mCallbackRecords) {
1571 final Call call = this;
1572 final Callback callback = record.getCallback();
1573 record.getHandler().post(new Runnable() {
1574 @Override
1575 public void run() {
1576 callback.onConnectionEvent(call, event, extras);
1577 }
1578 });
1579 }
1580 }
1581
1582 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001583 * Determines if two bundles are equal.
1584 *
1585 * @param bundle The original bundle.
1586 * @param newBundle The bundle to compare with.
1587 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1588 */
1589 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1590 if (bundle == null || newBundle == null) {
1591 return bundle == newBundle;
1592 }
1593
1594 if (bundle.size() != newBundle.size()) {
1595 return false;
1596 }
1597
1598 for(String key : bundle.keySet()) {
1599 if (key != null) {
1600 final Object value = bundle.get(key);
1601 final Object newValue = newBundle.get(key);
1602 if (!Objects.equals(value, newValue)) {
1603 return false;
1604 }
1605 }
1606 }
1607 return true;
1608 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001609}