blob: ded28b0cb4c05ff7619ef1a0d4d65a0bb71601f2 [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
Hall Liu95d55872017-01-25 17:12:49 -080019import android.annotation.IntDef;
20import android.annotation.Nullable;
Andrew Leeda80c872015-04-15 14:09:50 -070021import android.annotation.SystemApi;
Ihab Awade63fadb2014-07-09 21:52:04 -070022import android.net.Uri;
Nancy Chen10798dc2014-08-08 14:00:25 -070023import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070024import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080025import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070026
Hall Liu95d55872017-01-25 17:12:49 -080027import java.io.IOException;
28import java.io.InputStreamReader;
29import java.io.OutputStreamWriter;
Andrew Lee50aca232014-07-22 16:41:54 -070030import java.lang.String;
Hall Liu95d55872017-01-25 17:12:49 -080031import java.lang.annotation.Retention;
32import java.lang.annotation.RetentionPolicy;
33import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070034import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070035import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070036import java.util.Collections;
37import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070038import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070039import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070040import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070041
42/**
43 * Represents an ongoing phone call that the in-call app should present to the user.
44 */
45public final class Call {
46 /**
47 * The state of a {@code Call} when newly created.
48 */
49 public static final int STATE_NEW = 0;
50
51 /**
52 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
53 */
54 public static final int STATE_DIALING = 1;
55
56 /**
57 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
58 */
59 public static final int STATE_RINGING = 2;
60
61 /**
62 * The state of a {@code Call} when in a holding state.
63 */
64 public static final int STATE_HOLDING = 3;
65
66 /**
67 * The state of a {@code Call} when actively supporting conversation.
68 */
69 public static final int STATE_ACTIVE = 4;
70
71 /**
72 * The state of a {@code Call} when no further voice or other communication is being
73 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
74 * is no longer active, and the local data transport has or inevitably will release resources
75 * associated with this {@code Call}.
76 */
77 public static final int STATE_DISCONNECTED = 7;
78
Nancy Chen5da0fd52014-07-08 14:16:17 -070079 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070080 * The state of an outgoing {@code Call} when waiting on user to select a
81 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070082 */
Santos Cordone3c507b2015-04-23 14:44:19 -070083 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
84
85 /**
86 * @hide
87 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
88 */
89 @Deprecated
90 @SystemApi
91 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070092
Nancy Chene20930f2014-08-07 16:17:21 -070093 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070094 * The initial state of an outgoing {@code Call}.
95 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
96 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070097 */
98 public static final int STATE_CONNECTING = 9;
99
Nancy Chen513c8922014-09-17 14:47:20 -0700100 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700101 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
102 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
103 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
104 */
105 public static final int STATE_DISCONNECTING = 10;
106
107 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700108 * The state of an external call which is in the process of being pulled from a remote device to
109 * the local device.
110 * <p>
111 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
112 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
113 * <p>
114 * An {@link InCallService} will only see this state if it has the
115 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
116 * manifest.
117 */
118 public static final int STATE_PULLING_CALL = 11;
119
120 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700121 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
122 * extras. Used to pass the phone accounts to display on the front end to the user in order to
123 * select phone accounts to (for example) place a call.
Nancy Chen513c8922014-09-17 14:47:20 -0700124 */
125 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
126
Ihab Awade63fadb2014-07-09 21:52:04 -0700127 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800128
129 /** Call can currently be put on hold or unheld. */
130 public static final int CAPABILITY_HOLD = 0x00000001;
131
132 /** Call supports the hold feature. */
133 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
134
135 /**
136 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
137 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
138 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
139 * capability allows a merge button to be shown while the conference call is in the foreground
140 * of the in-call UI.
141 * <p>
142 * This is only intended for use by a {@link Conference}.
143 */
144 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
145
146 /**
147 * Calls within a conference can be swapped between foreground and background.
148 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
149 * <p>
150 * This is only intended for use by a {@link Conference}.
151 */
152 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
153
154 /**
155 * @hide
156 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700157 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800158
159 /** Call supports responding via text option. */
160 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
161
162 /** Call can be muted. */
163 public static final int CAPABILITY_MUTE = 0x00000040;
164
165 /**
166 * Call supports conference call management. This capability only applies to {@link Conference}
167 * calls which can have {@link Connection}s as children.
168 */
169 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
170
171 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700172 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800173 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700174 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800175
176 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700177 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800178 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700179 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800180
181 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700182 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800183 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700184 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700185 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800186
187 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700188 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800189 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700190 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
191
192 /**
193 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700194 */
195 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
196
197 /**
198 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700199 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700200 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700201 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202
203 /**
204 * Call is able to be separated from its parent {@code Conference}, if any.
205 */
206 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
207
208 /**
209 * Call is able to be individually disconnected when in a {@code Conference}.
210 */
211 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
212
213 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500214 * Speed up audio setup for MT call.
215 * @hide
216 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700217 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
218
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700219 /**
220 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700221 * @hide
222 */
223 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
224
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700225 /**
226 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700227 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700228 */
229 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
230
Bryce Lee81901682015-08-28 16:38:02 -0700231 /**
232 * Call sends responses through connection.
233 * @hide
234 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800235 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
236
237 /**
238 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
239 * <p>
240 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
241 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
242 * downgraded from a video call back to a VideoState of
243 * {@link VideoProfile#STATE_AUDIO_ONLY}.
244 * <p>
245 * Intuitively, a call which can be downgraded to audio should also have local and remote
246 * video
247 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
248 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
249 */
250 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700251
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700252 /**
253 * When set for an external call, indicates that this {@code Call} can be pulled from a
254 * remote device to the current device.
255 * <p>
256 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
257 * <p>
258 * An {@link InCallService} will only see calls with this capability if it has the
259 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
260 * in its manifest.
261 * <p>
262 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700263 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700264 */
265 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
266
Tyler Gunnd11a3152015-03-18 13:09:14 -0700267 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700268 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700269 //******************************************************************************************
270
271 /**
272 * Whether the call is currently a conference.
273 */
274 public static final int PROPERTY_CONFERENCE = 0x00000001;
275
276 /**
277 * Whether the call is a generic conference, where we do not know the precise state of
278 * participants in the conference (eg. on CDMA).
279 */
280 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
281
282 /**
283 * Whether the call is made while the device is in emergency callback mode.
284 */
285 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
286
287 /**
288 * Connection is using WIFI.
289 */
290 public static final int PROPERTY_WIFI = 0x00000008;
291
292 /**
293 * Call is using high definition audio.
294 */
295 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
296
Tony Maka68dcce2015-12-17 09:31:18 +0000297 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100298 * Whether the call is associated with the work profile.
299 */
300 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
301
302 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700303 * When set, indicates that this {@code Call} does not actually exist locally for the
304 * {@link ConnectionService}.
305 * <p>
306 * Consider, for example, a scenario where a user has two phones with the same phone number.
307 * When a user places a call on one device, the telephony stack can represent that call on
308 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700309 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700310 * <p>
311 * An {@link InCallService} will only see calls with this property if it has the
312 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
313 * in its manifest.
314 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700315 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700316 */
317 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
318
Brad Ebinger15847072016-05-18 11:08:36 -0700319 /**
320 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
321 */
322 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
323
Tyler Gunn24e18332017-02-10 09:42:49 -0800324 /**
325 * Indicates that the call is from a self-managed {@link ConnectionService}.
326 * <p>
327 * See also {@link Connection#PROPERTY_SELF_MANAGED}
328 */
329 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
330
Andrew Lee2378ea72015-04-29 14:38:11 -0700331 //******************************************************************************************
Tyler Gunn24e18332017-02-10 09:42:49 -0800332 // Next PROPERTY value: 0x00000200
Tyler Gunnd11a3152015-03-18 13:09:14 -0700333 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800334
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800335 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700336 private final Uri mHandle;
337 private final int mHandlePresentation;
338 private final String mCallerDisplayName;
339 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700340 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700341 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700342 private final int mCallProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800343 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700344 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700345 private final long mConnectTimeMillis;
346 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700347 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700348 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700349 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700350 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700351 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700352
353 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800354 * Whether the supplied capabilities supports the specified capability.
355 *
356 * @param capabilities A bit field of capabilities.
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 static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800361 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800362 }
363
364 /**
365 * Whether the capabilities of this {@code Details} supports the specified capability.
366 *
367 * @param capability The capability to check capabilities for.
368 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800369 */
370 public boolean can(int capability) {
371 return can(mCallCapabilities, capability);
372 }
373
374 /**
375 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
376 *
377 * @param capabilities A capability bit field.
378 * @return A human readable string representation.
379 */
380 public static String capabilitiesToString(int capabilities) {
381 StringBuilder builder = new StringBuilder();
382 builder.append("[Capabilities:");
383 if (can(capabilities, CAPABILITY_HOLD)) {
384 builder.append(" CAPABILITY_HOLD");
385 }
386 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
387 builder.append(" CAPABILITY_SUPPORT_HOLD");
388 }
389 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
390 builder.append(" CAPABILITY_MERGE_CONFERENCE");
391 }
392 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
393 builder.append(" CAPABILITY_SWAP_CONFERENCE");
394 }
395 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
396 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
397 }
398 if (can(capabilities, CAPABILITY_MUTE)) {
399 builder.append(" CAPABILITY_MUTE");
400 }
401 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
402 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
403 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700404 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
405 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
406 }
407 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
408 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
409 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700410 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
411 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800412 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700413 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
414 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
415 }
416 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
417 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
418 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800419 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
420 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
421 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700422 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
423 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800424 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500425 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700426 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500427 }
Rekha Kumar07366812015-03-24 16:42:31 -0700428 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
429 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
430 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700431 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
432 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
433 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700434 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
435 builder.append(" CAPABILITY_CAN_PULL_CALL");
436 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800437 builder.append("]");
438 return builder.toString();
439 }
440
441 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700442 * Whether the supplied properties includes the specified property.
443 *
444 * @param properties A bit field of properties.
445 * @param property The property to check properties for.
446 * @return Whether the specified property is supported.
447 */
448 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800449 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700450 }
451
452 /**
453 * Whether the properties of this {@code Details} includes the specified property.
454 *
455 * @param property The property to check properties for.
456 * @return Whether the specified property is supported.
457 */
458 public boolean hasProperty(int property) {
459 return hasProperty(mCallProperties, property);
460 }
461
462 /**
463 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
464 *
465 * @param properties A property bit field.
466 * @return A human readable string representation.
467 */
468 public static String propertiesToString(int properties) {
469 StringBuilder builder = new StringBuilder();
470 builder.append("[Properties:");
471 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
472 builder.append(" PROPERTY_CONFERENCE");
473 }
474 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
475 builder.append(" PROPERTY_GENERIC_CONFERENCE");
476 }
477 if (hasProperty(properties, PROPERTY_WIFI)) {
478 builder.append(" PROPERTY_WIFI");
479 }
480 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
481 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
482 }
483 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700484 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700485 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700486 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
487 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
488 }
Brad Ebinger15847072016-05-18 11:08:36 -0700489 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
490 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
491 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700492 builder.append("]");
493 return builder.toString();
494 }
495
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800496 /** {@hide} */
497 public String getTelecomCallId() {
498 return mTelecomCallId;
499 }
500
Andrew Lee2378ea72015-04-29 14:38:11 -0700501 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700502 * @return The handle (e.g., phone number) to which the {@code Call} is currently
503 * connected.
504 */
505 public Uri getHandle() {
506 return mHandle;
507 }
508
509 /**
510 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700511 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700512 */
513 public int getHandlePresentation() {
514 return mHandlePresentation;
515 }
516
517 /**
518 * @return The display name for the caller.
519 */
520 public String getCallerDisplayName() {
521 return mCallerDisplayName;
522 }
523
524 /**
525 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700526 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700527 */
528 public int getCallerDisplayNamePresentation() {
529 return mCallerDisplayNamePresentation;
530 }
531
532 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700533 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
534 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700535 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700536 public PhoneAccountHandle getAccountHandle() {
537 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700538 }
539
540 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800541 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
542 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700543 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700544 public int getCallCapabilities() {
545 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700546 }
547
548 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700549 * @return A bitmask of the properties of the {@code Call}, as defined by the various
550 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700551 */
552 public int getCallProperties() {
553 return mCallProperties;
554 }
555
556 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800557 * @return a bitmask of the audio routes available for the call.
558 *
559 * @hide
560 */
561 public int getSupportedAudioRoutes() {
562 return mSupportedAudioRoutes;
563 }
564
565 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700566 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700567 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700568 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700569 public DisconnectCause getDisconnectCause() {
570 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700571 }
572
573 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700574 * Returns the time the {@link Call} connected (i.e. became active). This information is
575 * updated periodically, but user interfaces should not rely on this to display the "call
576 * time clock". For the time when the call was first added to Telecom, see
577 * {@link #getCreationTimeMillis()}.
578 *
579 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700580 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700581 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700582 return mConnectTimeMillis;
583 }
584
585 /**
586 * @return Information about any calling gateway the {@code Call} may be using.
587 */
588 public GatewayInfo getGatewayInfo() {
589 return mGatewayInfo;
590 }
591
Andrew Lee7a341382014-07-15 17:05:08 -0700592 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700593 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700594 */
595 public int getVideoState() {
596 return mVideoState;
597 }
598
Ihab Awad5d0410f2014-07-30 10:07:40 -0700599 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700600 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700601 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700602 */
603 public StatusHints getStatusHints() {
604 return mStatusHints;
605 }
606
Nancy Chen10798dc2014-08-08 14:00:25 -0700607 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700608 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700609 */
610 public Bundle getExtras() {
611 return mExtras;
612 }
613
Santos Cordon6b7f9552015-05-27 17:21:45 -0700614 /**
615 * @return The extras used with the original intent to place this call.
616 */
617 public Bundle getIntentExtras() {
618 return mIntentExtras;
619 }
620
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700621 /**
622 * Returns the time when the call was first created and added to Telecom. This is the same
623 * time that is logged as the start time in the Call Log (see
624 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
625 * (became active), see {@link #getConnectTimeMillis()}.
626 *
627 * @return The creation time of the call, in millis since the epoch.
628 */
629 public long getCreationTimeMillis() {
630 return mCreationTimeMillis;
631 }
632
Ihab Awade63fadb2014-07-09 21:52:04 -0700633 @Override
634 public boolean equals(Object o) {
635 if (o instanceof Details) {
636 Details d = (Details) o;
637 return
638 Objects.equals(mHandle, d.mHandle) &&
639 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
640 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
641 Objects.equals(mCallerDisplayNamePresentation,
642 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700643 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700644 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700645 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700646 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700647 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700648 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700649 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700650 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700651 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700652 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
653 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700654 }
655 return false;
656 }
657
658 @Override
659 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700660 return Objects.hash(mHandle,
661 mHandlePresentation,
662 mCallerDisplayName,
663 mCallerDisplayNamePresentation,
664 mAccountHandle,
665 mCallCapabilities,
666 mCallProperties,
667 mDisconnectCause,
668 mConnectTimeMillis,
669 mGatewayInfo,
670 mVideoState,
671 mStatusHints,
672 mExtras,
673 mIntentExtras,
674 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700675 }
676
677 /** {@hide} */
678 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800679 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700680 Uri handle,
681 int handlePresentation,
682 String callerDisplayName,
683 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700684 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700685 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700686 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700687 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700688 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700689 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700690 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700691 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700692 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700693 Bundle intentExtras,
694 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800695 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700696 mHandle = handle;
697 mHandlePresentation = handlePresentation;
698 mCallerDisplayName = callerDisplayName;
699 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700700 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700701 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700702 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700703 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700704 mConnectTimeMillis = connectTimeMillis;
705 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700706 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700707 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700708 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700709 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700710 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700711 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800712
713 /** {@hide} */
714 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
715 return new Details(
716 parcelableCall.getId(),
717 parcelableCall.getHandle(),
718 parcelableCall.getHandlePresentation(),
719 parcelableCall.getCallerDisplayName(),
720 parcelableCall.getCallerDisplayNamePresentation(),
721 parcelableCall.getAccountHandle(),
722 parcelableCall.getCapabilities(),
723 parcelableCall.getProperties(),
724 parcelableCall.getDisconnectCause(),
725 parcelableCall.getConnectTimeMillis(),
726 parcelableCall.getGatewayInfo(),
727 parcelableCall.getVideoState(),
728 parcelableCall.getStatusHints(),
729 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700730 parcelableCall.getIntentExtras(),
731 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800732 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800733
734 @Override
735 public String toString() {
736 StringBuilder sb = new StringBuilder();
737 sb.append("[pa: ");
738 sb.append(mAccountHandle);
739 sb.append(", hdl: ");
740 sb.append(Log.pii(mHandle));
741 sb.append(", caps: ");
742 sb.append(capabilitiesToString(mCallCapabilities));
743 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700744 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800745 sb.append("]");
746 return sb.toString();
747 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700748 }
749
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700750 /**
751 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
752 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
753 * implementation.
754 * <p>
755 * You can handle these callbacks by extending the {@link Callback} class and overriding the
756 * callbacks that your {@link InCallService} is interested in. The callback methods include the
757 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
758 * {@link Callback} implementation, if desired.
759 * <p>
760 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
761 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
762 * (typically in {@link InCallService#onCallRemoved(Call)}).
763 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
764 * reach your implementation of {@link Callback}, so it is important to register your callback
765 * as soon as your {@link InCallService} is notified of a new call via
766 * {@link InCallService#onCallAdded(Call)}.
767 */
Andrew Leeda80c872015-04-15 14:09:50 -0700768 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700769 /**
770 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
771 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700772 * @param call The {@code Call} invoking this method.
773 * @param state The new state of the {@code Call}.
774 */
775 public void onStateChanged(Call call, int state) {}
776
777 /**
778 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
779 *
780 * @param call The {@code Call} invoking this method.
781 * @param parent The new parent of the {@code Call}.
782 */
783 public void onParentChanged(Call call, Call parent) {}
784
785 /**
786 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
787 *
788 * @param call The {@code Call} invoking this method.
789 * @param children The new children of the {@code Call}.
790 */
791 public void onChildrenChanged(Call call, List<Call> children) {}
792
793 /**
794 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
795 *
796 * @param call The {@code Call} invoking this method.
797 * @param details A {@code Details} object describing the {@code Call}.
798 */
799 public void onDetailsChanged(Call call, Details details) {}
800
801 /**
802 * Invoked when the text messages that can be used as responses to the incoming
803 * {@code Call} are loaded from the relevant database.
804 * See {@link #getCannedTextResponses()}.
805 *
806 * @param call The {@code Call} invoking this method.
807 * @param cannedTextResponses The text messages useable as responses.
808 */
809 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
810
811 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700812 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
813 * character. This causes the post-dial signals to stop pending user confirmation. An
814 * implementation should present this choice to the user and invoke
815 * {@link #postDialContinue(boolean)} when the user makes the choice.
816 *
817 * @param call The {@code Call} invoking this method.
818 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
819 */
820 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
821
822 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700823 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700824 *
825 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700826 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700827 */
Andrew Lee50aca232014-07-22 16:41:54 -0700828 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700829
830 /**
831 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
832 * up their UI for the {@code Call} in response to state transitions. Specifically,
833 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
834 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
835 * clients should wait for this method to be invoked.
836 *
837 * @param call The {@code Call} being destroyed.
838 */
839 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700840
841 /**
842 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
843 * conferenced.
844 *
845 * @param call The {@code Call} being updated.
846 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
847 * conferenced.
848 */
849 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700850
851 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700852 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
853 * <p>
854 * Where possible, the Call should make an attempt to handle {@link Connection} events which
855 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
856 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
857 * possible that a {@link ConnectionService} has defined its own Connection events which a
858 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700859 * <p>
860 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
861 *
862 * @param call The {@code Call} receiving the event.
863 * @param event The event.
864 * @param extras Extras associated with the connection event.
865 */
866 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -0800867
868 /**
869 * Invoked when the RTT mode changes for this call.
870 * @param call The call whose RTT mode has changed.
871 * @param mode the new RTT mode, one of
872 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
873 * or {@link RttCall#RTT_MODE_VCO}
874 */
875 public void onRttModeChanged(Call call, int mode) {}
876
877 /**
878 * Invoked when the call's RTT status changes, either from off to on or from on to off.
879 * @param call The call whose RTT status has changed.
880 * @param enabled whether RTT is now enabled or disabled
881 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
882 * on, null otherwise.
883 */
884 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
885
886 /**
887 * Invoked when the remote end of the connection has requested that an RTT communication
888 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
889 * with the same ID that this method is invoked with.
890 * @param call The call which the RTT request was placed on
891 * @param id The ID of the request.
892 */
893 public void onRttRequest(Call call, int id) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800894
895 /**
896 * Invoked when the RTT session failed to initiate for some reason, including rejection
897 * by the remote party.
898 * @param call The call which the RTT initiation failure occurred on.
899 * @param reason One of the status codes defined in
900 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
901 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
902 */
903 public void onRttInitiationFailure(Call call, int reason) {}
Hall Liu95d55872017-01-25 17:12:49 -0800904 }
905
906 /**
907 * A class that holds the state that describes the state of the RTT channel to the remote
908 * party, if it is active.
909 */
910 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -0800911 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -0800912 @Retention(RetentionPolicy.SOURCE)
913 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
914 public @interface RttAudioMode {}
915
916 /**
917 * For metrics use. Default value in the proto.
918 * @hide
919 */
920 public static final int RTT_MODE_INVALID = 0;
921
922 /**
923 * Indicates that there should be a bidirectional audio stream between the two parties
924 * on the call.
925 */
926 public static final int RTT_MODE_FULL = 1;
927
928 /**
929 * Indicates that the local user should be able to hear the audio stream from the remote
930 * user, but not vice versa. Equivalent to muting the microphone.
931 */
932 public static final int RTT_MODE_HCO = 2;
933
934 /**
935 * Indicates that the remote user should be able to hear the audio stream from the local
936 * user, but not vice versa. Equivalent to setting the volume to zero.
937 */
938 public static final int RTT_MODE_VCO = 3;
939
940 private static final int READ_BUFFER_SIZE = 1000;
941
942 private InputStreamReader mReceiveStream;
943 private OutputStreamWriter mTransmitStream;
944 private int mRttMode;
945 private final InCallAdapter mInCallAdapter;
Hall Liub64ac4c2017-02-06 10:49:48 -0800946 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -0800947 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
948
949 /**
950 * @hide
951 */
Hall Liub64ac4c2017-02-06 10:49:48 -0800952 public RttCall(String telecomCallId, InputStreamReader receiveStream,
953 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
954 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -0800955 mReceiveStream = receiveStream;
956 mTransmitStream = transmitStream;
957 mRttMode = mode;
958 mInCallAdapter = inCallAdapter;
959 }
960
961 /**
962 * Returns the current RTT audio mode.
963 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
964 * {@link #RTT_MODE_HCO}.
965 */
966 public int getRttAudioMode() {
967 return mRttMode;
968 }
969
970 /**
971 * Sets the RTT audio mode. The requested mode change will be communicated through
972 * {@link Callback#onRttModeChanged(Call, int)}.
973 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
974 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
975 */
976 public void setRttMode(@RttAudioMode int mode) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800977 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -0800978 }
979
980 /**
981 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
982 * RTT transmits text in real-time, this method should be called once for each character
983 * the user enters into the device.
984 *
985 * This method is not thread-safe -- calling it from multiple threads simultaneously may
986 * lead to interleaved text.
987 * @param input The message to send to the remote user.
988 */
989 public void write(String input) throws IOException {
990 mTransmitStream.write(input);
991 mTransmitStream.flush();
992 }
993
994 /**
995 * Reads a string from the remote user, blocking if there is no data available. Returns
996 * {@code null} if the RTT conversation has been terminated and there is no further data
997 * to read.
998 *
999 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1000 * lead to interleaved text.
1001 * @return A string containing text sent by the remote user, or {@code null} if the
1002 * conversation has been terminated or if there was an error while reading.
1003 */
1004 public String read() {
1005 try {
1006 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1007 if (numRead < 0) {
1008 return null;
1009 }
1010 return new String(mReadBuffer, 0, numRead);
1011 } catch (IOException e) {
1012 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
1013 return null;
1014 }
1015 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001016 }
1017
Andrew Leeda80c872015-04-15 14:09:50 -07001018 /**
1019 * @deprecated Use {@code Call.Callback} instead.
1020 * @hide
1021 */
1022 @Deprecated
1023 @SystemApi
1024 public static abstract class Listener extends Callback { }
1025
Ihab Awade63fadb2014-07-09 21:52:04 -07001026 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001027 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001028 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001029 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001030 private final List<Call> mChildren = new ArrayList<>();
1031 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001032 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001033 private final List<Call> mConferenceableCalls = new ArrayList<>();
1034 private final List<Call> mUnmodifiableConferenceableCalls =
1035 Collections.unmodifiableList(mConferenceableCalls);
1036
Santos Cordon823fd3c2014-08-07 18:35:18 -07001037 private boolean mChildrenCached;
1038 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001039 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001040 private List<String> mCannedTextResponses = null;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001041 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001042 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001043 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001044 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001045 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001046 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001047 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001048
1049 /**
1050 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1051 *
1052 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1053 * remaining or this {@code Call} is not in a post-dial state.
1054 */
1055 public String getRemainingPostDialSequence() {
1056 return mRemainingPostDialSequence;
1057 }
1058
1059 /**
1060 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001061 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001062 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001063 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001064 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001065 }
1066
1067 /**
1068 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1069 *
1070 * @param rejectWithMessage Whether to reject with a text message.
1071 * @param textMessage An optional text message with which to respond.
1072 */
1073 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001074 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001075 }
1076
1077 /**
1078 * Instructs this {@code Call} to disconnect.
1079 */
1080 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001081 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001082 }
1083
1084 /**
1085 * Instructs this {@code Call} to go on hold.
1086 */
1087 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001088 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001089 }
1090
1091 /**
1092 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1093 */
1094 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001095 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001096 }
1097
1098 /**
1099 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1100 *
1101 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1102 *
1103 * @param digit A character representing the DTMF digit for which to play the tone. This
1104 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1105 */
1106 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001107 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001108 }
1109
1110 /**
1111 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1112 * currently playing.
1113 *
1114 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1115 * currently playing, this method will do nothing.
1116 */
1117 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001118 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001119 }
1120
1121 /**
1122 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1123 *
1124 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1125 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001126 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001127 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001128 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1129 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001130 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001131 * {@code Call} will pause playing the tones and notify callbacks via
1132 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001133 * should display to the user an indication of this state and an affordance to continue
1134 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1135 * app should invoke the {@link #postDialContinue(boolean)} method.
1136 *
1137 * @param proceed Whether or not to continue with the post-dial sequence.
1138 */
1139 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001140 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001141 }
1142
1143 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001144 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001145 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001146 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001147 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1148 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001149
1150 }
1151
1152 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001153 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001154 *
1155 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001156 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001157 public void conference(Call callToConferenceWith) {
1158 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001159 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001160 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001161 }
1162
1163 /**
1164 * Instructs this {@code Call} to split from any conference call with which it may be
1165 * connected.
1166 */
1167 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001168 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001169 }
1170
1171 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001172 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001173 */
1174 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001175 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001176 }
1177
1178 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001179 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001180 */
1181 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001182 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001183 }
1184
1185 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001186 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1187 * device.
1188 * <p>
1189 * Calls to this method are ignored if the call does not have the
1190 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1191 * <p>
1192 * An {@link InCallService} will only see calls which support this method if it has the
1193 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1194 * in its manifest.
1195 */
1196 public void pullExternalCall() {
1197 // If this isn't an external call, ignore the request.
1198 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1199 return;
1200 }
1201
1202 mInCallAdapter.pullExternalCall(mTelecomCallId);
1203 }
1204
1205 /**
1206 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1207 * the {@link ConnectionService}.
1208 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001209 * Call events are used to communicate point in time information from an {@link InCallService}
1210 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1211 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1212 * {@link ConnectionService}.
1213 * <p>
1214 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1215 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1216 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001217 * Events are exposed to {@link ConnectionService} implementations via
1218 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1219 * <p>
1220 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001221 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1222 * ignore some events altogether.
1223 * <p>
1224 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1225 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1226 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1227 * they define their own event types in this namespace. When defining a custom event type,
1228 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1229 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1230 * <p>
1231 * When defining events and the associated extras, it is important to keep their behavior
1232 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1233 * events/extras should me maintained to ensure backwards compatibility with older
1234 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001235 *
1236 * @param event The connection event.
1237 * @param extras Bundle containing extra information associated with the event.
1238 */
1239 public void sendCallEvent(String event, Bundle extras) {
1240 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1241 }
1242
1243 /**
Hall Liu95d55872017-01-25 17:12:49 -08001244 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1245 * guaranteed, and notification of success will be via the
1246 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1247 */
1248 public void sendRttRequest() {
Hall Liub64ac4c2017-02-06 10:49:48 -08001249 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001250 }
1251
1252 /**
1253 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1254 * callback.
1255 * The ID used here should be the same as the ID that was received via the callback.
1256 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1257 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1258 */
1259 public void respondToRttRequest(int id, boolean accept) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001260 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001261 }
1262
1263 /**
1264 * Terminate the RTT session on this call. The resulting state change will be notified via
1265 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1266 */
1267 public void stopRtt() {
Hall Liub64ac4c2017-02-06 10:49:48 -08001268 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001269 }
1270
1271 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001272 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1273 * added.
1274 * <p>
1275 * No assumptions should be made as to how an In-Call UI or service will handle these
1276 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1277 *
1278 * @param extras The extras to add.
1279 */
1280 public final void putExtras(Bundle extras) {
1281 if (extras == null) {
1282 return;
1283 }
1284
1285 if (mExtras == null) {
1286 mExtras = new Bundle();
1287 }
1288 mExtras.putAll(extras);
1289 mInCallAdapter.putExtras(mTelecomCallId, extras);
1290 }
1291
1292 /**
1293 * Adds a boolean extra to this {@link Call}.
1294 *
1295 * @param key The extra key.
1296 * @param value The value.
1297 * @hide
1298 */
1299 public final void putExtra(String key, boolean value) {
1300 if (mExtras == null) {
1301 mExtras = new Bundle();
1302 }
1303 mExtras.putBoolean(key, value);
1304 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1305 }
1306
1307 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001308 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001309 *
1310 * @param key The extra key.
1311 * @param value The value.
1312 * @hide
1313 */
1314 public final void putExtra(String key, int value) {
1315 if (mExtras == null) {
1316 mExtras = new Bundle();
1317 }
1318 mExtras.putInt(key, value);
1319 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1320 }
1321
1322 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001323 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001324 *
1325 * @param key The extra key.
1326 * @param value The value.
1327 * @hide
1328 */
1329 public final void putExtra(String key, String value) {
1330 if (mExtras == null) {
1331 mExtras = new Bundle();
1332 }
1333 mExtras.putString(key, value);
1334 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1335 }
1336
1337 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001338 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001339 *
1340 * @param keys The keys of the extras to remove.
1341 */
1342 public final void removeExtras(List<String> keys) {
1343 if (mExtras != null) {
1344 for (String key : keys) {
1345 mExtras.remove(key);
1346 }
1347 if (mExtras.size() == 0) {
1348 mExtras = null;
1349 }
1350 }
1351 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1352 }
1353
1354 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001355 * Removes extras from this {@link Call}.
1356 *
1357 * @param keys The keys of the extras to remove.
1358 */
1359 public final void removeExtras(String ... keys) {
1360 removeExtras(Arrays.asList(keys));
1361 }
1362
1363 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001364 * Obtains the parent of this {@code Call} in a conference, if any.
1365 *
1366 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1367 * child of any conference {@code Call}s.
1368 */
1369 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001370 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001371 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001372 }
1373 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001374 }
1375
1376 /**
1377 * Obtains the children of this conference {@code Call}, if any.
1378 *
1379 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1380 * {@code List} otherwise.
1381 */
1382 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001383 if (!mChildrenCached) {
1384 mChildrenCached = true;
1385 mChildren.clear();
1386
1387 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001388 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001389 if (call == null) {
1390 // At least one child was still not found, so do not save true for "cached"
1391 mChildrenCached = false;
1392 } else {
1393 mChildren.add(call);
1394 }
1395 }
1396 }
1397
Ihab Awade63fadb2014-07-09 21:52:04 -07001398 return mUnmodifiableChildren;
1399 }
1400
1401 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001402 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1403 *
1404 * @return The list of conferenceable {@code Call}s.
1405 */
1406 public List<Call> getConferenceableCalls() {
1407 return mUnmodifiableConferenceableCalls;
1408 }
1409
1410 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001411 * Obtains the state of this {@code Call}.
1412 *
1413 * @return A state value, chosen from the {@code STATE_*} constants.
1414 */
1415 public int getState() {
1416 return mState;
1417 }
1418
1419 /**
1420 * Obtains a list of canned, pre-configured message responses to present to the user as
1421 * ways of rejecting this {@code Call} using via a text message.
1422 *
1423 * @see #reject(boolean, String)
1424 *
1425 * @return A list of canned text message responses.
1426 */
1427 public List<String> getCannedTextResponses() {
1428 return mCannedTextResponses;
1429 }
1430
1431 /**
1432 * Obtains an object that can be used to display video from this {@code Call}.
1433 *
Andrew Lee50aca232014-07-22 16:41:54 -07001434 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001435 */
Andrew Lee50aca232014-07-22 16:41:54 -07001436 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001437 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001438 }
1439
1440 /**
1441 * Obtains an object containing call details.
1442 *
1443 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1444 * result may be {@code null}.
1445 */
1446 public Details getDetails() {
1447 return mDetails;
1448 }
1449
1450 /**
Hall Liu95d55872017-01-25 17:12:49 -08001451 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1452 * receive RTT text data, as well as to change the RTT mode.
1453 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1454 */
1455 public @Nullable RttCall getRttCall() {
1456 return mRttCall;
1457 }
1458
1459 /**
1460 * Returns whether this call has an active RTT connection.
1461 * @return true if there is a connection, false otherwise.
1462 */
1463 public boolean isRttActive() {
1464 return mRttCall != null;
1465 }
1466
1467 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001468 * Registers a callback to this {@code Call}.
1469 *
1470 * @param callback A {@code Callback}.
1471 */
1472 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001473 registerCallback(callback, new Handler());
1474 }
1475
1476 /**
1477 * Registers a callback to this {@code Call}.
1478 *
1479 * @param callback A {@code Callback}.
1480 * @param handler A handler which command and status changes will be delivered to.
1481 */
1482 public void registerCallback(Callback callback, Handler handler) {
1483 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001484 // Don't allow new callback registration if the call is already being destroyed.
1485 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001486 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1487 }
Andrew Leeda80c872015-04-15 14:09:50 -07001488 }
1489
1490 /**
1491 * Unregisters a callback from this {@code Call}.
1492 *
1493 * @param callback A {@code Callback}.
1494 */
1495 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001496 // Don't allow callback deregistration if the call is already being destroyed.
1497 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001498 for (CallbackRecord<Callback> record : mCallbackRecords) {
1499 if (record.getCallback() == callback) {
1500 mCallbackRecords.remove(record);
1501 break;
1502 }
1503 }
Andrew Leeda80c872015-04-15 14:09:50 -07001504 }
1505 }
1506
Santos Cordon3c20d632016-02-25 16:12:35 -08001507 @Override
1508 public String toString() {
1509 return new StringBuilder().
1510 append("Call [id: ").
1511 append(mTelecomCallId).
1512 append(", state: ").
1513 append(stateToString(mState)).
1514 append(", details: ").
1515 append(mDetails).
1516 append("]").toString();
1517 }
1518
1519 /**
1520 * @param state An integer value of a {@code STATE_*} constant.
1521 * @return A string representation of the value.
1522 */
1523 private static String stateToString(int state) {
1524 switch (state) {
1525 case STATE_NEW:
1526 return "NEW";
1527 case STATE_RINGING:
1528 return "RINGING";
1529 case STATE_DIALING:
1530 return "DIALING";
1531 case STATE_ACTIVE:
1532 return "ACTIVE";
1533 case STATE_HOLDING:
1534 return "HOLDING";
1535 case STATE_DISCONNECTED:
1536 return "DISCONNECTED";
1537 case STATE_CONNECTING:
1538 return "CONNECTING";
1539 case STATE_DISCONNECTING:
1540 return "DISCONNECTING";
1541 case STATE_SELECT_PHONE_ACCOUNT:
1542 return "SELECT_PHONE_ACCOUNT";
1543 default:
1544 Log.w(Call.class, "Unknown state %d", state);
1545 return "UNKNOWN";
1546 }
1547 }
1548
Andrew Leeda80c872015-04-15 14:09:50 -07001549 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001550 * Adds a listener to this {@code Call}.
1551 *
1552 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001553 * @deprecated Use {@link #registerCallback} instead.
1554 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001555 */
Andrew Leeda80c872015-04-15 14:09:50 -07001556 @Deprecated
1557 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001558 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001559 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001560 }
1561
1562 /**
1563 * Removes a listener from this {@code Call}.
1564 *
1565 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001566 * @deprecated Use {@link #unregisterCallback} instead.
1567 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001568 */
Andrew Leeda80c872015-04-15 14:09:50 -07001569 @Deprecated
1570 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001571 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001572 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001573 }
1574
1575 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001576 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1577 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001578 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001579 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001580 mInCallAdapter = inCallAdapter;
1581 mState = STATE_NEW;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001582 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001583 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001584 }
1585
1586 /** {@hide} */
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001587 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001588 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001589 mPhone = phone;
1590 mTelecomCallId = telecomCallId;
1591 mInCallAdapter = inCallAdapter;
1592 mState = state;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001593 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001594 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001595 }
1596
1597 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001598 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001599 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001600 }
1601
1602 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001603 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001604
Ihab Awade63fadb2014-07-09 21:52:04 -07001605 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001606 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001607 boolean detailsChanged = !Objects.equals(mDetails, details);
1608 if (detailsChanged) {
1609 mDetails = details;
1610 }
1611
1612 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001613 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1614 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1615 mCannedTextResponses =
1616 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001617 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001618 }
1619
Tyler Gunn159f35c2017-03-02 09:28:37 -08001620 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1621 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001622 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001623 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001624 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001625 mVideoCallImpl = newVideoCallImpl;
1626 }
1627 if (mVideoCallImpl != null) {
1628 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001629 }
1630
Santos Cordone3c507b2015-04-23 14:44:19 -07001631 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001632 boolean stateChanged = mState != state;
1633 if (stateChanged) {
1634 mState = state;
1635 }
1636
Santos Cordon823fd3c2014-08-07 18:35:18 -07001637 String parentId = parcelableCall.getParentCallId();
1638 boolean parentChanged = !Objects.equals(mParentId, parentId);
1639 if (parentChanged) {
1640 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001641 }
1642
Santos Cordon823fd3c2014-08-07 18:35:18 -07001643 List<String> childCallIds = parcelableCall.getChildCallIds();
1644 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1645 if (childrenChanged) {
1646 mChildrenIds.clear();
1647 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1648 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001649 }
1650
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001651 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1652 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1653 for (String otherId : conferenceableCallIds) {
1654 if (callIdMap.containsKey(otherId)) {
1655 conferenceableCalls.add(callIdMap.get(otherId));
1656 }
1657 }
1658
1659 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1660 mConferenceableCalls.clear();
1661 mConferenceableCalls.addAll(conferenceableCalls);
1662 fireConferenceableCallsChanged();
1663 }
1664
Hall Liu95d55872017-01-25 17:12:49 -08001665 boolean isRttChanged = false;
1666 boolean rttModeChanged = false;
1667 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1668 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1669 InputStreamReader receiveStream = new InputStreamReader(
1670 new ParcelFileDescriptor.AutoCloseInputStream(
1671 parcelableRttCall.getReceiveStream()),
1672 StandardCharsets.UTF_8);
1673 OutputStreamWriter transmitStream = new OutputStreamWriter(
1674 new ParcelFileDescriptor.AutoCloseOutputStream(
1675 parcelableRttCall.getTransmitStream()),
1676 StandardCharsets.UTF_8);
Hall Liub64ac4c2017-02-06 10:49:48 -08001677 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08001678 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1679 if (mRttCall == null) {
1680 isRttChanged = true;
1681 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1682 rttModeChanged = true;
1683 }
1684 mRttCall = newRttCall;
1685 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1686 && parcelableCall.getIsRttCallChanged()) {
1687 isRttChanged = true;
1688 mRttCall = null;
1689 }
1690
Ihab Awade63fadb2014-07-09 21:52:04 -07001691 // Now we fire updates, ensuring that any client who listens to any of these notifications
1692 // gets the most up-to-date state.
1693
1694 if (stateChanged) {
1695 fireStateChanged(mState);
1696 }
1697 if (detailsChanged) {
1698 fireDetailsChanged(mDetails);
1699 }
1700 if (cannedTextResponsesChanged) {
1701 fireCannedTextResponsesLoaded(mCannedTextResponses);
1702 }
Andrew Lee50aca232014-07-22 16:41:54 -07001703 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001704 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001705 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001706 if (parentChanged) {
1707 fireParentChanged(getParent());
1708 }
1709 if (childrenChanged) {
1710 fireChildrenChanged(getChildren());
1711 }
Hall Liu95d55872017-01-25 17:12:49 -08001712 if (isRttChanged) {
1713 fireOnIsRttChanged(mRttCall != null, mRttCall);
1714 }
1715 if (rttModeChanged) {
1716 fireOnRttModeChanged(mRttCall.getRttAudioMode());
1717 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001718
1719 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1720 // remove ourselves from the Phone. Note that we do this after completing all state updates
1721 // so a client can cleanly transition all their UI to the state appropriate for a
1722 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1723 if (mState == STATE_DISCONNECTED) {
1724 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001725 }
1726 }
1727
1728 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001729 final void internalSetPostDialWait(String remaining) {
1730 mRemainingPostDialSequence = remaining;
1731 firePostDialWait(mRemainingPostDialSequence);
1732 }
1733
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001734 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001735 final void internalSetDisconnected() {
1736 if (mState != Call.STATE_DISCONNECTED) {
1737 mState = Call.STATE_DISCONNECTED;
1738 fireStateChanged(mState);
1739 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001740 }
1741 }
1742
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001743 /** {@hide} */
1744 final void internalOnConnectionEvent(String event, Bundle extras) {
1745 fireOnConnectionEvent(event, extras);
1746 }
1747
Hall Liu95d55872017-01-25 17:12:49 -08001748 /** {@hide} */
1749 final void internalOnRttUpgradeRequest(final int requestId) {
1750 for (CallbackRecord<Callback> record : mCallbackRecords) {
1751 final Call call = this;
1752 final Callback callback = record.getCallback();
1753 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
1754 }
1755 }
1756
Hall Liub64ac4c2017-02-06 10:49:48 -08001757 /** @hide */
1758 final void internalOnRttInitiationFailure(int reason) {
1759 for (CallbackRecord<Callback> record : mCallbackRecords) {
1760 final Call call = this;
1761 final Callback callback = record.getCallback();
1762 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
1763 }
1764 }
1765
Andrew Lee011728f2015-04-23 15:47:06 -07001766 private void fireStateChanged(final int newState) {
1767 for (CallbackRecord<Callback> record : mCallbackRecords) {
1768 final Call call = this;
1769 final Callback callback = record.getCallback();
1770 record.getHandler().post(new Runnable() {
1771 @Override
1772 public void run() {
1773 callback.onStateChanged(call, newState);
1774 }
1775 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001776 }
1777 }
1778
Andrew Lee011728f2015-04-23 15:47:06 -07001779 private void fireParentChanged(final Call newParent) {
1780 for (CallbackRecord<Callback> record : mCallbackRecords) {
1781 final Call call = this;
1782 final Callback callback = record.getCallback();
1783 record.getHandler().post(new Runnable() {
1784 @Override
1785 public void run() {
1786 callback.onParentChanged(call, newParent);
1787 }
1788 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001789 }
1790 }
1791
Andrew Lee011728f2015-04-23 15:47:06 -07001792 private void fireChildrenChanged(final List<Call> children) {
1793 for (CallbackRecord<Callback> record : mCallbackRecords) {
1794 final Call call = this;
1795 final Callback callback = record.getCallback();
1796 record.getHandler().post(new Runnable() {
1797 @Override
1798 public void run() {
1799 callback.onChildrenChanged(call, children);
1800 }
1801 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001802 }
1803 }
1804
Andrew Lee011728f2015-04-23 15:47:06 -07001805 private void fireDetailsChanged(final Details details) {
1806 for (CallbackRecord<Callback> record : mCallbackRecords) {
1807 final Call call = this;
1808 final Callback callback = record.getCallback();
1809 record.getHandler().post(new Runnable() {
1810 @Override
1811 public void run() {
1812 callback.onDetailsChanged(call, details);
1813 }
1814 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001815 }
1816 }
1817
Andrew Lee011728f2015-04-23 15:47:06 -07001818 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1819 for (CallbackRecord<Callback> record : mCallbackRecords) {
1820 final Call call = this;
1821 final Callback callback = record.getCallback();
1822 record.getHandler().post(new Runnable() {
1823 @Override
1824 public void run() {
1825 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1826 }
1827 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001828 }
1829 }
1830
Andrew Lee011728f2015-04-23 15:47:06 -07001831 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1832 for (CallbackRecord<Callback> record : mCallbackRecords) {
1833 final Call call = this;
1834 final Callback callback = record.getCallback();
1835 record.getHandler().post(new Runnable() {
1836 @Override
1837 public void run() {
1838 callback.onVideoCallChanged(call, videoCall);
1839 }
1840 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001841 }
1842 }
1843
Andrew Lee011728f2015-04-23 15:47:06 -07001844 private void firePostDialWait(final String remainingPostDialSequence) {
1845 for (CallbackRecord<Callback> record : mCallbackRecords) {
1846 final Call call = this;
1847 final Callback callback = record.getCallback();
1848 record.getHandler().post(new Runnable() {
1849 @Override
1850 public void run() {
1851 callback.onPostDialWait(call, remainingPostDialSequence);
1852 }
1853 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001854 }
1855 }
1856
1857 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001858 /**
1859 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1860 * onCallRemoved callback, we remove this call from the Phone's record
1861 * only once all of the registered onCallDestroyed callbacks are executed.
1862 * All the callbacks get removed from our records as a part of this operation
1863 * since onCallDestroyed is the final callback.
1864 */
1865 final Call call = this;
1866 if (mCallbackRecords.isEmpty()) {
1867 // No callbacks registered, remove the call from Phone's record.
1868 mPhone.internalRemoveCall(call);
1869 }
1870 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001871 final Callback callback = record.getCallback();
1872 record.getHandler().post(new Runnable() {
1873 @Override
1874 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001875 boolean isFinalRemoval = false;
1876 RuntimeException toThrow = null;
1877 try {
1878 callback.onCallDestroyed(call);
1879 } catch (RuntimeException e) {
1880 toThrow = e;
1881 }
1882 synchronized(Call.this) {
1883 mCallbackRecords.remove(record);
1884 if (mCallbackRecords.isEmpty()) {
1885 isFinalRemoval = true;
1886 }
1887 }
1888 if (isFinalRemoval) {
1889 mPhone.internalRemoveCall(call);
1890 }
1891 if (toThrow != null) {
1892 throw toThrow;
1893 }
Andrew Lee011728f2015-04-23 15:47:06 -07001894 }
1895 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001896 }
1897 }
1898
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001899 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001900 for (CallbackRecord<Callback> record : mCallbackRecords) {
1901 final Call call = this;
1902 final Callback callback = record.getCallback();
1903 record.getHandler().post(new Runnable() {
1904 @Override
1905 public void run() {
1906 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1907 }
1908 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001909 }
1910 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001911
1912 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001913 * Notifies listeners of an incoming connection event.
1914 * <p>
1915 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1916 *
1917 * @param event
1918 * @param extras
1919 */
1920 private void fireOnConnectionEvent(final String event, final Bundle extras) {
1921 for (CallbackRecord<Callback> record : mCallbackRecords) {
1922 final Call call = this;
1923 final Callback callback = record.getCallback();
1924 record.getHandler().post(new Runnable() {
1925 @Override
1926 public void run() {
1927 callback.onConnectionEvent(call, event, extras);
1928 }
1929 });
1930 }
1931 }
1932
1933 /**
Hall Liu95d55872017-01-25 17:12:49 -08001934 * Notifies listeners of an RTT on/off change
1935 *
1936 * @param enabled True if RTT is now enabled, false otherwise
1937 */
1938 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
1939 for (CallbackRecord<Callback> record : mCallbackRecords) {
1940 final Call call = this;
1941 final Callback callback = record.getCallback();
1942 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
1943 }
1944 }
1945
1946 /**
1947 * Notifies listeners of a RTT mode change
1948 *
1949 * @param mode The new RTT mode
1950 */
1951 private void fireOnRttModeChanged(final int mode) {
1952 for (CallbackRecord<Callback> record : mCallbackRecords) {
1953 final Call call = this;
1954 final Callback callback = record.getCallback();
1955 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
1956 }
1957 }
1958
1959 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001960 * Determines if two bundles are equal.
1961 *
1962 * @param bundle The original bundle.
1963 * @param newBundle The bundle to compare with.
1964 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1965 */
1966 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1967 if (bundle == null || newBundle == null) {
1968 return bundle == newBundle;
1969 }
1970
1971 if (bundle.size() != newBundle.size()) {
1972 return false;
1973 }
1974
1975 for(String key : bundle.keySet()) {
1976 if (key != null) {
1977 final Object value = bundle.get(key);
1978 final Object newValue = newBundle.get(key);
1979 if (!Objects.equals(value, newValue)) {
1980 return false;
1981 }
1982 }
1983 }
1984 return true;
1985 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001986}