blob: f822d5e23b2375e78d3e73108a85bf80515c0dc9 [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
mike dooley4af561f2016-12-20 08:55:17 -0800127 /**
mike dooley91217422017-03-09 12:58:42 -0800128 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
129 * when the last outgoing emergency call was made. This is used to identify potential emergency
130 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800131 */
132 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
133 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
134
Tyler Gunn8bf76572017-04-06 15:30:08 -0700135 /**
136 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
137 * Telecom that the user has requested that the current {@link Call} should be handed over
138 * to another {@link ConnectionService}.
139 * <p>
140 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
141 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
142 * @hide
143 */
144 public static final String EVENT_REQUEST_HANDOVER =
145 "android.telecom.event.REQUEST_HANDOVER";
146
147 /**
148 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
149 * {@link PhoneAccountHandle} to which a call should be handed over to.
150 * @hide
151 */
152 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
153 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
154
155 /**
156 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
157 * video state of the call when it is handed over to the new {@link PhoneAccount}.
158 * <p>
159 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
160 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
161 * {@link VideoProfile#STATE_TX_ENABLED}.
162 * @hide
163 */
164 public static final String EXTRA_HANDOVER_VIDEO_STATE =
165 "android.telecom.extra.HANDOVER_VIDEO_STATE";
166
167 /**
168 * Call event sent from Telecom via {@link Connection#onCallEvent(String, Bundle)} to
169 * inform a {@link Connection} that a handover initiated via {@link #EVENT_REQUEST_HANDOVER}
170 * has completed.
171 * @hide
172 */
173 public static final String EVENT_HANDOVER_COMPLETE = "android.telecom.event.HANDOVER_COMPLETE";
174
175 /**
176 * Call event sent from Telecom via {@link Connection#onCallEvent(String, Bundle)} to
177 * inform a {@link Connection} that a handover initiated via {@link #EVENT_REQUEST_HANDOVER}
178 * has failed to complete.
179 * @hide
180 */
181 public static final String EVENT_HANDOVER_FAILED = "android.telecom.event.HANDOVER_FAILED";
182
Ihab Awade63fadb2014-07-09 21:52:04 -0700183 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800184
185 /** Call can currently be put on hold or unheld. */
186 public static final int CAPABILITY_HOLD = 0x00000001;
187
188 /** Call supports the hold feature. */
189 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
190
191 /**
192 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
193 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
194 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
195 * capability allows a merge button to be shown while the conference call is in the foreground
196 * of the in-call UI.
197 * <p>
198 * This is only intended for use by a {@link Conference}.
199 */
200 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
201
202 /**
203 * Calls within a conference can be swapped between foreground and background.
204 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
205 * <p>
206 * This is only intended for use by a {@link Conference}.
207 */
208 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
209
210 /**
211 * @hide
212 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700213 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800214
215 /** Call supports responding via text option. */
216 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
217
218 /** Call can be muted. */
219 public static final int CAPABILITY_MUTE = 0x00000040;
220
221 /**
222 * Call supports conference call management. This capability only applies to {@link Conference}
223 * calls which can have {@link Connection}s as children.
224 */
225 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
226
227 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700228 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800229 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700230 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800231
232 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700233 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800234 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700235 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800236
237 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700238 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800239 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700240 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700241 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800242
243 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700244 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800245 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700246 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
247
248 /**
249 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700250 */
251 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
252
253 /**
254 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700255 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700256 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700257 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800258
259 /**
260 * Call is able to be separated from its parent {@code Conference}, if any.
261 */
262 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
263
264 /**
265 * Call is able to be individually disconnected when in a {@code Conference}.
266 */
267 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
268
269 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500270 * Speed up audio setup for MT call.
271 * @hide
272 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700273 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
274
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700275 /**
276 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700277 * @hide
278 */
279 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
280
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700281 /**
282 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700283 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700284 */
285 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
286
Bryce Lee81901682015-08-28 16:38:02 -0700287 /**
288 * Call sends responses through connection.
289 * @hide
290 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800291 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
292
293 /**
294 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
295 * <p>
296 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
297 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
298 * downgraded from a video call back to a VideoState of
299 * {@link VideoProfile#STATE_AUDIO_ONLY}.
300 * <p>
301 * Intuitively, a call which can be downgraded to audio should also have local and remote
302 * video
303 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
304 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
305 */
306 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700307
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700308 /**
309 * When set for an external call, indicates that this {@code Call} can be pulled from a
310 * remote device to the current device.
311 * <p>
312 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
313 * <p>
314 * An {@link InCallService} will only see calls with this capability if it has the
315 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
316 * in its manifest.
317 * <p>
318 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700319 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700320 */
321 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
322
Tyler Gunnd11a3152015-03-18 13:09:14 -0700323 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700324 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700325 //******************************************************************************************
326
327 /**
328 * Whether the call is currently a conference.
329 */
330 public static final int PROPERTY_CONFERENCE = 0x00000001;
331
332 /**
333 * Whether the call is a generic conference, where we do not know the precise state of
334 * participants in the conference (eg. on CDMA).
335 */
336 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
337
338 /**
339 * Whether the call is made while the device is in emergency callback mode.
340 */
341 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
342
343 /**
344 * Connection is using WIFI.
345 */
346 public static final int PROPERTY_WIFI = 0x00000008;
347
348 /**
349 * Call is using high definition audio.
350 */
351 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
352
Tony Maka68dcce2015-12-17 09:31:18 +0000353 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100354 * Whether the call is associated with the work profile.
355 */
356 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
357
358 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700359 * When set, indicates that this {@code Call} does not actually exist locally for the
360 * {@link ConnectionService}.
361 * <p>
362 * Consider, for example, a scenario where a user has two phones with the same phone number.
363 * When a user places a call on one device, the telephony stack can represent that call on
364 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700365 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700366 * <p>
367 * An {@link InCallService} will only see calls with this property if it has the
368 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
369 * in its manifest.
370 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700371 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700372 */
373 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
374
Brad Ebinger15847072016-05-18 11:08:36 -0700375 /**
376 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
377 */
378 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
379
Tyler Gunn24e18332017-02-10 09:42:49 -0800380 /**
381 * Indicates that the call is from a self-managed {@link ConnectionService}.
382 * <p>
383 * See also {@link Connection#PROPERTY_SELF_MANAGED}
384 */
385 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
386
Andrew Lee2378ea72015-04-29 14:38:11 -0700387 //******************************************************************************************
Tyler Gunn24e18332017-02-10 09:42:49 -0800388 // Next PROPERTY value: 0x00000200
Tyler Gunnd11a3152015-03-18 13:09:14 -0700389 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800390
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800391 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700392 private final Uri mHandle;
393 private final int mHandlePresentation;
394 private final String mCallerDisplayName;
395 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700396 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700397 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700398 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800399 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700400 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700401 private final long mConnectTimeMillis;
402 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700403 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700404 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700405 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700406 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700407 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700408
409 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800410 * Whether the supplied capabilities supports the specified capability.
411 *
412 * @param capabilities A bit field of capabilities.
413 * @param capability The capability to check capabilities for.
414 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800415 */
416 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800417 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800418 }
419
420 /**
421 * Whether the capabilities of this {@code Details} supports the specified capability.
422 *
423 * @param capability The capability to check capabilities for.
424 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800425 */
426 public boolean can(int capability) {
427 return can(mCallCapabilities, capability);
428 }
429
430 /**
431 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
432 *
433 * @param capabilities A capability bit field.
434 * @return A human readable string representation.
435 */
436 public static String capabilitiesToString(int capabilities) {
437 StringBuilder builder = new StringBuilder();
438 builder.append("[Capabilities:");
439 if (can(capabilities, CAPABILITY_HOLD)) {
440 builder.append(" CAPABILITY_HOLD");
441 }
442 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
443 builder.append(" CAPABILITY_SUPPORT_HOLD");
444 }
445 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
446 builder.append(" CAPABILITY_MERGE_CONFERENCE");
447 }
448 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
449 builder.append(" CAPABILITY_SWAP_CONFERENCE");
450 }
451 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
452 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
453 }
454 if (can(capabilities, CAPABILITY_MUTE)) {
455 builder.append(" CAPABILITY_MUTE");
456 }
457 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
458 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
459 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700460 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
461 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
462 }
463 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
464 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
465 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700466 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
467 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800468 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700469 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
470 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
471 }
472 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
473 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
474 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800475 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
476 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
477 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700478 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
479 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800480 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500481 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700482 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500483 }
Rekha Kumar07366812015-03-24 16:42:31 -0700484 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
485 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
486 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700487 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
488 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
489 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700490 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
491 builder.append(" CAPABILITY_CAN_PULL_CALL");
492 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800493 builder.append("]");
494 return builder.toString();
495 }
496
497 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700498 * Whether the supplied properties includes the specified property.
499 *
500 * @param properties A bit field of properties.
501 * @param property The property to check properties for.
502 * @return Whether the specified property is supported.
503 */
504 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800505 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700506 }
507
508 /**
509 * Whether the properties of this {@code Details} includes the specified property.
510 *
511 * @param property The property to check properties for.
512 * @return Whether the specified property is supported.
513 */
514 public boolean hasProperty(int property) {
515 return hasProperty(mCallProperties, property);
516 }
517
518 /**
519 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
520 *
521 * @param properties A property bit field.
522 * @return A human readable string representation.
523 */
524 public static String propertiesToString(int properties) {
525 StringBuilder builder = new StringBuilder();
526 builder.append("[Properties:");
527 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
528 builder.append(" PROPERTY_CONFERENCE");
529 }
530 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
531 builder.append(" PROPERTY_GENERIC_CONFERENCE");
532 }
533 if (hasProperty(properties, PROPERTY_WIFI)) {
534 builder.append(" PROPERTY_WIFI");
535 }
536 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
537 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
538 }
539 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700540 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700541 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700542 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
543 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
544 }
Brad Ebinger15847072016-05-18 11:08:36 -0700545 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
546 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
547 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700548 builder.append("]");
549 return builder.toString();
550 }
551
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800552 /** {@hide} */
553 public String getTelecomCallId() {
554 return mTelecomCallId;
555 }
556
Andrew Lee2378ea72015-04-29 14:38:11 -0700557 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700558 * @return The handle (e.g., phone number) to which the {@code Call} is currently
559 * connected.
560 */
561 public Uri getHandle() {
562 return mHandle;
563 }
564
565 /**
566 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700567 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700568 */
569 public int getHandlePresentation() {
570 return mHandlePresentation;
571 }
572
573 /**
574 * @return The display name for the caller.
575 */
576 public String getCallerDisplayName() {
577 return mCallerDisplayName;
578 }
579
580 /**
581 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700582 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700583 */
584 public int getCallerDisplayNamePresentation() {
585 return mCallerDisplayNamePresentation;
586 }
587
588 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700589 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
590 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700591 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700592 public PhoneAccountHandle getAccountHandle() {
593 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700594 }
595
596 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800597 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
598 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700599 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700600 public int getCallCapabilities() {
601 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700602 }
603
604 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700605 * @return A bitmask of the properties of the {@code Call}, as defined by the various
606 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700607 */
608 public int getCallProperties() {
609 return mCallProperties;
610 }
611
612 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800613 * @return a bitmask of the audio routes available for the call.
614 *
615 * @hide
616 */
617 public int getSupportedAudioRoutes() {
618 return mSupportedAudioRoutes;
619 }
620
621 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700622 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700623 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700624 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700625 public DisconnectCause getDisconnectCause() {
626 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700627 }
628
629 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700630 * Returns the time the {@link Call} connected (i.e. became active). This information is
631 * updated periodically, but user interfaces should not rely on this to display the "call
632 * time clock". For the time when the call was first added to Telecom, see
633 * {@link #getCreationTimeMillis()}.
634 *
635 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700636 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700637 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700638 return mConnectTimeMillis;
639 }
640
641 /**
642 * @return Information about any calling gateway the {@code Call} may be using.
643 */
644 public GatewayInfo getGatewayInfo() {
645 return mGatewayInfo;
646 }
647
Andrew Lee7a341382014-07-15 17:05:08 -0700648 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700649 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700650 */
651 public int getVideoState() {
652 return mVideoState;
653 }
654
Ihab Awad5d0410f2014-07-30 10:07:40 -0700655 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700656 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700657 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700658 */
659 public StatusHints getStatusHints() {
660 return mStatusHints;
661 }
662
Nancy Chen10798dc2014-08-08 14:00:25 -0700663 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700664 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700665 */
666 public Bundle getExtras() {
667 return mExtras;
668 }
669
Santos Cordon6b7f9552015-05-27 17:21:45 -0700670 /**
671 * @return The extras used with the original intent to place this call.
672 */
673 public Bundle getIntentExtras() {
674 return mIntentExtras;
675 }
676
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700677 /**
678 * Returns the time when the call was first created and added to Telecom. This is the same
679 * time that is logged as the start time in the Call Log (see
680 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
681 * (became active), see {@link #getConnectTimeMillis()}.
682 *
683 * @return The creation time of the call, in millis since the epoch.
684 */
685 public long getCreationTimeMillis() {
686 return mCreationTimeMillis;
687 }
688
Ihab Awade63fadb2014-07-09 21:52:04 -0700689 @Override
690 public boolean equals(Object o) {
691 if (o instanceof Details) {
692 Details d = (Details) o;
693 return
694 Objects.equals(mHandle, d.mHandle) &&
695 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
696 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
697 Objects.equals(mCallerDisplayNamePresentation,
698 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700699 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700700 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700701 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700702 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700703 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700704 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700705 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700706 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700707 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700708 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
709 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700710 }
711 return false;
712 }
713
714 @Override
715 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700716 return Objects.hash(mHandle,
717 mHandlePresentation,
718 mCallerDisplayName,
719 mCallerDisplayNamePresentation,
720 mAccountHandle,
721 mCallCapabilities,
722 mCallProperties,
723 mDisconnectCause,
724 mConnectTimeMillis,
725 mGatewayInfo,
726 mVideoState,
727 mStatusHints,
728 mExtras,
729 mIntentExtras,
730 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700731 }
732
733 /** {@hide} */
734 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800735 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700736 Uri handle,
737 int handlePresentation,
738 String callerDisplayName,
739 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700740 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700741 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700742 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700743 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700744 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700745 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700746 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700747 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700748 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700749 Bundle intentExtras,
750 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800751 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700752 mHandle = handle;
753 mHandlePresentation = handlePresentation;
754 mCallerDisplayName = callerDisplayName;
755 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700756 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700757 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700758 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700759 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700760 mConnectTimeMillis = connectTimeMillis;
761 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700762 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700763 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700764 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700765 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700766 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700767 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800768
769 /** {@hide} */
770 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
771 return new Details(
772 parcelableCall.getId(),
773 parcelableCall.getHandle(),
774 parcelableCall.getHandlePresentation(),
775 parcelableCall.getCallerDisplayName(),
776 parcelableCall.getCallerDisplayNamePresentation(),
777 parcelableCall.getAccountHandle(),
778 parcelableCall.getCapabilities(),
779 parcelableCall.getProperties(),
780 parcelableCall.getDisconnectCause(),
781 parcelableCall.getConnectTimeMillis(),
782 parcelableCall.getGatewayInfo(),
783 parcelableCall.getVideoState(),
784 parcelableCall.getStatusHints(),
785 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700786 parcelableCall.getIntentExtras(),
787 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800788 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800789
790 @Override
791 public String toString() {
792 StringBuilder sb = new StringBuilder();
793 sb.append("[pa: ");
794 sb.append(mAccountHandle);
795 sb.append(", hdl: ");
796 sb.append(Log.pii(mHandle));
797 sb.append(", caps: ");
798 sb.append(capabilitiesToString(mCallCapabilities));
799 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700800 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800801 sb.append("]");
802 return sb.toString();
803 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700804 }
805
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700806 /**
807 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
808 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
809 * implementation.
810 * <p>
811 * You can handle these callbacks by extending the {@link Callback} class and overriding the
812 * callbacks that your {@link InCallService} is interested in. The callback methods include the
813 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
814 * {@link Callback} implementation, if desired.
815 * <p>
816 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
817 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
818 * (typically in {@link InCallService#onCallRemoved(Call)}).
819 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
820 * reach your implementation of {@link Callback}, so it is important to register your callback
821 * as soon as your {@link InCallService} is notified of a new call via
822 * {@link InCallService#onCallAdded(Call)}.
823 */
Andrew Leeda80c872015-04-15 14:09:50 -0700824 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700825 /**
826 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
827 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700828 * @param call The {@code Call} invoking this method.
829 * @param state The new state of the {@code Call}.
830 */
831 public void onStateChanged(Call call, int state) {}
832
833 /**
834 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
835 *
836 * @param call The {@code Call} invoking this method.
837 * @param parent The new parent of the {@code Call}.
838 */
839 public void onParentChanged(Call call, Call parent) {}
840
841 /**
842 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
843 *
844 * @param call The {@code Call} invoking this method.
845 * @param children The new children of the {@code Call}.
846 */
847 public void onChildrenChanged(Call call, List<Call> children) {}
848
849 /**
850 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
851 *
852 * @param call The {@code Call} invoking this method.
853 * @param details A {@code Details} object describing the {@code Call}.
854 */
855 public void onDetailsChanged(Call call, Details details) {}
856
857 /**
858 * Invoked when the text messages that can be used as responses to the incoming
859 * {@code Call} are loaded from the relevant database.
860 * See {@link #getCannedTextResponses()}.
861 *
862 * @param call The {@code Call} invoking this method.
863 * @param cannedTextResponses The text messages useable as responses.
864 */
865 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
866
867 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700868 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
869 * character. This causes the post-dial signals to stop pending user confirmation. An
870 * implementation should present this choice to the user and invoke
871 * {@link #postDialContinue(boolean)} when the user makes the choice.
872 *
873 * @param call The {@code Call} invoking this method.
874 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
875 */
876 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
877
878 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700879 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700880 *
881 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700882 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700883 */
Andrew Lee50aca232014-07-22 16:41:54 -0700884 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700885
886 /**
887 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
888 * up their UI for the {@code Call} in response to state transitions. Specifically,
889 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
890 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
891 * clients should wait for this method to be invoked.
892 *
893 * @param call The {@code Call} being destroyed.
894 */
895 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700896
897 /**
898 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
899 * conferenced.
900 *
901 * @param call The {@code Call} being updated.
902 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
903 * conferenced.
904 */
905 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700906
907 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700908 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
909 * <p>
910 * Where possible, the Call should make an attempt to handle {@link Connection} events which
911 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
912 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
913 * possible that a {@link ConnectionService} has defined its own Connection events which a
914 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700915 * <p>
916 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
917 *
918 * @param call The {@code Call} receiving the event.
919 * @param event The event.
920 * @param extras Extras associated with the connection event.
921 */
922 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -0800923
924 /**
925 * Invoked when the RTT mode changes for this call.
926 * @param call The call whose RTT mode has changed.
927 * @param mode the new RTT mode, one of
928 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
929 * or {@link RttCall#RTT_MODE_VCO}
930 */
931 public void onRttModeChanged(Call call, int mode) {}
932
933 /**
934 * Invoked when the call's RTT status changes, either from off to on or from on to off.
935 * @param call The call whose RTT status has changed.
936 * @param enabled whether RTT is now enabled or disabled
937 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
938 * on, null otherwise.
939 */
940 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
941
942 /**
943 * Invoked when the remote end of the connection has requested that an RTT communication
944 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
945 * with the same ID that this method is invoked with.
946 * @param call The call which the RTT request was placed on
947 * @param id The ID of the request.
948 */
949 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -0800950
951 /**
952 * Invoked when the RTT session failed to initiate for some reason, including rejection
953 * by the remote party.
954 * @param call The call which the RTT initiation failure occurred on.
955 * @param reason One of the status codes defined in
956 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
957 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
958 */
959 public void onRttInitiationFailure(Call call, int reason) {}
Hall Liu95d55872017-01-25 17:12:49 -0800960 }
961
962 /**
963 * A class that holds the state that describes the state of the RTT channel to the remote
964 * party, if it is active.
965 */
966 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -0800967 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -0800968 @Retention(RetentionPolicy.SOURCE)
969 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
970 public @interface RttAudioMode {}
971
972 /**
973 * For metrics use. Default value in the proto.
974 * @hide
975 */
976 public static final int RTT_MODE_INVALID = 0;
977
978 /**
979 * Indicates that there should be a bidirectional audio stream between the two parties
980 * on the call.
981 */
982 public static final int RTT_MODE_FULL = 1;
983
984 /**
985 * Indicates that the local user should be able to hear the audio stream from the remote
986 * user, but not vice versa. Equivalent to muting the microphone.
987 */
988 public static final int RTT_MODE_HCO = 2;
989
990 /**
991 * Indicates that the remote user should be able to hear the audio stream from the local
992 * user, but not vice versa. Equivalent to setting the volume to zero.
993 */
994 public static final int RTT_MODE_VCO = 3;
995
996 private static final int READ_BUFFER_SIZE = 1000;
997
998 private InputStreamReader mReceiveStream;
999 private OutputStreamWriter mTransmitStream;
1000 private int mRttMode;
1001 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001002 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001003 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1004
1005 /**
1006 * @hide
1007 */
Hall Liu57006aa2017-02-06 10:49:48 -08001008 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1009 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1010 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001011 mReceiveStream = receiveStream;
1012 mTransmitStream = transmitStream;
1013 mRttMode = mode;
1014 mInCallAdapter = inCallAdapter;
1015 }
1016
1017 /**
1018 * Returns the current RTT audio mode.
1019 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1020 * {@link #RTT_MODE_HCO}.
1021 */
1022 public int getRttAudioMode() {
1023 return mRttMode;
1024 }
1025
1026 /**
1027 * Sets the RTT audio mode. The requested mode change will be communicated through
1028 * {@link Callback#onRttModeChanged(Call, int)}.
1029 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1030 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1031 */
1032 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001033 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001034 }
1035
1036 /**
1037 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1038 * RTT transmits text in real-time, this method should be called once for each character
1039 * the user enters into the device.
1040 *
1041 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1042 * lead to interleaved text.
1043 * @param input The message to send to the remote user.
1044 */
1045 public void write(String input) throws IOException {
1046 mTransmitStream.write(input);
1047 mTransmitStream.flush();
1048 }
1049
1050 /**
1051 * Reads a string from the remote user, blocking if there is no data available. Returns
1052 * {@code null} if the RTT conversation has been terminated and there is no further data
1053 * to read.
1054 *
1055 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1056 * lead to interleaved text.
1057 * @return A string containing text sent by the remote user, or {@code null} if the
1058 * conversation has been terminated or if there was an error while reading.
1059 */
Hall Liuffa4a812017-03-02 16:11:00 -08001060 public String read() throws IOException {
1061 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1062 if (numRead < 0) {
1063 return null;
1064 }
1065 return new String(mReadBuffer, 0, numRead);
1066 }
1067
1068 /**
1069 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1070 * be read.
1071 * @return A string containing text entered by the user, or {@code null} if the user has
1072 * not entered any new text yet.
1073 */
1074 public String readImmediately() throws IOException {
1075 if (mReceiveStream.ready()) {
1076 return read();
1077 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001078 return null;
1079 }
1080 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001081 }
1082
Andrew Leeda80c872015-04-15 14:09:50 -07001083 /**
1084 * @deprecated Use {@code Call.Callback} instead.
1085 * @hide
1086 */
1087 @Deprecated
1088 @SystemApi
1089 public static abstract class Listener extends Callback { }
1090
Ihab Awade63fadb2014-07-09 21:52:04 -07001091 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001092 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001093 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001094 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001095 private final List<Call> mChildren = new ArrayList<>();
1096 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001097 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001098 private final List<Call> mConferenceableCalls = new ArrayList<>();
1099 private final List<Call> mUnmodifiableConferenceableCalls =
1100 Collections.unmodifiableList(mConferenceableCalls);
1101
Santos Cordon823fd3c2014-08-07 18:35:18 -07001102 private boolean mChildrenCached;
1103 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001104 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001105 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001106 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001107 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001108 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001109 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001110 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001111 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001112 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001113
1114 /**
1115 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1116 *
1117 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1118 * remaining or this {@code Call} is not in a post-dial state.
1119 */
1120 public String getRemainingPostDialSequence() {
1121 return mRemainingPostDialSequence;
1122 }
1123
1124 /**
1125 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001126 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001127 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001128 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001129 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001130 }
1131
1132 /**
1133 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1134 *
1135 * @param rejectWithMessage Whether to reject with a text message.
1136 * @param textMessage An optional text message with which to respond.
1137 */
1138 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001139 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001140 }
1141
1142 /**
1143 * Instructs this {@code Call} to disconnect.
1144 */
1145 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001146 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001147 }
1148
1149 /**
1150 * Instructs this {@code Call} to go on hold.
1151 */
1152 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001153 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001154 }
1155
1156 /**
1157 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1158 */
1159 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001160 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001161 }
1162
1163 /**
1164 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1165 *
1166 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1167 *
1168 * @param digit A character representing the DTMF digit for which to play the tone. This
1169 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1170 */
1171 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001172 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001173 }
1174
1175 /**
1176 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1177 * currently playing.
1178 *
1179 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1180 * currently playing, this method will do nothing.
1181 */
1182 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001183 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001184 }
1185
1186 /**
1187 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1188 *
1189 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1190 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001191 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001192 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001193 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1194 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001195 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001196 * {@code Call} will pause playing the tones and notify callbacks via
1197 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001198 * should display to the user an indication of this state and an affordance to continue
1199 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1200 * app should invoke the {@link #postDialContinue(boolean)} method.
1201 *
1202 * @param proceed Whether or not to continue with the post-dial sequence.
1203 */
1204 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001205 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001206 }
1207
1208 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001209 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001210 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001211 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001212 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1213 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001214
1215 }
1216
1217 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001218 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001219 *
1220 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001221 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001222 public void conference(Call callToConferenceWith) {
1223 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001224 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001225 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001226 }
1227
1228 /**
1229 * Instructs this {@code Call} to split from any conference call with which it may be
1230 * connected.
1231 */
1232 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001233 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001234 }
1235
1236 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001237 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001238 */
1239 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001240 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001241 }
1242
1243 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001244 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001245 */
1246 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001247 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001248 }
1249
1250 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001251 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1252 * device.
1253 * <p>
1254 * Calls to this method are ignored if the call does not have the
1255 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1256 * <p>
1257 * An {@link InCallService} will only see calls which support this method if it has the
1258 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1259 * in its manifest.
1260 */
1261 public void pullExternalCall() {
1262 // If this isn't an external call, ignore the request.
1263 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1264 return;
1265 }
1266
1267 mInCallAdapter.pullExternalCall(mTelecomCallId);
1268 }
1269
1270 /**
1271 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1272 * the {@link ConnectionService}.
1273 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001274 * Call events are used to communicate point in time information from an {@link InCallService}
1275 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1276 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1277 * {@link ConnectionService}.
1278 * <p>
1279 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1280 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1281 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001282 * Events are exposed to {@link ConnectionService} implementations via
1283 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1284 * <p>
1285 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001286 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1287 * ignore some events altogether.
1288 * <p>
1289 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1290 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1291 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1292 * they define their own event types in this namespace. When defining a custom event type,
1293 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1294 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1295 * <p>
1296 * When defining events and the associated extras, it is important to keep their behavior
1297 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1298 * events/extras should me maintained to ensure backwards compatibility with older
1299 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001300 *
1301 * @param event The connection event.
1302 * @param extras Bundle containing extra information associated with the event.
1303 */
1304 public void sendCallEvent(String event, Bundle extras) {
1305 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1306 }
1307
1308 /**
Hall Liu95d55872017-01-25 17:12:49 -08001309 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1310 * guaranteed, and notification of success will be via the
1311 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1312 */
1313 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001314 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001315 }
1316
1317 /**
1318 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1319 * callback.
1320 * The ID used here should be the same as the ID that was received via the callback.
1321 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1322 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1323 */
1324 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001325 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001326 }
1327
1328 /**
1329 * Terminate the RTT session on this call. The resulting state change will be notified via
1330 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1331 */
1332 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001333 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001334 }
1335
1336 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001337 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1338 * added.
1339 * <p>
1340 * No assumptions should be made as to how an In-Call UI or service will handle these
1341 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1342 *
1343 * @param extras The extras to add.
1344 */
1345 public final void putExtras(Bundle extras) {
1346 if (extras == null) {
1347 return;
1348 }
1349
1350 if (mExtras == null) {
1351 mExtras = new Bundle();
1352 }
1353 mExtras.putAll(extras);
1354 mInCallAdapter.putExtras(mTelecomCallId, extras);
1355 }
1356
1357 /**
1358 * Adds a boolean extra to this {@link Call}.
1359 *
1360 * @param key The extra key.
1361 * @param value The value.
1362 * @hide
1363 */
1364 public final void putExtra(String key, boolean value) {
1365 if (mExtras == null) {
1366 mExtras = new Bundle();
1367 }
1368 mExtras.putBoolean(key, value);
1369 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1370 }
1371
1372 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001373 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001374 *
1375 * @param key The extra key.
1376 * @param value The value.
1377 * @hide
1378 */
1379 public final void putExtra(String key, int value) {
1380 if (mExtras == null) {
1381 mExtras = new Bundle();
1382 }
1383 mExtras.putInt(key, value);
1384 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1385 }
1386
1387 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001388 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001389 *
1390 * @param key The extra key.
1391 * @param value The value.
1392 * @hide
1393 */
1394 public final void putExtra(String key, String value) {
1395 if (mExtras == null) {
1396 mExtras = new Bundle();
1397 }
1398 mExtras.putString(key, value);
1399 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1400 }
1401
1402 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001403 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001404 *
1405 * @param keys The keys of the extras to remove.
1406 */
1407 public final void removeExtras(List<String> keys) {
1408 if (mExtras != null) {
1409 for (String key : keys) {
1410 mExtras.remove(key);
1411 }
1412 if (mExtras.size() == 0) {
1413 mExtras = null;
1414 }
1415 }
1416 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1417 }
1418
1419 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001420 * Removes extras from this {@link Call}.
1421 *
1422 * @param keys The keys of the extras to remove.
1423 */
1424 public final void removeExtras(String ... keys) {
1425 removeExtras(Arrays.asList(keys));
1426 }
1427
1428 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001429 * Obtains the parent of this {@code Call} in a conference, if any.
1430 *
1431 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1432 * child of any conference {@code Call}s.
1433 */
1434 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001435 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001436 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001437 }
1438 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001439 }
1440
1441 /**
1442 * Obtains the children of this conference {@code Call}, if any.
1443 *
1444 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1445 * {@code List} otherwise.
1446 */
1447 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001448 if (!mChildrenCached) {
1449 mChildrenCached = true;
1450 mChildren.clear();
1451
1452 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001453 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001454 if (call == null) {
1455 // At least one child was still not found, so do not save true for "cached"
1456 mChildrenCached = false;
1457 } else {
1458 mChildren.add(call);
1459 }
1460 }
1461 }
1462
Ihab Awade63fadb2014-07-09 21:52:04 -07001463 return mUnmodifiableChildren;
1464 }
1465
1466 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001467 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1468 *
1469 * @return The list of conferenceable {@code Call}s.
1470 */
1471 public List<Call> getConferenceableCalls() {
1472 return mUnmodifiableConferenceableCalls;
1473 }
1474
1475 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001476 * Obtains the state of this {@code Call}.
1477 *
1478 * @return A state value, chosen from the {@code STATE_*} constants.
1479 */
1480 public int getState() {
1481 return mState;
1482 }
1483
1484 /**
1485 * Obtains a list of canned, pre-configured message responses to present to the user as
1486 * ways of rejecting this {@code Call} using via a text message.
1487 *
1488 * @see #reject(boolean, String)
1489 *
1490 * @return A list of canned text message responses.
1491 */
1492 public List<String> getCannedTextResponses() {
1493 return mCannedTextResponses;
1494 }
1495
1496 /**
1497 * Obtains an object that can be used to display video from this {@code Call}.
1498 *
Andrew Lee50aca232014-07-22 16:41:54 -07001499 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001500 */
Andrew Lee50aca232014-07-22 16:41:54 -07001501 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001502 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001503 }
1504
1505 /**
1506 * Obtains an object containing call details.
1507 *
1508 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1509 * result may be {@code null}.
1510 */
1511 public Details getDetails() {
1512 return mDetails;
1513 }
1514
1515 /**
Hall Liu95d55872017-01-25 17:12:49 -08001516 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1517 * receive RTT text data, as well as to change the RTT mode.
1518 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1519 */
1520 public @Nullable RttCall getRttCall() {
1521 return mRttCall;
1522 }
1523
1524 /**
1525 * Returns whether this call has an active RTT connection.
1526 * @return true if there is a connection, false otherwise.
1527 */
1528 public boolean isRttActive() {
1529 return mRttCall != null;
1530 }
1531
1532 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001533 * Registers a callback to this {@code Call}.
1534 *
1535 * @param callback A {@code Callback}.
1536 */
1537 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001538 registerCallback(callback, new Handler());
1539 }
1540
1541 /**
1542 * Registers a callback to this {@code Call}.
1543 *
1544 * @param callback A {@code Callback}.
1545 * @param handler A handler which command and status changes will be delivered to.
1546 */
1547 public void registerCallback(Callback callback, Handler handler) {
1548 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001549 // Don't allow new callback registration if the call is already being destroyed.
1550 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001551 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1552 }
Andrew Leeda80c872015-04-15 14:09:50 -07001553 }
1554
1555 /**
1556 * Unregisters a callback from this {@code Call}.
1557 *
1558 * @param callback A {@code Callback}.
1559 */
1560 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001561 // Don't allow callback deregistration if the call is already being destroyed.
1562 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001563 for (CallbackRecord<Callback> record : mCallbackRecords) {
1564 if (record.getCallback() == callback) {
1565 mCallbackRecords.remove(record);
1566 break;
1567 }
1568 }
Andrew Leeda80c872015-04-15 14:09:50 -07001569 }
1570 }
1571
Santos Cordon3c20d632016-02-25 16:12:35 -08001572 @Override
1573 public String toString() {
1574 return new StringBuilder().
1575 append("Call [id: ").
1576 append(mTelecomCallId).
1577 append(", state: ").
1578 append(stateToString(mState)).
1579 append(", details: ").
1580 append(mDetails).
1581 append("]").toString();
1582 }
1583
1584 /**
1585 * @param state An integer value of a {@code STATE_*} constant.
1586 * @return A string representation of the value.
1587 */
1588 private static String stateToString(int state) {
1589 switch (state) {
1590 case STATE_NEW:
1591 return "NEW";
1592 case STATE_RINGING:
1593 return "RINGING";
1594 case STATE_DIALING:
1595 return "DIALING";
1596 case STATE_ACTIVE:
1597 return "ACTIVE";
1598 case STATE_HOLDING:
1599 return "HOLDING";
1600 case STATE_DISCONNECTED:
1601 return "DISCONNECTED";
1602 case STATE_CONNECTING:
1603 return "CONNECTING";
1604 case STATE_DISCONNECTING:
1605 return "DISCONNECTING";
1606 case STATE_SELECT_PHONE_ACCOUNT:
1607 return "SELECT_PHONE_ACCOUNT";
1608 default:
1609 Log.w(Call.class, "Unknown state %d", state);
1610 return "UNKNOWN";
1611 }
1612 }
1613
Andrew Leeda80c872015-04-15 14:09:50 -07001614 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001615 * Adds a listener to this {@code Call}.
1616 *
1617 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001618 * @deprecated Use {@link #registerCallback} instead.
1619 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001620 */
Andrew Leeda80c872015-04-15 14:09:50 -07001621 @Deprecated
1622 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001623 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001624 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001625 }
1626
1627 /**
1628 * Removes a listener from this {@code Call}.
1629 *
1630 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001631 * @deprecated Use {@link #unregisterCallback} instead.
1632 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001633 */
Andrew Leeda80c872015-04-15 14:09:50 -07001634 @Deprecated
1635 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001636 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001637 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001638 }
1639
1640 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001641 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1642 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001643 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001644 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001645 mInCallAdapter = inCallAdapter;
1646 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001647 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001648 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001649 }
1650
1651 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001652 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001653 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001654 mPhone = phone;
1655 mTelecomCallId = telecomCallId;
1656 mInCallAdapter = inCallAdapter;
1657 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001658 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001659 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001660 }
1661
1662 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001663 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001664 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001665 }
1666
1667 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001668 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001669
Ihab Awade63fadb2014-07-09 21:52:04 -07001670 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001671 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001672 boolean detailsChanged = !Objects.equals(mDetails, details);
1673 if (detailsChanged) {
1674 mDetails = details;
1675 }
1676
1677 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001678 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1679 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1680 mCannedTextResponses =
1681 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001682 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001683 }
1684
Tyler Gunn159f35c2017-03-02 09:28:37 -08001685 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1686 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001687 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001688 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001689 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001690 mVideoCallImpl = newVideoCallImpl;
1691 }
1692 if (mVideoCallImpl != null) {
1693 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001694 }
1695
Santos Cordone3c507b2015-04-23 14:44:19 -07001696 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001697 boolean stateChanged = mState != state;
1698 if (stateChanged) {
1699 mState = state;
1700 }
1701
Santos Cordon823fd3c2014-08-07 18:35:18 -07001702 String parentId = parcelableCall.getParentCallId();
1703 boolean parentChanged = !Objects.equals(mParentId, parentId);
1704 if (parentChanged) {
1705 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001706 }
1707
Santos Cordon823fd3c2014-08-07 18:35:18 -07001708 List<String> childCallIds = parcelableCall.getChildCallIds();
1709 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1710 if (childrenChanged) {
1711 mChildrenIds.clear();
1712 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1713 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001714 }
1715
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001716 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1717 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1718 for (String otherId : conferenceableCallIds) {
1719 if (callIdMap.containsKey(otherId)) {
1720 conferenceableCalls.add(callIdMap.get(otherId));
1721 }
1722 }
1723
1724 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1725 mConferenceableCalls.clear();
1726 mConferenceableCalls.addAll(conferenceableCalls);
1727 fireConferenceableCallsChanged();
1728 }
1729
Hall Liu95d55872017-01-25 17:12:49 -08001730 boolean isRttChanged = false;
1731 boolean rttModeChanged = false;
1732 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1733 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1734 InputStreamReader receiveStream = new InputStreamReader(
1735 new ParcelFileDescriptor.AutoCloseInputStream(
1736 parcelableRttCall.getReceiveStream()),
1737 StandardCharsets.UTF_8);
1738 OutputStreamWriter transmitStream = new OutputStreamWriter(
1739 new ParcelFileDescriptor.AutoCloseOutputStream(
1740 parcelableRttCall.getTransmitStream()),
1741 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08001742 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08001743 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1744 if (mRttCall == null) {
1745 isRttChanged = true;
1746 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1747 rttModeChanged = true;
1748 }
1749 mRttCall = newRttCall;
1750 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1751 && parcelableCall.getIsRttCallChanged()) {
1752 isRttChanged = true;
1753 mRttCall = null;
1754 }
1755
Ihab Awade63fadb2014-07-09 21:52:04 -07001756 // Now we fire updates, ensuring that any client who listens to any of these notifications
1757 // gets the most up-to-date state.
1758
1759 if (stateChanged) {
1760 fireStateChanged(mState);
1761 }
1762 if (detailsChanged) {
1763 fireDetailsChanged(mDetails);
1764 }
1765 if (cannedTextResponsesChanged) {
1766 fireCannedTextResponsesLoaded(mCannedTextResponses);
1767 }
Andrew Lee50aca232014-07-22 16:41:54 -07001768 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001769 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001770 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001771 if (parentChanged) {
1772 fireParentChanged(getParent());
1773 }
1774 if (childrenChanged) {
1775 fireChildrenChanged(getChildren());
1776 }
Hall Liu95d55872017-01-25 17:12:49 -08001777 if (isRttChanged) {
1778 fireOnIsRttChanged(mRttCall != null, mRttCall);
1779 }
1780 if (rttModeChanged) {
1781 fireOnRttModeChanged(mRttCall.getRttAudioMode());
1782 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001783
1784 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1785 // remove ourselves from the Phone. Note that we do this after completing all state updates
1786 // so a client can cleanly transition all their UI to the state appropriate for a
1787 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1788 if (mState == STATE_DISCONNECTED) {
1789 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001790 }
1791 }
1792
1793 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001794 final void internalSetPostDialWait(String remaining) {
1795 mRemainingPostDialSequence = remaining;
1796 firePostDialWait(mRemainingPostDialSequence);
1797 }
1798
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001799 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001800 final void internalSetDisconnected() {
1801 if (mState != Call.STATE_DISCONNECTED) {
1802 mState = Call.STATE_DISCONNECTED;
1803 fireStateChanged(mState);
1804 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001805 }
1806 }
1807
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001808 /** {@hide} */
1809 final void internalOnConnectionEvent(String event, Bundle extras) {
1810 fireOnConnectionEvent(event, extras);
1811 }
1812
Hall Liu95d55872017-01-25 17:12:49 -08001813 /** {@hide} */
1814 final void internalOnRttUpgradeRequest(final int requestId) {
1815 for (CallbackRecord<Callback> record : mCallbackRecords) {
1816 final Call call = this;
1817 final Callback callback = record.getCallback();
1818 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
1819 }
1820 }
1821
Hall Liu57006aa2017-02-06 10:49:48 -08001822 /** @hide */
1823 final void internalOnRttInitiationFailure(int reason) {
1824 for (CallbackRecord<Callback> record : mCallbackRecords) {
1825 final Call call = this;
1826 final Callback callback = record.getCallback();
1827 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
1828 }
1829 }
1830
Andrew Lee011728f2015-04-23 15:47:06 -07001831 private void fireStateChanged(final int newState) {
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.onStateChanged(call, newState);
1839 }
1840 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001841 }
1842 }
1843
Andrew Lee011728f2015-04-23 15:47:06 -07001844 private void fireParentChanged(final Call newParent) {
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.onParentChanged(call, newParent);
1852 }
1853 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001854 }
1855 }
1856
Andrew Lee011728f2015-04-23 15:47:06 -07001857 private void fireChildrenChanged(final List<Call> children) {
1858 for (CallbackRecord<Callback> record : mCallbackRecords) {
1859 final Call call = this;
1860 final Callback callback = record.getCallback();
1861 record.getHandler().post(new Runnable() {
1862 @Override
1863 public void run() {
1864 callback.onChildrenChanged(call, children);
1865 }
1866 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001867 }
1868 }
1869
Andrew Lee011728f2015-04-23 15:47:06 -07001870 private void fireDetailsChanged(final Details details) {
1871 for (CallbackRecord<Callback> record : mCallbackRecords) {
1872 final Call call = this;
1873 final Callback callback = record.getCallback();
1874 record.getHandler().post(new Runnable() {
1875 @Override
1876 public void run() {
1877 callback.onDetailsChanged(call, details);
1878 }
1879 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001880 }
1881 }
1882
Andrew Lee011728f2015-04-23 15:47:06 -07001883 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1884 for (CallbackRecord<Callback> record : mCallbackRecords) {
1885 final Call call = this;
1886 final Callback callback = record.getCallback();
1887 record.getHandler().post(new Runnable() {
1888 @Override
1889 public void run() {
1890 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1891 }
1892 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001893 }
1894 }
1895
Andrew Lee011728f2015-04-23 15:47:06 -07001896 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1897 for (CallbackRecord<Callback> record : mCallbackRecords) {
1898 final Call call = this;
1899 final Callback callback = record.getCallback();
1900 record.getHandler().post(new Runnable() {
1901 @Override
1902 public void run() {
1903 callback.onVideoCallChanged(call, videoCall);
1904 }
1905 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001906 }
1907 }
1908
Andrew Lee011728f2015-04-23 15:47:06 -07001909 private void firePostDialWait(final String remainingPostDialSequence) {
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.onPostDialWait(call, remainingPostDialSequence);
1917 }
1918 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001919 }
1920 }
1921
1922 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001923 /**
1924 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1925 * onCallRemoved callback, we remove this call from the Phone's record
1926 * only once all of the registered onCallDestroyed callbacks are executed.
1927 * All the callbacks get removed from our records as a part of this operation
1928 * since onCallDestroyed is the final callback.
1929 */
1930 final Call call = this;
1931 if (mCallbackRecords.isEmpty()) {
1932 // No callbacks registered, remove the call from Phone's record.
1933 mPhone.internalRemoveCall(call);
1934 }
1935 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001936 final Callback callback = record.getCallback();
1937 record.getHandler().post(new Runnable() {
1938 @Override
1939 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001940 boolean isFinalRemoval = false;
1941 RuntimeException toThrow = null;
1942 try {
1943 callback.onCallDestroyed(call);
1944 } catch (RuntimeException e) {
1945 toThrow = e;
1946 }
1947 synchronized(Call.this) {
1948 mCallbackRecords.remove(record);
1949 if (mCallbackRecords.isEmpty()) {
1950 isFinalRemoval = true;
1951 }
1952 }
1953 if (isFinalRemoval) {
1954 mPhone.internalRemoveCall(call);
1955 }
1956 if (toThrow != null) {
1957 throw toThrow;
1958 }
Andrew Lee011728f2015-04-23 15:47:06 -07001959 }
1960 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001961 }
1962 }
1963
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001964 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001965 for (CallbackRecord<Callback> record : mCallbackRecords) {
1966 final Call call = this;
1967 final Callback callback = record.getCallback();
1968 record.getHandler().post(new Runnable() {
1969 @Override
1970 public void run() {
1971 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1972 }
1973 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001974 }
1975 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001976
1977 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001978 * Notifies listeners of an incoming connection event.
1979 * <p>
1980 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1981 *
1982 * @param event
1983 * @param extras
1984 */
1985 private void fireOnConnectionEvent(final String event, final Bundle extras) {
1986 for (CallbackRecord<Callback> record : mCallbackRecords) {
1987 final Call call = this;
1988 final Callback callback = record.getCallback();
1989 record.getHandler().post(new Runnable() {
1990 @Override
1991 public void run() {
1992 callback.onConnectionEvent(call, event, extras);
1993 }
1994 });
1995 }
1996 }
1997
1998 /**
Hall Liu95d55872017-01-25 17:12:49 -08001999 * Notifies listeners of an RTT on/off change
2000 *
2001 * @param enabled True if RTT is now enabled, false otherwise
2002 */
2003 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2004 for (CallbackRecord<Callback> record : mCallbackRecords) {
2005 final Call call = this;
2006 final Callback callback = record.getCallback();
2007 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2008 }
2009 }
2010
2011 /**
2012 * Notifies listeners of a RTT mode change
2013 *
2014 * @param mode The new RTT mode
2015 */
2016 private void fireOnRttModeChanged(final int mode) {
2017 for (CallbackRecord<Callback> record : mCallbackRecords) {
2018 final Call call = this;
2019 final Callback callback = record.getCallback();
2020 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2021 }
2022 }
2023
2024 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002025 * Determines if two bundles are equal.
2026 *
2027 * @param bundle The original bundle.
2028 * @param newBundle The bundle to compare with.
2029 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2030 */
2031 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2032 if (bundle == null || newBundle == null) {
2033 return bundle == newBundle;
2034 }
2035
2036 if (bundle.size() != newBundle.size()) {
2037 return false;
2038 }
2039
2040 for(String key : bundle.keySet()) {
2041 if (key != null) {
2042 final Object value = bundle.get(key);
2043 final Object newValue = newBundle.get(key);
2044 if (!Objects.equals(value, newValue)) {
2045 return false;
2046 }
2047 }
2048 }
2049 return true;
2050 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002051}