blob: de9020250f25a75cac72465627b65c2fc11c8353 [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 /**
Nancy Chen513c8922014-09-17 14:47:20 -070098 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
99 * extras. Used to pass the phone accounts to display on the front end to the user in order to
100 * select phone accounts to (for example) place a call.
Nancy Chen513c8922014-09-17 14:47:20 -0700101 */
102 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
103
Ihab Awade63fadb2014-07-09 21:52:04 -0700104 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800105
106 /** Call can currently be put on hold or unheld. */
107 public static final int CAPABILITY_HOLD = 0x00000001;
108
109 /** Call supports the hold feature. */
110 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
111
112 /**
113 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
114 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
115 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
116 * capability allows a merge button to be shown while the conference call is in the foreground
117 * of the in-call UI.
118 * <p>
119 * This is only intended for use by a {@link Conference}.
120 */
121 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
122
123 /**
124 * Calls within a conference can be swapped between foreground and background.
125 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
126 * <p>
127 * This is only intended for use by a {@link Conference}.
128 */
129 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
130
131 /**
132 * @hide
133 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700134 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800135
136 /** Call supports responding via text option. */
137 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
138
139 /** Call can be muted. */
140 public static final int CAPABILITY_MUTE = 0x00000040;
141
142 /**
143 * Call supports conference call management. This capability only applies to {@link Conference}
144 * calls which can have {@link Connection}s as children.
145 */
146 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
147
148 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700149 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800150 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700151 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800152
153 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700154 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800155 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700156 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800157
158 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700159 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800160 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700161 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700162 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800163
164 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700165 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800166 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700167 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
168
169 /**
170 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700171 */
172 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
173
174 /**
175 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700176 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700177 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700178 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800179
180 /**
181 * Call is able to be separated from its parent {@code Conference}, if any.
182 */
183 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
184
185 /**
186 * Call is able to be individually disconnected when in a {@code Conference}.
187 */
188 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
189
190 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500191 * Speed up audio setup for MT call.
192 * @hide
193 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700194 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
195
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700196 /**
197 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700198 * @hide
199 */
200 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
201
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700202 /**
203 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700204 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700205 */
206 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
207
Bryce Lee81901682015-08-28 16:38:02 -0700208 /**
209 * Call sends responses through connection.
210 * @hide
211 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800212 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
213
214 /**
215 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
216 * <p>
217 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
218 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
219 * downgraded from a video call back to a VideoState of
220 * {@link VideoProfile#STATE_AUDIO_ONLY}.
221 * <p>
222 * Intuitively, a call which can be downgraded to audio should also have local and remote
223 * video
224 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
225 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
226 */
227 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700228
Tyler Gunnd11a3152015-03-18 13:09:14 -0700229 //******************************************************************************************
Bryce Lee81901682015-08-28 16:38:02 -0700230 // Next CAPABILITY value: 0x00800000
Andrew Lee2378ea72015-04-29 14:38:11 -0700231 //******************************************************************************************
232
233 /**
234 * Whether the call is currently a conference.
235 */
236 public static final int PROPERTY_CONFERENCE = 0x00000001;
237
238 /**
239 * Whether the call is a generic conference, where we do not know the precise state of
240 * participants in the conference (eg. on CDMA).
241 */
242 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
243
244 /**
245 * Whether the call is made while the device is in emergency callback mode.
246 */
247 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
248
249 /**
250 * Connection is using WIFI.
251 */
252 public static final int PROPERTY_WIFI = 0x00000008;
253
254 /**
255 * Call is using high definition audio.
256 */
257 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
258
Tony Maka68dcce2015-12-17 09:31:18 +0000259 /**
260 * Whether the call is associated with the work profile.
261 */
262 public static final int PROPERTY_WORK_CALL = 0x00000020;
263
Andrew Lee2378ea72015-04-29 14:38:11 -0700264 //******************************************************************************************
Tony Maka68dcce2015-12-17 09:31:18 +0000265 // Next PROPERTY value: 0x00000040
Tyler Gunnd11a3152015-03-18 13:09:14 -0700266 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800267
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800268 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700269 private final Uri mHandle;
270 private final int mHandlePresentation;
271 private final String mCallerDisplayName;
272 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700273 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700274 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700275 private final int mCallProperties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700276 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700277 private final long mConnectTimeMillis;
278 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700279 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700280 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700281 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700282 private final Bundle mIntentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700283
284 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800285 * Whether the supplied capabilities supports the specified capability.
286 *
287 * @param capabilities A bit field of capabilities.
288 * @param capability The capability to check capabilities for.
289 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800290 */
291 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800292 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800293 }
294
295 /**
296 * Whether the capabilities of this {@code Details} supports the specified capability.
297 *
298 * @param capability The capability to check capabilities for.
299 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800300 */
301 public boolean can(int capability) {
302 return can(mCallCapabilities, capability);
303 }
304
305 /**
306 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
307 *
308 * @param capabilities A capability bit field.
309 * @return A human readable string representation.
310 */
311 public static String capabilitiesToString(int capabilities) {
312 StringBuilder builder = new StringBuilder();
313 builder.append("[Capabilities:");
314 if (can(capabilities, CAPABILITY_HOLD)) {
315 builder.append(" CAPABILITY_HOLD");
316 }
317 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
318 builder.append(" CAPABILITY_SUPPORT_HOLD");
319 }
320 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
321 builder.append(" CAPABILITY_MERGE_CONFERENCE");
322 }
323 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
324 builder.append(" CAPABILITY_SWAP_CONFERENCE");
325 }
326 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
327 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
328 }
329 if (can(capabilities, CAPABILITY_MUTE)) {
330 builder.append(" CAPABILITY_MUTE");
331 }
332 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
333 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
334 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700335 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
336 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
337 }
338 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
339 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
340 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700341 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
342 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800343 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700344 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
345 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
346 }
347 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
348 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
349 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800350 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
351 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
352 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700353 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
354 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800355 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500356 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700357 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500358 }
Rekha Kumar07366812015-03-24 16:42:31 -0700359 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
360 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
361 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700362 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
363 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
364 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800365 builder.append("]");
366 return builder.toString();
367 }
368
369 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700370 * Whether the supplied properties includes the specified property.
371 *
372 * @param properties A bit field of properties.
373 * @param property The property to check properties for.
374 * @return Whether the specified property is supported.
375 */
376 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800377 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700378 }
379
380 /**
381 * Whether the properties of this {@code Details} includes the specified property.
382 *
383 * @param property The property to check properties for.
384 * @return Whether the specified property is supported.
385 */
386 public boolean hasProperty(int property) {
387 return hasProperty(mCallProperties, property);
388 }
389
390 /**
391 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
392 *
393 * @param properties A property bit field.
394 * @return A human readable string representation.
395 */
396 public static String propertiesToString(int properties) {
397 StringBuilder builder = new StringBuilder();
398 builder.append("[Properties:");
399 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
400 builder.append(" PROPERTY_CONFERENCE");
401 }
402 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
403 builder.append(" PROPERTY_GENERIC_CONFERENCE");
404 }
405 if (hasProperty(properties, PROPERTY_WIFI)) {
406 builder.append(" PROPERTY_WIFI");
407 }
408 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
409 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
410 }
411 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700412 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700413 }
414 builder.append("]");
415 return builder.toString();
416 }
417
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800418 /** {@hide} */
419 public String getTelecomCallId() {
420 return mTelecomCallId;
421 }
422
Andrew Lee2378ea72015-04-29 14:38:11 -0700423 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700424 * @return The handle (e.g., phone number) to which the {@code Call} is currently
425 * connected.
426 */
427 public Uri getHandle() {
428 return mHandle;
429 }
430
431 /**
432 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700433 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700434 */
435 public int getHandlePresentation() {
436 return mHandlePresentation;
437 }
438
439 /**
440 * @return The display name for the caller.
441 */
442 public String getCallerDisplayName() {
443 return mCallerDisplayName;
444 }
445
446 /**
447 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700448 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700449 */
450 public int getCallerDisplayNamePresentation() {
451 return mCallerDisplayNamePresentation;
452 }
453
454 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700455 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
456 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700457 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700458 public PhoneAccountHandle getAccountHandle() {
459 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700460 }
461
462 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800463 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
464 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700465 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700466 public int getCallCapabilities() {
467 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700468 }
469
470 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700471 * @return A bitmask of the properties of the {@code Call}, as defined by the various
472 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700473 */
474 public int getCallProperties() {
475 return mCallProperties;
476 }
477
478 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700479 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700480 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700481 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700482 public DisconnectCause getDisconnectCause() {
483 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700484 }
485
486 /**
487 * @return The time the {@code Call} has been connected. This information is updated
488 * periodically, but user interfaces should not rely on this to display any "call time
489 * clock".
490 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700491 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700492 return mConnectTimeMillis;
493 }
494
495 /**
496 * @return Information about any calling gateway the {@code Call} may be using.
497 */
498 public GatewayInfo getGatewayInfo() {
499 return mGatewayInfo;
500 }
501
Andrew Lee7a341382014-07-15 17:05:08 -0700502 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700503 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700504 */
505 public int getVideoState() {
506 return mVideoState;
507 }
508
Ihab Awad5d0410f2014-07-30 10:07:40 -0700509 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700510 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700511 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700512 */
513 public StatusHints getStatusHints() {
514 return mStatusHints;
515 }
516
Nancy Chen10798dc2014-08-08 14:00:25 -0700517 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700518 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700519 */
520 public Bundle getExtras() {
521 return mExtras;
522 }
523
Santos Cordon6b7f9552015-05-27 17:21:45 -0700524 /**
525 * @return The extras used with the original intent to place this call.
526 */
527 public Bundle getIntentExtras() {
528 return mIntentExtras;
529 }
530
Ihab Awade63fadb2014-07-09 21:52:04 -0700531 @Override
532 public boolean equals(Object o) {
533 if (o instanceof Details) {
534 Details d = (Details) o;
535 return
536 Objects.equals(mHandle, d.mHandle) &&
537 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
538 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
539 Objects.equals(mCallerDisplayNamePresentation,
540 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700541 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700542 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700543 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700544 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700545 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700546 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700547 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700548 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700549 areBundlesEqual(mExtras, d.mExtras) &&
550 areBundlesEqual(mIntentExtras, d.mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700551 }
552 return false;
553 }
554
555 @Override
556 public int hashCode() {
557 return
558 Objects.hashCode(mHandle) +
559 Objects.hashCode(mHandlePresentation) +
560 Objects.hashCode(mCallerDisplayName) +
561 Objects.hashCode(mCallerDisplayNamePresentation) +
Evan Charlton8c8a0622014-07-20 12:31:00 -0700562 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700563 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700564 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700565 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700566 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700567 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700568 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700569 Objects.hashCode(mStatusHints) +
Santos Cordon6b7f9552015-05-27 17:21:45 -0700570 Objects.hashCode(mExtras) +
571 Objects.hashCode(mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700572 }
573
574 /** {@hide} */
575 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800576 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700577 Uri handle,
578 int handlePresentation,
579 String callerDisplayName,
580 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700581 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700582 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700583 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700584 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700585 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700586 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700587 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700588 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700589 Bundle extras,
590 Bundle intentExtras) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800591 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700592 mHandle = handle;
593 mHandlePresentation = handlePresentation;
594 mCallerDisplayName = callerDisplayName;
595 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700596 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700597 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700598 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700599 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700600 mConnectTimeMillis = connectTimeMillis;
601 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700602 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700603 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700604 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700605 mIntentExtras = intentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700606 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800607
608 /** {@hide} */
609 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
610 return new Details(
611 parcelableCall.getId(),
612 parcelableCall.getHandle(),
613 parcelableCall.getHandlePresentation(),
614 parcelableCall.getCallerDisplayName(),
615 parcelableCall.getCallerDisplayNamePresentation(),
616 parcelableCall.getAccountHandle(),
617 parcelableCall.getCapabilities(),
618 parcelableCall.getProperties(),
619 parcelableCall.getDisconnectCause(),
620 parcelableCall.getConnectTimeMillis(),
621 parcelableCall.getGatewayInfo(),
622 parcelableCall.getVideoState(),
623 parcelableCall.getStatusHints(),
624 parcelableCall.getExtras(),
625 parcelableCall.getIntentExtras());
626 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700627 }
628
Andrew Leeda80c872015-04-15 14:09:50 -0700629 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700630 /**
631 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
632 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700633 * @param call The {@code Call} invoking this method.
634 * @param state The new state of the {@code Call}.
635 */
636 public void onStateChanged(Call call, int state) {}
637
638 /**
639 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
640 *
641 * @param call The {@code Call} invoking this method.
642 * @param parent The new parent of the {@code Call}.
643 */
644 public void onParentChanged(Call call, Call parent) {}
645
646 /**
647 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
648 *
649 * @param call The {@code Call} invoking this method.
650 * @param children The new children of the {@code Call}.
651 */
652 public void onChildrenChanged(Call call, List<Call> children) {}
653
654 /**
655 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
656 *
657 * @param call The {@code Call} invoking this method.
658 * @param details A {@code Details} object describing the {@code Call}.
659 */
660 public void onDetailsChanged(Call call, Details details) {}
661
662 /**
663 * Invoked when the text messages that can be used as responses to the incoming
664 * {@code Call} are loaded from the relevant database.
665 * See {@link #getCannedTextResponses()}.
666 *
667 * @param call The {@code Call} invoking this method.
668 * @param cannedTextResponses The text messages useable as responses.
669 */
670 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
671
672 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700673 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
674 * character. This causes the post-dial signals to stop pending user confirmation. An
675 * implementation should present this choice to the user and invoke
676 * {@link #postDialContinue(boolean)} when the user makes the choice.
677 *
678 * @param call The {@code Call} invoking this method.
679 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
680 */
681 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
682
683 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700684 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700685 *
686 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700687 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700688 */
Andrew Lee50aca232014-07-22 16:41:54 -0700689 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700690
691 /**
692 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
693 * up their UI for the {@code Call} in response to state transitions. Specifically,
694 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
695 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
696 * clients should wait for this method to be invoked.
697 *
698 * @param call The {@code Call} being destroyed.
699 */
700 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700701
702 /**
703 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
704 * conferenced.
705 *
706 * @param call The {@code Call} being updated.
707 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
708 * conferenced.
709 */
710 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700711 }
712
Andrew Leeda80c872015-04-15 14:09:50 -0700713 /**
714 * @deprecated Use {@code Call.Callback} instead.
715 * @hide
716 */
717 @Deprecated
718 @SystemApi
719 public static abstract class Listener extends Callback { }
720
Ihab Awade63fadb2014-07-09 21:52:04 -0700721 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700722 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700723 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700724 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -0700725 private final List<Call> mChildren = new ArrayList<>();
726 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -0700727 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700728 private final List<Call> mConferenceableCalls = new ArrayList<>();
729 private final List<Call> mUnmodifiableConferenceableCalls =
730 Collections.unmodifiableList(mConferenceableCalls);
731
Santos Cordon823fd3c2014-08-07 18:35:18 -0700732 private boolean mChildrenCached;
733 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700734 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -0700735 private List<String> mCannedTextResponses = null;
736 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -0800737 private VideoCallImpl mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -0700738 private Details mDetails;
Ihab Awade63fadb2014-07-09 21:52:04 -0700739
740 /**
741 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
742 *
743 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
744 * remaining or this {@code Call} is not in a post-dial state.
745 */
746 public String getRemainingPostDialSequence() {
747 return mRemainingPostDialSequence;
748 }
749
750 /**
751 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700752 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -0700753 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700754 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700755 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700756 }
757
758 /**
759 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
760 *
761 * @param rejectWithMessage Whether to reject with a text message.
762 * @param textMessage An optional text message with which to respond.
763 */
764 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700765 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -0700766 }
767
768 /**
769 * Instructs this {@code Call} to disconnect.
770 */
771 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700772 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700773 }
774
775 /**
776 * Instructs this {@code Call} to go on hold.
777 */
778 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700779 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700780 }
781
782 /**
783 * Instructs this {@link #STATE_HOLDING} call to release from hold.
784 */
785 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700786 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700787 }
788
789 /**
790 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
791 *
792 * Any other currently playing DTMF tone in the specified call is immediately stopped.
793 *
794 * @param digit A character representing the DTMF digit for which to play the tone. This
795 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
796 */
797 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700798 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -0700799 }
800
801 /**
802 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
803 * currently playing.
804 *
805 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
806 * currently playing, this method will do nothing.
807 */
808 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700809 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700810 }
811
812 /**
813 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
814 *
815 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
816 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -0700817 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700818 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700819 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
820 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700821 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -0700822 * {@code Call} will pause playing the tones and notify callbacks via
823 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -0700824 * should display to the user an indication of this state and an affordance to continue
825 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
826 * app should invoke the {@link #postDialContinue(boolean)} method.
827 *
828 * @param proceed Whether or not to continue with the post-dial sequence.
829 */
830 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700831 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -0700832 }
833
834 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700835 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -0700836 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700837 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700838 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
839 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700840
841 }
842
843 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700844 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700845 *
846 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -0700847 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700848 public void conference(Call callToConferenceWith) {
849 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700850 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700851 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700852 }
853
854 /**
855 * Instructs this {@code Call} to split from any conference call with which it may be
856 * connected.
857 */
858 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700859 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700860 }
861
862 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800863 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700864 */
865 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700866 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700867 }
868
869 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800870 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700871 */
872 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700873 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700874 }
875
876 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700877 * Obtains the parent of this {@code Call} in a conference, if any.
878 *
879 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
880 * child of any conference {@code Call}s.
881 */
882 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700883 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700884 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700885 }
886 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -0700887 }
888
889 /**
890 * Obtains the children of this conference {@code Call}, if any.
891 *
892 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
893 * {@code List} otherwise.
894 */
895 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700896 if (!mChildrenCached) {
897 mChildrenCached = true;
898 mChildren.clear();
899
900 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700901 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700902 if (call == null) {
903 // At least one child was still not found, so do not save true for "cached"
904 mChildrenCached = false;
905 } else {
906 mChildren.add(call);
907 }
908 }
909 }
910
Ihab Awade63fadb2014-07-09 21:52:04 -0700911 return mUnmodifiableChildren;
912 }
913
914 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700915 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
916 *
917 * @return The list of conferenceable {@code Call}s.
918 */
919 public List<Call> getConferenceableCalls() {
920 return mUnmodifiableConferenceableCalls;
921 }
922
923 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700924 * Obtains the state of this {@code Call}.
925 *
926 * @return A state value, chosen from the {@code STATE_*} constants.
927 */
928 public int getState() {
929 return mState;
930 }
931
932 /**
933 * Obtains a list of canned, pre-configured message responses to present to the user as
934 * ways of rejecting this {@code Call} using via a text message.
935 *
936 * @see #reject(boolean, String)
937 *
938 * @return A list of canned text message responses.
939 */
940 public List<String> getCannedTextResponses() {
941 return mCannedTextResponses;
942 }
943
944 /**
945 * Obtains an object that can be used to display video from this {@code Call}.
946 *
Andrew Lee50aca232014-07-22 16:41:54 -0700947 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700948 */
Andrew Lee50aca232014-07-22 16:41:54 -0700949 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -0800950 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -0700951 }
952
953 /**
954 * Obtains an object containing call details.
955 *
956 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
957 * result may be {@code null}.
958 */
959 public Details getDetails() {
960 return mDetails;
961 }
962
963 /**
Andrew Leeda80c872015-04-15 14:09:50 -0700964 * Registers a callback to this {@code Call}.
965 *
966 * @param callback A {@code Callback}.
967 */
968 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700969 registerCallback(callback, new Handler());
970 }
971
972 /**
973 * Registers a callback to this {@code Call}.
974 *
975 * @param callback A {@code Callback}.
976 * @param handler A handler which command and status changes will be delivered to.
977 */
978 public void registerCallback(Callback callback, Handler handler) {
979 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -0700980 // Don't allow new callback registration if the call is already being destroyed.
981 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -0700982 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
983 }
Andrew Leeda80c872015-04-15 14:09:50 -0700984 }
985
986 /**
987 * Unregisters a callback from this {@code Call}.
988 *
989 * @param callback A {@code Callback}.
990 */
991 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -0700992 // Don't allow callback deregistration if the call is already being destroyed.
993 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -0700994 for (CallbackRecord<Callback> record : mCallbackRecords) {
995 if (record.getCallback() == callback) {
996 mCallbackRecords.remove(record);
997 break;
998 }
999 }
Andrew Leeda80c872015-04-15 14:09:50 -07001000 }
1001 }
1002
1003 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001004 * Adds a listener to this {@code Call}.
1005 *
1006 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001007 * @deprecated Use {@link #registerCallback} instead.
1008 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001009 */
Andrew Leeda80c872015-04-15 14:09:50 -07001010 @Deprecated
1011 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001012 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001013 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001014 }
1015
1016 /**
1017 * Removes a listener from this {@code Call}.
1018 *
1019 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001020 * @deprecated Use {@link #unregisterCallback} instead.
1021 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001022 */
Andrew Leeda80c872015-04-15 14:09:50 -07001023 @Deprecated
1024 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001025 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001026 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001027 }
1028
1029 /** {@hide} */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001030 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001031 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001032 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001033 mInCallAdapter = inCallAdapter;
1034 mState = STATE_NEW;
1035 }
1036
1037 /** {@hide} */
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001038 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state) {
1039 mPhone = phone;
1040 mTelecomCallId = telecomCallId;
1041 mInCallAdapter = inCallAdapter;
1042 mState = state;
1043 }
1044
1045 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001046 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001047 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001048 }
1049
1050 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001051 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001052 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001053 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001054 boolean detailsChanged = !Objects.equals(mDetails, details);
1055 if (detailsChanged) {
1056 mDetails = details;
1057 }
1058
1059 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001060 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1061 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1062 mCannedTextResponses =
1063 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001064 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001065 }
1066
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001067 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl();
Tyler Gunn75958422015-04-15 14:23:42 -07001068 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001069 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001070 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001071 mVideoCallImpl = newVideoCallImpl;
1072 }
1073 if (mVideoCallImpl != null) {
1074 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001075 }
1076
Santos Cordone3c507b2015-04-23 14:44:19 -07001077 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001078 boolean stateChanged = mState != state;
1079 if (stateChanged) {
1080 mState = state;
1081 }
1082
Santos Cordon823fd3c2014-08-07 18:35:18 -07001083 String parentId = parcelableCall.getParentCallId();
1084 boolean parentChanged = !Objects.equals(mParentId, parentId);
1085 if (parentChanged) {
1086 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001087 }
1088
Santos Cordon823fd3c2014-08-07 18:35:18 -07001089 List<String> childCallIds = parcelableCall.getChildCallIds();
1090 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1091 if (childrenChanged) {
1092 mChildrenIds.clear();
1093 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1094 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001095 }
1096
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001097 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1098 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1099 for (String otherId : conferenceableCallIds) {
1100 if (callIdMap.containsKey(otherId)) {
1101 conferenceableCalls.add(callIdMap.get(otherId));
1102 }
1103 }
1104
1105 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1106 mConferenceableCalls.clear();
1107 mConferenceableCalls.addAll(conferenceableCalls);
1108 fireConferenceableCallsChanged();
1109 }
1110
Ihab Awade63fadb2014-07-09 21:52:04 -07001111 // Now we fire updates, ensuring that any client who listens to any of these notifications
1112 // gets the most up-to-date state.
1113
1114 if (stateChanged) {
1115 fireStateChanged(mState);
1116 }
1117 if (detailsChanged) {
1118 fireDetailsChanged(mDetails);
1119 }
1120 if (cannedTextResponsesChanged) {
1121 fireCannedTextResponsesLoaded(mCannedTextResponses);
1122 }
Andrew Lee50aca232014-07-22 16:41:54 -07001123 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001124 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001125 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001126 if (parentChanged) {
1127 fireParentChanged(getParent());
1128 }
1129 if (childrenChanged) {
1130 fireChildrenChanged(getChildren());
1131 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001132
1133 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1134 // remove ourselves from the Phone. Note that we do this after completing all state updates
1135 // so a client can cleanly transition all their UI to the state appropriate for a
1136 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1137 if (mState == STATE_DISCONNECTED) {
1138 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001139 }
1140 }
1141
1142 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001143 final void internalSetPostDialWait(String remaining) {
1144 mRemainingPostDialSequence = remaining;
1145 firePostDialWait(mRemainingPostDialSequence);
1146 }
1147
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001148 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001149 final void internalSetDisconnected() {
1150 if (mState != Call.STATE_DISCONNECTED) {
1151 mState = Call.STATE_DISCONNECTED;
1152 fireStateChanged(mState);
1153 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001154 }
1155 }
1156
Andrew Lee011728f2015-04-23 15:47:06 -07001157 private void fireStateChanged(final int newState) {
1158 for (CallbackRecord<Callback> record : mCallbackRecords) {
1159 final Call call = this;
1160 final Callback callback = record.getCallback();
1161 record.getHandler().post(new Runnable() {
1162 @Override
1163 public void run() {
1164 callback.onStateChanged(call, newState);
1165 }
1166 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001167 }
1168 }
1169
Andrew Lee011728f2015-04-23 15:47:06 -07001170 private void fireParentChanged(final Call newParent) {
1171 for (CallbackRecord<Callback> record : mCallbackRecords) {
1172 final Call call = this;
1173 final Callback callback = record.getCallback();
1174 record.getHandler().post(new Runnable() {
1175 @Override
1176 public void run() {
1177 callback.onParentChanged(call, newParent);
1178 }
1179 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001180 }
1181 }
1182
Andrew Lee011728f2015-04-23 15:47:06 -07001183 private void fireChildrenChanged(final List<Call> children) {
1184 for (CallbackRecord<Callback> record : mCallbackRecords) {
1185 final Call call = this;
1186 final Callback callback = record.getCallback();
1187 record.getHandler().post(new Runnable() {
1188 @Override
1189 public void run() {
1190 callback.onChildrenChanged(call, children);
1191 }
1192 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001193 }
1194 }
1195
Andrew Lee011728f2015-04-23 15:47:06 -07001196 private void fireDetailsChanged(final Details details) {
1197 for (CallbackRecord<Callback> record : mCallbackRecords) {
1198 final Call call = this;
1199 final Callback callback = record.getCallback();
1200 record.getHandler().post(new Runnable() {
1201 @Override
1202 public void run() {
1203 callback.onDetailsChanged(call, details);
1204 }
1205 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001206 }
1207 }
1208
Andrew Lee011728f2015-04-23 15:47:06 -07001209 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1210 for (CallbackRecord<Callback> record : mCallbackRecords) {
1211 final Call call = this;
1212 final Callback callback = record.getCallback();
1213 record.getHandler().post(new Runnable() {
1214 @Override
1215 public void run() {
1216 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1217 }
1218 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001219 }
1220 }
1221
Andrew Lee011728f2015-04-23 15:47:06 -07001222 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1223 for (CallbackRecord<Callback> record : mCallbackRecords) {
1224 final Call call = this;
1225 final Callback callback = record.getCallback();
1226 record.getHandler().post(new Runnable() {
1227 @Override
1228 public void run() {
1229 callback.onVideoCallChanged(call, videoCall);
1230 }
1231 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001232 }
1233 }
1234
Andrew Lee011728f2015-04-23 15:47:06 -07001235 private void firePostDialWait(final String remainingPostDialSequence) {
1236 for (CallbackRecord<Callback> record : mCallbackRecords) {
1237 final Call call = this;
1238 final Callback callback = record.getCallback();
1239 record.getHandler().post(new Runnable() {
1240 @Override
1241 public void run() {
1242 callback.onPostDialWait(call, remainingPostDialSequence);
1243 }
1244 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001245 }
1246 }
1247
1248 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001249 /**
1250 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1251 * onCallRemoved callback, we remove this call from the Phone's record
1252 * only once all of the registered onCallDestroyed callbacks are executed.
1253 * All the callbacks get removed from our records as a part of this operation
1254 * since onCallDestroyed is the final callback.
1255 */
1256 final Call call = this;
1257 if (mCallbackRecords.isEmpty()) {
1258 // No callbacks registered, remove the call from Phone's record.
1259 mPhone.internalRemoveCall(call);
1260 }
1261 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001262 final Callback callback = record.getCallback();
1263 record.getHandler().post(new Runnable() {
1264 @Override
1265 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001266 boolean isFinalRemoval = false;
1267 RuntimeException toThrow = null;
1268 try {
1269 callback.onCallDestroyed(call);
1270 } catch (RuntimeException e) {
1271 toThrow = e;
1272 }
1273 synchronized(Call.this) {
1274 mCallbackRecords.remove(record);
1275 if (mCallbackRecords.isEmpty()) {
1276 isFinalRemoval = true;
1277 }
1278 }
1279 if (isFinalRemoval) {
1280 mPhone.internalRemoveCall(call);
1281 }
1282 if (toThrow != null) {
1283 throw toThrow;
1284 }
Andrew Lee011728f2015-04-23 15:47:06 -07001285 }
1286 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001287 }
1288 }
1289
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001290 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001291 for (CallbackRecord<Callback> record : mCallbackRecords) {
1292 final Call call = this;
1293 final Callback callback = record.getCallback();
1294 record.getHandler().post(new Runnable() {
1295 @Override
1296 public void run() {
1297 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1298 }
1299 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001300 }
1301 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001302
1303 /**
1304 * Determines if two bundles are equal.
1305 *
1306 * @param bundle The original bundle.
1307 * @param newBundle The bundle to compare with.
1308 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1309 */
1310 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1311 if (bundle == null || newBundle == null) {
1312 return bundle == newBundle;
1313 }
1314
1315 if (bundle.size() != newBundle.size()) {
1316 return false;
1317 }
1318
1319 for(String key : bundle.keySet()) {
1320 if (key != null) {
1321 final Object value = bundle.get(key);
1322 final Object newValue = newBundle.get(key);
1323 if (!Objects.equals(value, newValue)) {
1324 return false;
1325 }
1326 }
1327 }
1328 return true;
1329 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001330}