blob: e756a577613f130532ddc240e536c3084b8c8715 [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;
Andrew Lee011728f2015-04-23 15:47:06 -070027import java.util.LinkedList;
Ihab Awade63fadb2014-07-09 21:52:04 -070028import 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 /**
Nancy Chen513c8922014-09-17 14:47:20 -070099 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
100 * extras. Used to pass the phone accounts to display on the front end to the user in order to
101 * select phone accounts to (for example) place a call.
Nancy Chen513c8922014-09-17 14:47:20 -0700102 */
103 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
104
Ihab Awade63fadb2014-07-09 21:52:04 -0700105 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800106
107 /** Call can currently be put on hold or unheld. */
108 public static final int CAPABILITY_HOLD = 0x00000001;
109
110 /** Call supports the hold feature. */
111 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
112
113 /**
114 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
115 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
116 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
117 * capability allows a merge button to be shown while the conference call is in the foreground
118 * of the in-call UI.
119 * <p>
120 * This is only intended for use by a {@link Conference}.
121 */
122 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
123
124 /**
125 * Calls within a conference can be swapped between foreground and background.
126 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
127 * <p>
128 * This is only intended for use by a {@link Conference}.
129 */
130 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
131
132 /**
133 * @hide
134 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700135 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800136
137 /** Call supports responding via text option. */
138 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
139
140 /** Call can be muted. */
141 public static final int CAPABILITY_MUTE = 0x00000040;
142
143 /**
144 * Call supports conference call management. This capability only applies to {@link Conference}
145 * calls which can have {@link Connection}s as children.
146 */
147 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
148
149 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700150 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800151 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700152 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800153
154 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700155 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800156 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700157 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800158
159 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700160 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800161 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700162 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700163 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800164
165 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700166 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800167 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700168 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
169
170 /**
171 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700172 */
173 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
174
175 /**
176 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700177 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700178 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700179 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800180
181 /**
182 * Call is able to be separated from its parent {@code Conference}, if any.
183 */
184 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
185
186 /**
187 * Call is able to be individually disconnected when in a {@code Conference}.
188 */
189 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
190
191 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500192 * Speed up audio setup for MT call.
193 * @hide
194 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700195 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
196
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700197 /**
198 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700199 * @hide
200 */
201 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
202
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700203 /**
204 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700205 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700206 */
207 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
208
Tyler Gunnd11a3152015-03-18 13:09:14 -0700209 //******************************************************************************************
Andrew Lee2378ea72015-04-29 14:38:11 -0700210 // Next CAPABILITY value: 0x00004000
211 //******************************************************************************************
212
213 /**
214 * Whether the call is currently a conference.
215 */
216 public static final int PROPERTY_CONFERENCE = 0x00000001;
217
218 /**
219 * Whether the call is a generic conference, where we do not know the precise state of
220 * participants in the conference (eg. on CDMA).
221 */
222 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
223
224 /**
225 * Whether the call is made while the device is in emergency callback mode.
226 */
227 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
228
229 /**
230 * Connection is using WIFI.
231 */
232 public static final int PROPERTY_WIFI = 0x00000008;
233
234 /**
235 * Call is using high definition audio.
236 */
237 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
238
239 //******************************************************************************************
240 // Next PROPERTY value: 0x00000020
Tyler Gunnd11a3152015-03-18 13:09:14 -0700241 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800242
Ihab Awade63fadb2014-07-09 21:52:04 -0700243 private final Uri mHandle;
244 private final int mHandlePresentation;
245 private final String mCallerDisplayName;
246 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700247 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700248 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700249 private final int mCallProperties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700250 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700251 private final long mConnectTimeMillis;
252 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700253 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700254 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700255 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700256 private final Bundle mIntentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700257
258 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800259 * Whether the supplied capabilities supports the specified capability.
260 *
261 * @param capabilities A bit field of capabilities.
262 * @param capability The capability to check capabilities for.
263 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800264 */
265 public static boolean can(int capabilities, int capability) {
266 return (capabilities & capability) != 0;
267 }
268
269 /**
270 * Whether the capabilities of this {@code Details} supports the specified capability.
271 *
272 * @param capability The capability to check capabilities for.
273 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800274 */
275 public boolean can(int capability) {
276 return can(mCallCapabilities, capability);
277 }
278
279 /**
280 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
281 *
282 * @param capabilities A capability bit field.
283 * @return A human readable string representation.
284 */
285 public static String capabilitiesToString(int capabilities) {
286 StringBuilder builder = new StringBuilder();
287 builder.append("[Capabilities:");
288 if (can(capabilities, CAPABILITY_HOLD)) {
289 builder.append(" CAPABILITY_HOLD");
290 }
291 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
292 builder.append(" CAPABILITY_SUPPORT_HOLD");
293 }
294 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
295 builder.append(" CAPABILITY_MERGE_CONFERENCE");
296 }
297 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
298 builder.append(" CAPABILITY_SWAP_CONFERENCE");
299 }
300 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
301 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
302 }
303 if (can(capabilities, CAPABILITY_MUTE)) {
304 builder.append(" CAPABILITY_MUTE");
305 }
306 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
307 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
308 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700309 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
310 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
311 }
312 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
313 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
314 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700315 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
316 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800317 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700318 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
319 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
320 }
321 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
322 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
323 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700324 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
325 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800326 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500327 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700328 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500329 }
Rekha Kumar07366812015-03-24 16:42:31 -0700330 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
331 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
332 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700333 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
334 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
335 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800336 builder.append("]");
337 return builder.toString();
338 }
339
340 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700341 * Whether the supplied properties includes the specified property.
342 *
343 * @param properties A bit field of properties.
344 * @param property The property to check properties for.
345 * @return Whether the specified property is supported.
346 */
347 public static boolean hasProperty(int properties, int property) {
348 return (properties & property) != 0;
349 }
350
351 /**
352 * Whether the properties of this {@code Details} includes the specified property.
353 *
354 * @param property The property to check properties for.
355 * @return Whether the specified property is supported.
356 */
357 public boolean hasProperty(int property) {
358 return hasProperty(mCallProperties, property);
359 }
360
361 /**
362 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
363 *
364 * @param properties A property bit field.
365 * @return A human readable string representation.
366 */
367 public static String propertiesToString(int properties) {
368 StringBuilder builder = new StringBuilder();
369 builder.append("[Properties:");
370 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
371 builder.append(" PROPERTY_CONFERENCE");
372 }
373 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
374 builder.append(" PROPERTY_GENERIC_CONFERENCE");
375 }
376 if (hasProperty(properties, PROPERTY_WIFI)) {
377 builder.append(" PROPERTY_WIFI");
378 }
379 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
380 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
381 }
382 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700383 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700384 }
385 builder.append("]");
386 return builder.toString();
387 }
388
389 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700390 * @return The handle (e.g., phone number) to which the {@code Call} is currently
391 * connected.
392 */
393 public Uri getHandle() {
394 return mHandle;
395 }
396
397 /**
398 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700399 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700400 */
401 public int getHandlePresentation() {
402 return mHandlePresentation;
403 }
404
405 /**
406 * @return The display name for the caller.
407 */
408 public String getCallerDisplayName() {
409 return mCallerDisplayName;
410 }
411
412 /**
413 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700414 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700415 */
416 public int getCallerDisplayNamePresentation() {
417 return mCallerDisplayNamePresentation;
418 }
419
420 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700421 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
422 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700423 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700424 public PhoneAccountHandle getAccountHandle() {
425 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700426 }
427
428 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800429 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
430 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700431 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700432 public int getCallCapabilities() {
433 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700434 }
435
436 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700437 * @return A bitmask of the properties of the {@code Call}, as defined by the various
438 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700439 */
440 public int getCallProperties() {
441 return mCallProperties;
442 }
443
444 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700445 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700446 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700447 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700448 public DisconnectCause getDisconnectCause() {
449 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700450 }
451
452 /**
453 * @return The time the {@code Call} has been connected. This information is updated
454 * periodically, but user interfaces should not rely on this to display any "call time
455 * clock".
456 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700457 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700458 return mConnectTimeMillis;
459 }
460
461 /**
462 * @return Information about any calling gateway the {@code Call} may be using.
463 */
464 public GatewayInfo getGatewayInfo() {
465 return mGatewayInfo;
466 }
467
Andrew Lee7a341382014-07-15 17:05:08 -0700468 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700469 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700470 */
471 public int getVideoState() {
472 return mVideoState;
473 }
474
Ihab Awad5d0410f2014-07-30 10:07:40 -0700475 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700476 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700477 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700478 */
479 public StatusHints getStatusHints() {
480 return mStatusHints;
481 }
482
Nancy Chen10798dc2014-08-08 14:00:25 -0700483 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700484 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700485 */
486 public Bundle getExtras() {
487 return mExtras;
488 }
489
Santos Cordon6b7f9552015-05-27 17:21:45 -0700490 /**
491 * @return The extras used with the original intent to place this call.
492 */
493 public Bundle getIntentExtras() {
494 return mIntentExtras;
495 }
496
Ihab Awade63fadb2014-07-09 21:52:04 -0700497 @Override
498 public boolean equals(Object o) {
499 if (o instanceof Details) {
500 Details d = (Details) o;
501 return
502 Objects.equals(mHandle, d.mHandle) &&
503 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
504 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
505 Objects.equals(mCallerDisplayNamePresentation,
506 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700507 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700508 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700509 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700510 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700511 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700512 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700513 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700514 Objects.equals(mStatusHints, d.mStatusHints) &&
Santos Cordon6b7f9552015-05-27 17:21:45 -0700515 Objects.equals(mExtras, d.mExtras) &&
516 Objects.equals(mIntentExtras, d.mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700517 }
518 return false;
519 }
520
521 @Override
522 public int hashCode() {
523 return
524 Objects.hashCode(mHandle) +
525 Objects.hashCode(mHandlePresentation) +
526 Objects.hashCode(mCallerDisplayName) +
527 Objects.hashCode(mCallerDisplayNamePresentation) +
Evan Charlton8c8a0622014-07-20 12:31:00 -0700528 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700529 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700530 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700531 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700532 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700533 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700534 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700535 Objects.hashCode(mStatusHints) +
Santos Cordon6b7f9552015-05-27 17:21:45 -0700536 Objects.hashCode(mExtras) +
537 Objects.hashCode(mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700538 }
539
540 /** {@hide} */
541 public Details(
542 Uri handle,
543 int handlePresentation,
544 String callerDisplayName,
545 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700546 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700547 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700548 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700549 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700550 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700551 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700552 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700553 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700554 Bundle extras,
555 Bundle intentExtras) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700556 mHandle = handle;
557 mHandlePresentation = handlePresentation;
558 mCallerDisplayName = callerDisplayName;
559 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700560 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700561 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700562 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700563 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700564 mConnectTimeMillis = connectTimeMillis;
565 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700566 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700567 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700568 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700569 mIntentExtras = intentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700570 }
571 }
572
Andrew Leeda80c872015-04-15 14:09:50 -0700573 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700574 /**
575 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
576 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700577 * @param call The {@code Call} invoking this method.
578 * @param state The new state of the {@code Call}.
579 */
580 public void onStateChanged(Call call, int state) {}
581
582 /**
583 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
584 *
585 * @param call The {@code Call} invoking this method.
586 * @param parent The new parent of the {@code Call}.
587 */
588 public void onParentChanged(Call call, Call parent) {}
589
590 /**
591 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
592 *
593 * @param call The {@code Call} invoking this method.
594 * @param children The new children of the {@code Call}.
595 */
596 public void onChildrenChanged(Call call, List<Call> children) {}
597
598 /**
599 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
600 *
601 * @param call The {@code Call} invoking this method.
602 * @param details A {@code Details} object describing the {@code Call}.
603 */
604 public void onDetailsChanged(Call call, Details details) {}
605
606 /**
607 * Invoked when the text messages that can be used as responses to the incoming
608 * {@code Call} are loaded from the relevant database.
609 * See {@link #getCannedTextResponses()}.
610 *
611 * @param call The {@code Call} invoking this method.
612 * @param cannedTextResponses The text messages useable as responses.
613 */
614 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
615
616 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700617 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
618 * character. This causes the post-dial signals to stop pending user confirmation. An
619 * implementation should present this choice to the user and invoke
620 * {@link #postDialContinue(boolean)} when the user makes the choice.
621 *
622 * @param call The {@code Call} invoking this method.
623 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
624 */
625 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
626
627 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700628 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700629 *
630 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700631 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700632 */
Andrew Lee50aca232014-07-22 16:41:54 -0700633 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700634
635 /**
636 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
637 * up their UI for the {@code Call} in response to state transitions. Specifically,
638 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
639 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
640 * clients should wait for this method to be invoked.
641 *
642 * @param call The {@code Call} being destroyed.
643 */
644 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700645
646 /**
647 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
648 * conferenced.
649 *
650 * @param call The {@code Call} being updated.
651 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
652 * conferenced.
653 */
654 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700655 }
656
Andrew Leeda80c872015-04-15 14:09:50 -0700657 /**
658 * @deprecated Use {@code Call.Callback} instead.
659 * @hide
660 */
661 @Deprecated
662 @SystemApi
663 public static abstract class Listener extends Callback { }
664
Ihab Awade63fadb2014-07-09 21:52:04 -0700665 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700666 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700667 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700668 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -0700669 private final List<Call> mChildren = new ArrayList<>();
670 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -0700671 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700672 private final List<Call> mConferenceableCalls = new ArrayList<>();
673 private final List<Call> mUnmodifiableConferenceableCalls =
674 Collections.unmodifiableList(mConferenceableCalls);
675
Santos Cordon823fd3c2014-08-07 18:35:18 -0700676 private boolean mChildrenCached;
677 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700678 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -0700679 private List<String> mCannedTextResponses = null;
680 private String mRemainingPostDialSequence;
Andrew Lee50aca232014-07-22 16:41:54 -0700681 private InCallService.VideoCall mVideoCall;
Ihab Awade63fadb2014-07-09 21:52:04 -0700682 private Details mDetails;
Ihab Awade63fadb2014-07-09 21:52:04 -0700683
684 /**
685 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
686 *
687 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
688 * remaining or this {@code Call} is not in a post-dial state.
689 */
690 public String getRemainingPostDialSequence() {
691 return mRemainingPostDialSequence;
692 }
693
694 /**
695 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700696 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -0700697 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700698 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700699 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700700 }
701
702 /**
703 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
704 *
705 * @param rejectWithMessage Whether to reject with a text message.
706 * @param textMessage An optional text message with which to respond.
707 */
708 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700709 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -0700710 }
711
712 /**
713 * Instructs this {@code Call} to disconnect.
714 */
715 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700716 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700717 }
718
719 /**
720 * Instructs this {@code Call} to go on hold.
721 */
722 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700723 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700724 }
725
726 /**
727 * Instructs this {@link #STATE_HOLDING} call to release from hold.
728 */
729 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700730 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700731 }
732
733 /**
734 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
735 *
736 * Any other currently playing DTMF tone in the specified call is immediately stopped.
737 *
738 * @param digit A character representing the DTMF digit for which to play the tone. This
739 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
740 */
741 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700742 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -0700743 }
744
745 /**
746 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
747 * currently playing.
748 *
749 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
750 * currently playing, this method will do nothing.
751 */
752 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700753 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700754 }
755
756 /**
757 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
758 *
759 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
760 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -0700761 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700762 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700763 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
764 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700765 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -0700766 * {@code Call} will pause playing the tones and notify callbacks via
767 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -0700768 * should display to the user an indication of this state and an affordance to continue
769 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
770 * app should invoke the {@link #postDialContinue(boolean)} method.
771 *
772 * @param proceed Whether or not to continue with the post-dial sequence.
773 */
774 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700775 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -0700776 }
777
778 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700779 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -0700780 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700781 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700782 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
783 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700784
785 }
786
787 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700788 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700789 *
790 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -0700791 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700792 public void conference(Call callToConferenceWith) {
793 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700794 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700795 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700796 }
797
798 /**
799 * Instructs this {@code Call} to split from any conference call with which it may be
800 * connected.
801 */
802 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700803 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700804 }
805
806 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800807 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700808 */
809 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700810 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700811 }
812
813 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800814 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700815 */
816 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700817 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700818 }
819
820 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700821 * Obtains the parent of this {@code Call} in a conference, if any.
822 *
823 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
824 * child of any conference {@code Call}s.
825 */
826 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700827 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700828 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700829 }
830 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -0700831 }
832
833 /**
834 * Obtains the children of this conference {@code Call}, if any.
835 *
836 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
837 * {@code List} otherwise.
838 */
839 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700840 if (!mChildrenCached) {
841 mChildrenCached = true;
842 mChildren.clear();
843
844 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700845 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700846 if (call == null) {
847 // At least one child was still not found, so do not save true for "cached"
848 mChildrenCached = false;
849 } else {
850 mChildren.add(call);
851 }
852 }
853 }
854
Ihab Awade63fadb2014-07-09 21:52:04 -0700855 return mUnmodifiableChildren;
856 }
857
858 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700859 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
860 *
861 * @return The list of conferenceable {@code Call}s.
862 */
863 public List<Call> getConferenceableCalls() {
864 return mUnmodifiableConferenceableCalls;
865 }
866
867 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700868 * Obtains the state of this {@code Call}.
869 *
870 * @return A state value, chosen from the {@code STATE_*} constants.
871 */
872 public int getState() {
873 return mState;
874 }
875
876 /**
877 * Obtains a list of canned, pre-configured message responses to present to the user as
878 * ways of rejecting this {@code Call} using via a text message.
879 *
880 * @see #reject(boolean, String)
881 *
882 * @return A list of canned text message responses.
883 */
884 public List<String> getCannedTextResponses() {
885 return mCannedTextResponses;
886 }
887
888 /**
889 * Obtains an object that can be used to display video from this {@code Call}.
890 *
Andrew Lee50aca232014-07-22 16:41:54 -0700891 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700892 */
Andrew Lee50aca232014-07-22 16:41:54 -0700893 public InCallService.VideoCall getVideoCall() {
894 return mVideoCall;
Ihab Awade63fadb2014-07-09 21:52:04 -0700895 }
896
897 /**
898 * Obtains an object containing call details.
899 *
900 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
901 * result may be {@code null}.
902 */
903 public Details getDetails() {
904 return mDetails;
905 }
906
907 /**
Andrew Leeda80c872015-04-15 14:09:50 -0700908 * Registers a callback to this {@code Call}.
909 *
910 * @param callback A {@code Callback}.
911 */
912 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700913 registerCallback(callback, new Handler());
914 }
915
916 /**
917 * Registers a callback to this {@code Call}.
918 *
919 * @param callback A {@code Callback}.
920 * @param handler A handler which command and status changes will be delivered to.
921 */
922 public void registerCallback(Callback callback, Handler handler) {
923 unregisterCallback(callback);
924 if (callback != null && handler != null) {
925 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
926 }
Andrew Leeda80c872015-04-15 14:09:50 -0700927 }
928
929 /**
930 * Unregisters a callback from this {@code Call}.
931 *
932 * @param callback A {@code Callback}.
933 */
934 public void unregisterCallback(Callback callback) {
935 if (callback != null) {
Andrew Lee011728f2015-04-23 15:47:06 -0700936 for (CallbackRecord<Callback> record : mCallbackRecords) {
937 if (record.getCallback() == callback) {
938 mCallbackRecords.remove(record);
939 break;
940 }
941 }
Andrew Leeda80c872015-04-15 14:09:50 -0700942 }
943 }
944
945 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700946 * Adds a listener to this {@code Call}.
947 *
948 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -0700949 * @deprecated Use {@link #registerCallback} instead.
950 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -0700951 */
Andrew Leeda80c872015-04-15 14:09:50 -0700952 @Deprecated
953 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -0700954 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -0700955 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -0700956 }
957
958 /**
959 * Removes a listener from this {@code Call}.
960 *
961 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -0700962 * @deprecated Use {@link #unregisterCallback} instead.
963 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -0700964 */
Andrew Leeda80c872015-04-15 14:09:50 -0700965 @Deprecated
966 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -0700967 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -0700968 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -0700969 }
970
Andrew Leeda80c872015-04-15 14:09:50 -0700971
Ihab Awade63fadb2014-07-09 21:52:04 -0700972 /** {@hide} */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700973 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700974 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700975 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700976 mInCallAdapter = inCallAdapter;
977 mState = STATE_NEW;
978 }
979
980 /** {@hide} */
981 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700982 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700983 }
984
985 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700986 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700987 // First, we update the internal state as far as possible before firing any updates.
Ihab Awade63fadb2014-07-09 21:52:04 -0700988 Details details = new Details(
Santos Cordon88b771d2014-07-19 13:10:40 -0700989 parcelableCall.getHandle(),
990 parcelableCall.getHandlePresentation(),
991 parcelableCall.getCallerDisplayName(),
992 parcelableCall.getCallerDisplayNamePresentation(),
993 parcelableCall.getAccountHandle(),
994 parcelableCall.getCapabilities(),
Andrew Lee223ad142014-08-27 16:33:08 -0700995 parcelableCall.getProperties(),
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700996 parcelableCall.getDisconnectCause(),
Santos Cordon88b771d2014-07-19 13:10:40 -0700997 parcelableCall.getConnectTimeMillis(),
998 parcelableCall.getGatewayInfo(),
999 parcelableCall.getVideoState(),
Nancy Chen10798dc2014-08-08 14:00:25 -07001000 parcelableCall.getStatusHints(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001001 parcelableCall.getExtras(),
1002 parcelableCall.getIntentExtras());
Ihab Awade63fadb2014-07-09 21:52:04 -07001003 boolean detailsChanged = !Objects.equals(mDetails, details);
1004 if (detailsChanged) {
1005 mDetails = details;
1006 }
1007
1008 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001009 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1010 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1011 mCannedTextResponses =
1012 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Ihab Awade63fadb2014-07-09 21:52:04 -07001013 }
1014
Tyler Gunn75958422015-04-15 14:23:42 -07001015 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn45382162015-05-06 08:52:27 -07001016 !Objects.equals(mVideoCall, parcelableCall.getVideoCall(this));
Andrew Lee50aca232014-07-22 16:41:54 -07001017 if (videoCallChanged) {
Tyler Gunn45382162015-05-06 08:52:27 -07001018 mVideoCall = parcelableCall.getVideoCall(this);
Ihab Awade63fadb2014-07-09 21:52:04 -07001019 }
1020
Santos Cordone3c507b2015-04-23 14:44:19 -07001021 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001022 boolean stateChanged = mState != state;
1023 if (stateChanged) {
1024 mState = state;
1025 }
1026
Santos Cordon823fd3c2014-08-07 18:35:18 -07001027 String parentId = parcelableCall.getParentCallId();
1028 boolean parentChanged = !Objects.equals(mParentId, parentId);
1029 if (parentChanged) {
1030 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001031 }
1032
Santos Cordon823fd3c2014-08-07 18:35:18 -07001033 List<String> childCallIds = parcelableCall.getChildCallIds();
1034 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1035 if (childrenChanged) {
1036 mChildrenIds.clear();
1037 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1038 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001039 }
1040
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001041 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1042 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1043 for (String otherId : conferenceableCallIds) {
1044 if (callIdMap.containsKey(otherId)) {
1045 conferenceableCalls.add(callIdMap.get(otherId));
1046 }
1047 }
1048
1049 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1050 mConferenceableCalls.clear();
1051 mConferenceableCalls.addAll(conferenceableCalls);
1052 fireConferenceableCallsChanged();
1053 }
1054
Ihab Awade63fadb2014-07-09 21:52:04 -07001055 // Now we fire updates, ensuring that any client who listens to any of these notifications
1056 // gets the most up-to-date state.
1057
1058 if (stateChanged) {
1059 fireStateChanged(mState);
1060 }
1061 if (detailsChanged) {
1062 fireDetailsChanged(mDetails);
1063 }
1064 if (cannedTextResponsesChanged) {
1065 fireCannedTextResponsesLoaded(mCannedTextResponses);
1066 }
Andrew Lee50aca232014-07-22 16:41:54 -07001067 if (videoCallChanged) {
1068 fireVideoCallChanged(mVideoCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001069 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001070 if (parentChanged) {
1071 fireParentChanged(getParent());
1072 }
1073 if (childrenChanged) {
1074 fireChildrenChanged(getChildren());
1075 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001076
1077 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1078 // remove ourselves from the Phone. Note that we do this after completing all state updates
1079 // so a client can cleanly transition all their UI to the state appropriate for a
1080 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1081 if (mState == STATE_DISCONNECTED) {
1082 fireCallDestroyed();
1083 mPhone.internalRemoveCall(this);
1084 }
1085 }
1086
1087 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001088 final void internalSetPostDialWait(String remaining) {
1089 mRemainingPostDialSequence = remaining;
1090 firePostDialWait(mRemainingPostDialSequence);
1091 }
1092
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001093 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001094 final void internalSetDisconnected() {
1095 if (mState != Call.STATE_DISCONNECTED) {
1096 mState = Call.STATE_DISCONNECTED;
1097 fireStateChanged(mState);
1098 fireCallDestroyed();
1099 mPhone.internalRemoveCall(this);
1100 }
1101 }
1102
Andrew Lee011728f2015-04-23 15:47:06 -07001103 private void fireStateChanged(final int newState) {
1104 for (CallbackRecord<Callback> record : mCallbackRecords) {
1105 final Call call = this;
1106 final Callback callback = record.getCallback();
1107 record.getHandler().post(new Runnable() {
1108 @Override
1109 public void run() {
1110 callback.onStateChanged(call, newState);
1111 }
1112 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001113 }
1114 }
1115
Andrew Lee011728f2015-04-23 15:47:06 -07001116 private void fireParentChanged(final Call newParent) {
1117 for (CallbackRecord<Callback> record : mCallbackRecords) {
1118 final Call call = this;
1119 final Callback callback = record.getCallback();
1120 record.getHandler().post(new Runnable() {
1121 @Override
1122 public void run() {
1123 callback.onParentChanged(call, newParent);
1124 }
1125 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001126 }
1127 }
1128
Andrew Lee011728f2015-04-23 15:47:06 -07001129 private void fireChildrenChanged(final List<Call> children) {
1130 for (CallbackRecord<Callback> record : mCallbackRecords) {
1131 final Call call = this;
1132 final Callback callback = record.getCallback();
1133 record.getHandler().post(new Runnable() {
1134 @Override
1135 public void run() {
1136 callback.onChildrenChanged(call, children);
1137 }
1138 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001139 }
1140 }
1141
Andrew Lee011728f2015-04-23 15:47:06 -07001142 private void fireDetailsChanged(final Details details) {
1143 for (CallbackRecord<Callback> record : mCallbackRecords) {
1144 final Call call = this;
1145 final Callback callback = record.getCallback();
1146 record.getHandler().post(new Runnable() {
1147 @Override
1148 public void run() {
1149 callback.onDetailsChanged(call, details);
1150 }
1151 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001152 }
1153 }
1154
Andrew Lee011728f2015-04-23 15:47:06 -07001155 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1156 for (CallbackRecord<Callback> record : mCallbackRecords) {
1157 final Call call = this;
1158 final Callback callback = record.getCallback();
1159 record.getHandler().post(new Runnable() {
1160 @Override
1161 public void run() {
1162 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1163 }
1164 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001165 }
1166 }
1167
Andrew Lee011728f2015-04-23 15:47:06 -07001168 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1169 for (CallbackRecord<Callback> record : mCallbackRecords) {
1170 final Call call = this;
1171 final Callback callback = record.getCallback();
1172 record.getHandler().post(new Runnable() {
1173 @Override
1174 public void run() {
1175 callback.onVideoCallChanged(call, videoCall);
1176 }
1177 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001178 }
1179 }
1180
Andrew Lee011728f2015-04-23 15:47:06 -07001181 private void firePostDialWait(final String remainingPostDialSequence) {
1182 for (CallbackRecord<Callback> record : mCallbackRecords) {
1183 final Call call = this;
1184 final Callback callback = record.getCallback();
1185 record.getHandler().post(new Runnable() {
1186 @Override
1187 public void run() {
1188 callback.onPostDialWait(call, remainingPostDialSequence);
1189 }
1190 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001191 }
1192 }
1193
1194 private void fireCallDestroyed() {
Andrew Lee011728f2015-04-23 15:47:06 -07001195 for (CallbackRecord<Callback> record: mCallbackRecords) {
1196 final Call call = this;
1197 final Callback callback = record.getCallback();
1198 record.getHandler().post(new Runnable() {
1199 @Override
1200 public void run() {
1201 callback.onCallDestroyed(call);
1202 }
1203 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001204 }
1205 }
1206
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001207 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001208 for (CallbackRecord<Callback> record : mCallbackRecords) {
1209 final Call call = this;
1210 final Callback callback = record.getCallback();
1211 record.getHandler().post(new Runnable() {
1212 @Override
1213 public void run() {
1214 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1215 }
1216 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001217 }
1218 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001219}