blob: c69b7c2771acd22ede8115347d1bdcc2aa6d4618 [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;
Tyler Gunn071be6f2016-05-10 14:52:33 -070026import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070027import java.util.Collections;
28import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070029import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070030import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070031import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070032
33/**
34 * Represents an ongoing phone call that the in-call app should present to the user.
35 */
36public final class Call {
37 /**
38 * The state of a {@code Call} when newly created.
39 */
40 public static final int STATE_NEW = 0;
41
42 /**
43 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
44 */
45 public static final int STATE_DIALING = 1;
46
47 /**
48 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
49 */
50 public static final int STATE_RINGING = 2;
51
52 /**
53 * The state of a {@code Call} when in a holding state.
54 */
55 public static final int STATE_HOLDING = 3;
56
57 /**
58 * The state of a {@code Call} when actively supporting conversation.
59 */
60 public static final int STATE_ACTIVE = 4;
61
62 /**
63 * The state of a {@code Call} when no further voice or other communication is being
64 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
65 * is no longer active, and the local data transport has or inevitably will release resources
66 * associated with this {@code Call}.
67 */
68 public static final int STATE_DISCONNECTED = 7;
69
Nancy Chen5da0fd52014-07-08 14:16:17 -070070 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070071 * The state of an outgoing {@code Call} when waiting on user to select a
72 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070073 */
Santos Cordone3c507b2015-04-23 14:44:19 -070074 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
75
76 /**
77 * @hide
78 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
79 */
80 @Deprecated
81 @SystemApi
82 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070083
Nancy Chene20930f2014-08-07 16:17:21 -070084 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070085 * The initial state of an outgoing {@code Call}.
86 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
87 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070088 */
89 public static final int STATE_CONNECTING = 9;
90
Nancy Chen513c8922014-09-17 14:47:20 -070091 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -070092 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
93 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
94 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
95 */
96 public static final int STATE_DISCONNECTING = 10;
97
98 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -070099 * The state of an external call which is in the process of being pulled from a remote device to
100 * the local device.
101 * <p>
102 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
103 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
104 * <p>
105 * An {@link InCallService} will only see this state if it has the
106 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
107 * manifest.
108 */
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 Gunn876dbfb2016-03-14 15:18:07 -0700255 */
256 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
257
Tyler Gunnd11a3152015-03-18 13:09:14 -0700258 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700259 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700260 //******************************************************************************************
261
262 /**
263 * Whether the call is currently a conference.
264 */
265 public static final int PROPERTY_CONFERENCE = 0x00000001;
266
267 /**
268 * Whether the call is a generic conference, where we do not know the precise state of
269 * participants in the conference (eg. on CDMA).
270 */
271 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
272
273 /**
274 * Whether the call is made while the device is in emergency callback mode.
275 */
276 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
277
278 /**
279 * Connection is using WIFI.
280 */
281 public static final int PROPERTY_WIFI = 0x00000008;
282
283 /**
284 * Call is using high definition audio.
285 */
286 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
287
Tony Maka68dcce2015-12-17 09:31:18 +0000288 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100289 * Whether the call is associated with the work profile.
290 */
291 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
292
293 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700294 * When set, indicates that this {@code Call} does not actually exist locally for the
295 * {@link ConnectionService}.
296 * <p>
297 * Consider, for example, a scenario where a user has two phones with the same phone number.
298 * When a user places a call on one device, the telephony stack can represent that call on
299 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700300 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700301 * <p>
302 * An {@link InCallService} will only see calls with this property if it has the
303 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
304 * in its manifest.
305 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700306 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700307 */
308 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
309
Brad Ebinger15847072016-05-18 11:08:36 -0700310 /**
311 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
312 */
313 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
314
Andrew Lee2378ea72015-04-29 14:38:11 -0700315 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700316 // Next PROPERTY value: 0x00000100
Tyler Gunnd11a3152015-03-18 13:09:14 -0700317 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800318
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800319 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700320 private final Uri mHandle;
321 private final int mHandlePresentation;
322 private final String mCallerDisplayName;
323 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700324 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700325 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700326 private final int mCallProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800327 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700328 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700329 private final long mConnectTimeMillis;
330 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700331 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700332 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700333 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700334 private final Bundle mIntentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700335
336 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800337 * Whether the supplied capabilities supports the specified capability.
338 *
339 * @param capabilities A bit field of capabilities.
340 * @param capability The capability to check capabilities for.
341 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800342 */
343 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800344 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800345 }
346
347 /**
348 * Whether the capabilities of this {@code Details} supports the specified capability.
349 *
350 * @param capability The capability to check capabilities for.
351 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800352 */
353 public boolean can(int capability) {
354 return can(mCallCapabilities, capability);
355 }
356
357 /**
358 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
359 *
360 * @param capabilities A capability bit field.
361 * @return A human readable string representation.
362 */
363 public static String capabilitiesToString(int capabilities) {
364 StringBuilder builder = new StringBuilder();
365 builder.append("[Capabilities:");
366 if (can(capabilities, CAPABILITY_HOLD)) {
367 builder.append(" CAPABILITY_HOLD");
368 }
369 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
370 builder.append(" CAPABILITY_SUPPORT_HOLD");
371 }
372 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
373 builder.append(" CAPABILITY_MERGE_CONFERENCE");
374 }
375 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
376 builder.append(" CAPABILITY_SWAP_CONFERENCE");
377 }
378 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
379 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
380 }
381 if (can(capabilities, CAPABILITY_MUTE)) {
382 builder.append(" CAPABILITY_MUTE");
383 }
384 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
385 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
386 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700387 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
388 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
389 }
390 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
391 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
392 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700393 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
394 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800395 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700396 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
397 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
398 }
399 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
400 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
401 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800402 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
403 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
404 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700405 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
406 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800407 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500408 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700409 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500410 }
Rekha Kumar07366812015-03-24 16:42:31 -0700411 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
412 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
413 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700414 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
415 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
416 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700417 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
418 builder.append(" CAPABILITY_CAN_PULL_CALL");
419 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800420 builder.append("]");
421 return builder.toString();
422 }
423
424 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700425 * Whether the supplied properties includes the specified property.
426 *
427 * @param properties A bit field of properties.
428 * @param property The property to check properties for.
429 * @return Whether the specified property is supported.
430 */
431 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800432 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700433 }
434
435 /**
436 * Whether the properties of this {@code Details} includes the specified property.
437 *
438 * @param property The property to check properties for.
439 * @return Whether the specified property is supported.
440 */
441 public boolean hasProperty(int property) {
442 return hasProperty(mCallProperties, property);
443 }
444
445 /**
446 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
447 *
448 * @param properties A property bit field.
449 * @return A human readable string representation.
450 */
451 public static String propertiesToString(int properties) {
452 StringBuilder builder = new StringBuilder();
453 builder.append("[Properties:");
454 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
455 builder.append(" PROPERTY_CONFERENCE");
456 }
457 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
458 builder.append(" PROPERTY_GENERIC_CONFERENCE");
459 }
460 if (hasProperty(properties, PROPERTY_WIFI)) {
461 builder.append(" PROPERTY_WIFI");
462 }
463 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
464 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
465 }
466 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700467 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700468 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700469 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
470 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
471 }
Brad Ebinger15847072016-05-18 11:08:36 -0700472 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
473 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
474 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700475 builder.append("]");
476 return builder.toString();
477 }
478
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800479 /** {@hide} */
480 public String getTelecomCallId() {
481 return mTelecomCallId;
482 }
483
Andrew Lee2378ea72015-04-29 14:38:11 -0700484 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700485 * @return The handle (e.g., phone number) to which the {@code Call} is currently
486 * connected.
487 */
488 public Uri getHandle() {
489 return mHandle;
490 }
491
492 /**
493 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700494 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700495 */
496 public int getHandlePresentation() {
497 return mHandlePresentation;
498 }
499
500 /**
501 * @return The display name for the caller.
502 */
503 public String getCallerDisplayName() {
504 return mCallerDisplayName;
505 }
506
507 /**
508 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700509 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700510 */
511 public int getCallerDisplayNamePresentation() {
512 return mCallerDisplayNamePresentation;
513 }
514
515 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700516 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
517 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700518 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700519 public PhoneAccountHandle getAccountHandle() {
520 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700521 }
522
523 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800524 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
525 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700526 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700527 public int getCallCapabilities() {
528 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700529 }
530
531 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700532 * @return A bitmask of the properties of the {@code Call}, as defined by the various
533 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700534 */
535 public int getCallProperties() {
536 return mCallProperties;
537 }
538
539 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800540 * @return a bitmask of the audio routes available for the call.
541 *
542 * @hide
543 */
544 public int getSupportedAudioRoutes() {
545 return mSupportedAudioRoutes;
546 }
547
548 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700549 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700550 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700551 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700552 public DisconnectCause getDisconnectCause() {
553 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700554 }
555
556 /**
557 * @return The time the {@code Call} has been connected. This information is updated
558 * periodically, but user interfaces should not rely on this to display any "call time
559 * clock".
560 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700561 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700562 return mConnectTimeMillis;
563 }
564
565 /**
566 * @return Information about any calling gateway the {@code Call} may be using.
567 */
568 public GatewayInfo getGatewayInfo() {
569 return mGatewayInfo;
570 }
571
Andrew Lee7a341382014-07-15 17:05:08 -0700572 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700573 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700574 */
575 public int getVideoState() {
576 return mVideoState;
577 }
578
Ihab Awad5d0410f2014-07-30 10:07:40 -0700579 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700580 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700581 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700582 */
583 public StatusHints getStatusHints() {
584 return mStatusHints;
585 }
586
Nancy Chen10798dc2014-08-08 14:00:25 -0700587 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700588 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700589 */
590 public Bundle getExtras() {
591 return mExtras;
592 }
593
Santos Cordon6b7f9552015-05-27 17:21:45 -0700594 /**
595 * @return The extras used with the original intent to place this call.
596 */
597 public Bundle getIntentExtras() {
598 return mIntentExtras;
599 }
600
Ihab Awade63fadb2014-07-09 21:52:04 -0700601 @Override
602 public boolean equals(Object o) {
603 if (o instanceof Details) {
604 Details d = (Details) o;
605 return
606 Objects.equals(mHandle, d.mHandle) &&
607 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
608 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
609 Objects.equals(mCallerDisplayNamePresentation,
610 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700611 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700612 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700613 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700614 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700615 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700616 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700617 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700618 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700619 areBundlesEqual(mExtras, d.mExtras) &&
620 areBundlesEqual(mIntentExtras, d.mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700621 }
622 return false;
623 }
624
625 @Override
626 public int hashCode() {
627 return
628 Objects.hashCode(mHandle) +
629 Objects.hashCode(mHandlePresentation) +
630 Objects.hashCode(mCallerDisplayName) +
631 Objects.hashCode(mCallerDisplayNamePresentation) +
Evan Charlton8c8a0622014-07-20 12:31:00 -0700632 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700633 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700634 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700635 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700636 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700637 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700638 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700639 Objects.hashCode(mStatusHints) +
Santos Cordon6b7f9552015-05-27 17:21:45 -0700640 Objects.hashCode(mExtras) +
641 Objects.hashCode(mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700642 }
643
644 /** {@hide} */
645 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800646 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700647 Uri handle,
648 int handlePresentation,
649 String callerDisplayName,
650 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700651 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700652 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700653 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700654 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700655 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700656 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700657 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700658 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700659 Bundle extras,
660 Bundle intentExtras) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800661 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700662 mHandle = handle;
663 mHandlePresentation = handlePresentation;
664 mCallerDisplayName = callerDisplayName;
665 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700666 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700667 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700668 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700669 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700670 mConnectTimeMillis = connectTimeMillis;
671 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700672 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700673 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700674 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700675 mIntentExtras = intentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700676 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800677
678 /** {@hide} */
679 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
680 return new Details(
681 parcelableCall.getId(),
682 parcelableCall.getHandle(),
683 parcelableCall.getHandlePresentation(),
684 parcelableCall.getCallerDisplayName(),
685 parcelableCall.getCallerDisplayNamePresentation(),
686 parcelableCall.getAccountHandle(),
687 parcelableCall.getCapabilities(),
688 parcelableCall.getProperties(),
689 parcelableCall.getDisconnectCause(),
690 parcelableCall.getConnectTimeMillis(),
691 parcelableCall.getGatewayInfo(),
692 parcelableCall.getVideoState(),
693 parcelableCall.getStatusHints(),
694 parcelableCall.getExtras(),
695 parcelableCall.getIntentExtras());
696 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800697
698 @Override
699 public String toString() {
700 StringBuilder sb = new StringBuilder();
701 sb.append("[pa: ");
702 sb.append(mAccountHandle);
703 sb.append(", hdl: ");
704 sb.append(Log.pii(mHandle));
705 sb.append(", caps: ");
706 sb.append(capabilitiesToString(mCallCapabilities));
707 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700708 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800709 sb.append("]");
710 return sb.toString();
711 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700712 }
713
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700714 /**
715 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
716 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
717 * implementation.
718 * <p>
719 * You can handle these callbacks by extending the {@link Callback} class and overriding the
720 * callbacks that your {@link InCallService} is interested in. The callback methods include the
721 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
722 * {@link Callback} implementation, if desired.
723 * <p>
724 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
725 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
726 * (typically in {@link InCallService#onCallRemoved(Call)}).
727 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
728 * reach your implementation of {@link Callback}, so it is important to register your callback
729 * as soon as your {@link InCallService} is notified of a new call via
730 * {@link InCallService#onCallAdded(Call)}.
731 */
Andrew Leeda80c872015-04-15 14:09:50 -0700732 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700733 /**
734 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
735 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700736 * @param call The {@code Call} invoking this method.
737 * @param state The new state of the {@code Call}.
738 */
739 public void onStateChanged(Call call, int state) {}
740
741 /**
742 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
743 *
744 * @param call The {@code Call} invoking this method.
745 * @param parent The new parent of the {@code Call}.
746 */
747 public void onParentChanged(Call call, Call parent) {}
748
749 /**
750 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
751 *
752 * @param call The {@code Call} invoking this method.
753 * @param children The new children of the {@code Call}.
754 */
755 public void onChildrenChanged(Call call, List<Call> children) {}
756
757 /**
758 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
759 *
760 * @param call The {@code Call} invoking this method.
761 * @param details A {@code Details} object describing the {@code Call}.
762 */
763 public void onDetailsChanged(Call call, Details details) {}
764
765 /**
766 * Invoked when the text messages that can be used as responses to the incoming
767 * {@code Call} are loaded from the relevant database.
768 * See {@link #getCannedTextResponses()}.
769 *
770 * @param call The {@code Call} invoking this method.
771 * @param cannedTextResponses The text messages useable as responses.
772 */
773 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
774
775 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700776 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
777 * character. This causes the post-dial signals to stop pending user confirmation. An
778 * implementation should present this choice to the user and invoke
779 * {@link #postDialContinue(boolean)} when the user makes the choice.
780 *
781 * @param call The {@code Call} invoking this method.
782 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
783 */
784 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
785
786 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700787 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700788 *
789 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700790 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700791 */
Andrew Lee50aca232014-07-22 16:41:54 -0700792 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700793
794 /**
795 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
796 * up their UI for the {@code Call} in response to state transitions. Specifically,
797 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
798 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
799 * clients should wait for this method to be invoked.
800 *
801 * @param call The {@code Call} being destroyed.
802 */
803 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700804
805 /**
806 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
807 * conferenced.
808 *
809 * @param call The {@code Call} being updated.
810 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
811 * conferenced.
812 */
813 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700814
815 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700816 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
817 * <p>
818 * Where possible, the Call should make an attempt to handle {@link Connection} events which
819 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
820 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
821 * possible that a {@link ConnectionService} has defined its own Connection events which a
822 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700823 * <p>
824 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
825 *
826 * @param call The {@code Call} receiving the event.
827 * @param event The event.
828 * @param extras Extras associated with the connection event.
829 */
830 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700831 }
832
Andrew Leeda80c872015-04-15 14:09:50 -0700833 /**
834 * @deprecated Use {@code Call.Callback} instead.
835 * @hide
836 */
837 @Deprecated
838 @SystemApi
839 public static abstract class Listener extends Callback { }
840
Ihab Awade63fadb2014-07-09 21:52:04 -0700841 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700842 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700843 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700844 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -0700845 private final List<Call> mChildren = new ArrayList<>();
846 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -0700847 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700848 private final List<Call> mConferenceableCalls = new ArrayList<>();
849 private final List<Call> mUnmodifiableConferenceableCalls =
850 Collections.unmodifiableList(mConferenceableCalls);
851
Santos Cordon823fd3c2014-08-07 18:35:18 -0700852 private boolean mChildrenCached;
853 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700854 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -0700855 private List<String> mCannedTextResponses = null;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800856 private String mCallingPackage;
Ihab Awade63fadb2014-07-09 21:52:04 -0700857 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -0800858 private VideoCallImpl mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -0700859 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -0700860 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700861
862 /**
863 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
864 *
865 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
866 * remaining or this {@code Call} is not in a post-dial state.
867 */
868 public String getRemainingPostDialSequence() {
869 return mRemainingPostDialSequence;
870 }
871
872 /**
873 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700874 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -0700875 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700876 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700877 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700878 }
879
880 /**
881 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
882 *
883 * @param rejectWithMessage Whether to reject with a text message.
884 * @param textMessage An optional text message with which to respond.
885 */
886 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700887 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -0700888 }
889
890 /**
891 * Instructs this {@code Call} to disconnect.
892 */
893 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700894 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700895 }
896
897 /**
898 * Instructs this {@code Call} to go on hold.
899 */
900 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700901 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700902 }
903
904 /**
905 * Instructs this {@link #STATE_HOLDING} call to release from hold.
906 */
907 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700908 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700909 }
910
911 /**
912 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
913 *
914 * Any other currently playing DTMF tone in the specified call is immediately stopped.
915 *
916 * @param digit A character representing the DTMF digit for which to play the tone. This
917 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
918 */
919 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700920 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -0700921 }
922
923 /**
924 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
925 * currently playing.
926 *
927 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
928 * currently playing, this method will do nothing.
929 */
930 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700931 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700932 }
933
934 /**
935 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
936 *
937 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
938 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -0700939 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700940 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700941 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
942 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700943 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -0700944 * {@code Call} will pause playing the tones and notify callbacks via
945 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -0700946 * should display to the user an indication of this state and an affordance to continue
947 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
948 * app should invoke the {@link #postDialContinue(boolean)} method.
949 *
950 * @param proceed Whether or not to continue with the post-dial sequence.
951 */
952 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700953 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -0700954 }
955
956 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700957 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -0700958 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700959 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700960 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
961 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700962
963 }
964
965 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700966 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700967 *
968 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -0700969 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700970 public void conference(Call callToConferenceWith) {
971 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700972 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700973 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700974 }
975
976 /**
977 * Instructs this {@code Call} to split from any conference call with which it may be
978 * connected.
979 */
980 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700981 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700982 }
983
984 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800985 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700986 */
987 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700988 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700989 }
990
991 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800992 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700993 */
994 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700995 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700996 }
997
998 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700999 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1000 * device.
1001 * <p>
1002 * Calls to this method are ignored if the call does not have the
1003 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1004 * <p>
1005 * An {@link InCallService} will only see calls which support this method if it has the
1006 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1007 * in its manifest.
1008 */
1009 public void pullExternalCall() {
1010 // If this isn't an external call, ignore the request.
1011 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1012 return;
1013 }
1014
1015 mInCallAdapter.pullExternalCall(mTelecomCallId);
1016 }
1017
1018 /**
1019 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1020 * the {@link ConnectionService}.
1021 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001022 * Call events are used to communicate point in time information from an {@link InCallService}
1023 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1024 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1025 * {@link ConnectionService}.
1026 * <p>
1027 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1028 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1029 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001030 * Events are exposed to {@link ConnectionService} implementations via
1031 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1032 * <p>
1033 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001034 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1035 * ignore some events altogether.
1036 * <p>
1037 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1038 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1039 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1040 * they define their own event types in this namespace. When defining a custom event type,
1041 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1042 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1043 * <p>
1044 * When defining events and the associated extras, it is important to keep their behavior
1045 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1046 * events/extras should me maintained to ensure backwards compatibility with older
1047 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001048 *
1049 * @param event The connection event.
1050 * @param extras Bundle containing extra information associated with the event.
1051 */
1052 public void sendCallEvent(String event, Bundle extras) {
1053 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1054 }
1055
1056 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001057 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1058 * added.
1059 * <p>
1060 * No assumptions should be made as to how an In-Call UI or service will handle these
1061 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1062 *
1063 * @param extras The extras to add.
1064 */
1065 public final void putExtras(Bundle extras) {
1066 if (extras == null) {
1067 return;
1068 }
1069
1070 if (mExtras == null) {
1071 mExtras = new Bundle();
1072 }
1073 mExtras.putAll(extras);
1074 mInCallAdapter.putExtras(mTelecomCallId, extras);
1075 }
1076
1077 /**
1078 * Adds a boolean extra to this {@link Call}.
1079 *
1080 * @param key The extra key.
1081 * @param value The value.
1082 * @hide
1083 */
1084 public final void putExtra(String key, boolean value) {
1085 if (mExtras == null) {
1086 mExtras = new Bundle();
1087 }
1088 mExtras.putBoolean(key, value);
1089 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1090 }
1091
1092 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001093 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001094 *
1095 * @param key The extra key.
1096 * @param value The value.
1097 * @hide
1098 */
1099 public final void putExtra(String key, int value) {
1100 if (mExtras == null) {
1101 mExtras = new Bundle();
1102 }
1103 mExtras.putInt(key, value);
1104 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1105 }
1106
1107 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001108 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001109 *
1110 * @param key The extra key.
1111 * @param value The value.
1112 * @hide
1113 */
1114 public final void putExtra(String key, String value) {
1115 if (mExtras == null) {
1116 mExtras = new Bundle();
1117 }
1118 mExtras.putString(key, value);
1119 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1120 }
1121
1122 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001123 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001124 *
1125 * @param keys The keys of the extras to remove.
1126 */
1127 public final void removeExtras(List<String> keys) {
1128 if (mExtras != null) {
1129 for (String key : keys) {
1130 mExtras.remove(key);
1131 }
1132 if (mExtras.size() == 0) {
1133 mExtras = null;
1134 }
1135 }
1136 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1137 }
1138
1139 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001140 * Removes extras from this {@link Call}.
1141 *
1142 * @param keys The keys of the extras to remove.
1143 */
1144 public final void removeExtras(String ... keys) {
1145 removeExtras(Arrays.asList(keys));
1146 }
1147
1148 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001149 * Obtains the parent of this {@code Call} in a conference, if any.
1150 *
1151 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1152 * child of any conference {@code Call}s.
1153 */
1154 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001155 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001156 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001157 }
1158 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001159 }
1160
1161 /**
1162 * Obtains the children of this conference {@code Call}, if any.
1163 *
1164 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1165 * {@code List} otherwise.
1166 */
1167 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001168 if (!mChildrenCached) {
1169 mChildrenCached = true;
1170 mChildren.clear();
1171
1172 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001173 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001174 if (call == null) {
1175 // At least one child was still not found, so do not save true for "cached"
1176 mChildrenCached = false;
1177 } else {
1178 mChildren.add(call);
1179 }
1180 }
1181 }
1182
Ihab Awade63fadb2014-07-09 21:52:04 -07001183 return mUnmodifiableChildren;
1184 }
1185
1186 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001187 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1188 *
1189 * @return The list of conferenceable {@code Call}s.
1190 */
1191 public List<Call> getConferenceableCalls() {
1192 return mUnmodifiableConferenceableCalls;
1193 }
1194
1195 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001196 * Obtains the state of this {@code Call}.
1197 *
1198 * @return A state value, chosen from the {@code STATE_*} constants.
1199 */
1200 public int getState() {
1201 return mState;
1202 }
1203
1204 /**
1205 * Obtains a list of canned, pre-configured message responses to present to the user as
1206 * ways of rejecting this {@code Call} using via a text message.
1207 *
1208 * @see #reject(boolean, String)
1209 *
1210 * @return A list of canned text message responses.
1211 */
1212 public List<String> getCannedTextResponses() {
1213 return mCannedTextResponses;
1214 }
1215
1216 /**
1217 * Obtains an object that can be used to display video from this {@code Call}.
1218 *
Andrew Lee50aca232014-07-22 16:41:54 -07001219 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001220 */
Andrew Lee50aca232014-07-22 16:41:54 -07001221 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001222 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001223 }
1224
1225 /**
1226 * Obtains an object containing call details.
1227 *
1228 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1229 * result may be {@code null}.
1230 */
1231 public Details getDetails() {
1232 return mDetails;
1233 }
1234
1235 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001236 * Registers a callback to this {@code Call}.
1237 *
1238 * @param callback A {@code Callback}.
1239 */
1240 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001241 registerCallback(callback, new Handler());
1242 }
1243
1244 /**
1245 * Registers a callback to this {@code Call}.
1246 *
1247 * @param callback A {@code Callback}.
1248 * @param handler A handler which command and status changes will be delivered to.
1249 */
1250 public void registerCallback(Callback callback, Handler handler) {
1251 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001252 // Don't allow new callback registration if the call is already being destroyed.
1253 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001254 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1255 }
Andrew Leeda80c872015-04-15 14:09:50 -07001256 }
1257
1258 /**
1259 * Unregisters a callback from this {@code Call}.
1260 *
1261 * @param callback A {@code Callback}.
1262 */
1263 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001264 // Don't allow callback deregistration if the call is already being destroyed.
1265 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001266 for (CallbackRecord<Callback> record : mCallbackRecords) {
1267 if (record.getCallback() == callback) {
1268 mCallbackRecords.remove(record);
1269 break;
1270 }
1271 }
Andrew Leeda80c872015-04-15 14:09:50 -07001272 }
1273 }
1274
Santos Cordon3c20d632016-02-25 16:12:35 -08001275 @Override
1276 public String toString() {
1277 return new StringBuilder().
1278 append("Call [id: ").
1279 append(mTelecomCallId).
1280 append(", state: ").
1281 append(stateToString(mState)).
1282 append(", details: ").
1283 append(mDetails).
1284 append("]").toString();
1285 }
1286
1287 /**
1288 * @param state An integer value of a {@code STATE_*} constant.
1289 * @return A string representation of the value.
1290 */
1291 private static String stateToString(int state) {
1292 switch (state) {
1293 case STATE_NEW:
1294 return "NEW";
1295 case STATE_RINGING:
1296 return "RINGING";
1297 case STATE_DIALING:
1298 return "DIALING";
1299 case STATE_ACTIVE:
1300 return "ACTIVE";
1301 case STATE_HOLDING:
1302 return "HOLDING";
1303 case STATE_DISCONNECTED:
1304 return "DISCONNECTED";
1305 case STATE_CONNECTING:
1306 return "CONNECTING";
1307 case STATE_DISCONNECTING:
1308 return "DISCONNECTING";
1309 case STATE_SELECT_PHONE_ACCOUNT:
1310 return "SELECT_PHONE_ACCOUNT";
1311 default:
1312 Log.w(Call.class, "Unknown state %d", state);
1313 return "UNKNOWN";
1314 }
1315 }
1316
Andrew Leeda80c872015-04-15 14:09:50 -07001317 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001318 * Adds a listener to this {@code Call}.
1319 *
1320 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001321 * @deprecated Use {@link #registerCallback} instead.
1322 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001323 */
Andrew Leeda80c872015-04-15 14:09:50 -07001324 @Deprecated
1325 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001326 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001327 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001328 }
1329
1330 /**
1331 * Removes a listener from this {@code Call}.
1332 *
1333 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001334 * @deprecated Use {@link #unregisterCallback} instead.
1335 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001336 */
Andrew Leeda80c872015-04-15 14:09:50 -07001337 @Deprecated
1338 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001339 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001340 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001341 }
1342
1343 /** {@hide} */
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001344 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001345 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001346 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001347 mInCallAdapter = inCallAdapter;
1348 mState = STATE_NEW;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001349 mCallingPackage = callingPackage;
Ihab Awade63fadb2014-07-09 21:52:04 -07001350 }
1351
1352 /** {@hide} */
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001353 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
1354 String callingPackage) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001355 mPhone = phone;
1356 mTelecomCallId = telecomCallId;
1357 mInCallAdapter = inCallAdapter;
1358 mState = state;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001359 mCallingPackage = callingPackage;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001360 }
1361
1362 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001363 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001364 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001365 }
1366
1367 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001368 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001369
Ihab Awade63fadb2014-07-09 21:52:04 -07001370 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001371 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001372 boolean detailsChanged = !Objects.equals(mDetails, details);
1373 if (detailsChanged) {
1374 mDetails = details;
1375 }
1376
1377 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001378 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1379 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1380 mCannedTextResponses =
1381 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001382 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001383 }
1384
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001385 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage);
Tyler Gunn75958422015-04-15 14:23:42 -07001386 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001387 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001388 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001389 mVideoCallImpl = newVideoCallImpl;
1390 }
1391 if (mVideoCallImpl != null) {
1392 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001393 }
1394
Santos Cordone3c507b2015-04-23 14:44:19 -07001395 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001396 boolean stateChanged = mState != state;
1397 if (stateChanged) {
1398 mState = state;
1399 }
1400
Santos Cordon823fd3c2014-08-07 18:35:18 -07001401 String parentId = parcelableCall.getParentCallId();
1402 boolean parentChanged = !Objects.equals(mParentId, parentId);
1403 if (parentChanged) {
1404 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001405 }
1406
Santos Cordon823fd3c2014-08-07 18:35:18 -07001407 List<String> childCallIds = parcelableCall.getChildCallIds();
1408 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1409 if (childrenChanged) {
1410 mChildrenIds.clear();
1411 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1412 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001413 }
1414
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001415 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1416 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1417 for (String otherId : conferenceableCallIds) {
1418 if (callIdMap.containsKey(otherId)) {
1419 conferenceableCalls.add(callIdMap.get(otherId));
1420 }
1421 }
1422
1423 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1424 mConferenceableCalls.clear();
1425 mConferenceableCalls.addAll(conferenceableCalls);
1426 fireConferenceableCallsChanged();
1427 }
1428
Ihab Awade63fadb2014-07-09 21:52:04 -07001429 // Now we fire updates, ensuring that any client who listens to any of these notifications
1430 // gets the most up-to-date state.
1431
1432 if (stateChanged) {
1433 fireStateChanged(mState);
1434 }
1435 if (detailsChanged) {
1436 fireDetailsChanged(mDetails);
1437 }
1438 if (cannedTextResponsesChanged) {
1439 fireCannedTextResponsesLoaded(mCannedTextResponses);
1440 }
Andrew Lee50aca232014-07-22 16:41:54 -07001441 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001442 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001443 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001444 if (parentChanged) {
1445 fireParentChanged(getParent());
1446 }
1447 if (childrenChanged) {
1448 fireChildrenChanged(getChildren());
1449 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001450
1451 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1452 // remove ourselves from the Phone. Note that we do this after completing all state updates
1453 // so a client can cleanly transition all their UI to the state appropriate for a
1454 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1455 if (mState == STATE_DISCONNECTED) {
1456 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001457 }
1458 }
1459
1460 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001461 final void internalSetPostDialWait(String remaining) {
1462 mRemainingPostDialSequence = remaining;
1463 firePostDialWait(mRemainingPostDialSequence);
1464 }
1465
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001466 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001467 final void internalSetDisconnected() {
1468 if (mState != Call.STATE_DISCONNECTED) {
1469 mState = Call.STATE_DISCONNECTED;
1470 fireStateChanged(mState);
1471 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001472 }
1473 }
1474
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001475 /** {@hide} */
1476 final void internalOnConnectionEvent(String event, Bundle extras) {
1477 fireOnConnectionEvent(event, extras);
1478 }
1479
Andrew Lee011728f2015-04-23 15:47:06 -07001480 private void fireStateChanged(final int newState) {
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.onStateChanged(call, newState);
1488 }
1489 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001490 }
1491 }
1492
Andrew Lee011728f2015-04-23 15:47:06 -07001493 private void fireParentChanged(final Call newParent) {
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.onParentChanged(call, newParent);
1501 }
1502 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001503 }
1504 }
1505
Andrew Lee011728f2015-04-23 15:47:06 -07001506 private void fireChildrenChanged(final List<Call> children) {
1507 for (CallbackRecord<Callback> record : mCallbackRecords) {
1508 final Call call = this;
1509 final Callback callback = record.getCallback();
1510 record.getHandler().post(new Runnable() {
1511 @Override
1512 public void run() {
1513 callback.onChildrenChanged(call, children);
1514 }
1515 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001516 }
1517 }
1518
Andrew Lee011728f2015-04-23 15:47:06 -07001519 private void fireDetailsChanged(final Details details) {
1520 for (CallbackRecord<Callback> record : mCallbackRecords) {
1521 final Call call = this;
1522 final Callback callback = record.getCallback();
1523 record.getHandler().post(new Runnable() {
1524 @Override
1525 public void run() {
1526 callback.onDetailsChanged(call, details);
1527 }
1528 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001529 }
1530 }
1531
Andrew Lee011728f2015-04-23 15:47:06 -07001532 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1533 for (CallbackRecord<Callback> record : mCallbackRecords) {
1534 final Call call = this;
1535 final Callback callback = record.getCallback();
1536 record.getHandler().post(new Runnable() {
1537 @Override
1538 public void run() {
1539 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1540 }
1541 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001542 }
1543 }
1544
Andrew Lee011728f2015-04-23 15:47:06 -07001545 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1546 for (CallbackRecord<Callback> record : mCallbackRecords) {
1547 final Call call = this;
1548 final Callback callback = record.getCallback();
1549 record.getHandler().post(new Runnable() {
1550 @Override
1551 public void run() {
1552 callback.onVideoCallChanged(call, videoCall);
1553 }
1554 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001555 }
1556 }
1557
Andrew Lee011728f2015-04-23 15:47:06 -07001558 private void firePostDialWait(final String remainingPostDialSequence) {
1559 for (CallbackRecord<Callback> record : mCallbackRecords) {
1560 final Call call = this;
1561 final Callback callback = record.getCallback();
1562 record.getHandler().post(new Runnable() {
1563 @Override
1564 public void run() {
1565 callback.onPostDialWait(call, remainingPostDialSequence);
1566 }
1567 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001568 }
1569 }
1570
1571 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001572 /**
1573 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1574 * onCallRemoved callback, we remove this call from the Phone's record
1575 * only once all of the registered onCallDestroyed callbacks are executed.
1576 * All the callbacks get removed from our records as a part of this operation
1577 * since onCallDestroyed is the final callback.
1578 */
1579 final Call call = this;
1580 if (mCallbackRecords.isEmpty()) {
1581 // No callbacks registered, remove the call from Phone's record.
1582 mPhone.internalRemoveCall(call);
1583 }
1584 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001585 final Callback callback = record.getCallback();
1586 record.getHandler().post(new Runnable() {
1587 @Override
1588 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001589 boolean isFinalRemoval = false;
1590 RuntimeException toThrow = null;
1591 try {
1592 callback.onCallDestroyed(call);
1593 } catch (RuntimeException e) {
1594 toThrow = e;
1595 }
1596 synchronized(Call.this) {
1597 mCallbackRecords.remove(record);
1598 if (mCallbackRecords.isEmpty()) {
1599 isFinalRemoval = true;
1600 }
1601 }
1602 if (isFinalRemoval) {
1603 mPhone.internalRemoveCall(call);
1604 }
1605 if (toThrow != null) {
1606 throw toThrow;
1607 }
Andrew Lee011728f2015-04-23 15:47:06 -07001608 }
1609 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001610 }
1611 }
1612
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001613 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001614 for (CallbackRecord<Callback> record : mCallbackRecords) {
1615 final Call call = this;
1616 final Callback callback = record.getCallback();
1617 record.getHandler().post(new Runnable() {
1618 @Override
1619 public void run() {
1620 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1621 }
1622 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001623 }
1624 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001625
1626 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001627 * Notifies listeners of an incoming connection event.
1628 * <p>
1629 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1630 *
1631 * @param event
1632 * @param extras
1633 */
1634 private void fireOnConnectionEvent(final String event, final Bundle extras) {
1635 for (CallbackRecord<Callback> record : mCallbackRecords) {
1636 final Call call = this;
1637 final Callback callback = record.getCallback();
1638 record.getHandler().post(new Runnable() {
1639 @Override
1640 public void run() {
1641 callback.onConnectionEvent(call, event, extras);
1642 }
1643 });
1644 }
1645 }
1646
1647 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001648 * Determines if two bundles are equal.
1649 *
1650 * @param bundle The original bundle.
1651 * @param newBundle The bundle to compare with.
1652 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1653 */
1654 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1655 if (bundle == null || newBundle == null) {
1656 return bundle == newBundle;
1657 }
1658
1659 if (bundle.size() != newBundle.size()) {
1660 return false;
1661 }
1662
1663 for(String key : bundle.keySet()) {
1664 if (key != null) {
1665 final Object value = bundle.get(key);
1666 final Object newValue = newBundle.get(key);
1667 if (!Objects.equals(value, newValue)) {
1668 return false;
1669 }
1670 }
1671 }
1672 return true;
1673 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001674}