blob: d79a102efb78d150783883ff2ea1ec46ab1afed4 [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;
Ihab Awade63fadb2014-07-09 21:52:04 -0700351
352 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800353 * Whether the supplied capabilities supports the specified capability.
354 *
355 * @param capabilities A bit field of capabilities.
356 * @param capability The capability to check capabilities for.
357 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800358 */
359 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800360 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800361 }
362
363 /**
364 * Whether the capabilities of this {@code Details} supports the specified capability.
365 *
366 * @param capability The capability to check capabilities for.
367 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800368 */
369 public boolean can(int capability) {
370 return can(mCallCapabilities, capability);
371 }
372
373 /**
374 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
375 *
376 * @param capabilities A capability bit field.
377 * @return A human readable string representation.
378 */
379 public static String capabilitiesToString(int capabilities) {
380 StringBuilder builder = new StringBuilder();
381 builder.append("[Capabilities:");
382 if (can(capabilities, CAPABILITY_HOLD)) {
383 builder.append(" CAPABILITY_HOLD");
384 }
385 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
386 builder.append(" CAPABILITY_SUPPORT_HOLD");
387 }
388 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
389 builder.append(" CAPABILITY_MERGE_CONFERENCE");
390 }
391 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
392 builder.append(" CAPABILITY_SWAP_CONFERENCE");
393 }
394 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
395 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
396 }
397 if (can(capabilities, CAPABILITY_MUTE)) {
398 builder.append(" CAPABILITY_MUTE");
399 }
400 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
401 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
402 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700403 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
404 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
405 }
406 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
407 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
408 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700409 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
410 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800411 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700412 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
413 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
414 }
415 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
416 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
417 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800418 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
419 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
420 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700421 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
422 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800423 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500424 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700425 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500426 }
Rekha Kumar07366812015-03-24 16:42:31 -0700427 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
428 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
429 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700430 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
431 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
432 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700433 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
434 builder.append(" CAPABILITY_CAN_PULL_CALL");
435 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800436 builder.append("]");
437 return builder.toString();
438 }
439
440 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700441 * Whether the supplied properties includes the specified property.
442 *
443 * @param properties A bit field of properties.
444 * @param property The property to check properties for.
445 * @return Whether the specified property is supported.
446 */
447 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800448 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700449 }
450
451 /**
452 * Whether the properties of this {@code Details} includes the specified property.
453 *
454 * @param property The property to check properties for.
455 * @return Whether the specified property is supported.
456 */
457 public boolean hasProperty(int property) {
458 return hasProperty(mCallProperties, property);
459 }
460
461 /**
462 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
463 *
464 * @param properties A property bit field.
465 * @return A human readable string representation.
466 */
467 public static String propertiesToString(int properties) {
468 StringBuilder builder = new StringBuilder();
469 builder.append("[Properties:");
470 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
471 builder.append(" PROPERTY_CONFERENCE");
472 }
473 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
474 builder.append(" PROPERTY_GENERIC_CONFERENCE");
475 }
476 if (hasProperty(properties, PROPERTY_WIFI)) {
477 builder.append(" PROPERTY_WIFI");
478 }
479 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
480 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
481 }
482 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700483 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700484 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700485 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
486 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
487 }
Brad Ebinger15847072016-05-18 11:08:36 -0700488 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
489 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
490 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700491 builder.append("]");
492 return builder.toString();
493 }
494
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800495 /** {@hide} */
496 public String getTelecomCallId() {
497 return mTelecomCallId;
498 }
499
Andrew Lee2378ea72015-04-29 14:38:11 -0700500 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700501 * @return The handle (e.g., phone number) to which the {@code Call} is currently
502 * connected.
503 */
504 public Uri getHandle() {
505 return mHandle;
506 }
507
508 /**
509 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700510 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700511 */
512 public int getHandlePresentation() {
513 return mHandlePresentation;
514 }
515
516 /**
517 * @return The display name for the caller.
518 */
519 public String getCallerDisplayName() {
520 return mCallerDisplayName;
521 }
522
523 /**
524 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700525 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700526 */
527 public int getCallerDisplayNamePresentation() {
528 return mCallerDisplayNamePresentation;
529 }
530
531 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700532 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
533 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700534 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700535 public PhoneAccountHandle getAccountHandle() {
536 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700537 }
538
539 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800540 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
541 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700542 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700543 public int getCallCapabilities() {
544 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700545 }
546
547 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700548 * @return A bitmask of the properties of the {@code Call}, as defined by the various
549 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700550 */
551 public int getCallProperties() {
552 return mCallProperties;
553 }
554
555 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800556 * @return a bitmask of the audio routes available for the call.
557 *
558 * @hide
559 */
560 public int getSupportedAudioRoutes() {
561 return mSupportedAudioRoutes;
562 }
563
564 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700565 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700566 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700567 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700568 public DisconnectCause getDisconnectCause() {
569 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700570 }
571
572 /**
573 * @return The time the {@code Call} has been connected. This information is updated
574 * periodically, but user interfaces should not rely on this to display any "call time
575 * clock".
576 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700577 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700578 return mConnectTimeMillis;
579 }
580
581 /**
582 * @return Information about any calling gateway the {@code Call} may be using.
583 */
584 public GatewayInfo getGatewayInfo() {
585 return mGatewayInfo;
586 }
587
Andrew Lee7a341382014-07-15 17:05:08 -0700588 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700589 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700590 */
591 public int getVideoState() {
592 return mVideoState;
593 }
594
Ihab Awad5d0410f2014-07-30 10:07:40 -0700595 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700596 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700597 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700598 */
599 public StatusHints getStatusHints() {
600 return mStatusHints;
601 }
602
Nancy Chen10798dc2014-08-08 14:00:25 -0700603 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700604 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700605 */
606 public Bundle getExtras() {
607 return mExtras;
608 }
609
Santos Cordon6b7f9552015-05-27 17:21:45 -0700610 /**
611 * @return The extras used with the original intent to place this call.
612 */
613 public Bundle getIntentExtras() {
614 return mIntentExtras;
615 }
616
Ihab Awade63fadb2014-07-09 21:52:04 -0700617 @Override
618 public boolean equals(Object o) {
619 if (o instanceof Details) {
620 Details d = (Details) o;
621 return
622 Objects.equals(mHandle, d.mHandle) &&
623 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
624 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
625 Objects.equals(mCallerDisplayNamePresentation,
626 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700627 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700628 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700629 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700630 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700631 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700632 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700633 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700634 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700635 areBundlesEqual(mExtras, d.mExtras) &&
636 areBundlesEqual(mIntentExtras, d.mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700637 }
638 return false;
639 }
640
641 @Override
642 public int hashCode() {
643 return
644 Objects.hashCode(mHandle) +
645 Objects.hashCode(mHandlePresentation) +
646 Objects.hashCode(mCallerDisplayName) +
647 Objects.hashCode(mCallerDisplayNamePresentation) +
Evan Charlton8c8a0622014-07-20 12:31:00 -0700648 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700649 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700650 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700651 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700652 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700653 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700654 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700655 Objects.hashCode(mStatusHints) +
Santos Cordon6b7f9552015-05-27 17:21:45 -0700656 Objects.hashCode(mExtras) +
657 Objects.hashCode(mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700658 }
659
660 /** {@hide} */
661 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800662 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700663 Uri handle,
664 int handlePresentation,
665 String callerDisplayName,
666 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700667 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700668 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700669 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700670 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700671 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700672 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700673 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700674 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700675 Bundle extras,
676 Bundle intentExtras) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800677 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700678 mHandle = handle;
679 mHandlePresentation = handlePresentation;
680 mCallerDisplayName = callerDisplayName;
681 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700682 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700683 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700684 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700685 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700686 mConnectTimeMillis = connectTimeMillis;
687 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700688 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700689 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700690 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700691 mIntentExtras = intentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700692 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800693
694 /** {@hide} */
695 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
696 return new Details(
697 parcelableCall.getId(),
698 parcelableCall.getHandle(),
699 parcelableCall.getHandlePresentation(),
700 parcelableCall.getCallerDisplayName(),
701 parcelableCall.getCallerDisplayNamePresentation(),
702 parcelableCall.getAccountHandle(),
703 parcelableCall.getCapabilities(),
704 parcelableCall.getProperties(),
705 parcelableCall.getDisconnectCause(),
706 parcelableCall.getConnectTimeMillis(),
707 parcelableCall.getGatewayInfo(),
708 parcelableCall.getVideoState(),
709 parcelableCall.getStatusHints(),
710 parcelableCall.getExtras(),
711 parcelableCall.getIntentExtras());
712 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800713
714 @Override
715 public String toString() {
716 StringBuilder sb = new StringBuilder();
717 sb.append("[pa: ");
718 sb.append(mAccountHandle);
719 sb.append(", hdl: ");
720 sb.append(Log.pii(mHandle));
721 sb.append(", caps: ");
722 sb.append(capabilitiesToString(mCallCapabilities));
723 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700724 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800725 sb.append("]");
726 return sb.toString();
727 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700728 }
729
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700730 /**
731 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
732 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
733 * implementation.
734 * <p>
735 * You can handle these callbacks by extending the {@link Callback} class and overriding the
736 * callbacks that your {@link InCallService} is interested in. The callback methods include the
737 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
738 * {@link Callback} implementation, if desired.
739 * <p>
740 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
741 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
742 * (typically in {@link InCallService#onCallRemoved(Call)}).
743 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
744 * reach your implementation of {@link Callback}, so it is important to register your callback
745 * as soon as your {@link InCallService} is notified of a new call via
746 * {@link InCallService#onCallAdded(Call)}.
747 */
Andrew Leeda80c872015-04-15 14:09:50 -0700748 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700749 /**
750 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
751 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700752 * @param call The {@code Call} invoking this method.
753 * @param state The new state of the {@code Call}.
754 */
755 public void onStateChanged(Call call, int state) {}
756
757 /**
758 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
759 *
760 * @param call The {@code Call} invoking this method.
761 * @param parent The new parent of the {@code Call}.
762 */
763 public void onParentChanged(Call call, Call parent) {}
764
765 /**
766 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
767 *
768 * @param call The {@code Call} invoking this method.
769 * @param children The new children of the {@code Call}.
770 */
771 public void onChildrenChanged(Call call, List<Call> children) {}
772
773 /**
774 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
775 *
776 * @param call The {@code Call} invoking this method.
777 * @param details A {@code Details} object describing the {@code Call}.
778 */
779 public void onDetailsChanged(Call call, Details details) {}
780
781 /**
782 * Invoked when the text messages that can be used as responses to the incoming
783 * {@code Call} are loaded from the relevant database.
784 * See {@link #getCannedTextResponses()}.
785 *
786 * @param call The {@code Call} invoking this method.
787 * @param cannedTextResponses The text messages useable as responses.
788 */
789 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
790
791 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700792 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
793 * character. This causes the post-dial signals to stop pending user confirmation. An
794 * implementation should present this choice to the user and invoke
795 * {@link #postDialContinue(boolean)} when the user makes the choice.
796 *
797 * @param call The {@code Call} invoking this method.
798 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
799 */
800 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
801
802 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700803 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700804 *
805 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700806 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700807 */
Andrew Lee50aca232014-07-22 16:41:54 -0700808 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700809
810 /**
811 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
812 * up their UI for the {@code Call} in response to state transitions. Specifically,
813 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
814 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
815 * clients should wait for this method to be invoked.
816 *
817 * @param call The {@code Call} being destroyed.
818 */
819 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700820
821 /**
822 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
823 * conferenced.
824 *
825 * @param call The {@code Call} being updated.
826 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
827 * conferenced.
828 */
829 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700830
831 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700832 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
833 * <p>
834 * Where possible, the Call should make an attempt to handle {@link Connection} events which
835 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
836 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
837 * possible that a {@link ConnectionService} has defined its own Connection events which a
838 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700839 * <p>
840 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
841 *
842 * @param call The {@code Call} receiving the event.
843 * @param event The event.
844 * @param extras Extras associated with the connection event.
845 */
846 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -0800847
848 /**
849 * Invoked when the RTT mode changes for this call.
850 * @param call The call whose RTT mode has changed.
851 * @param mode the new RTT mode, one of
852 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
853 * or {@link RttCall#RTT_MODE_VCO}
854 */
855 public void onRttModeChanged(Call call, int mode) {}
856
857 /**
858 * Invoked when the call's RTT status changes, either from off to on or from on to off.
859 * @param call The call whose RTT status has changed.
860 * @param enabled whether RTT is now enabled or disabled
861 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
862 * on, null otherwise.
863 */
864 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
865
866 /**
867 * Invoked when the remote end of the connection has requested that an RTT communication
868 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
869 * with the same ID that this method is invoked with.
870 * @param call The call which the RTT request was placed on
871 * @param id The ID of the request.
872 */
873 public void onRttRequest(Call call, int id) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800874
875 /**
876 * Invoked when the RTT session failed to initiate for some reason, including rejection
877 * by the remote party.
878 * @param call The call which the RTT initiation failure occurred on.
879 * @param reason One of the status codes defined in
880 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
881 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
882 */
883 public void onRttInitiationFailure(Call call, int reason) {}
Hall Liu95d55872017-01-25 17:12:49 -0800884 }
885
886 /**
887 * A class that holds the state that describes the state of the RTT channel to the remote
888 * party, if it is active.
889 */
890 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -0800891 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -0800892 @Retention(RetentionPolicy.SOURCE)
893 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
894 public @interface RttAudioMode {}
895
896 /**
897 * For metrics use. Default value in the proto.
898 * @hide
899 */
900 public static final int RTT_MODE_INVALID = 0;
901
902 /**
903 * Indicates that there should be a bidirectional audio stream between the two parties
904 * on the call.
905 */
906 public static final int RTT_MODE_FULL = 1;
907
908 /**
909 * Indicates that the local user should be able to hear the audio stream from the remote
910 * user, but not vice versa. Equivalent to muting the microphone.
911 */
912 public static final int RTT_MODE_HCO = 2;
913
914 /**
915 * Indicates that the remote user should be able to hear the audio stream from the local
916 * user, but not vice versa. Equivalent to setting the volume to zero.
917 */
918 public static final int RTT_MODE_VCO = 3;
919
920 private static final int READ_BUFFER_SIZE = 1000;
921
922 private InputStreamReader mReceiveStream;
923 private OutputStreamWriter mTransmitStream;
924 private int mRttMode;
925 private final InCallAdapter mInCallAdapter;
Hall Liub64ac4c2017-02-06 10:49:48 -0800926 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -0800927 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
928
929 /**
930 * @hide
931 */
Hall Liub64ac4c2017-02-06 10:49:48 -0800932 public RttCall(String telecomCallId, InputStreamReader receiveStream,
933 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
934 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -0800935 mReceiveStream = receiveStream;
936 mTransmitStream = transmitStream;
937 mRttMode = mode;
938 mInCallAdapter = inCallAdapter;
939 }
940
941 /**
942 * Returns the current RTT audio mode.
943 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
944 * {@link #RTT_MODE_HCO}.
945 */
946 public int getRttAudioMode() {
947 return mRttMode;
948 }
949
950 /**
951 * Sets the RTT audio mode. The requested mode change will be communicated through
952 * {@link Callback#onRttModeChanged(Call, int)}.
953 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
954 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
955 */
956 public void setRttMode(@RttAudioMode int mode) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800957 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -0800958 }
959
960 /**
961 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
962 * RTT transmits text in real-time, this method should be called once for each character
963 * the user enters into the device.
964 *
965 * This method is not thread-safe -- calling it from multiple threads simultaneously may
966 * lead to interleaved text.
967 * @param input The message to send to the remote user.
968 */
969 public void write(String input) throws IOException {
970 mTransmitStream.write(input);
971 mTransmitStream.flush();
972 }
973
974 /**
975 * Reads a string from the remote user, blocking if there is no data available. Returns
976 * {@code null} if the RTT conversation has been terminated and there is no further data
977 * to read.
978 *
979 * This method is not thread-safe -- calling it from multiple threads simultaneously may
980 * lead to interleaved text.
981 * @return A string containing text sent by the remote user, or {@code null} if the
982 * conversation has been terminated or if there was an error while reading.
983 */
Hall Liuffa4a812017-03-02 16:11:00 -0800984 public String read() throws IOException {
985 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
986 if (numRead < 0) {
987 return null;
988 }
989 return new String(mReadBuffer, 0, numRead);
990 }
991
992 /**
993 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
994 * be read.
995 * @return A string containing text entered by the user, or {@code null} if the user has
996 * not entered any new text yet.
997 */
998 public String readImmediately() throws IOException {
999 if (mReceiveStream.ready()) {
1000 return read();
1001 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001002 return null;
1003 }
1004 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001005 }
1006
Andrew Leeda80c872015-04-15 14:09:50 -07001007 /**
1008 * @deprecated Use {@code Call.Callback} instead.
1009 * @hide
1010 */
1011 @Deprecated
1012 @SystemApi
1013 public static abstract class Listener extends Callback { }
1014
Ihab Awade63fadb2014-07-09 21:52:04 -07001015 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001016 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001017 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001018 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001019 private final List<Call> mChildren = new ArrayList<>();
1020 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001021 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001022 private final List<Call> mConferenceableCalls = new ArrayList<>();
1023 private final List<Call> mUnmodifiableConferenceableCalls =
1024 Collections.unmodifiableList(mConferenceableCalls);
1025
Santos Cordon823fd3c2014-08-07 18:35:18 -07001026 private boolean mChildrenCached;
1027 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001028 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001029 private List<String> mCannedTextResponses = null;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001030 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001031 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001032 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001033 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001034 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001035 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001036 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001037
1038 /**
1039 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1040 *
1041 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1042 * remaining or this {@code Call} is not in a post-dial state.
1043 */
1044 public String getRemainingPostDialSequence() {
1045 return mRemainingPostDialSequence;
1046 }
1047
1048 /**
1049 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001050 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001051 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001052 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001053 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001054 }
1055
1056 /**
1057 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1058 *
1059 * @param rejectWithMessage Whether to reject with a text message.
1060 * @param textMessage An optional text message with which to respond.
1061 */
1062 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001063 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001064 }
1065
1066 /**
1067 * Instructs this {@code Call} to disconnect.
1068 */
1069 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001070 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001071 }
1072
1073 /**
1074 * Instructs this {@code Call} to go on hold.
1075 */
1076 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001077 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001078 }
1079
1080 /**
1081 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1082 */
1083 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001084 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001085 }
1086
1087 /**
1088 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1089 *
1090 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1091 *
1092 * @param digit A character representing the DTMF digit for which to play the tone. This
1093 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1094 */
1095 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001096 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001097 }
1098
1099 /**
1100 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1101 * currently playing.
1102 *
1103 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1104 * currently playing, this method will do nothing.
1105 */
1106 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001107 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001108 }
1109
1110 /**
1111 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1112 *
1113 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1114 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001115 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001116 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001117 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1118 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001119 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001120 * {@code Call} will pause playing the tones and notify callbacks via
1121 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001122 * should display to the user an indication of this state and an affordance to continue
1123 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1124 * app should invoke the {@link #postDialContinue(boolean)} method.
1125 *
1126 * @param proceed Whether or not to continue with the post-dial sequence.
1127 */
1128 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001129 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001130 }
1131
1132 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001133 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001134 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001135 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001136 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1137 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001138
1139 }
1140
1141 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001142 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001143 *
1144 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001145 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001146 public void conference(Call callToConferenceWith) {
1147 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001148 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001149 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001150 }
1151
1152 /**
1153 * Instructs this {@code Call} to split from any conference call with which it may be
1154 * connected.
1155 */
1156 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001157 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001158 }
1159
1160 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001161 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001162 */
1163 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001164 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001165 }
1166
1167 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001168 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001169 */
1170 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001171 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001172 }
1173
1174 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001175 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1176 * device.
1177 * <p>
1178 * Calls to this method are ignored if the call does not have the
1179 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1180 * <p>
1181 * An {@link InCallService} will only see calls which support this method if it has the
1182 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1183 * in its manifest.
1184 */
1185 public void pullExternalCall() {
1186 // If this isn't an external call, ignore the request.
1187 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1188 return;
1189 }
1190
1191 mInCallAdapter.pullExternalCall(mTelecomCallId);
1192 }
1193
1194 /**
1195 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1196 * the {@link ConnectionService}.
1197 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001198 * Call events are used to communicate point in time information from an {@link InCallService}
1199 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1200 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1201 * {@link ConnectionService}.
1202 * <p>
1203 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1204 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1205 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001206 * Events are exposed to {@link ConnectionService} implementations via
1207 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1208 * <p>
1209 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001210 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1211 * ignore some events altogether.
1212 * <p>
1213 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1214 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1215 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1216 * they define their own event types in this namespace. When defining a custom event type,
1217 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1218 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1219 * <p>
1220 * When defining events and the associated extras, it is important to keep their behavior
1221 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1222 * events/extras should me maintained to ensure backwards compatibility with older
1223 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001224 *
1225 * @param event The connection event.
1226 * @param extras Bundle containing extra information associated with the event.
1227 */
1228 public void sendCallEvent(String event, Bundle extras) {
1229 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1230 }
1231
1232 /**
Hall Liu95d55872017-01-25 17:12:49 -08001233 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1234 * guaranteed, and notification of success will be via the
1235 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1236 */
1237 public void sendRttRequest() {
Hall Liub64ac4c2017-02-06 10:49:48 -08001238 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001239 }
1240
1241 /**
1242 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1243 * callback.
1244 * The ID used here should be the same as the ID that was received via the callback.
1245 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1246 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1247 */
1248 public void respondToRttRequest(int id, boolean accept) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001249 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001250 }
1251
1252 /**
1253 * Terminate the RTT session on this call. The resulting state change will be notified via
1254 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1255 */
1256 public void stopRtt() {
Hall Liub64ac4c2017-02-06 10:49:48 -08001257 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001258 }
1259
1260 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001261 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1262 * added.
1263 * <p>
1264 * No assumptions should be made as to how an In-Call UI or service will handle these
1265 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1266 *
1267 * @param extras The extras to add.
1268 */
1269 public final void putExtras(Bundle extras) {
1270 if (extras == null) {
1271 return;
1272 }
1273
1274 if (mExtras == null) {
1275 mExtras = new Bundle();
1276 }
1277 mExtras.putAll(extras);
1278 mInCallAdapter.putExtras(mTelecomCallId, extras);
1279 }
1280
1281 /**
1282 * Adds a boolean extra to this {@link Call}.
1283 *
1284 * @param key The extra key.
1285 * @param value The value.
1286 * @hide
1287 */
1288 public final void putExtra(String key, boolean value) {
1289 if (mExtras == null) {
1290 mExtras = new Bundle();
1291 }
1292 mExtras.putBoolean(key, value);
1293 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1294 }
1295
1296 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001297 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001298 *
1299 * @param key The extra key.
1300 * @param value The value.
1301 * @hide
1302 */
1303 public final void putExtra(String key, int value) {
1304 if (mExtras == null) {
1305 mExtras = new Bundle();
1306 }
1307 mExtras.putInt(key, value);
1308 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1309 }
1310
1311 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001312 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001313 *
1314 * @param key The extra key.
1315 * @param value The value.
1316 * @hide
1317 */
1318 public final void putExtra(String key, String value) {
1319 if (mExtras == null) {
1320 mExtras = new Bundle();
1321 }
1322 mExtras.putString(key, value);
1323 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1324 }
1325
1326 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001327 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001328 *
1329 * @param keys The keys of the extras to remove.
1330 */
1331 public final void removeExtras(List<String> keys) {
1332 if (mExtras != null) {
1333 for (String key : keys) {
1334 mExtras.remove(key);
1335 }
1336 if (mExtras.size() == 0) {
1337 mExtras = null;
1338 }
1339 }
1340 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1341 }
1342
1343 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001344 * Removes extras from this {@link Call}.
1345 *
1346 * @param keys The keys of the extras to remove.
1347 */
1348 public final void removeExtras(String ... keys) {
1349 removeExtras(Arrays.asList(keys));
1350 }
1351
1352 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001353 * Obtains the parent of this {@code Call} in a conference, if any.
1354 *
1355 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1356 * child of any conference {@code Call}s.
1357 */
1358 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001359 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001360 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001361 }
1362 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001363 }
1364
1365 /**
1366 * Obtains the children of this conference {@code Call}, if any.
1367 *
1368 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1369 * {@code List} otherwise.
1370 */
1371 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001372 if (!mChildrenCached) {
1373 mChildrenCached = true;
1374 mChildren.clear();
1375
1376 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001377 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001378 if (call == null) {
1379 // At least one child was still not found, so do not save true for "cached"
1380 mChildrenCached = false;
1381 } else {
1382 mChildren.add(call);
1383 }
1384 }
1385 }
1386
Ihab Awade63fadb2014-07-09 21:52:04 -07001387 return mUnmodifiableChildren;
1388 }
1389
1390 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001391 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1392 *
1393 * @return The list of conferenceable {@code Call}s.
1394 */
1395 public List<Call> getConferenceableCalls() {
1396 return mUnmodifiableConferenceableCalls;
1397 }
1398
1399 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001400 * Obtains the state of this {@code Call}.
1401 *
1402 * @return A state value, chosen from the {@code STATE_*} constants.
1403 */
1404 public int getState() {
1405 return mState;
1406 }
1407
1408 /**
1409 * Obtains a list of canned, pre-configured message responses to present to the user as
1410 * ways of rejecting this {@code Call} using via a text message.
1411 *
1412 * @see #reject(boolean, String)
1413 *
1414 * @return A list of canned text message responses.
1415 */
1416 public List<String> getCannedTextResponses() {
1417 return mCannedTextResponses;
1418 }
1419
1420 /**
1421 * Obtains an object that can be used to display video from this {@code Call}.
1422 *
Andrew Lee50aca232014-07-22 16:41:54 -07001423 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001424 */
Andrew Lee50aca232014-07-22 16:41:54 -07001425 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001426 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001427 }
1428
1429 /**
1430 * Obtains an object containing call details.
1431 *
1432 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1433 * result may be {@code null}.
1434 */
1435 public Details getDetails() {
1436 return mDetails;
1437 }
1438
1439 /**
Hall Liu95d55872017-01-25 17:12:49 -08001440 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1441 * receive RTT text data, as well as to change the RTT mode.
1442 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1443 */
1444 public @Nullable RttCall getRttCall() {
1445 return mRttCall;
1446 }
1447
1448 /**
1449 * Returns whether this call has an active RTT connection.
1450 * @return true if there is a connection, false otherwise.
1451 */
1452 public boolean isRttActive() {
1453 return mRttCall != null;
1454 }
1455
1456 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001457 * Registers a callback to this {@code Call}.
1458 *
1459 * @param callback A {@code Callback}.
1460 */
1461 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001462 registerCallback(callback, new Handler());
1463 }
1464
1465 /**
1466 * Registers a callback to this {@code Call}.
1467 *
1468 * @param callback A {@code Callback}.
1469 * @param handler A handler which command and status changes will be delivered to.
1470 */
1471 public void registerCallback(Callback callback, Handler handler) {
1472 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001473 // Don't allow new callback registration if the call is already being destroyed.
1474 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001475 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1476 }
Andrew Leeda80c872015-04-15 14:09:50 -07001477 }
1478
1479 /**
1480 * Unregisters a callback from this {@code Call}.
1481 *
1482 * @param callback A {@code Callback}.
1483 */
1484 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001485 // Don't allow callback deregistration if the call is already being destroyed.
1486 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001487 for (CallbackRecord<Callback> record : mCallbackRecords) {
1488 if (record.getCallback() == callback) {
1489 mCallbackRecords.remove(record);
1490 break;
1491 }
1492 }
Andrew Leeda80c872015-04-15 14:09:50 -07001493 }
1494 }
1495
Santos Cordon3c20d632016-02-25 16:12:35 -08001496 @Override
1497 public String toString() {
1498 return new StringBuilder().
1499 append("Call [id: ").
1500 append(mTelecomCallId).
1501 append(", state: ").
1502 append(stateToString(mState)).
1503 append(", details: ").
1504 append(mDetails).
1505 append("]").toString();
1506 }
1507
1508 /**
1509 * @param state An integer value of a {@code STATE_*} constant.
1510 * @return A string representation of the value.
1511 */
1512 private static String stateToString(int state) {
1513 switch (state) {
1514 case STATE_NEW:
1515 return "NEW";
1516 case STATE_RINGING:
1517 return "RINGING";
1518 case STATE_DIALING:
1519 return "DIALING";
1520 case STATE_ACTIVE:
1521 return "ACTIVE";
1522 case STATE_HOLDING:
1523 return "HOLDING";
1524 case STATE_DISCONNECTED:
1525 return "DISCONNECTED";
1526 case STATE_CONNECTING:
1527 return "CONNECTING";
1528 case STATE_DISCONNECTING:
1529 return "DISCONNECTING";
1530 case STATE_SELECT_PHONE_ACCOUNT:
1531 return "SELECT_PHONE_ACCOUNT";
1532 default:
1533 Log.w(Call.class, "Unknown state %d", state);
1534 return "UNKNOWN";
1535 }
1536 }
1537
Andrew Leeda80c872015-04-15 14:09:50 -07001538 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001539 * Adds a listener to this {@code Call}.
1540 *
1541 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001542 * @deprecated Use {@link #registerCallback} instead.
1543 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001544 */
Andrew Leeda80c872015-04-15 14:09:50 -07001545 @Deprecated
1546 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001547 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001548 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001549 }
1550
1551 /**
1552 * Removes a listener from this {@code Call}.
1553 *
1554 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001555 * @deprecated Use {@link #unregisterCallback} instead.
1556 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001557 */
Andrew Leeda80c872015-04-15 14:09:50 -07001558 @Deprecated
1559 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001560 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001561 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001562 }
1563
1564 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001565 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1566 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001567 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001568 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001569 mInCallAdapter = inCallAdapter;
1570 mState = STATE_NEW;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001571 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001572 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001573 }
1574
1575 /** {@hide} */
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001576 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001577 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001578 mPhone = phone;
1579 mTelecomCallId = telecomCallId;
1580 mInCallAdapter = inCallAdapter;
1581 mState = state;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001582 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001583 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001584 }
1585
1586 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001587 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001588 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001589 }
1590
1591 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001592 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001593
Ihab Awade63fadb2014-07-09 21:52:04 -07001594 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001595 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001596 boolean detailsChanged = !Objects.equals(mDetails, details);
1597 if (detailsChanged) {
1598 mDetails = details;
1599 }
1600
1601 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001602 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1603 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1604 mCannedTextResponses =
1605 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001606 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001607 }
1608
Tyler Gunn159f35c2017-03-02 09:28:37 -08001609 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1610 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001611 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001612 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001613 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001614 mVideoCallImpl = newVideoCallImpl;
1615 }
1616 if (mVideoCallImpl != null) {
1617 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001618 }
1619
Santos Cordone3c507b2015-04-23 14:44:19 -07001620 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001621 boolean stateChanged = mState != state;
1622 if (stateChanged) {
1623 mState = state;
1624 }
1625
Santos Cordon823fd3c2014-08-07 18:35:18 -07001626 String parentId = parcelableCall.getParentCallId();
1627 boolean parentChanged = !Objects.equals(mParentId, parentId);
1628 if (parentChanged) {
1629 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001630 }
1631
Santos Cordon823fd3c2014-08-07 18:35:18 -07001632 List<String> childCallIds = parcelableCall.getChildCallIds();
1633 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1634 if (childrenChanged) {
1635 mChildrenIds.clear();
1636 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1637 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001638 }
1639
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001640 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1641 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1642 for (String otherId : conferenceableCallIds) {
1643 if (callIdMap.containsKey(otherId)) {
1644 conferenceableCalls.add(callIdMap.get(otherId));
1645 }
1646 }
1647
1648 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1649 mConferenceableCalls.clear();
1650 mConferenceableCalls.addAll(conferenceableCalls);
1651 fireConferenceableCallsChanged();
1652 }
1653
Hall Liu95d55872017-01-25 17:12:49 -08001654 boolean isRttChanged = false;
1655 boolean rttModeChanged = false;
1656 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1657 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1658 InputStreamReader receiveStream = new InputStreamReader(
1659 new ParcelFileDescriptor.AutoCloseInputStream(
1660 parcelableRttCall.getReceiveStream()),
1661 StandardCharsets.UTF_8);
1662 OutputStreamWriter transmitStream = new OutputStreamWriter(
1663 new ParcelFileDescriptor.AutoCloseOutputStream(
1664 parcelableRttCall.getTransmitStream()),
1665 StandardCharsets.UTF_8);
Hall Liub64ac4c2017-02-06 10:49:48 -08001666 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08001667 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1668 if (mRttCall == null) {
1669 isRttChanged = true;
1670 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1671 rttModeChanged = true;
1672 }
1673 mRttCall = newRttCall;
1674 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1675 && parcelableCall.getIsRttCallChanged()) {
1676 isRttChanged = true;
1677 mRttCall = null;
1678 }
1679
Ihab Awade63fadb2014-07-09 21:52:04 -07001680 // Now we fire updates, ensuring that any client who listens to any of these notifications
1681 // gets the most up-to-date state.
1682
1683 if (stateChanged) {
1684 fireStateChanged(mState);
1685 }
1686 if (detailsChanged) {
1687 fireDetailsChanged(mDetails);
1688 }
1689 if (cannedTextResponsesChanged) {
1690 fireCannedTextResponsesLoaded(mCannedTextResponses);
1691 }
Andrew Lee50aca232014-07-22 16:41:54 -07001692 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001693 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001694 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001695 if (parentChanged) {
1696 fireParentChanged(getParent());
1697 }
1698 if (childrenChanged) {
1699 fireChildrenChanged(getChildren());
1700 }
Hall Liu95d55872017-01-25 17:12:49 -08001701 if (isRttChanged) {
1702 fireOnIsRttChanged(mRttCall != null, mRttCall);
1703 }
1704 if (rttModeChanged) {
1705 fireOnRttModeChanged(mRttCall.getRttAudioMode());
1706 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001707
1708 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1709 // remove ourselves from the Phone. Note that we do this after completing all state updates
1710 // so a client can cleanly transition all their UI to the state appropriate for a
1711 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1712 if (mState == STATE_DISCONNECTED) {
1713 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001714 }
1715 }
1716
1717 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001718 final void internalSetPostDialWait(String remaining) {
1719 mRemainingPostDialSequence = remaining;
1720 firePostDialWait(mRemainingPostDialSequence);
1721 }
1722
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001723 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001724 final void internalSetDisconnected() {
1725 if (mState != Call.STATE_DISCONNECTED) {
1726 mState = Call.STATE_DISCONNECTED;
1727 fireStateChanged(mState);
1728 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001729 }
1730 }
1731
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001732 /** {@hide} */
1733 final void internalOnConnectionEvent(String event, Bundle extras) {
1734 fireOnConnectionEvent(event, extras);
1735 }
1736
Hall Liu95d55872017-01-25 17:12:49 -08001737 /** {@hide} */
1738 final void internalOnRttUpgradeRequest(final int requestId) {
1739 for (CallbackRecord<Callback> record : mCallbackRecords) {
1740 final Call call = this;
1741 final Callback callback = record.getCallback();
1742 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
1743 }
1744 }
1745
Hall Liub64ac4c2017-02-06 10:49:48 -08001746 /** @hide */
1747 final void internalOnRttInitiationFailure(int reason) {
1748 for (CallbackRecord<Callback> record : mCallbackRecords) {
1749 final Call call = this;
1750 final Callback callback = record.getCallback();
1751 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
1752 }
1753 }
1754
Andrew Lee011728f2015-04-23 15:47:06 -07001755 private void fireStateChanged(final int newState) {
1756 for (CallbackRecord<Callback> record : mCallbackRecords) {
1757 final Call call = this;
1758 final Callback callback = record.getCallback();
1759 record.getHandler().post(new Runnable() {
1760 @Override
1761 public void run() {
1762 callback.onStateChanged(call, newState);
1763 }
1764 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001765 }
1766 }
1767
Andrew Lee011728f2015-04-23 15:47:06 -07001768 private void fireParentChanged(final Call newParent) {
1769 for (CallbackRecord<Callback> record : mCallbackRecords) {
1770 final Call call = this;
1771 final Callback callback = record.getCallback();
1772 record.getHandler().post(new Runnable() {
1773 @Override
1774 public void run() {
1775 callback.onParentChanged(call, newParent);
1776 }
1777 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001778 }
1779 }
1780
Andrew Lee011728f2015-04-23 15:47:06 -07001781 private void fireChildrenChanged(final List<Call> children) {
1782 for (CallbackRecord<Callback> record : mCallbackRecords) {
1783 final Call call = this;
1784 final Callback callback = record.getCallback();
1785 record.getHandler().post(new Runnable() {
1786 @Override
1787 public void run() {
1788 callback.onChildrenChanged(call, children);
1789 }
1790 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001791 }
1792 }
1793
Andrew Lee011728f2015-04-23 15:47:06 -07001794 private void fireDetailsChanged(final Details details) {
1795 for (CallbackRecord<Callback> record : mCallbackRecords) {
1796 final Call call = this;
1797 final Callback callback = record.getCallback();
1798 record.getHandler().post(new Runnable() {
1799 @Override
1800 public void run() {
1801 callback.onDetailsChanged(call, details);
1802 }
1803 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001804 }
1805 }
1806
Andrew Lee011728f2015-04-23 15:47:06 -07001807 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1808 for (CallbackRecord<Callback> record : mCallbackRecords) {
1809 final Call call = this;
1810 final Callback callback = record.getCallback();
1811 record.getHandler().post(new Runnable() {
1812 @Override
1813 public void run() {
1814 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1815 }
1816 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001817 }
1818 }
1819
Andrew Lee011728f2015-04-23 15:47:06 -07001820 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1821 for (CallbackRecord<Callback> record : mCallbackRecords) {
1822 final Call call = this;
1823 final Callback callback = record.getCallback();
1824 record.getHandler().post(new Runnable() {
1825 @Override
1826 public void run() {
1827 callback.onVideoCallChanged(call, videoCall);
1828 }
1829 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001830 }
1831 }
1832
Andrew Lee011728f2015-04-23 15:47:06 -07001833 private void firePostDialWait(final String remainingPostDialSequence) {
1834 for (CallbackRecord<Callback> record : mCallbackRecords) {
1835 final Call call = this;
1836 final Callback callback = record.getCallback();
1837 record.getHandler().post(new Runnable() {
1838 @Override
1839 public void run() {
1840 callback.onPostDialWait(call, remainingPostDialSequence);
1841 }
1842 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001843 }
1844 }
1845
1846 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001847 /**
1848 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1849 * onCallRemoved callback, we remove this call from the Phone's record
1850 * only once all of the registered onCallDestroyed callbacks are executed.
1851 * All the callbacks get removed from our records as a part of this operation
1852 * since onCallDestroyed is the final callback.
1853 */
1854 final Call call = this;
1855 if (mCallbackRecords.isEmpty()) {
1856 // No callbacks registered, remove the call from Phone's record.
1857 mPhone.internalRemoveCall(call);
1858 }
1859 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001860 final Callback callback = record.getCallback();
1861 record.getHandler().post(new Runnable() {
1862 @Override
1863 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001864 boolean isFinalRemoval = false;
1865 RuntimeException toThrow = null;
1866 try {
1867 callback.onCallDestroyed(call);
1868 } catch (RuntimeException e) {
1869 toThrow = e;
1870 }
1871 synchronized(Call.this) {
1872 mCallbackRecords.remove(record);
1873 if (mCallbackRecords.isEmpty()) {
1874 isFinalRemoval = true;
1875 }
1876 }
1877 if (isFinalRemoval) {
1878 mPhone.internalRemoveCall(call);
1879 }
1880 if (toThrow != null) {
1881 throw toThrow;
1882 }
Andrew Lee011728f2015-04-23 15:47:06 -07001883 }
1884 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001885 }
1886 }
1887
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001888 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001889 for (CallbackRecord<Callback> record : mCallbackRecords) {
1890 final Call call = this;
1891 final Callback callback = record.getCallback();
1892 record.getHandler().post(new Runnable() {
1893 @Override
1894 public void run() {
1895 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1896 }
1897 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001898 }
1899 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001900
1901 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001902 * Notifies listeners of an incoming connection event.
1903 * <p>
1904 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1905 *
1906 * @param event
1907 * @param extras
1908 */
1909 private void fireOnConnectionEvent(final String event, final Bundle extras) {
1910 for (CallbackRecord<Callback> record : mCallbackRecords) {
1911 final Call call = this;
1912 final Callback callback = record.getCallback();
1913 record.getHandler().post(new Runnable() {
1914 @Override
1915 public void run() {
1916 callback.onConnectionEvent(call, event, extras);
1917 }
1918 });
1919 }
1920 }
1921
1922 /**
Hall Liu95d55872017-01-25 17:12:49 -08001923 * Notifies listeners of an RTT on/off change
1924 *
1925 * @param enabled True if RTT is now enabled, false otherwise
1926 */
1927 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
1928 for (CallbackRecord<Callback> record : mCallbackRecords) {
1929 final Call call = this;
1930 final Callback callback = record.getCallback();
1931 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
1932 }
1933 }
1934
1935 /**
1936 * Notifies listeners of a RTT mode change
1937 *
1938 * @param mode The new RTT mode
1939 */
1940 private void fireOnRttModeChanged(final int mode) {
1941 for (CallbackRecord<Callback> record : mCallbackRecords) {
1942 final Call call = this;
1943 final Callback callback = record.getCallback();
1944 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
1945 }
1946 }
1947
1948 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001949 * Determines if two bundles are equal.
1950 *
1951 * @param bundle The original bundle.
1952 * @param newBundle The bundle to compare with.
1953 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1954 */
1955 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1956 if (bundle == null || newBundle == null) {
1957 return bundle == newBundle;
1958 }
1959
1960 if (bundle.size() != newBundle.size()) {
1961 return false;
1962 }
1963
1964 for(String key : bundle.keySet()) {
1965 if (key != null) {
1966 final Object value = bundle.get(key);
1967 final Object newValue = newBundle.get(key);
1968 if (!Objects.equals(value, newValue)) {
1969 return false;
1970 }
1971 }
1972 }
1973 return true;
1974 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001975}