blob: f129c33936c9af96c9707b883dbc8637823f3c37 [file] [log] [blame]
Ihab Awade63fadb2014-07-09 21:52:04 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awade63fadb2014-07-09 21:52:04 -070018
Andrew Leeda80c872015-04-15 14:09:50 -070019import android.annotation.SystemApi;
Ihab Awade63fadb2014-07-09 21:52:04 -070020import android.net.Uri;
Nancy Chen10798dc2014-08-08 14:00:25 -070021import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070022import android.os.Handler;
Ihab Awade63fadb2014-07-09 21:52:04 -070023
Andrew Lee50aca232014-07-22 16:41:54 -070024import java.lang.String;
Ihab Awade63fadb2014-07-09 21:52:04 -070025import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070026import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070027import java.util.Collections;
28import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070029import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070030import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070031import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070032
33/**
34 * Represents an ongoing phone call that the in-call app should present to the user.
35 */
36public final class Call {
37 /**
38 * The state of a {@code Call} when newly created.
39 */
40 public static final int STATE_NEW = 0;
41
42 /**
43 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
44 */
45 public static final int STATE_DIALING = 1;
46
47 /**
48 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
49 */
50 public static final int STATE_RINGING = 2;
51
52 /**
53 * The state of a {@code Call} when in a holding state.
54 */
55 public static final int STATE_HOLDING = 3;
56
57 /**
58 * The state of a {@code Call} when actively supporting conversation.
59 */
60 public static final int STATE_ACTIVE = 4;
61
62 /**
63 * The state of a {@code Call} when no further voice or other communication is being
64 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
65 * is no longer active, and the local data transport has or inevitably will release resources
66 * associated with this {@code Call}.
67 */
68 public static final int STATE_DISCONNECTED = 7;
69
Nancy Chen5da0fd52014-07-08 14:16:17 -070070 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070071 * The state of an outgoing {@code Call} when waiting on user to select a
72 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070073 */
Santos Cordone3c507b2015-04-23 14:44:19 -070074 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
75
76 /**
77 * @hide
78 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
79 */
80 @Deprecated
81 @SystemApi
82 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070083
Nancy Chene20930f2014-08-07 16:17:21 -070084 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070085 * The initial state of an outgoing {@code Call}.
86 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
87 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070088 */
89 public static final int STATE_CONNECTING = 9;
90
Nancy Chen513c8922014-09-17 14:47:20 -070091 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -070092 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
93 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
94 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
95 */
96 public static final int STATE_DISCONNECTING = 10;
97
98 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -070099 * The state of an external call which is in the process of being pulled from a remote device to
100 * the local device.
101 * <p>
102 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
103 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
104 * <p>
105 * An {@link InCallService} will only see this state if it has the
106 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
107 * manifest.
108 */
109 public static final int STATE_PULLING_CALL = 11;
110
111 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700112 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
113 * extras. Used to pass the phone accounts to display on the front end to the user in order to
114 * select phone accounts to (for example) place a call.
Nancy Chen513c8922014-09-17 14:47:20 -0700115 */
116 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
117
Ihab Awade63fadb2014-07-09 21:52:04 -0700118 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800119
120 /** Call can currently be put on hold or unheld. */
121 public static final int CAPABILITY_HOLD = 0x00000001;
122
123 /** Call supports the hold feature. */
124 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
125
126 /**
127 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
128 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
129 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
130 * capability allows a merge button to be shown while the conference call is in the foreground
131 * of the in-call UI.
132 * <p>
133 * This is only intended for use by a {@link Conference}.
134 */
135 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
136
137 /**
138 * Calls within a conference can be swapped between foreground and background.
139 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
140 * <p>
141 * This is only intended for use by a {@link Conference}.
142 */
143 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
144
145 /**
146 * @hide
147 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700148 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800149
150 /** Call supports responding via text option. */
151 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
152
153 /** Call can be muted. */
154 public static final int CAPABILITY_MUTE = 0x00000040;
155
156 /**
157 * Call supports conference call management. This capability only applies to {@link Conference}
158 * calls which can have {@link Connection}s as children.
159 */
160 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
161
162 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700163 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800164 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700165 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800166
167 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700168 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800169 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700170 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800171
172 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700173 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800174 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700175 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700176 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800177
178 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700179 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800180 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700181 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
182
183 /**
184 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700185 */
186 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
187
188 /**
189 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700190 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700191 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700192 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800193
194 /**
195 * Call is able to be separated from its parent {@code Conference}, if any.
196 */
197 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
198
199 /**
200 * Call is able to be individually disconnected when in a {@code Conference}.
201 */
202 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
203
204 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500205 * Speed up audio setup for MT call.
206 * @hide
207 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700208 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
209
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700210 /**
211 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700212 * @hide
213 */
214 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
215
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700216 /**
217 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700218 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700219 */
220 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
221
Bryce Lee81901682015-08-28 16:38:02 -0700222 /**
223 * Call sends responses through connection.
224 * @hide
225 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800226 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
227
228 /**
229 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
230 * <p>
231 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
232 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
233 * downgraded from a video call back to a VideoState of
234 * {@link VideoProfile#STATE_AUDIO_ONLY}.
235 * <p>
236 * Intuitively, a call which can be downgraded to audio should also have local and remote
237 * video
238 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
239 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
240 */
241 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700242
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700243 /**
244 * When set for an external call, indicates that this {@code Call} can be pulled from a
245 * remote device to the current device.
246 * <p>
247 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
248 * <p>
249 * An {@link InCallService} will only see calls with this capability if it has the
250 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
251 * in its manifest.
252 * <p>
253 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700254 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700255 */
256 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
257
Tyler Gunnd11a3152015-03-18 13:09:14 -0700258 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700259 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700260 //******************************************************************************************
261
262 /**
263 * Whether the call is currently a conference.
264 */
265 public static final int PROPERTY_CONFERENCE = 0x00000001;
266
267 /**
268 * Whether the call is a generic conference, where we do not know the precise state of
269 * participants in the conference (eg. on CDMA).
270 */
271 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
272
273 /**
274 * Whether the call is made while the device is in emergency callback mode.
275 */
276 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
277
278 /**
279 * Connection is using WIFI.
280 */
281 public static final int PROPERTY_WIFI = 0x00000008;
282
283 /**
284 * Call is using high definition audio.
285 */
286 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
287
Tony Maka68dcce2015-12-17 09:31:18 +0000288 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100289 * Whether the call is associated with the work profile.
290 */
291 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
292
293 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700294 * When set, indicates that this {@code Call} does not actually exist locally for the
295 * {@link ConnectionService}.
296 * <p>
297 * Consider, for example, a scenario where a user has two phones with the same phone number.
298 * When a user places a call on one device, the telephony stack can represent that call on
299 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700300 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700301 * <p>
302 * An {@link InCallService} will only see calls with this property if it has the
303 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
304 * in its manifest.
305 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700306 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700307 */
308 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
309
Brad Ebinger15847072016-05-18 11:08:36 -0700310 /**
311 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
312 */
313 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
314
Tyler Gunn24e18332017-02-10 09:42:49 -0800315 /**
316 * Indicates that the call is from a self-managed {@link ConnectionService}.
317 * <p>
318 * See also {@link Connection#PROPERTY_SELF_MANAGED}
319 */
320 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
321
Andrew Lee2378ea72015-04-29 14:38:11 -0700322 //******************************************************************************************
Tyler Gunn24e18332017-02-10 09:42:49 -0800323 // Next PROPERTY value: 0x00000200
Tyler Gunnd11a3152015-03-18 13:09:14 -0700324 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800325
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800326 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700327 private final Uri mHandle;
328 private final int mHandlePresentation;
329 private final String mCallerDisplayName;
330 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700331 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700332 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700333 private final int mCallProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800334 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700335 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700336 private final long mConnectTimeMillis;
337 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700338 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700339 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700340 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700341 private final Bundle mIntentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700342
343 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800344 * Whether the supplied capabilities supports the specified capability.
345 *
346 * @param capabilities A bit field of capabilities.
347 * @param capability The capability to check capabilities for.
348 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800349 */
350 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800351 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800352 }
353
354 /**
355 * Whether the capabilities of this {@code Details} supports the specified capability.
356 *
357 * @param capability The capability to check capabilities for.
358 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800359 */
360 public boolean can(int capability) {
361 return can(mCallCapabilities, capability);
362 }
363
364 /**
365 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
366 *
367 * @param capabilities A capability bit field.
368 * @return A human readable string representation.
369 */
370 public static String capabilitiesToString(int capabilities) {
371 StringBuilder builder = new StringBuilder();
372 builder.append("[Capabilities:");
373 if (can(capabilities, CAPABILITY_HOLD)) {
374 builder.append(" CAPABILITY_HOLD");
375 }
376 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
377 builder.append(" CAPABILITY_SUPPORT_HOLD");
378 }
379 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
380 builder.append(" CAPABILITY_MERGE_CONFERENCE");
381 }
382 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
383 builder.append(" CAPABILITY_SWAP_CONFERENCE");
384 }
385 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
386 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
387 }
388 if (can(capabilities, CAPABILITY_MUTE)) {
389 builder.append(" CAPABILITY_MUTE");
390 }
391 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
392 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
393 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700394 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
395 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
396 }
397 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
398 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
399 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700400 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
401 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800402 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700403 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
404 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
405 }
406 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
407 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
408 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800409 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
410 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
411 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700412 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
413 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800414 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500415 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700416 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500417 }
Rekha Kumar07366812015-03-24 16:42:31 -0700418 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
419 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
420 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700421 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
422 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
423 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700424 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
425 builder.append(" CAPABILITY_CAN_PULL_CALL");
426 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800427 builder.append("]");
428 return builder.toString();
429 }
430
431 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700432 * Whether the supplied properties includes the specified property.
433 *
434 * @param properties A bit field of properties.
435 * @param property The property to check properties for.
436 * @return Whether the specified property is supported.
437 */
438 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800439 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700440 }
441
442 /**
443 * Whether the properties of this {@code Details} includes the specified property.
444 *
445 * @param property The property to check properties for.
446 * @return Whether the specified property is supported.
447 */
448 public boolean hasProperty(int property) {
449 return hasProperty(mCallProperties, property);
450 }
451
452 /**
453 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
454 *
455 * @param properties A property bit field.
456 * @return A human readable string representation.
457 */
458 public static String propertiesToString(int properties) {
459 StringBuilder builder = new StringBuilder();
460 builder.append("[Properties:");
461 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
462 builder.append(" PROPERTY_CONFERENCE");
463 }
464 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
465 builder.append(" PROPERTY_GENERIC_CONFERENCE");
466 }
467 if (hasProperty(properties, PROPERTY_WIFI)) {
468 builder.append(" PROPERTY_WIFI");
469 }
470 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
471 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
472 }
473 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700474 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700475 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700476 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
477 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
478 }
Brad Ebinger15847072016-05-18 11:08:36 -0700479 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
480 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
481 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700482 builder.append("]");
483 return builder.toString();
484 }
485
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800486 /** {@hide} */
487 public String getTelecomCallId() {
488 return mTelecomCallId;
489 }
490
Andrew Lee2378ea72015-04-29 14:38:11 -0700491 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700492 * @return The handle (e.g., phone number) to which the {@code Call} is currently
493 * connected.
494 */
495 public Uri getHandle() {
496 return mHandle;
497 }
498
499 /**
500 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700501 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700502 */
503 public int getHandlePresentation() {
504 return mHandlePresentation;
505 }
506
507 /**
508 * @return The display name for the caller.
509 */
510 public String getCallerDisplayName() {
511 return mCallerDisplayName;
512 }
513
514 /**
515 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700516 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700517 */
518 public int getCallerDisplayNamePresentation() {
519 return mCallerDisplayNamePresentation;
520 }
521
522 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700523 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
524 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700525 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700526 public PhoneAccountHandle getAccountHandle() {
527 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700528 }
529
530 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800531 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
532 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700533 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700534 public int getCallCapabilities() {
535 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700536 }
537
538 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700539 * @return A bitmask of the properties of the {@code Call}, as defined by the various
540 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700541 */
542 public int getCallProperties() {
543 return mCallProperties;
544 }
545
546 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800547 * @return a bitmask of the audio routes available for the call.
548 *
549 * @hide
550 */
551 public int getSupportedAudioRoutes() {
552 return mSupportedAudioRoutes;
553 }
554
555 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700556 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700557 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700558 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700559 public DisconnectCause getDisconnectCause() {
560 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700561 }
562
563 /**
564 * @return The time the {@code Call} has been connected. This information is updated
565 * periodically, but user interfaces should not rely on this to display any "call time
566 * clock".
567 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700568 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700569 return mConnectTimeMillis;
570 }
571
572 /**
573 * @return Information about any calling gateway the {@code Call} may be using.
574 */
575 public GatewayInfo getGatewayInfo() {
576 return mGatewayInfo;
577 }
578
Andrew Lee7a341382014-07-15 17:05:08 -0700579 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700580 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700581 */
582 public int getVideoState() {
583 return mVideoState;
584 }
585
Ihab Awad5d0410f2014-07-30 10:07:40 -0700586 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700587 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700588 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700589 */
590 public StatusHints getStatusHints() {
591 return mStatusHints;
592 }
593
Nancy Chen10798dc2014-08-08 14:00:25 -0700594 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700595 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700596 */
597 public Bundle getExtras() {
598 return mExtras;
599 }
600
Santos Cordon6b7f9552015-05-27 17:21:45 -0700601 /**
602 * @return The extras used with the original intent to place this call.
603 */
604 public Bundle getIntentExtras() {
605 return mIntentExtras;
606 }
607
Ihab Awade63fadb2014-07-09 21:52:04 -0700608 @Override
609 public boolean equals(Object o) {
610 if (o instanceof Details) {
611 Details d = (Details) o;
612 return
613 Objects.equals(mHandle, d.mHandle) &&
614 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
615 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
616 Objects.equals(mCallerDisplayNamePresentation,
617 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700618 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700619 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700620 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700621 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700622 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700623 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700624 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700625 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700626 areBundlesEqual(mExtras, d.mExtras) &&
627 areBundlesEqual(mIntentExtras, d.mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700628 }
629 return false;
630 }
631
632 @Override
633 public int hashCode() {
634 return
635 Objects.hashCode(mHandle) +
636 Objects.hashCode(mHandlePresentation) +
637 Objects.hashCode(mCallerDisplayName) +
638 Objects.hashCode(mCallerDisplayNamePresentation) +
Evan Charlton8c8a0622014-07-20 12:31:00 -0700639 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700640 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700641 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700642 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700643 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700644 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700645 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700646 Objects.hashCode(mStatusHints) +
Santos Cordon6b7f9552015-05-27 17:21:45 -0700647 Objects.hashCode(mExtras) +
648 Objects.hashCode(mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700649 }
650
651 /** {@hide} */
652 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800653 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700654 Uri handle,
655 int handlePresentation,
656 String callerDisplayName,
657 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700658 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700659 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700660 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700661 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700662 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700663 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700664 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700665 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700666 Bundle extras,
667 Bundle intentExtras) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800668 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700669 mHandle = handle;
670 mHandlePresentation = handlePresentation;
671 mCallerDisplayName = callerDisplayName;
672 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700673 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700674 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700675 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700676 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700677 mConnectTimeMillis = connectTimeMillis;
678 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700679 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700680 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700681 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700682 mIntentExtras = intentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700683 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800684
685 /** {@hide} */
686 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
687 return new Details(
688 parcelableCall.getId(),
689 parcelableCall.getHandle(),
690 parcelableCall.getHandlePresentation(),
691 parcelableCall.getCallerDisplayName(),
692 parcelableCall.getCallerDisplayNamePresentation(),
693 parcelableCall.getAccountHandle(),
694 parcelableCall.getCapabilities(),
695 parcelableCall.getProperties(),
696 parcelableCall.getDisconnectCause(),
697 parcelableCall.getConnectTimeMillis(),
698 parcelableCall.getGatewayInfo(),
699 parcelableCall.getVideoState(),
700 parcelableCall.getStatusHints(),
701 parcelableCall.getExtras(),
702 parcelableCall.getIntentExtras());
703 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800704
705 @Override
706 public String toString() {
707 StringBuilder sb = new StringBuilder();
708 sb.append("[pa: ");
709 sb.append(mAccountHandle);
710 sb.append(", hdl: ");
711 sb.append(Log.pii(mHandle));
712 sb.append(", caps: ");
713 sb.append(capabilitiesToString(mCallCapabilities));
714 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700715 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800716 sb.append("]");
717 return sb.toString();
718 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700719 }
720
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700721 /**
722 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
723 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
724 * implementation.
725 * <p>
726 * You can handle these callbacks by extending the {@link Callback} class and overriding the
727 * callbacks that your {@link InCallService} is interested in. The callback methods include the
728 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
729 * {@link Callback} implementation, if desired.
730 * <p>
731 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
732 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
733 * (typically in {@link InCallService#onCallRemoved(Call)}).
734 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
735 * reach your implementation of {@link Callback}, so it is important to register your callback
736 * as soon as your {@link InCallService} is notified of a new call via
737 * {@link InCallService#onCallAdded(Call)}.
738 */
Andrew Leeda80c872015-04-15 14:09:50 -0700739 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700740 /**
741 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
742 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700743 * @param call The {@code Call} invoking this method.
744 * @param state The new state of the {@code Call}.
745 */
746 public void onStateChanged(Call call, int state) {}
747
748 /**
749 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
750 *
751 * @param call The {@code Call} invoking this method.
752 * @param parent The new parent of the {@code Call}.
753 */
754 public void onParentChanged(Call call, Call parent) {}
755
756 /**
757 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
758 *
759 * @param call The {@code Call} invoking this method.
760 * @param children The new children of the {@code Call}.
761 */
762 public void onChildrenChanged(Call call, List<Call> children) {}
763
764 /**
765 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
766 *
767 * @param call The {@code Call} invoking this method.
768 * @param details A {@code Details} object describing the {@code Call}.
769 */
770 public void onDetailsChanged(Call call, Details details) {}
771
772 /**
773 * Invoked when the text messages that can be used as responses to the incoming
774 * {@code Call} are loaded from the relevant database.
775 * See {@link #getCannedTextResponses()}.
776 *
777 * @param call The {@code Call} invoking this method.
778 * @param cannedTextResponses The text messages useable as responses.
779 */
780 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
781
782 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700783 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
784 * character. This causes the post-dial signals to stop pending user confirmation. An
785 * implementation should present this choice to the user and invoke
786 * {@link #postDialContinue(boolean)} when the user makes the choice.
787 *
788 * @param call The {@code Call} invoking this method.
789 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
790 */
791 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
792
793 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700794 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700795 *
796 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700797 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700798 */
Andrew Lee50aca232014-07-22 16:41:54 -0700799 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700800
801 /**
802 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
803 * up their UI for the {@code Call} in response to state transitions. Specifically,
804 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
805 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
806 * clients should wait for this method to be invoked.
807 *
808 * @param call The {@code Call} being destroyed.
809 */
810 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700811
812 /**
813 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
814 * conferenced.
815 *
816 * @param call The {@code Call} being updated.
817 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
818 * conferenced.
819 */
820 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700821
822 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700823 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
824 * <p>
825 * Where possible, the Call should make an attempt to handle {@link Connection} events which
826 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
827 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
828 * possible that a {@link ConnectionService} has defined its own Connection events which a
829 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700830 * <p>
831 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
832 *
833 * @param call The {@code Call} receiving the event.
834 * @param event The event.
835 * @param extras Extras associated with the connection event.
836 */
837 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700838 }
839
Andrew Leeda80c872015-04-15 14:09:50 -0700840 /**
841 * @deprecated Use {@code Call.Callback} instead.
842 * @hide
843 */
844 @Deprecated
845 @SystemApi
846 public static abstract class Listener extends Callback { }
847
Ihab Awade63fadb2014-07-09 21:52:04 -0700848 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700849 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700850 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700851 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -0700852 private final List<Call> mChildren = new ArrayList<>();
853 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -0700854 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700855 private final List<Call> mConferenceableCalls = new ArrayList<>();
856 private final List<Call> mUnmodifiableConferenceableCalls =
857 Collections.unmodifiableList(mConferenceableCalls);
858
Santos Cordon823fd3c2014-08-07 18:35:18 -0700859 private boolean mChildrenCached;
860 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700861 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -0700862 private List<String> mCannedTextResponses = null;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800863 private String mCallingPackage;
Ihab Awade63fadb2014-07-09 21:52:04 -0700864 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -0800865 private VideoCallImpl mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -0700866 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -0700867 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700868
869 /**
870 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
871 *
872 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
873 * remaining or this {@code Call} is not in a post-dial state.
874 */
875 public String getRemainingPostDialSequence() {
876 return mRemainingPostDialSequence;
877 }
878
879 /**
880 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700881 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -0700882 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700883 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700884 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700885 }
886
887 /**
888 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
889 *
890 * @param rejectWithMessage Whether to reject with a text message.
891 * @param textMessage An optional text message with which to respond.
892 */
893 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700894 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -0700895 }
896
897 /**
898 * Instructs this {@code Call} to disconnect.
899 */
900 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700901 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700902 }
903
904 /**
905 * Instructs this {@code Call} to go on hold.
906 */
907 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700908 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700909 }
910
911 /**
912 * Instructs this {@link #STATE_HOLDING} call to release from hold.
913 */
914 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700915 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700916 }
917
918 /**
919 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
920 *
921 * Any other currently playing DTMF tone in the specified call is immediately stopped.
922 *
923 * @param digit A character representing the DTMF digit for which to play the tone. This
924 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
925 */
926 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700927 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -0700928 }
929
930 /**
931 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
932 * currently playing.
933 *
934 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
935 * currently playing, this method will do nothing.
936 */
937 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700938 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700939 }
940
941 /**
942 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
943 *
944 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
945 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -0700946 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700947 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700948 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
949 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700950 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -0700951 * {@code Call} will pause playing the tones and notify callbacks via
952 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -0700953 * should display to the user an indication of this state and an affordance to continue
954 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
955 * app should invoke the {@link #postDialContinue(boolean)} method.
956 *
957 * @param proceed Whether or not to continue with the post-dial sequence.
958 */
959 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700960 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -0700961 }
962
963 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700964 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -0700965 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700966 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700967 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
968 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700969
970 }
971
972 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700973 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700974 *
975 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -0700976 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700977 public void conference(Call callToConferenceWith) {
978 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700979 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700980 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700981 }
982
983 /**
984 * Instructs this {@code Call} to split from any conference call with which it may be
985 * connected.
986 */
987 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700988 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700989 }
990
991 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800992 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700993 */
994 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700995 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700996 }
997
998 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800999 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001000 */
1001 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001002 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001003 }
1004
1005 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001006 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1007 * device.
1008 * <p>
1009 * Calls to this method are ignored if the call does not have the
1010 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1011 * <p>
1012 * An {@link InCallService} will only see calls which support this method if it has the
1013 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1014 * in its manifest.
1015 */
1016 public void pullExternalCall() {
1017 // If this isn't an external call, ignore the request.
1018 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1019 return;
1020 }
1021
1022 mInCallAdapter.pullExternalCall(mTelecomCallId);
1023 }
1024
1025 /**
1026 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1027 * the {@link ConnectionService}.
1028 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001029 * Call events are used to communicate point in time information from an {@link InCallService}
1030 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1031 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1032 * {@link ConnectionService}.
1033 * <p>
1034 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1035 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1036 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001037 * Events are exposed to {@link ConnectionService} implementations via
1038 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1039 * <p>
1040 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001041 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1042 * ignore some events altogether.
1043 * <p>
1044 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1045 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1046 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1047 * they define their own event types in this namespace. When defining a custom event type,
1048 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1049 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1050 * <p>
1051 * When defining events and the associated extras, it is important to keep their behavior
1052 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1053 * events/extras should me maintained to ensure backwards compatibility with older
1054 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001055 *
1056 * @param event The connection event.
1057 * @param extras Bundle containing extra information associated with the event.
1058 */
1059 public void sendCallEvent(String event, Bundle extras) {
1060 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1061 }
1062
1063 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001064 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1065 * added.
1066 * <p>
1067 * No assumptions should be made as to how an In-Call UI or service will handle these
1068 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1069 *
1070 * @param extras The extras to add.
1071 */
1072 public final void putExtras(Bundle extras) {
1073 if (extras == null) {
1074 return;
1075 }
1076
1077 if (mExtras == null) {
1078 mExtras = new Bundle();
1079 }
1080 mExtras.putAll(extras);
1081 mInCallAdapter.putExtras(mTelecomCallId, extras);
1082 }
1083
1084 /**
1085 * Adds a boolean extra to this {@link Call}.
1086 *
1087 * @param key The extra key.
1088 * @param value The value.
1089 * @hide
1090 */
1091 public final void putExtra(String key, boolean value) {
1092 if (mExtras == null) {
1093 mExtras = new Bundle();
1094 }
1095 mExtras.putBoolean(key, value);
1096 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1097 }
1098
1099 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001100 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001101 *
1102 * @param key The extra key.
1103 * @param value The value.
1104 * @hide
1105 */
1106 public final void putExtra(String key, int value) {
1107 if (mExtras == null) {
1108 mExtras = new Bundle();
1109 }
1110 mExtras.putInt(key, value);
1111 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1112 }
1113
1114 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001115 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001116 *
1117 * @param key The extra key.
1118 * @param value The value.
1119 * @hide
1120 */
1121 public final void putExtra(String key, String value) {
1122 if (mExtras == null) {
1123 mExtras = new Bundle();
1124 }
1125 mExtras.putString(key, value);
1126 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1127 }
1128
1129 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001130 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001131 *
1132 * @param keys The keys of the extras to remove.
1133 */
1134 public final void removeExtras(List<String> keys) {
1135 if (mExtras != null) {
1136 for (String key : keys) {
1137 mExtras.remove(key);
1138 }
1139 if (mExtras.size() == 0) {
1140 mExtras = null;
1141 }
1142 }
1143 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1144 }
1145
1146 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001147 * Removes extras from this {@link Call}.
1148 *
1149 * @param keys The keys of the extras to remove.
1150 */
1151 public final void removeExtras(String ... keys) {
1152 removeExtras(Arrays.asList(keys));
1153 }
1154
1155 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001156 * Obtains the parent of this {@code Call} in a conference, if any.
1157 *
1158 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1159 * child of any conference {@code Call}s.
1160 */
1161 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001162 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001163 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001164 }
1165 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001166 }
1167
1168 /**
1169 * Obtains the children of this conference {@code Call}, if any.
1170 *
1171 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1172 * {@code List} otherwise.
1173 */
1174 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001175 if (!mChildrenCached) {
1176 mChildrenCached = true;
1177 mChildren.clear();
1178
1179 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001180 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001181 if (call == null) {
1182 // At least one child was still not found, so do not save true for "cached"
1183 mChildrenCached = false;
1184 } else {
1185 mChildren.add(call);
1186 }
1187 }
1188 }
1189
Ihab Awade63fadb2014-07-09 21:52:04 -07001190 return mUnmodifiableChildren;
1191 }
1192
1193 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001194 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1195 *
1196 * @return The list of conferenceable {@code Call}s.
1197 */
1198 public List<Call> getConferenceableCalls() {
1199 return mUnmodifiableConferenceableCalls;
1200 }
1201
1202 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001203 * Obtains the state of this {@code Call}.
1204 *
1205 * @return A state value, chosen from the {@code STATE_*} constants.
1206 */
1207 public int getState() {
1208 return mState;
1209 }
1210
1211 /**
1212 * Obtains a list of canned, pre-configured message responses to present to the user as
1213 * ways of rejecting this {@code Call} using via a text message.
1214 *
1215 * @see #reject(boolean, String)
1216 *
1217 * @return A list of canned text message responses.
1218 */
1219 public List<String> getCannedTextResponses() {
1220 return mCannedTextResponses;
1221 }
1222
1223 /**
1224 * Obtains an object that can be used to display video from this {@code Call}.
1225 *
Andrew Lee50aca232014-07-22 16:41:54 -07001226 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001227 */
Andrew Lee50aca232014-07-22 16:41:54 -07001228 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001229 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001230 }
1231
1232 /**
1233 * Obtains an object containing call details.
1234 *
1235 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1236 * result may be {@code null}.
1237 */
1238 public Details getDetails() {
1239 return mDetails;
1240 }
1241
1242 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001243 * Registers a callback to this {@code Call}.
1244 *
1245 * @param callback A {@code Callback}.
1246 */
1247 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001248 registerCallback(callback, new Handler());
1249 }
1250
1251 /**
1252 * Registers a callback to this {@code Call}.
1253 *
1254 * @param callback A {@code Callback}.
1255 * @param handler A handler which command and status changes will be delivered to.
1256 */
1257 public void registerCallback(Callback callback, Handler handler) {
1258 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001259 // Don't allow new callback registration if the call is already being destroyed.
1260 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001261 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1262 }
Andrew Leeda80c872015-04-15 14:09:50 -07001263 }
1264
1265 /**
1266 * Unregisters a callback from this {@code Call}.
1267 *
1268 * @param callback A {@code Callback}.
1269 */
1270 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001271 // Don't allow callback deregistration if the call is already being destroyed.
1272 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001273 for (CallbackRecord<Callback> record : mCallbackRecords) {
1274 if (record.getCallback() == callback) {
1275 mCallbackRecords.remove(record);
1276 break;
1277 }
1278 }
Andrew Leeda80c872015-04-15 14:09:50 -07001279 }
1280 }
1281
Santos Cordon3c20d632016-02-25 16:12:35 -08001282 @Override
1283 public String toString() {
1284 return new StringBuilder().
1285 append("Call [id: ").
1286 append(mTelecomCallId).
1287 append(", state: ").
1288 append(stateToString(mState)).
1289 append(", details: ").
1290 append(mDetails).
1291 append("]").toString();
1292 }
1293
1294 /**
1295 * @param state An integer value of a {@code STATE_*} constant.
1296 * @return A string representation of the value.
1297 */
1298 private static String stateToString(int state) {
1299 switch (state) {
1300 case STATE_NEW:
1301 return "NEW";
1302 case STATE_RINGING:
1303 return "RINGING";
1304 case STATE_DIALING:
1305 return "DIALING";
1306 case STATE_ACTIVE:
1307 return "ACTIVE";
1308 case STATE_HOLDING:
1309 return "HOLDING";
1310 case STATE_DISCONNECTED:
1311 return "DISCONNECTED";
1312 case STATE_CONNECTING:
1313 return "CONNECTING";
1314 case STATE_DISCONNECTING:
1315 return "DISCONNECTING";
1316 case STATE_SELECT_PHONE_ACCOUNT:
1317 return "SELECT_PHONE_ACCOUNT";
1318 default:
1319 Log.w(Call.class, "Unknown state %d", state);
1320 return "UNKNOWN";
1321 }
1322 }
1323
Andrew Leeda80c872015-04-15 14:09:50 -07001324 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001325 * Adds a listener to this {@code Call}.
1326 *
1327 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001328 * @deprecated Use {@link #registerCallback} instead.
1329 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001330 */
Andrew Leeda80c872015-04-15 14:09:50 -07001331 @Deprecated
1332 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001333 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001334 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001335 }
1336
1337 /**
1338 * Removes a listener from this {@code Call}.
1339 *
1340 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001341 * @deprecated Use {@link #unregisterCallback} instead.
1342 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001343 */
Andrew Leeda80c872015-04-15 14:09:50 -07001344 @Deprecated
1345 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001346 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001347 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001348 }
1349
1350 /** {@hide} */
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001351 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001352 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001353 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001354 mInCallAdapter = inCallAdapter;
1355 mState = STATE_NEW;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001356 mCallingPackage = callingPackage;
Ihab Awade63fadb2014-07-09 21:52:04 -07001357 }
1358
1359 /** {@hide} */
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001360 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
1361 String callingPackage) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001362 mPhone = phone;
1363 mTelecomCallId = telecomCallId;
1364 mInCallAdapter = inCallAdapter;
1365 mState = state;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001366 mCallingPackage = callingPackage;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001367 }
1368
1369 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001370 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001371 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001372 }
1373
1374 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001375 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001376
Ihab Awade63fadb2014-07-09 21:52:04 -07001377 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001378 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001379 boolean detailsChanged = !Objects.equals(mDetails, details);
1380 if (detailsChanged) {
1381 mDetails = details;
1382 }
1383
1384 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001385 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1386 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1387 mCannedTextResponses =
1388 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001389 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001390 }
1391
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001392 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage);
Tyler Gunn75958422015-04-15 14:23:42 -07001393 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001394 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001395 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001396 mVideoCallImpl = newVideoCallImpl;
1397 }
1398 if (mVideoCallImpl != null) {
1399 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001400 }
1401
Santos Cordone3c507b2015-04-23 14:44:19 -07001402 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001403 boolean stateChanged = mState != state;
1404 if (stateChanged) {
1405 mState = state;
1406 }
1407
Santos Cordon823fd3c2014-08-07 18:35:18 -07001408 String parentId = parcelableCall.getParentCallId();
1409 boolean parentChanged = !Objects.equals(mParentId, parentId);
1410 if (parentChanged) {
1411 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001412 }
1413
Santos Cordon823fd3c2014-08-07 18:35:18 -07001414 List<String> childCallIds = parcelableCall.getChildCallIds();
1415 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1416 if (childrenChanged) {
1417 mChildrenIds.clear();
1418 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1419 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001420 }
1421
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001422 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1423 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1424 for (String otherId : conferenceableCallIds) {
1425 if (callIdMap.containsKey(otherId)) {
1426 conferenceableCalls.add(callIdMap.get(otherId));
1427 }
1428 }
1429
1430 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1431 mConferenceableCalls.clear();
1432 mConferenceableCalls.addAll(conferenceableCalls);
1433 fireConferenceableCallsChanged();
1434 }
1435
Ihab Awade63fadb2014-07-09 21:52:04 -07001436 // Now we fire updates, ensuring that any client who listens to any of these notifications
1437 // gets the most up-to-date state.
1438
1439 if (stateChanged) {
1440 fireStateChanged(mState);
1441 }
1442 if (detailsChanged) {
1443 fireDetailsChanged(mDetails);
1444 }
1445 if (cannedTextResponsesChanged) {
1446 fireCannedTextResponsesLoaded(mCannedTextResponses);
1447 }
Andrew Lee50aca232014-07-22 16:41:54 -07001448 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001449 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001450 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001451 if (parentChanged) {
1452 fireParentChanged(getParent());
1453 }
1454 if (childrenChanged) {
1455 fireChildrenChanged(getChildren());
1456 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001457
1458 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1459 // remove ourselves from the Phone. Note that we do this after completing all state updates
1460 // so a client can cleanly transition all their UI to the state appropriate for a
1461 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1462 if (mState == STATE_DISCONNECTED) {
1463 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001464 }
1465 }
1466
1467 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001468 final void internalSetPostDialWait(String remaining) {
1469 mRemainingPostDialSequence = remaining;
1470 firePostDialWait(mRemainingPostDialSequence);
1471 }
1472
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001473 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001474 final void internalSetDisconnected() {
1475 if (mState != Call.STATE_DISCONNECTED) {
1476 mState = Call.STATE_DISCONNECTED;
1477 fireStateChanged(mState);
1478 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001479 }
1480 }
1481
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001482 /** {@hide} */
1483 final void internalOnConnectionEvent(String event, Bundle extras) {
1484 fireOnConnectionEvent(event, extras);
1485 }
1486
Andrew Lee011728f2015-04-23 15:47:06 -07001487 private void fireStateChanged(final int newState) {
1488 for (CallbackRecord<Callback> record : mCallbackRecords) {
1489 final Call call = this;
1490 final Callback callback = record.getCallback();
1491 record.getHandler().post(new Runnable() {
1492 @Override
1493 public void run() {
1494 callback.onStateChanged(call, newState);
1495 }
1496 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001497 }
1498 }
1499
Andrew Lee011728f2015-04-23 15:47:06 -07001500 private void fireParentChanged(final Call newParent) {
1501 for (CallbackRecord<Callback> record : mCallbackRecords) {
1502 final Call call = this;
1503 final Callback callback = record.getCallback();
1504 record.getHandler().post(new Runnable() {
1505 @Override
1506 public void run() {
1507 callback.onParentChanged(call, newParent);
1508 }
1509 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001510 }
1511 }
1512
Andrew Lee011728f2015-04-23 15:47:06 -07001513 private void fireChildrenChanged(final List<Call> children) {
1514 for (CallbackRecord<Callback> record : mCallbackRecords) {
1515 final Call call = this;
1516 final Callback callback = record.getCallback();
1517 record.getHandler().post(new Runnable() {
1518 @Override
1519 public void run() {
1520 callback.onChildrenChanged(call, children);
1521 }
1522 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001523 }
1524 }
1525
Andrew Lee011728f2015-04-23 15:47:06 -07001526 private void fireDetailsChanged(final Details details) {
1527 for (CallbackRecord<Callback> record : mCallbackRecords) {
1528 final Call call = this;
1529 final Callback callback = record.getCallback();
1530 record.getHandler().post(new Runnable() {
1531 @Override
1532 public void run() {
1533 callback.onDetailsChanged(call, details);
1534 }
1535 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001536 }
1537 }
1538
Andrew Lee011728f2015-04-23 15:47:06 -07001539 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1540 for (CallbackRecord<Callback> record : mCallbackRecords) {
1541 final Call call = this;
1542 final Callback callback = record.getCallback();
1543 record.getHandler().post(new Runnable() {
1544 @Override
1545 public void run() {
1546 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1547 }
1548 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001549 }
1550 }
1551
Andrew Lee011728f2015-04-23 15:47:06 -07001552 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1553 for (CallbackRecord<Callback> record : mCallbackRecords) {
1554 final Call call = this;
1555 final Callback callback = record.getCallback();
1556 record.getHandler().post(new Runnable() {
1557 @Override
1558 public void run() {
1559 callback.onVideoCallChanged(call, videoCall);
1560 }
1561 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001562 }
1563 }
1564
Andrew Lee011728f2015-04-23 15:47:06 -07001565 private void firePostDialWait(final String remainingPostDialSequence) {
1566 for (CallbackRecord<Callback> record : mCallbackRecords) {
1567 final Call call = this;
1568 final Callback callback = record.getCallback();
1569 record.getHandler().post(new Runnable() {
1570 @Override
1571 public void run() {
1572 callback.onPostDialWait(call, remainingPostDialSequence);
1573 }
1574 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001575 }
1576 }
1577
1578 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001579 /**
1580 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1581 * onCallRemoved callback, we remove this call from the Phone's record
1582 * only once all of the registered onCallDestroyed callbacks are executed.
1583 * All the callbacks get removed from our records as a part of this operation
1584 * since onCallDestroyed is the final callback.
1585 */
1586 final Call call = this;
1587 if (mCallbackRecords.isEmpty()) {
1588 // No callbacks registered, remove the call from Phone's record.
1589 mPhone.internalRemoveCall(call);
1590 }
1591 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001592 final Callback callback = record.getCallback();
1593 record.getHandler().post(new Runnable() {
1594 @Override
1595 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001596 boolean isFinalRemoval = false;
1597 RuntimeException toThrow = null;
1598 try {
1599 callback.onCallDestroyed(call);
1600 } catch (RuntimeException e) {
1601 toThrow = e;
1602 }
1603 synchronized(Call.this) {
1604 mCallbackRecords.remove(record);
1605 if (mCallbackRecords.isEmpty()) {
1606 isFinalRemoval = true;
1607 }
1608 }
1609 if (isFinalRemoval) {
1610 mPhone.internalRemoveCall(call);
1611 }
1612 if (toThrow != null) {
1613 throw toThrow;
1614 }
Andrew Lee011728f2015-04-23 15:47:06 -07001615 }
1616 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001617 }
1618 }
1619
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001620 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001621 for (CallbackRecord<Callback> record : mCallbackRecords) {
1622 final Call call = this;
1623 final Callback callback = record.getCallback();
1624 record.getHandler().post(new Runnable() {
1625 @Override
1626 public void run() {
1627 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1628 }
1629 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001630 }
1631 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001632
1633 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001634 * Notifies listeners of an incoming connection event.
1635 * <p>
1636 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1637 *
1638 * @param event
1639 * @param extras
1640 */
1641 private void fireOnConnectionEvent(final String event, final Bundle extras) {
1642 for (CallbackRecord<Callback> record : mCallbackRecords) {
1643 final Call call = this;
1644 final Callback callback = record.getCallback();
1645 record.getHandler().post(new Runnable() {
1646 @Override
1647 public void run() {
1648 callback.onConnectionEvent(call, event, extras);
1649 }
1650 });
1651 }
1652 }
1653
1654 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001655 * Determines if two bundles are equal.
1656 *
1657 * @param bundle The original bundle.
1658 * @param newBundle The bundle to compare with.
1659 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1660 */
1661 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1662 if (bundle == null || newBundle == null) {
1663 return bundle == newBundle;
1664 }
1665
1666 if (bundle.size() != newBundle.size()) {
1667 return false;
1668 }
1669
1670 for(String key : bundle.keySet()) {
1671 if (key != null) {
1672 final Object value = bundle.get(key);
1673 final Object newValue = newBundle.get(key);
1674 if (!Objects.equals(value, newValue)) {
1675 return false;
1676 }
1677 }
1678 }
1679 return true;
1680 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001681}