blob: 10808da8785ee9e0a8bd2a99343f0628f8e30893 [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 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800627
628 @Override
629 public String toString() {
630 StringBuilder sb = new StringBuilder();
631 sb.append("[pa: ");
632 sb.append(mAccountHandle);
633 sb.append(", hdl: ");
634 sb.append(Log.pii(mHandle));
635 sb.append(", caps: ");
636 sb.append(capabilitiesToString(mCallCapabilities));
637 sb.append(", props: ");
638 sb.append(mCallProperties);
639 sb.append("]");
640 return sb.toString();
641 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700642 }
643
Andrew Leeda80c872015-04-15 14:09:50 -0700644 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700645 /**
646 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
647 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700648 * @param call The {@code Call} invoking this method.
649 * @param state The new state of the {@code Call}.
650 */
651 public void onStateChanged(Call call, int state) {}
652
653 /**
654 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
655 *
656 * @param call The {@code Call} invoking this method.
657 * @param parent The new parent of the {@code Call}.
658 */
659 public void onParentChanged(Call call, Call parent) {}
660
661 /**
662 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
663 *
664 * @param call The {@code Call} invoking this method.
665 * @param children The new children of the {@code Call}.
666 */
667 public void onChildrenChanged(Call call, List<Call> children) {}
668
669 /**
670 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
671 *
672 * @param call The {@code Call} invoking this method.
673 * @param details A {@code Details} object describing the {@code Call}.
674 */
675 public void onDetailsChanged(Call call, Details details) {}
676
677 /**
678 * Invoked when the text messages that can be used as responses to the incoming
679 * {@code Call} are loaded from the relevant database.
680 * See {@link #getCannedTextResponses()}.
681 *
682 * @param call The {@code Call} invoking this method.
683 * @param cannedTextResponses The text messages useable as responses.
684 */
685 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
686
687 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700688 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
689 * character. This causes the post-dial signals to stop pending user confirmation. An
690 * implementation should present this choice to the user and invoke
691 * {@link #postDialContinue(boolean)} when the user makes the choice.
692 *
693 * @param call The {@code Call} invoking this method.
694 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
695 */
696 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
697
698 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700699 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700700 *
701 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700702 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700703 */
Andrew Lee50aca232014-07-22 16:41:54 -0700704 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700705
706 /**
707 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
708 * up their UI for the {@code Call} in response to state transitions. Specifically,
709 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
710 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
711 * clients should wait for this method to be invoked.
712 *
713 * @param call The {@code Call} being destroyed.
714 */
715 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700716
717 /**
718 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
719 * conferenced.
720 *
721 * @param call The {@code Call} being updated.
722 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
723 * conferenced.
724 */
725 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700726 }
727
Andrew Leeda80c872015-04-15 14:09:50 -0700728 /**
729 * @deprecated Use {@code Call.Callback} instead.
730 * @hide
731 */
732 @Deprecated
733 @SystemApi
734 public static abstract class Listener extends Callback { }
735
Ihab Awade63fadb2014-07-09 21:52:04 -0700736 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700737 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700738 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700739 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -0700740 private final List<Call> mChildren = new ArrayList<>();
741 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -0700742 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700743 private final List<Call> mConferenceableCalls = new ArrayList<>();
744 private final List<Call> mUnmodifiableConferenceableCalls =
745 Collections.unmodifiableList(mConferenceableCalls);
746
Santos Cordon823fd3c2014-08-07 18:35:18 -0700747 private boolean mChildrenCached;
748 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700749 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -0700750 private List<String> mCannedTextResponses = null;
751 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -0800752 private VideoCallImpl mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -0700753 private Details mDetails;
Ihab Awade63fadb2014-07-09 21:52:04 -0700754
755 /**
756 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
757 *
758 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
759 * remaining or this {@code Call} is not in a post-dial state.
760 */
761 public String getRemainingPostDialSequence() {
762 return mRemainingPostDialSequence;
763 }
764
765 /**
766 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700767 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -0700768 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700769 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700770 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700771 }
772
773 /**
774 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
775 *
776 * @param rejectWithMessage Whether to reject with a text message.
777 * @param textMessage An optional text message with which to respond.
778 */
779 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700780 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -0700781 }
782
783 /**
784 * Instructs this {@code Call} to disconnect.
785 */
786 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700787 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700788 }
789
790 /**
791 * Instructs this {@code Call} to go on hold.
792 */
793 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700794 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700795 }
796
797 /**
798 * Instructs this {@link #STATE_HOLDING} call to release from hold.
799 */
800 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700801 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700802 }
803
804 /**
805 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
806 *
807 * Any other currently playing DTMF tone in the specified call is immediately stopped.
808 *
809 * @param digit A character representing the DTMF digit for which to play the tone. This
810 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
811 */
812 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700813 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -0700814 }
815
816 /**
817 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
818 * currently playing.
819 *
820 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
821 * currently playing, this method will do nothing.
822 */
823 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700824 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700825 }
826
827 /**
828 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
829 *
830 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
831 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -0700832 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700833 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700834 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
835 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700836 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -0700837 * {@code Call} will pause playing the tones and notify callbacks via
838 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -0700839 * should display to the user an indication of this state and an affordance to continue
840 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
841 * app should invoke the {@link #postDialContinue(boolean)} method.
842 *
843 * @param proceed Whether or not to continue with the post-dial sequence.
844 */
845 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700846 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -0700847 }
848
849 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700850 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -0700851 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700852 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700853 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
854 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700855
856 }
857
858 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700859 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700860 *
861 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -0700862 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700863 public void conference(Call callToConferenceWith) {
864 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700865 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700866 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700867 }
868
869 /**
870 * Instructs this {@code Call} to split from any conference call with which it may be
871 * connected.
872 */
873 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700874 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700875 }
876
877 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800878 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700879 */
880 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700881 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700882 }
883
884 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800885 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700886 */
887 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700888 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700889 }
890
891 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700892 * Obtains the parent of this {@code Call} in a conference, if any.
893 *
894 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
895 * child of any conference {@code Call}s.
896 */
897 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700898 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700899 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700900 }
901 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -0700902 }
903
904 /**
905 * Obtains the children of this conference {@code Call}, if any.
906 *
907 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
908 * {@code List} otherwise.
909 */
910 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700911 if (!mChildrenCached) {
912 mChildrenCached = true;
913 mChildren.clear();
914
915 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700916 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700917 if (call == null) {
918 // At least one child was still not found, so do not save true for "cached"
919 mChildrenCached = false;
920 } else {
921 mChildren.add(call);
922 }
923 }
924 }
925
Ihab Awade63fadb2014-07-09 21:52:04 -0700926 return mUnmodifiableChildren;
927 }
928
929 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700930 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
931 *
932 * @return The list of conferenceable {@code Call}s.
933 */
934 public List<Call> getConferenceableCalls() {
935 return mUnmodifiableConferenceableCalls;
936 }
937
938 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700939 * Obtains the state of this {@code Call}.
940 *
941 * @return A state value, chosen from the {@code STATE_*} constants.
942 */
943 public int getState() {
944 return mState;
945 }
946
947 /**
948 * Obtains a list of canned, pre-configured message responses to present to the user as
949 * ways of rejecting this {@code Call} using via a text message.
950 *
951 * @see #reject(boolean, String)
952 *
953 * @return A list of canned text message responses.
954 */
955 public List<String> getCannedTextResponses() {
956 return mCannedTextResponses;
957 }
958
959 /**
960 * Obtains an object that can be used to display video from this {@code Call}.
961 *
Andrew Lee50aca232014-07-22 16:41:54 -0700962 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700963 */
Andrew Lee50aca232014-07-22 16:41:54 -0700964 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -0800965 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -0700966 }
967
968 /**
969 * Obtains an object containing call details.
970 *
971 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
972 * result may be {@code null}.
973 */
974 public Details getDetails() {
975 return mDetails;
976 }
977
978 /**
Andrew Leeda80c872015-04-15 14:09:50 -0700979 * Registers a callback to this {@code Call}.
980 *
981 * @param callback A {@code Callback}.
982 */
983 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700984 registerCallback(callback, new Handler());
985 }
986
987 /**
988 * Registers a callback to this {@code Call}.
989 *
990 * @param callback A {@code Callback}.
991 * @param handler A handler which command and status changes will be delivered to.
992 */
993 public void registerCallback(Callback callback, Handler handler) {
994 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -0700995 // Don't allow new callback registration if the call is already being destroyed.
996 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -0700997 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
998 }
Andrew Leeda80c872015-04-15 14:09:50 -0700999 }
1000
1001 /**
1002 * Unregisters a callback from this {@code Call}.
1003 *
1004 * @param callback A {@code Callback}.
1005 */
1006 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001007 // Don't allow callback deregistration if the call is already being destroyed.
1008 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001009 for (CallbackRecord<Callback> record : mCallbackRecords) {
1010 if (record.getCallback() == callback) {
1011 mCallbackRecords.remove(record);
1012 break;
1013 }
1014 }
Andrew Leeda80c872015-04-15 14:09:50 -07001015 }
1016 }
1017
Santos Cordon3c20d632016-02-25 16:12:35 -08001018 @Override
1019 public String toString() {
1020 return new StringBuilder().
1021 append("Call [id: ").
1022 append(mTelecomCallId).
1023 append(", state: ").
1024 append(stateToString(mState)).
1025 append(", details: ").
1026 append(mDetails).
1027 append("]").toString();
1028 }
1029
1030 /**
1031 * @param state An integer value of a {@code STATE_*} constant.
1032 * @return A string representation of the value.
1033 */
1034 private static String stateToString(int state) {
1035 switch (state) {
1036 case STATE_NEW:
1037 return "NEW";
1038 case STATE_RINGING:
1039 return "RINGING";
1040 case STATE_DIALING:
1041 return "DIALING";
1042 case STATE_ACTIVE:
1043 return "ACTIVE";
1044 case STATE_HOLDING:
1045 return "HOLDING";
1046 case STATE_DISCONNECTED:
1047 return "DISCONNECTED";
1048 case STATE_CONNECTING:
1049 return "CONNECTING";
1050 case STATE_DISCONNECTING:
1051 return "DISCONNECTING";
1052 case STATE_SELECT_PHONE_ACCOUNT:
1053 return "SELECT_PHONE_ACCOUNT";
1054 default:
1055 Log.w(Call.class, "Unknown state %d", state);
1056 return "UNKNOWN";
1057 }
1058 }
1059
Andrew Leeda80c872015-04-15 14:09:50 -07001060 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001061 * Adds a listener to this {@code Call}.
1062 *
1063 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001064 * @deprecated Use {@link #registerCallback} instead.
1065 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001066 */
Andrew Leeda80c872015-04-15 14:09:50 -07001067 @Deprecated
1068 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001069 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001070 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001071 }
1072
1073 /**
1074 * Removes a listener from this {@code Call}.
1075 *
1076 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001077 * @deprecated Use {@link #unregisterCallback} instead.
1078 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001079 */
Andrew Leeda80c872015-04-15 14:09:50 -07001080 @Deprecated
1081 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001082 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001083 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001084 }
1085
1086 /** {@hide} */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001087 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001088 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001089 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001090 mInCallAdapter = inCallAdapter;
1091 mState = STATE_NEW;
1092 }
1093
1094 /** {@hide} */
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001095 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state) {
1096 mPhone = phone;
1097 mTelecomCallId = telecomCallId;
1098 mInCallAdapter = inCallAdapter;
1099 mState = state;
1100 }
1101
1102 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001103 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001104 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001105 }
1106
1107 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001108 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001109 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001110 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001111 boolean detailsChanged = !Objects.equals(mDetails, details);
1112 if (detailsChanged) {
1113 mDetails = details;
1114 }
1115
1116 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001117 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1118 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1119 mCannedTextResponses =
1120 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001121 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001122 }
1123
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001124 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl();
Tyler Gunn75958422015-04-15 14:23:42 -07001125 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001126 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001127 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001128 mVideoCallImpl = newVideoCallImpl;
1129 }
1130 if (mVideoCallImpl != null) {
1131 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001132 }
1133
Santos Cordone3c507b2015-04-23 14:44:19 -07001134 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001135 boolean stateChanged = mState != state;
1136 if (stateChanged) {
1137 mState = state;
1138 }
1139
Santos Cordon823fd3c2014-08-07 18:35:18 -07001140 String parentId = parcelableCall.getParentCallId();
1141 boolean parentChanged = !Objects.equals(mParentId, parentId);
1142 if (parentChanged) {
1143 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001144 }
1145
Santos Cordon823fd3c2014-08-07 18:35:18 -07001146 List<String> childCallIds = parcelableCall.getChildCallIds();
1147 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1148 if (childrenChanged) {
1149 mChildrenIds.clear();
1150 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1151 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001152 }
1153
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001154 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1155 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1156 for (String otherId : conferenceableCallIds) {
1157 if (callIdMap.containsKey(otherId)) {
1158 conferenceableCalls.add(callIdMap.get(otherId));
1159 }
1160 }
1161
1162 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1163 mConferenceableCalls.clear();
1164 mConferenceableCalls.addAll(conferenceableCalls);
1165 fireConferenceableCallsChanged();
1166 }
1167
Ihab Awade63fadb2014-07-09 21:52:04 -07001168 // Now we fire updates, ensuring that any client who listens to any of these notifications
1169 // gets the most up-to-date state.
1170
1171 if (stateChanged) {
1172 fireStateChanged(mState);
1173 }
1174 if (detailsChanged) {
1175 fireDetailsChanged(mDetails);
1176 }
1177 if (cannedTextResponsesChanged) {
1178 fireCannedTextResponsesLoaded(mCannedTextResponses);
1179 }
Andrew Lee50aca232014-07-22 16:41:54 -07001180 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001181 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001182 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001183 if (parentChanged) {
1184 fireParentChanged(getParent());
1185 }
1186 if (childrenChanged) {
1187 fireChildrenChanged(getChildren());
1188 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001189
1190 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1191 // remove ourselves from the Phone. Note that we do this after completing all state updates
1192 // so a client can cleanly transition all their UI to the state appropriate for a
1193 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1194 if (mState == STATE_DISCONNECTED) {
1195 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001196 }
1197 }
1198
1199 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001200 final void internalSetPostDialWait(String remaining) {
1201 mRemainingPostDialSequence = remaining;
1202 firePostDialWait(mRemainingPostDialSequence);
1203 }
1204
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001205 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001206 final void internalSetDisconnected() {
1207 if (mState != Call.STATE_DISCONNECTED) {
1208 mState = Call.STATE_DISCONNECTED;
1209 fireStateChanged(mState);
1210 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001211 }
1212 }
1213
Andrew Lee011728f2015-04-23 15:47:06 -07001214 private void fireStateChanged(final int newState) {
1215 for (CallbackRecord<Callback> record : mCallbackRecords) {
1216 final Call call = this;
1217 final Callback callback = record.getCallback();
1218 record.getHandler().post(new Runnable() {
1219 @Override
1220 public void run() {
1221 callback.onStateChanged(call, newState);
1222 }
1223 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001224 }
1225 }
1226
Andrew Lee011728f2015-04-23 15:47:06 -07001227 private void fireParentChanged(final Call newParent) {
1228 for (CallbackRecord<Callback> record : mCallbackRecords) {
1229 final Call call = this;
1230 final Callback callback = record.getCallback();
1231 record.getHandler().post(new Runnable() {
1232 @Override
1233 public void run() {
1234 callback.onParentChanged(call, newParent);
1235 }
1236 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001237 }
1238 }
1239
Andrew Lee011728f2015-04-23 15:47:06 -07001240 private void fireChildrenChanged(final List<Call> children) {
1241 for (CallbackRecord<Callback> record : mCallbackRecords) {
1242 final Call call = this;
1243 final Callback callback = record.getCallback();
1244 record.getHandler().post(new Runnable() {
1245 @Override
1246 public void run() {
1247 callback.onChildrenChanged(call, children);
1248 }
1249 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001250 }
1251 }
1252
Andrew Lee011728f2015-04-23 15:47:06 -07001253 private void fireDetailsChanged(final Details details) {
1254 for (CallbackRecord<Callback> record : mCallbackRecords) {
1255 final Call call = this;
1256 final Callback callback = record.getCallback();
1257 record.getHandler().post(new Runnable() {
1258 @Override
1259 public void run() {
1260 callback.onDetailsChanged(call, details);
1261 }
1262 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001263 }
1264 }
1265
Andrew Lee011728f2015-04-23 15:47:06 -07001266 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1267 for (CallbackRecord<Callback> record : mCallbackRecords) {
1268 final Call call = this;
1269 final Callback callback = record.getCallback();
1270 record.getHandler().post(new Runnable() {
1271 @Override
1272 public void run() {
1273 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1274 }
1275 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001276 }
1277 }
1278
Andrew Lee011728f2015-04-23 15:47:06 -07001279 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1280 for (CallbackRecord<Callback> record : mCallbackRecords) {
1281 final Call call = this;
1282 final Callback callback = record.getCallback();
1283 record.getHandler().post(new Runnable() {
1284 @Override
1285 public void run() {
1286 callback.onVideoCallChanged(call, videoCall);
1287 }
1288 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001289 }
1290 }
1291
Andrew Lee011728f2015-04-23 15:47:06 -07001292 private void firePostDialWait(final String remainingPostDialSequence) {
1293 for (CallbackRecord<Callback> record : mCallbackRecords) {
1294 final Call call = this;
1295 final Callback callback = record.getCallback();
1296 record.getHandler().post(new Runnable() {
1297 @Override
1298 public void run() {
1299 callback.onPostDialWait(call, remainingPostDialSequence);
1300 }
1301 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001302 }
1303 }
1304
1305 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001306 /**
1307 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1308 * onCallRemoved callback, we remove this call from the Phone's record
1309 * only once all of the registered onCallDestroyed callbacks are executed.
1310 * All the callbacks get removed from our records as a part of this operation
1311 * since onCallDestroyed is the final callback.
1312 */
1313 final Call call = this;
1314 if (mCallbackRecords.isEmpty()) {
1315 // No callbacks registered, remove the call from Phone's record.
1316 mPhone.internalRemoveCall(call);
1317 }
1318 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001319 final Callback callback = record.getCallback();
1320 record.getHandler().post(new Runnable() {
1321 @Override
1322 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001323 boolean isFinalRemoval = false;
1324 RuntimeException toThrow = null;
1325 try {
1326 callback.onCallDestroyed(call);
1327 } catch (RuntimeException e) {
1328 toThrow = e;
1329 }
1330 synchronized(Call.this) {
1331 mCallbackRecords.remove(record);
1332 if (mCallbackRecords.isEmpty()) {
1333 isFinalRemoval = true;
1334 }
1335 }
1336 if (isFinalRemoval) {
1337 mPhone.internalRemoveCall(call);
1338 }
1339 if (toThrow != null) {
1340 throw toThrow;
1341 }
Andrew Lee011728f2015-04-23 15:47:06 -07001342 }
1343 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001344 }
1345 }
1346
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001347 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001348 for (CallbackRecord<Callback> record : mCallbackRecords) {
1349 final Call call = this;
1350 final Callback callback = record.getCallback();
1351 record.getHandler().post(new Runnable() {
1352 @Override
1353 public void run() {
1354 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1355 }
1356 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001357 }
1358 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001359
1360 /**
1361 * Determines if two bundles are equal.
1362 *
1363 * @param bundle The original bundle.
1364 * @param newBundle The bundle to compare with.
1365 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1366 */
1367 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1368 if (bundle == null || newBundle == null) {
1369 return bundle == newBundle;
1370 }
1371
1372 if (bundle.size() != newBundle.size()) {
1373 return false;
1374 }
1375
1376 for(String key : bundle.keySet()) {
1377 if (key != null) {
1378 final Object value = bundle.get(key);
1379 final Object newValue = newBundle.get(key);
1380 if (!Objects.equals(value, newValue)) {
1381 return false;
1382 }
1383 }
1384 }
1385 return true;
1386 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001387}