blob: 5557510de14029367b3d7b6907920b931a9431d4 [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 /**
289 * Whether the call is associated with the work profile.
290 */
291 public static final int PROPERTY_WORK_CALL = 0x00000020;
292
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700293 /**
294 * 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
Andrew Lee2378ea72015-04-29 14:38:11 -0700310 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700311 // Next PROPERTY value: 0x00000100
Tyler Gunnd11a3152015-03-18 13:09:14 -0700312 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800313
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800314 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700315 private final Uri mHandle;
316 private final int mHandlePresentation;
317 private final String mCallerDisplayName;
318 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700319 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700320 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700321 private final int mCallProperties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700322 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700323 private final long mConnectTimeMillis;
324 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700325 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700326 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700327 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700328 private final Bundle mIntentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700329
330 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800331 * Whether the supplied capabilities supports the specified capability.
332 *
333 * @param capabilities A bit field of capabilities.
334 * @param capability The capability to check capabilities for.
335 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800336 */
337 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800338 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800339 }
340
341 /**
342 * Whether the capabilities of this {@code Details} supports the specified capability.
343 *
344 * @param capability The capability to check capabilities for.
345 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800346 */
347 public boolean can(int capability) {
348 return can(mCallCapabilities, capability);
349 }
350
351 /**
352 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
353 *
354 * @param capabilities A capability bit field.
355 * @return A human readable string representation.
356 */
357 public static String capabilitiesToString(int capabilities) {
358 StringBuilder builder = new StringBuilder();
359 builder.append("[Capabilities:");
360 if (can(capabilities, CAPABILITY_HOLD)) {
361 builder.append(" CAPABILITY_HOLD");
362 }
363 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
364 builder.append(" CAPABILITY_SUPPORT_HOLD");
365 }
366 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
367 builder.append(" CAPABILITY_MERGE_CONFERENCE");
368 }
369 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
370 builder.append(" CAPABILITY_SWAP_CONFERENCE");
371 }
372 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
373 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
374 }
375 if (can(capabilities, CAPABILITY_MUTE)) {
376 builder.append(" CAPABILITY_MUTE");
377 }
378 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
379 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
380 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700381 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
382 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
383 }
384 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
385 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
386 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700387 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
388 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800389 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700390 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
391 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
392 }
393 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
394 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
395 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800396 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
397 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
398 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700399 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
400 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800401 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500402 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700403 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500404 }
Rekha Kumar07366812015-03-24 16:42:31 -0700405 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
406 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
407 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700408 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
409 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
410 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700411 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
412 builder.append(" CAPABILITY_CAN_PULL_CALL");
413 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800414 builder.append("]");
415 return builder.toString();
416 }
417
418 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700419 * Whether the supplied properties includes the specified property.
420 *
421 * @param properties A bit field of properties.
422 * @param property The property to check properties for.
423 * @return Whether the specified property is supported.
424 */
425 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800426 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700427 }
428
429 /**
430 * Whether the properties of this {@code Details} includes the specified property.
431 *
432 * @param property The property to check properties for.
433 * @return Whether the specified property is supported.
434 */
435 public boolean hasProperty(int property) {
436 return hasProperty(mCallProperties, property);
437 }
438
439 /**
440 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
441 *
442 * @param properties A property bit field.
443 * @return A human readable string representation.
444 */
445 public static String propertiesToString(int properties) {
446 StringBuilder builder = new StringBuilder();
447 builder.append("[Properties:");
448 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
449 builder.append(" PROPERTY_CONFERENCE");
450 }
451 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
452 builder.append(" PROPERTY_GENERIC_CONFERENCE");
453 }
454 if (hasProperty(properties, PROPERTY_WIFI)) {
455 builder.append(" PROPERTY_WIFI");
456 }
457 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
458 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
459 }
460 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700461 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700462 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700463 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
464 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
465 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700466 builder.append("]");
467 return builder.toString();
468 }
469
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800470 /** {@hide} */
471 public String getTelecomCallId() {
472 return mTelecomCallId;
473 }
474
Andrew Lee2378ea72015-04-29 14:38:11 -0700475 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700476 * @return The handle (e.g., phone number) to which the {@code Call} is currently
477 * connected.
478 */
479 public Uri getHandle() {
480 return mHandle;
481 }
482
483 /**
484 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700485 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700486 */
487 public int getHandlePresentation() {
488 return mHandlePresentation;
489 }
490
491 /**
492 * @return The display name for the caller.
493 */
494 public String getCallerDisplayName() {
495 return mCallerDisplayName;
496 }
497
498 /**
499 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700500 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700501 */
502 public int getCallerDisplayNamePresentation() {
503 return mCallerDisplayNamePresentation;
504 }
505
506 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700507 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
508 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700509 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700510 public PhoneAccountHandle getAccountHandle() {
511 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700512 }
513
514 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800515 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
516 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700517 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700518 public int getCallCapabilities() {
519 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700520 }
521
522 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700523 * @return A bitmask of the properties of the {@code Call}, as defined by the various
524 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700525 */
526 public int getCallProperties() {
527 return mCallProperties;
528 }
529
530 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700531 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700532 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700533 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700534 public DisconnectCause getDisconnectCause() {
535 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700536 }
537
538 /**
539 * @return The time the {@code Call} has been connected. This information is updated
540 * periodically, but user interfaces should not rely on this to display any "call time
541 * clock".
542 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700543 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700544 return mConnectTimeMillis;
545 }
546
547 /**
548 * @return Information about any calling gateway the {@code Call} may be using.
549 */
550 public GatewayInfo getGatewayInfo() {
551 return mGatewayInfo;
552 }
553
Andrew Lee7a341382014-07-15 17:05:08 -0700554 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700555 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700556 */
557 public int getVideoState() {
558 return mVideoState;
559 }
560
Ihab Awad5d0410f2014-07-30 10:07:40 -0700561 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700562 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700563 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700564 */
565 public StatusHints getStatusHints() {
566 return mStatusHints;
567 }
568
Nancy Chen10798dc2014-08-08 14:00:25 -0700569 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700570 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700571 */
572 public Bundle getExtras() {
573 return mExtras;
574 }
575
Santos Cordon6b7f9552015-05-27 17:21:45 -0700576 /**
577 * @return The extras used with the original intent to place this call.
578 */
579 public Bundle getIntentExtras() {
580 return mIntentExtras;
581 }
582
Ihab Awade63fadb2014-07-09 21:52:04 -0700583 @Override
584 public boolean equals(Object o) {
585 if (o instanceof Details) {
586 Details d = (Details) o;
587 return
588 Objects.equals(mHandle, d.mHandle) &&
589 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
590 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
591 Objects.equals(mCallerDisplayNamePresentation,
592 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700593 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700594 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700595 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700596 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700597 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700598 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700599 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700600 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700601 areBundlesEqual(mExtras, d.mExtras) &&
602 areBundlesEqual(mIntentExtras, d.mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700603 }
604 return false;
605 }
606
607 @Override
608 public int hashCode() {
609 return
610 Objects.hashCode(mHandle) +
611 Objects.hashCode(mHandlePresentation) +
612 Objects.hashCode(mCallerDisplayName) +
613 Objects.hashCode(mCallerDisplayNamePresentation) +
Evan Charlton8c8a0622014-07-20 12:31:00 -0700614 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700615 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700616 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700617 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700618 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700619 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700620 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700621 Objects.hashCode(mStatusHints) +
Santos Cordon6b7f9552015-05-27 17:21:45 -0700622 Objects.hashCode(mExtras) +
623 Objects.hashCode(mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700624 }
625
626 /** {@hide} */
627 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800628 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700629 Uri handle,
630 int handlePresentation,
631 String callerDisplayName,
632 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700633 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700634 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700635 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700636 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700637 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700638 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700639 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700640 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700641 Bundle extras,
642 Bundle intentExtras) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800643 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700644 mHandle = handle;
645 mHandlePresentation = handlePresentation;
646 mCallerDisplayName = callerDisplayName;
647 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700648 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700649 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700650 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700651 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700652 mConnectTimeMillis = connectTimeMillis;
653 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700654 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700655 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700656 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700657 mIntentExtras = intentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700658 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800659
660 /** {@hide} */
661 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
662 return new Details(
663 parcelableCall.getId(),
664 parcelableCall.getHandle(),
665 parcelableCall.getHandlePresentation(),
666 parcelableCall.getCallerDisplayName(),
667 parcelableCall.getCallerDisplayNamePresentation(),
668 parcelableCall.getAccountHandle(),
669 parcelableCall.getCapabilities(),
670 parcelableCall.getProperties(),
671 parcelableCall.getDisconnectCause(),
672 parcelableCall.getConnectTimeMillis(),
673 parcelableCall.getGatewayInfo(),
674 parcelableCall.getVideoState(),
675 parcelableCall.getStatusHints(),
676 parcelableCall.getExtras(),
677 parcelableCall.getIntentExtras());
678 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800679
680 @Override
681 public String toString() {
682 StringBuilder sb = new StringBuilder();
683 sb.append("[pa: ");
684 sb.append(mAccountHandle);
685 sb.append(", hdl: ");
686 sb.append(Log.pii(mHandle));
687 sb.append(", caps: ");
688 sb.append(capabilitiesToString(mCallCapabilities));
689 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700690 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800691 sb.append("]");
692 return sb.toString();
693 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700694 }
695
Andrew Leeda80c872015-04-15 14:09:50 -0700696 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700697 /**
698 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
699 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700700 * @param call The {@code Call} invoking this method.
701 * @param state The new state of the {@code Call}.
702 */
703 public void onStateChanged(Call call, int state) {}
704
705 /**
706 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
707 *
708 * @param call The {@code Call} invoking this method.
709 * @param parent The new parent of the {@code Call}.
710 */
711 public void onParentChanged(Call call, Call parent) {}
712
713 /**
714 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
715 *
716 * @param call The {@code Call} invoking this method.
717 * @param children The new children of the {@code Call}.
718 */
719 public void onChildrenChanged(Call call, List<Call> children) {}
720
721 /**
722 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
723 *
724 * @param call The {@code Call} invoking this method.
725 * @param details A {@code Details} object describing the {@code Call}.
726 */
727 public void onDetailsChanged(Call call, Details details) {}
728
729 /**
730 * Invoked when the text messages that can be used as responses to the incoming
731 * {@code Call} are loaded from the relevant database.
732 * See {@link #getCannedTextResponses()}.
733 *
734 * @param call The {@code Call} invoking this method.
735 * @param cannedTextResponses The text messages useable as responses.
736 */
737 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
738
739 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700740 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
741 * character. This causes the post-dial signals to stop pending user confirmation. An
742 * implementation should present this choice to the user and invoke
743 * {@link #postDialContinue(boolean)} when the user makes the choice.
744 *
745 * @param call The {@code Call} invoking this method.
746 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
747 */
748 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
749
750 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700751 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700752 *
753 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700754 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700755 */
Andrew Lee50aca232014-07-22 16:41:54 -0700756 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700757
758 /**
759 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
760 * up their UI for the {@code Call} in response to state transitions. Specifically,
761 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
762 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
763 * clients should wait for this method to be invoked.
764 *
765 * @param call The {@code Call} being destroyed.
766 */
767 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700768
769 /**
770 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
771 * conferenced.
772 *
773 * @param call The {@code Call} being updated.
774 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
775 * conferenced.
776 */
777 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700778
779 /**
780 * Invoked when a call receives an event from its associated {@link Connection}.
781 * <p>
782 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
783 *
784 * @param call The {@code Call} receiving the event.
785 * @param event The event.
786 * @param extras Extras associated with the connection event.
787 */
788 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700789 }
790
Andrew Leeda80c872015-04-15 14:09:50 -0700791 /**
792 * @deprecated Use {@code Call.Callback} instead.
793 * @hide
794 */
795 @Deprecated
796 @SystemApi
797 public static abstract class Listener extends Callback { }
798
Ihab Awade63fadb2014-07-09 21:52:04 -0700799 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700800 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700801 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700802 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -0700803 private final List<Call> mChildren = new ArrayList<>();
804 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -0700805 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700806 private final List<Call> mConferenceableCalls = new ArrayList<>();
807 private final List<Call> mUnmodifiableConferenceableCalls =
808 Collections.unmodifiableList(mConferenceableCalls);
809
Santos Cordon823fd3c2014-08-07 18:35:18 -0700810 private boolean mChildrenCached;
811 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700812 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -0700813 private List<String> mCannedTextResponses = null;
814 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -0800815 private VideoCallImpl mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -0700816 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -0700817 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700818
819 /**
820 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
821 *
822 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
823 * remaining or this {@code Call} is not in a post-dial state.
824 */
825 public String getRemainingPostDialSequence() {
826 return mRemainingPostDialSequence;
827 }
828
829 /**
830 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700831 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -0700832 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700833 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700834 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700835 }
836
837 /**
838 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
839 *
840 * @param rejectWithMessage Whether to reject with a text message.
841 * @param textMessage An optional text message with which to respond.
842 */
843 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700844 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -0700845 }
846
847 /**
848 * Instructs this {@code Call} to disconnect.
849 */
850 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700851 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700852 }
853
854 /**
855 * Instructs this {@code Call} to go on hold.
856 */
857 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700858 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700859 }
860
861 /**
862 * Instructs this {@link #STATE_HOLDING} call to release from hold.
863 */
864 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700865 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700866 }
867
868 /**
869 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
870 *
871 * Any other currently playing DTMF tone in the specified call is immediately stopped.
872 *
873 * @param digit A character representing the DTMF digit for which to play the tone. This
874 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
875 */
876 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700877 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -0700878 }
879
880 /**
881 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
882 * currently playing.
883 *
884 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
885 * currently playing, this method will do nothing.
886 */
887 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700888 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700889 }
890
891 /**
892 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
893 *
894 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
895 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -0700896 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700897 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700898 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
899 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700900 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -0700901 * {@code Call} will pause playing the tones and notify callbacks via
902 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -0700903 * should display to the user an indication of this state and an affordance to continue
904 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
905 * app should invoke the {@link #postDialContinue(boolean)} method.
906 *
907 * @param proceed Whether or not to continue with the post-dial sequence.
908 */
909 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700910 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -0700911 }
912
913 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700914 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -0700915 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700916 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700917 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
918 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700919
920 }
921
922 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700923 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700924 *
925 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -0700926 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700927 public void conference(Call callToConferenceWith) {
928 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700929 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700930 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700931 }
932
933 /**
934 * Instructs this {@code Call} to split from any conference call with which it may be
935 * connected.
936 */
937 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700938 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700939 }
940
941 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800942 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700943 */
944 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700945 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700946 }
947
948 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800949 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700950 */
951 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700952 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700953 }
954
955 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700956 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
957 * device.
958 * <p>
959 * Calls to this method are ignored if the call does not have the
960 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
961 * <p>
962 * An {@link InCallService} will only see calls which support this method if it has the
963 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
964 * in its manifest.
965 */
966 public void pullExternalCall() {
967 // If this isn't an external call, ignore the request.
968 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
969 return;
970 }
971
972 mInCallAdapter.pullExternalCall(mTelecomCallId);
973 }
974
975 /**
976 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
977 * the {@link ConnectionService}.
978 * <p>
979 * Events are exposed to {@link ConnectionService} implementations via
980 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
981 * <p>
982 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
983 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
984 *
985 * @param event The connection event.
986 * @param extras Bundle containing extra information associated with the event.
987 */
988 public void sendCallEvent(String event, Bundle extras) {
989 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
990 }
991
992 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700993 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
994 * added.
995 * <p>
996 * No assumptions should be made as to how an In-Call UI or service will handle these
997 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
998 *
999 * @param extras The extras to add.
1000 */
1001 public final void putExtras(Bundle extras) {
1002 if (extras == null) {
1003 return;
1004 }
1005
1006 if (mExtras == null) {
1007 mExtras = new Bundle();
1008 }
1009 mExtras.putAll(extras);
1010 mInCallAdapter.putExtras(mTelecomCallId, extras);
1011 }
1012
1013 /**
1014 * Adds a boolean extra to this {@link Call}.
1015 *
1016 * @param key The extra key.
1017 * @param value The value.
1018 * @hide
1019 */
1020 public final void putExtra(String key, boolean value) {
1021 if (mExtras == null) {
1022 mExtras = new Bundle();
1023 }
1024 mExtras.putBoolean(key, value);
1025 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1026 }
1027
1028 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001029 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001030 *
1031 * @param key The extra key.
1032 * @param value The value.
1033 * @hide
1034 */
1035 public final void putExtra(String key, int value) {
1036 if (mExtras == null) {
1037 mExtras = new Bundle();
1038 }
1039 mExtras.putInt(key, value);
1040 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1041 }
1042
1043 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001044 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001045 *
1046 * @param key The extra key.
1047 * @param value The value.
1048 * @hide
1049 */
1050 public final void putExtra(String key, String value) {
1051 if (mExtras == null) {
1052 mExtras = new Bundle();
1053 }
1054 mExtras.putString(key, value);
1055 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1056 }
1057
1058 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001059 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001060 *
1061 * @param keys The keys of the extras to remove.
1062 */
1063 public final void removeExtras(List<String> keys) {
1064 if (mExtras != null) {
1065 for (String key : keys) {
1066 mExtras.remove(key);
1067 }
1068 if (mExtras.size() == 0) {
1069 mExtras = null;
1070 }
1071 }
1072 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1073 }
1074
1075 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001076 * Removes extras from this {@link Call}.
1077 *
1078 * @param keys The keys of the extras to remove.
1079 */
1080 public final void removeExtras(String ... keys) {
1081 removeExtras(Arrays.asList(keys));
1082 }
1083
1084 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001085 * Obtains the parent of this {@code Call} in a conference, if any.
1086 *
1087 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1088 * child of any conference {@code Call}s.
1089 */
1090 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001091 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001092 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001093 }
1094 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001095 }
1096
1097 /**
1098 * Obtains the children of this conference {@code Call}, if any.
1099 *
1100 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1101 * {@code List} otherwise.
1102 */
1103 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001104 if (!mChildrenCached) {
1105 mChildrenCached = true;
1106 mChildren.clear();
1107
1108 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001109 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001110 if (call == null) {
1111 // At least one child was still not found, so do not save true for "cached"
1112 mChildrenCached = false;
1113 } else {
1114 mChildren.add(call);
1115 }
1116 }
1117 }
1118
Ihab Awade63fadb2014-07-09 21:52:04 -07001119 return mUnmodifiableChildren;
1120 }
1121
1122 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001123 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1124 *
1125 * @return The list of conferenceable {@code Call}s.
1126 */
1127 public List<Call> getConferenceableCalls() {
1128 return mUnmodifiableConferenceableCalls;
1129 }
1130
1131 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001132 * Obtains the state of this {@code Call}.
1133 *
1134 * @return A state value, chosen from the {@code STATE_*} constants.
1135 */
1136 public int getState() {
1137 return mState;
1138 }
1139
1140 /**
1141 * Obtains a list of canned, pre-configured message responses to present to the user as
1142 * ways of rejecting this {@code Call} using via a text message.
1143 *
1144 * @see #reject(boolean, String)
1145 *
1146 * @return A list of canned text message responses.
1147 */
1148 public List<String> getCannedTextResponses() {
1149 return mCannedTextResponses;
1150 }
1151
1152 /**
1153 * Obtains an object that can be used to display video from this {@code Call}.
1154 *
Andrew Lee50aca232014-07-22 16:41:54 -07001155 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001156 */
Andrew Lee50aca232014-07-22 16:41:54 -07001157 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001158 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001159 }
1160
1161 /**
1162 * Obtains an object containing call details.
1163 *
1164 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1165 * result may be {@code null}.
1166 */
1167 public Details getDetails() {
1168 return mDetails;
1169 }
1170
1171 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001172 * Registers a callback to this {@code Call}.
1173 *
1174 * @param callback A {@code Callback}.
1175 */
1176 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001177 registerCallback(callback, new Handler());
1178 }
1179
1180 /**
1181 * Registers a callback to this {@code Call}.
1182 *
1183 * @param callback A {@code Callback}.
1184 * @param handler A handler which command and status changes will be delivered to.
1185 */
1186 public void registerCallback(Callback callback, Handler handler) {
1187 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001188 // Don't allow new callback registration if the call is already being destroyed.
1189 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001190 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1191 }
Andrew Leeda80c872015-04-15 14:09:50 -07001192 }
1193
1194 /**
1195 * Unregisters a callback from this {@code Call}.
1196 *
1197 * @param callback A {@code Callback}.
1198 */
1199 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001200 // Don't allow callback deregistration if the call is already being destroyed.
1201 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001202 for (CallbackRecord<Callback> record : mCallbackRecords) {
1203 if (record.getCallback() == callback) {
1204 mCallbackRecords.remove(record);
1205 break;
1206 }
1207 }
Andrew Leeda80c872015-04-15 14:09:50 -07001208 }
1209 }
1210
Santos Cordon3c20d632016-02-25 16:12:35 -08001211 @Override
1212 public String toString() {
1213 return new StringBuilder().
1214 append("Call [id: ").
1215 append(mTelecomCallId).
1216 append(", state: ").
1217 append(stateToString(mState)).
1218 append(", details: ").
1219 append(mDetails).
1220 append("]").toString();
1221 }
1222
1223 /**
1224 * @param state An integer value of a {@code STATE_*} constant.
1225 * @return A string representation of the value.
1226 */
1227 private static String stateToString(int state) {
1228 switch (state) {
1229 case STATE_NEW:
1230 return "NEW";
1231 case STATE_RINGING:
1232 return "RINGING";
1233 case STATE_DIALING:
1234 return "DIALING";
1235 case STATE_ACTIVE:
1236 return "ACTIVE";
1237 case STATE_HOLDING:
1238 return "HOLDING";
1239 case STATE_DISCONNECTED:
1240 return "DISCONNECTED";
1241 case STATE_CONNECTING:
1242 return "CONNECTING";
1243 case STATE_DISCONNECTING:
1244 return "DISCONNECTING";
1245 case STATE_SELECT_PHONE_ACCOUNT:
1246 return "SELECT_PHONE_ACCOUNT";
1247 default:
1248 Log.w(Call.class, "Unknown state %d", state);
1249 return "UNKNOWN";
1250 }
1251 }
1252
Andrew Leeda80c872015-04-15 14:09:50 -07001253 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001254 * Adds a listener to this {@code Call}.
1255 *
1256 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001257 * @deprecated Use {@link #registerCallback} instead.
1258 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001259 */
Andrew Leeda80c872015-04-15 14:09:50 -07001260 @Deprecated
1261 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001262 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001263 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001264 }
1265
1266 /**
1267 * Removes a listener from this {@code Call}.
1268 *
1269 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001270 * @deprecated Use {@link #unregisterCallback} instead.
1271 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001272 */
Andrew Leeda80c872015-04-15 14:09:50 -07001273 @Deprecated
1274 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001275 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001276 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001277 }
1278
1279 /** {@hide} */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001280 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001281 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001282 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001283 mInCallAdapter = inCallAdapter;
1284 mState = STATE_NEW;
1285 }
1286
1287 /** {@hide} */
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001288 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state) {
1289 mPhone = phone;
1290 mTelecomCallId = telecomCallId;
1291 mInCallAdapter = inCallAdapter;
1292 mState = state;
1293 }
1294
1295 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001296 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001297 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001298 }
1299
1300 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001301 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001302 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001303 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001304 boolean detailsChanged = !Objects.equals(mDetails, details);
1305 if (detailsChanged) {
1306 mDetails = details;
1307 }
1308
1309 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001310 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1311 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1312 mCannedTextResponses =
1313 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001314 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001315 }
1316
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001317 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl();
Tyler Gunn75958422015-04-15 14:23:42 -07001318 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001319 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001320 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001321 mVideoCallImpl = newVideoCallImpl;
1322 }
1323 if (mVideoCallImpl != null) {
1324 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001325 }
1326
Santos Cordone3c507b2015-04-23 14:44:19 -07001327 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001328 boolean stateChanged = mState != state;
1329 if (stateChanged) {
1330 mState = state;
1331 }
1332
Santos Cordon823fd3c2014-08-07 18:35:18 -07001333 String parentId = parcelableCall.getParentCallId();
1334 boolean parentChanged = !Objects.equals(mParentId, parentId);
1335 if (parentChanged) {
1336 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001337 }
1338
Santos Cordon823fd3c2014-08-07 18:35:18 -07001339 List<String> childCallIds = parcelableCall.getChildCallIds();
1340 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1341 if (childrenChanged) {
1342 mChildrenIds.clear();
1343 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1344 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001345 }
1346
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001347 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1348 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1349 for (String otherId : conferenceableCallIds) {
1350 if (callIdMap.containsKey(otherId)) {
1351 conferenceableCalls.add(callIdMap.get(otherId));
1352 }
1353 }
1354
1355 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1356 mConferenceableCalls.clear();
1357 mConferenceableCalls.addAll(conferenceableCalls);
1358 fireConferenceableCallsChanged();
1359 }
1360
Ihab Awade63fadb2014-07-09 21:52:04 -07001361 // Now we fire updates, ensuring that any client who listens to any of these notifications
1362 // gets the most up-to-date state.
1363
1364 if (stateChanged) {
1365 fireStateChanged(mState);
1366 }
1367 if (detailsChanged) {
1368 fireDetailsChanged(mDetails);
1369 }
1370 if (cannedTextResponsesChanged) {
1371 fireCannedTextResponsesLoaded(mCannedTextResponses);
1372 }
Andrew Lee50aca232014-07-22 16:41:54 -07001373 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001374 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001375 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001376 if (parentChanged) {
1377 fireParentChanged(getParent());
1378 }
1379 if (childrenChanged) {
1380 fireChildrenChanged(getChildren());
1381 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001382
1383 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1384 // remove ourselves from the Phone. Note that we do this after completing all state updates
1385 // so a client can cleanly transition all their UI to the state appropriate for a
1386 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1387 if (mState == STATE_DISCONNECTED) {
1388 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001389 }
1390 }
1391
1392 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001393 final void internalSetPostDialWait(String remaining) {
1394 mRemainingPostDialSequence = remaining;
1395 firePostDialWait(mRemainingPostDialSequence);
1396 }
1397
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001398 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001399 final void internalSetDisconnected() {
1400 if (mState != Call.STATE_DISCONNECTED) {
1401 mState = Call.STATE_DISCONNECTED;
1402 fireStateChanged(mState);
1403 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001404 }
1405 }
1406
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001407 /** {@hide} */
1408 final void internalOnConnectionEvent(String event, Bundle extras) {
1409 fireOnConnectionEvent(event, extras);
1410 }
1411
Andrew Lee011728f2015-04-23 15:47:06 -07001412 private void fireStateChanged(final int newState) {
1413 for (CallbackRecord<Callback> record : mCallbackRecords) {
1414 final Call call = this;
1415 final Callback callback = record.getCallback();
1416 record.getHandler().post(new Runnable() {
1417 @Override
1418 public void run() {
1419 callback.onStateChanged(call, newState);
1420 }
1421 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001422 }
1423 }
1424
Andrew Lee011728f2015-04-23 15:47:06 -07001425 private void fireParentChanged(final Call newParent) {
1426 for (CallbackRecord<Callback> record : mCallbackRecords) {
1427 final Call call = this;
1428 final Callback callback = record.getCallback();
1429 record.getHandler().post(new Runnable() {
1430 @Override
1431 public void run() {
1432 callback.onParentChanged(call, newParent);
1433 }
1434 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001435 }
1436 }
1437
Andrew Lee011728f2015-04-23 15:47:06 -07001438 private void fireChildrenChanged(final List<Call> children) {
1439 for (CallbackRecord<Callback> record : mCallbackRecords) {
1440 final Call call = this;
1441 final Callback callback = record.getCallback();
1442 record.getHandler().post(new Runnable() {
1443 @Override
1444 public void run() {
1445 callback.onChildrenChanged(call, children);
1446 }
1447 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001448 }
1449 }
1450
Andrew Lee011728f2015-04-23 15:47:06 -07001451 private void fireDetailsChanged(final Details details) {
1452 for (CallbackRecord<Callback> record : mCallbackRecords) {
1453 final Call call = this;
1454 final Callback callback = record.getCallback();
1455 record.getHandler().post(new Runnable() {
1456 @Override
1457 public void run() {
1458 callback.onDetailsChanged(call, details);
1459 }
1460 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001461 }
1462 }
1463
Andrew Lee011728f2015-04-23 15:47:06 -07001464 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1465 for (CallbackRecord<Callback> record : mCallbackRecords) {
1466 final Call call = this;
1467 final Callback callback = record.getCallback();
1468 record.getHandler().post(new Runnable() {
1469 @Override
1470 public void run() {
1471 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1472 }
1473 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001474 }
1475 }
1476
Andrew Lee011728f2015-04-23 15:47:06 -07001477 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1478 for (CallbackRecord<Callback> record : mCallbackRecords) {
1479 final Call call = this;
1480 final Callback callback = record.getCallback();
1481 record.getHandler().post(new Runnable() {
1482 @Override
1483 public void run() {
1484 callback.onVideoCallChanged(call, videoCall);
1485 }
1486 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001487 }
1488 }
1489
Andrew Lee011728f2015-04-23 15:47:06 -07001490 private void firePostDialWait(final String remainingPostDialSequence) {
1491 for (CallbackRecord<Callback> record : mCallbackRecords) {
1492 final Call call = this;
1493 final Callback callback = record.getCallback();
1494 record.getHandler().post(new Runnable() {
1495 @Override
1496 public void run() {
1497 callback.onPostDialWait(call, remainingPostDialSequence);
1498 }
1499 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001500 }
1501 }
1502
1503 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001504 /**
1505 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1506 * onCallRemoved callback, we remove this call from the Phone's record
1507 * only once all of the registered onCallDestroyed callbacks are executed.
1508 * All the callbacks get removed from our records as a part of this operation
1509 * since onCallDestroyed is the final callback.
1510 */
1511 final Call call = this;
1512 if (mCallbackRecords.isEmpty()) {
1513 // No callbacks registered, remove the call from Phone's record.
1514 mPhone.internalRemoveCall(call);
1515 }
1516 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001517 final Callback callback = record.getCallback();
1518 record.getHandler().post(new Runnable() {
1519 @Override
1520 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001521 boolean isFinalRemoval = false;
1522 RuntimeException toThrow = null;
1523 try {
1524 callback.onCallDestroyed(call);
1525 } catch (RuntimeException e) {
1526 toThrow = e;
1527 }
1528 synchronized(Call.this) {
1529 mCallbackRecords.remove(record);
1530 if (mCallbackRecords.isEmpty()) {
1531 isFinalRemoval = true;
1532 }
1533 }
1534 if (isFinalRemoval) {
1535 mPhone.internalRemoveCall(call);
1536 }
1537 if (toThrow != null) {
1538 throw toThrow;
1539 }
Andrew Lee011728f2015-04-23 15:47:06 -07001540 }
1541 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001542 }
1543 }
1544
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001545 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001546 for (CallbackRecord<Callback> record : mCallbackRecords) {
1547 final Call call = this;
1548 final Callback callback = record.getCallback();
1549 record.getHandler().post(new Runnable() {
1550 @Override
1551 public void run() {
1552 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1553 }
1554 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001555 }
1556 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001557
1558 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001559 * Notifies listeners of an incoming connection event.
1560 * <p>
1561 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1562 *
1563 * @param event
1564 * @param extras
1565 */
1566 private void fireOnConnectionEvent(final String event, final Bundle extras) {
1567 for (CallbackRecord<Callback> record : mCallbackRecords) {
1568 final Call call = this;
1569 final Callback callback = record.getCallback();
1570 record.getHandler().post(new Runnable() {
1571 @Override
1572 public void run() {
1573 callback.onConnectionEvent(call, event, extras);
1574 }
1575 });
1576 }
1577 }
1578
1579 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001580 * Determines if two bundles are equal.
1581 *
1582 * @param bundle The original bundle.
1583 * @param newBundle The bundle to compare with.
1584 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1585 */
1586 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1587 if (bundle == null || newBundle == null) {
1588 return bundle == newBundle;
1589 }
1590
1591 if (bundle.size() != newBundle.size()) {
1592 return false;
1593 }
1594
1595 for(String key : bundle.keySet()) {
1596 if (key != null) {
1597 final Object value = bundle.get(key);
1598 final Object newValue = newBundle.get(key);
1599 if (!Objects.equals(value, newValue)) {
1600 return false;
1601 }
1602 }
1603 }
1604 return true;
1605 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001606}