blob: b4c6e6aefbce0f29023e76c58979ff3601f341ba [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
Tyler Gunn720c6642016-03-22 09:02:47 -0700253 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700254 */
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
Tyler Gunn720c6642016-03-22 09:02:47 -0700299 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700300 * <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>
Tyler Gunn720c6642016-03-22 09:02:47 -0700305 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700306 */
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: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700689 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800690 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;
Tyler Gunndee56a82016-03-23 16:06:34 -0700816 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700817
818 /**
819 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
820 *
821 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
822 * remaining or this {@code Call} is not in a post-dial state.
823 */
824 public String getRemainingPostDialSequence() {
825 return mRemainingPostDialSequence;
826 }
827
828 /**
829 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700830 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -0700831 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700832 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700833 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700834 }
835
836 /**
837 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
838 *
839 * @param rejectWithMessage Whether to reject with a text message.
840 * @param textMessage An optional text message with which to respond.
841 */
842 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700843 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -0700844 }
845
846 /**
847 * Instructs this {@code Call} to disconnect.
848 */
849 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700850 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700851 }
852
853 /**
854 * Instructs this {@code Call} to go on hold.
855 */
856 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700857 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700858 }
859
860 /**
861 * Instructs this {@link #STATE_HOLDING} call to release from hold.
862 */
863 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700864 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700865 }
866
867 /**
868 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
869 *
870 * Any other currently playing DTMF tone in the specified call is immediately stopped.
871 *
872 * @param digit A character representing the DTMF digit for which to play the tone. This
873 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
874 */
875 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700876 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -0700877 }
878
879 /**
880 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
881 * currently playing.
882 *
883 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
884 * currently playing, this method will do nothing.
885 */
886 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700887 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700888 }
889
890 /**
891 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
892 *
893 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
894 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -0700895 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700896 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700897 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
898 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700899 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -0700900 * {@code Call} will pause playing the tones and notify callbacks via
901 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -0700902 * should display to the user an indication of this state and an affordance to continue
903 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
904 * app should invoke the {@link #postDialContinue(boolean)} method.
905 *
906 * @param proceed Whether or not to continue with the post-dial sequence.
907 */
908 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700909 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -0700910 }
911
912 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700913 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -0700914 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700915 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700916 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
917 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700918
919 }
920
921 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700922 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700923 *
924 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -0700925 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700926 public void conference(Call callToConferenceWith) {
927 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700928 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700929 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700930 }
931
932 /**
933 * Instructs this {@code Call} to split from any conference call with which it may be
934 * connected.
935 */
936 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700937 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700938 }
939
940 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800941 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700942 */
943 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700944 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700945 }
946
947 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800948 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700949 */
950 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700951 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700952 }
953
954 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700955 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
956 * device.
957 * <p>
958 * Calls to this method are ignored if the call does not have the
959 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
960 * <p>
961 * An {@link InCallService} will only see calls which support this method if it has the
962 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
963 * in its manifest.
964 */
965 public void pullExternalCall() {
966 // If this isn't an external call, ignore the request.
967 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
968 return;
969 }
970
971 mInCallAdapter.pullExternalCall(mTelecomCallId);
972 }
973
974 /**
975 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
976 * the {@link ConnectionService}.
977 * <p>
978 * Events are exposed to {@link ConnectionService} implementations via
979 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
980 * <p>
981 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
982 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
983 *
984 * @param event The connection event.
985 * @param extras Bundle containing extra information associated with the event.
986 */
987 public void sendCallEvent(String event, Bundle extras) {
988 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
989 }
990
991 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700992 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
993 * added.
994 * <p>
995 * No assumptions should be made as to how an In-Call UI or service will handle these
996 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
997 *
998 * @param extras The extras to add.
999 */
1000 public final void putExtras(Bundle extras) {
1001 if (extras == null) {
1002 return;
1003 }
1004
1005 if (mExtras == null) {
1006 mExtras = new Bundle();
1007 }
1008 mExtras.putAll(extras);
1009 mInCallAdapter.putExtras(mTelecomCallId, extras);
1010 }
1011
1012 /**
1013 * Adds a boolean extra to this {@link Call}.
1014 *
1015 * @param key The extra key.
1016 * @param value The value.
1017 * @hide
1018 */
1019 public final void putExtra(String key, boolean value) {
1020 if (mExtras == null) {
1021 mExtras = new Bundle();
1022 }
1023 mExtras.putBoolean(key, value);
1024 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1025 }
1026
1027 /**
1028 * Adds an integer extra to this {@code Connection}.
1029 *
1030 * @param key The extra key.
1031 * @param value The value.
1032 * @hide
1033 */
1034 public final void putExtra(String key, int value) {
1035 if (mExtras == null) {
1036 mExtras = new Bundle();
1037 }
1038 mExtras.putInt(key, value);
1039 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1040 }
1041
1042 /**
1043 * Adds a string extra to this {@code Connection}.
1044 *
1045 * @param key The extra key.
1046 * @param value The value.
1047 * @hide
1048 */
1049 public final void putExtra(String key, String value) {
1050 if (mExtras == null) {
1051 mExtras = new Bundle();
1052 }
1053 mExtras.putString(key, value);
1054 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1055 }
1056
1057 /**
1058 * Removes extras from this {@code Connection}.
1059 *
1060 * @param keys The keys of the extras to remove.
1061 */
1062 public final void removeExtras(List<String> keys) {
1063 if (mExtras != null) {
1064 for (String key : keys) {
1065 mExtras.remove(key);
1066 }
1067 if (mExtras.size() == 0) {
1068 mExtras = null;
1069 }
1070 }
1071 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1072 }
1073
1074 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001075 * Obtains the parent of this {@code Call} in a conference, if any.
1076 *
1077 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1078 * child of any conference {@code Call}s.
1079 */
1080 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001081 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001082 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001083 }
1084 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001085 }
1086
1087 /**
1088 * Obtains the children of this conference {@code Call}, if any.
1089 *
1090 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1091 * {@code List} otherwise.
1092 */
1093 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001094 if (!mChildrenCached) {
1095 mChildrenCached = true;
1096 mChildren.clear();
1097
1098 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001099 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001100 if (call == null) {
1101 // At least one child was still not found, so do not save true for "cached"
1102 mChildrenCached = false;
1103 } else {
1104 mChildren.add(call);
1105 }
1106 }
1107 }
1108
Ihab Awade63fadb2014-07-09 21:52:04 -07001109 return mUnmodifiableChildren;
1110 }
1111
1112 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001113 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1114 *
1115 * @return The list of conferenceable {@code Call}s.
1116 */
1117 public List<Call> getConferenceableCalls() {
1118 return mUnmodifiableConferenceableCalls;
1119 }
1120
1121 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001122 * Obtains the state of this {@code Call}.
1123 *
1124 * @return A state value, chosen from the {@code STATE_*} constants.
1125 */
1126 public int getState() {
1127 return mState;
1128 }
1129
1130 /**
1131 * Obtains a list of canned, pre-configured message responses to present to the user as
1132 * ways of rejecting this {@code Call} using via a text message.
1133 *
1134 * @see #reject(boolean, String)
1135 *
1136 * @return A list of canned text message responses.
1137 */
1138 public List<String> getCannedTextResponses() {
1139 return mCannedTextResponses;
1140 }
1141
1142 /**
1143 * Obtains an object that can be used to display video from this {@code Call}.
1144 *
Andrew Lee50aca232014-07-22 16:41:54 -07001145 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001146 */
Andrew Lee50aca232014-07-22 16:41:54 -07001147 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001148 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001149 }
1150
1151 /**
1152 * Obtains an object containing call details.
1153 *
1154 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1155 * result may be {@code null}.
1156 */
1157 public Details getDetails() {
1158 return mDetails;
1159 }
1160
1161 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001162 * Registers a callback to this {@code Call}.
1163 *
1164 * @param callback A {@code Callback}.
1165 */
1166 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001167 registerCallback(callback, new Handler());
1168 }
1169
1170 /**
1171 * Registers a callback to this {@code Call}.
1172 *
1173 * @param callback A {@code Callback}.
1174 * @param handler A handler which command and status changes will be delivered to.
1175 */
1176 public void registerCallback(Callback callback, Handler handler) {
1177 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001178 // Don't allow new callback registration if the call is already being destroyed.
1179 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001180 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1181 }
Andrew Leeda80c872015-04-15 14:09:50 -07001182 }
1183
1184 /**
1185 * Unregisters a callback from this {@code Call}.
1186 *
1187 * @param callback A {@code Callback}.
1188 */
1189 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001190 // Don't allow callback deregistration if the call is already being destroyed.
1191 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001192 for (CallbackRecord<Callback> record : mCallbackRecords) {
1193 if (record.getCallback() == callback) {
1194 mCallbackRecords.remove(record);
1195 break;
1196 }
1197 }
Andrew Leeda80c872015-04-15 14:09:50 -07001198 }
1199 }
1200
Santos Cordon3c20d632016-02-25 16:12:35 -08001201 @Override
1202 public String toString() {
1203 return new StringBuilder().
1204 append("Call [id: ").
1205 append(mTelecomCallId).
1206 append(", state: ").
1207 append(stateToString(mState)).
1208 append(", details: ").
1209 append(mDetails).
1210 append("]").toString();
1211 }
1212
1213 /**
1214 * @param state An integer value of a {@code STATE_*} constant.
1215 * @return A string representation of the value.
1216 */
1217 private static String stateToString(int state) {
1218 switch (state) {
1219 case STATE_NEW:
1220 return "NEW";
1221 case STATE_RINGING:
1222 return "RINGING";
1223 case STATE_DIALING:
1224 return "DIALING";
1225 case STATE_ACTIVE:
1226 return "ACTIVE";
1227 case STATE_HOLDING:
1228 return "HOLDING";
1229 case STATE_DISCONNECTED:
1230 return "DISCONNECTED";
1231 case STATE_CONNECTING:
1232 return "CONNECTING";
1233 case STATE_DISCONNECTING:
1234 return "DISCONNECTING";
1235 case STATE_SELECT_PHONE_ACCOUNT:
1236 return "SELECT_PHONE_ACCOUNT";
1237 default:
1238 Log.w(Call.class, "Unknown state %d", state);
1239 return "UNKNOWN";
1240 }
1241 }
1242
Andrew Leeda80c872015-04-15 14:09:50 -07001243 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001244 * Adds a listener to this {@code Call}.
1245 *
1246 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001247 * @deprecated Use {@link #registerCallback} instead.
1248 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001249 */
Andrew Leeda80c872015-04-15 14:09:50 -07001250 @Deprecated
1251 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001252 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001253 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001254 }
1255
1256 /**
1257 * Removes a listener from this {@code Call}.
1258 *
1259 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001260 * @deprecated Use {@link #unregisterCallback} 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 removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001266 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001267 }
1268
1269 /** {@hide} */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001270 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001271 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001272 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001273 mInCallAdapter = inCallAdapter;
1274 mState = STATE_NEW;
1275 }
1276
1277 /** {@hide} */
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001278 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state) {
1279 mPhone = phone;
1280 mTelecomCallId = telecomCallId;
1281 mInCallAdapter = inCallAdapter;
1282 mState = state;
1283 }
1284
1285 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001286 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001287 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001288 }
1289
1290 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001291 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001292 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001293 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001294 boolean detailsChanged = !Objects.equals(mDetails, details);
1295 if (detailsChanged) {
1296 mDetails = details;
1297 }
1298
1299 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001300 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1301 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1302 mCannedTextResponses =
1303 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001304 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001305 }
1306
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001307 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl();
Tyler Gunn75958422015-04-15 14:23:42 -07001308 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001309 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001310 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001311 mVideoCallImpl = newVideoCallImpl;
1312 }
1313 if (mVideoCallImpl != null) {
1314 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001315 }
1316
Santos Cordone3c507b2015-04-23 14:44:19 -07001317 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001318 boolean stateChanged = mState != state;
1319 if (stateChanged) {
1320 mState = state;
1321 }
1322
Santos Cordon823fd3c2014-08-07 18:35:18 -07001323 String parentId = parcelableCall.getParentCallId();
1324 boolean parentChanged = !Objects.equals(mParentId, parentId);
1325 if (parentChanged) {
1326 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001327 }
1328
Santos Cordon823fd3c2014-08-07 18:35:18 -07001329 List<String> childCallIds = parcelableCall.getChildCallIds();
1330 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1331 if (childrenChanged) {
1332 mChildrenIds.clear();
1333 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1334 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001335 }
1336
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001337 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1338 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1339 for (String otherId : conferenceableCallIds) {
1340 if (callIdMap.containsKey(otherId)) {
1341 conferenceableCalls.add(callIdMap.get(otherId));
1342 }
1343 }
1344
1345 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1346 mConferenceableCalls.clear();
1347 mConferenceableCalls.addAll(conferenceableCalls);
1348 fireConferenceableCallsChanged();
1349 }
1350
Ihab Awade63fadb2014-07-09 21:52:04 -07001351 // Now we fire updates, ensuring that any client who listens to any of these notifications
1352 // gets the most up-to-date state.
1353
1354 if (stateChanged) {
1355 fireStateChanged(mState);
1356 }
1357 if (detailsChanged) {
1358 fireDetailsChanged(mDetails);
1359 }
1360 if (cannedTextResponsesChanged) {
1361 fireCannedTextResponsesLoaded(mCannedTextResponses);
1362 }
Andrew Lee50aca232014-07-22 16:41:54 -07001363 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001364 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001365 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001366 if (parentChanged) {
1367 fireParentChanged(getParent());
1368 }
1369 if (childrenChanged) {
1370 fireChildrenChanged(getChildren());
1371 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001372
1373 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1374 // remove ourselves from the Phone. Note that we do this after completing all state updates
1375 // so a client can cleanly transition all their UI to the state appropriate for a
1376 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1377 if (mState == STATE_DISCONNECTED) {
1378 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001379 }
1380 }
1381
1382 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001383 final void internalSetPostDialWait(String remaining) {
1384 mRemainingPostDialSequence = remaining;
1385 firePostDialWait(mRemainingPostDialSequence);
1386 }
1387
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001388 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001389 final void internalSetDisconnected() {
1390 if (mState != Call.STATE_DISCONNECTED) {
1391 mState = Call.STATE_DISCONNECTED;
1392 fireStateChanged(mState);
1393 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001394 }
1395 }
1396
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001397 /** {@hide} */
1398 final void internalOnConnectionEvent(String event, Bundle extras) {
1399 fireOnConnectionEvent(event, extras);
1400 }
1401
Andrew Lee011728f2015-04-23 15:47:06 -07001402 private void fireStateChanged(final int newState) {
1403 for (CallbackRecord<Callback> record : mCallbackRecords) {
1404 final Call call = this;
1405 final Callback callback = record.getCallback();
1406 record.getHandler().post(new Runnable() {
1407 @Override
1408 public void run() {
1409 callback.onStateChanged(call, newState);
1410 }
1411 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001412 }
1413 }
1414
Andrew Lee011728f2015-04-23 15:47:06 -07001415 private void fireParentChanged(final Call newParent) {
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.onParentChanged(call, newParent);
1423 }
1424 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001425 }
1426 }
1427
Andrew Lee011728f2015-04-23 15:47:06 -07001428 private void fireChildrenChanged(final List<Call> children) {
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.onChildrenChanged(call, children);
1436 }
1437 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001438 }
1439 }
1440
Andrew Lee011728f2015-04-23 15:47:06 -07001441 private void fireDetailsChanged(final Details details) {
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.onDetailsChanged(call, details);
1449 }
1450 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001451 }
1452 }
1453
Andrew Lee011728f2015-04-23 15:47:06 -07001454 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
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.onCannedTextResponsesLoaded(call, cannedTextResponses);
1462 }
1463 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001464 }
1465 }
1466
Andrew Lee011728f2015-04-23 15:47:06 -07001467 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
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.onVideoCallChanged(call, videoCall);
1475 }
1476 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001477 }
1478 }
1479
Andrew Lee011728f2015-04-23 15:47:06 -07001480 private void firePostDialWait(final String remainingPostDialSequence) {
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.onPostDialWait(call, remainingPostDialSequence);
1488 }
1489 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001490 }
1491 }
1492
1493 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001494 /**
1495 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1496 * onCallRemoved callback, we remove this call from the Phone's record
1497 * only once all of the registered onCallDestroyed callbacks are executed.
1498 * All the callbacks get removed from our records as a part of this operation
1499 * since onCallDestroyed is the final callback.
1500 */
1501 final Call call = this;
1502 if (mCallbackRecords.isEmpty()) {
1503 // No callbacks registered, remove the call from Phone's record.
1504 mPhone.internalRemoveCall(call);
1505 }
1506 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001507 final Callback callback = record.getCallback();
1508 record.getHandler().post(new Runnable() {
1509 @Override
1510 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001511 boolean isFinalRemoval = false;
1512 RuntimeException toThrow = null;
1513 try {
1514 callback.onCallDestroyed(call);
1515 } catch (RuntimeException e) {
1516 toThrow = e;
1517 }
1518 synchronized(Call.this) {
1519 mCallbackRecords.remove(record);
1520 if (mCallbackRecords.isEmpty()) {
1521 isFinalRemoval = true;
1522 }
1523 }
1524 if (isFinalRemoval) {
1525 mPhone.internalRemoveCall(call);
1526 }
1527 if (toThrow != null) {
1528 throw toThrow;
1529 }
Andrew Lee011728f2015-04-23 15:47:06 -07001530 }
1531 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001532 }
1533 }
1534
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001535 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001536 for (CallbackRecord<Callback> record : mCallbackRecords) {
1537 final Call call = this;
1538 final Callback callback = record.getCallback();
1539 record.getHandler().post(new Runnable() {
1540 @Override
1541 public void run() {
1542 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1543 }
1544 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001545 }
1546 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001547
1548 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001549 * Notifies listeners of an incoming connection event.
1550 * <p>
1551 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1552 *
1553 * @param event
1554 * @param extras
1555 */
1556 private void fireOnConnectionEvent(final String event, final Bundle extras) {
1557 for (CallbackRecord<Callback> record : mCallbackRecords) {
1558 final Call call = this;
1559 final Callback callback = record.getCallback();
1560 record.getHandler().post(new Runnable() {
1561 @Override
1562 public void run() {
1563 callback.onConnectionEvent(call, event, extras);
1564 }
1565 });
1566 }
1567 }
1568
1569 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001570 * Determines if two bundles are equal.
1571 *
1572 * @param bundle The original bundle.
1573 * @param newBundle The bundle to compare with.
1574 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1575 */
1576 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1577 if (bundle == null || newBundle == null) {
1578 return bundle == newBundle;
1579 }
1580
1581 if (bundle.size() != newBundle.size()) {
1582 return false;
1583 }
1584
1585 for(String key : bundle.keySet()) {
1586 if (key != null) {
1587 final Object value = bundle.get(key);
1588 final Object newValue = newBundle.get(key);
1589 if (!Objects.equals(value, newValue)) {
1590 return false;
1591 }
1592 }
1593 }
1594 return true;
1595 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001596}