blob: 08bc9bcc4003c0c94ab2b41b79da2409a7a6bda1 [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;
Mathew Inwood42346d12018-08-01 11:33:05 +010022import android.annotation.UnsupportedAppUsage;
Ihab Awade63fadb2014-07-09 21:52:04 -070023import android.net.Uri;
Nancy Chen10798dc2014-08-08 14:00:25 -070024import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070025import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080026import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070027
Hall Liu95d55872017-01-25 17:12:49 -080028import java.io.IOException;
29import java.io.InputStreamReader;
30import java.io.OutputStreamWriter;
Andrew Lee50aca232014-07-22 16:41:54 -070031import java.lang.String;
Hall Liu95d55872017-01-25 17:12:49 -080032import java.lang.annotation.Retention;
33import java.lang.annotation.RetentionPolicy;
34import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070035import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070036import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070037import java.util.Collections;
38import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070039import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070040import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070041import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070042
43/**
44 * Represents an ongoing phone call that the in-call app should present to the user.
45 */
46public final class Call {
47 /**
48 * The state of a {@code Call} when newly created.
49 */
50 public static final int STATE_NEW = 0;
51
52 /**
53 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
54 */
55 public static final int STATE_DIALING = 1;
56
57 /**
58 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
59 */
60 public static final int STATE_RINGING = 2;
61
62 /**
63 * The state of a {@code Call} when in a holding state.
64 */
65 public static final int STATE_HOLDING = 3;
66
67 /**
68 * The state of a {@code Call} when actively supporting conversation.
69 */
70 public static final int STATE_ACTIVE = 4;
71
72 /**
73 * The state of a {@code Call} when no further voice or other communication is being
74 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
75 * is no longer active, and the local data transport has or inevitably will release resources
76 * associated with this {@code Call}.
77 */
78 public static final int STATE_DISCONNECTED = 7;
79
Nancy Chen5da0fd52014-07-08 14:16:17 -070080 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070081 * The state of an outgoing {@code Call} when waiting on user to select a
82 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070083 */
Santos Cordone3c507b2015-04-23 14:44:19 -070084 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
85
86 /**
87 * @hide
88 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
89 */
90 @Deprecated
91 @SystemApi
92 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070093
Nancy Chene20930f2014-08-07 16:17:21 -070094 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070095 * The initial state of an outgoing {@code Call}.
96 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
97 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070098 */
99 public static final int STATE_CONNECTING = 9;
100
Nancy Chen513c8922014-09-17 14:47:20 -0700101 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700102 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
103 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
104 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
105 */
106 public static final int STATE_DISCONNECTING = 10;
107
108 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700109 * The state of an external call which is in the process of being pulled from a remote device to
110 * the local device.
111 * <p>
112 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
113 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
114 * <p>
115 * An {@link InCallService} will only see this state if it has the
116 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
117 * manifest.
118 */
119 public static final int STATE_PULLING_CALL = 11;
120
121 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700122 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
123 * extras. Used to pass the phone accounts to display on the front end to the user in order to
124 * select phone accounts to (for example) place a call.
Nancy Chen513c8922014-09-17 14:47:20 -0700125 */
126 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
127
mike dooley4af561f2016-12-20 08:55:17 -0800128 /**
mike dooley91217422017-03-09 12:58:42 -0800129 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
130 * when the last outgoing emergency call was made. This is used to identify potential emergency
131 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800132 */
133 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
134 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
135
Tyler Gunn8bf76572017-04-06 15:30:08 -0700136 /**
137 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
138 * Telecom that the user has requested that the current {@link Call} should be handed over
139 * to another {@link ConnectionService}.
140 * <p>
141 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
142 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
143 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700144 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
145 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700146 */
147 public static final String EVENT_REQUEST_HANDOVER =
148 "android.telecom.event.REQUEST_HANDOVER";
149
150 /**
151 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
152 * {@link PhoneAccountHandle} to which a call should be handed over to.
153 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700154 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
155 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700156 */
157 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
158 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
159
160 /**
161 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
162 * video state of the call when it is handed over to the new {@link PhoneAccount}.
163 * <p>
164 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
165 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
166 * {@link VideoProfile#STATE_TX_ENABLED}.
167 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700168 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
169 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700170 */
171 public static final String EXTRA_HANDOVER_VIDEO_STATE =
172 "android.telecom.extra.HANDOVER_VIDEO_STATE";
173
174 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700175 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
176 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
177 * information to the handover {@link ConnectionService} specified by
178 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
179 * <p>
180 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
181 * {@link ConnectionService} via the request extras when
182 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
183 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700184 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700185 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
186 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700187 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700188 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700189
190 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700191 * Call event sent from Telecom to the handover {@link ConnectionService} via
192 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
193 * to the {@link ConnectionService} has completed successfully.
194 * <p>
195 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700196 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700197 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
198 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700199 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700200 public static final String EVENT_HANDOVER_COMPLETE =
201 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700202
203 /**
204 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
205 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
206 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
207 * {@code null}.
208 * <p>
209 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
210 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700211 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
212 * APIs instead.
Tyler Gunn34a2b312017-06-23 08:32:00 -0700213 */
214 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
215 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
216
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700217 /**
218 * Call event sent from Telecom to the handover {@link ConnectionService} via
219 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
220 * to the {@link ConnectionService} has failed.
221 * <p>
222 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
223 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700224 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
225 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700226 */
227 public static final String EVENT_HANDOVER_FAILED =
228 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700229
Ihab Awade63fadb2014-07-09 21:52:04 -0700230 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800231
232 /** Call can currently be put on hold or unheld. */
233 public static final int CAPABILITY_HOLD = 0x00000001;
234
235 /** Call supports the hold feature. */
236 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
237
238 /**
239 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
240 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
241 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
242 * capability allows a merge button to be shown while the conference call is in the foreground
243 * of the in-call UI.
244 * <p>
245 * This is only intended for use by a {@link Conference}.
246 */
247 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
248
249 /**
250 * Calls within a conference can be swapped between foreground and background.
251 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
252 * <p>
253 * This is only intended for use by a {@link Conference}.
254 */
255 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
256
257 /**
258 * @hide
259 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700260 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800261
262 /** Call supports responding via text option. */
263 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
264
265 /** Call can be muted. */
266 public static final int CAPABILITY_MUTE = 0x00000040;
267
268 /**
269 * Call supports conference call management. This capability only applies to {@link Conference}
270 * calls which can have {@link Connection}s as children.
271 */
272 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
273
274 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700275 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800276 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700277 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800278
279 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700280 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800281 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700282 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800283
284 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700285 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800286 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700287 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700288 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800289
290 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700291 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800292 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700293 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
294
295 /**
296 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700297 */
298 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
299
300 /**
301 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700302 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700303 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700304 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800305
306 /**
307 * Call is able to be separated from its parent {@code Conference}, if any.
308 */
309 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
310
311 /**
312 * Call is able to be individually disconnected when in a {@code Conference}.
313 */
314 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
315
316 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500317 * Speed up audio setup for MT call.
318 * @hide
319 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700320 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
321
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700322 /**
323 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700324 * @hide
325 */
Mathew Inwood42346d12018-08-01 11:33:05 +0100326 @UnsupportedAppUsage
Rekha Kumar07366812015-03-24 16:42:31 -0700327 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
328
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700329 /**
330 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700331 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700332 */
333 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
334
Bryce Lee81901682015-08-28 16:38:02 -0700335 /**
336 * Call sends responses through connection.
337 * @hide
338 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800339 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
340
341 /**
342 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
343 * <p>
344 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
345 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
346 * downgraded from a video call back to a VideoState of
347 * {@link VideoProfile#STATE_AUDIO_ONLY}.
348 * <p>
349 * Intuitively, a call which can be downgraded to audio should also have local and remote
350 * video
351 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
352 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
353 */
354 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700355
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700356 /**
357 * When set for an external call, indicates that this {@code Call} can be pulled from a
358 * remote device to the current device.
359 * <p>
360 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
361 * <p>
362 * An {@link InCallService} will only see calls with this capability if it has the
363 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
364 * in its manifest.
365 * <p>
366 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700367 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700368 */
369 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
370
Pooja Jaind34698d2017-12-28 14:15:31 +0530371 /** Call supports the deflect feature. */
372 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
373
Tyler Gunnd11a3152015-03-18 13:09:14 -0700374 //******************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530375 // Next CAPABILITY value: 0x02000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700376 //******************************************************************************************
377
378 /**
379 * Whether the call is currently a conference.
380 */
381 public static final int PROPERTY_CONFERENCE = 0x00000001;
382
383 /**
384 * Whether the call is a generic conference, where we do not know the precise state of
385 * participants in the conference (eg. on CDMA).
386 */
387 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
388
389 /**
390 * Whether the call is made while the device is in emergency callback mode.
391 */
392 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
393
394 /**
395 * Connection is using WIFI.
396 */
397 public static final int PROPERTY_WIFI = 0x00000008;
398
399 /**
400 * Call is using high definition audio.
401 */
402 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
403
Tony Maka68dcce2015-12-17 09:31:18 +0000404 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100405 * Whether the call is associated with the work profile.
406 */
407 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
408
409 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700410 * When set, indicates that this {@code Call} does not actually exist locally for the
411 * {@link ConnectionService}.
412 * <p>
413 * Consider, for example, a scenario where a user has two phones with the same phone number.
414 * When a user places a call on one device, the telephony stack can represent that call on
415 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700416 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700417 * <p>
418 * An {@link InCallService} will only see calls with this property if it has the
419 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
420 * in its manifest.
421 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700422 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700423 */
424 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
425
Brad Ebinger15847072016-05-18 11:08:36 -0700426 /**
427 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
428 */
429 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
430
Tyler Gunn24e18332017-02-10 09:42:49 -0800431 /**
432 * Indicates that the call is from a self-managed {@link ConnectionService}.
433 * <p>
434 * See also {@link Connection#PROPERTY_SELF_MANAGED}
435 */
436 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
437
Eric Erfanianec881872017-12-06 16:27:53 -0800438 /**
439 * Indicates the call used Assisted Dialing.
440 * See also {@link Connection#PROPERTY_ASSISTED_DIALING_USED}
441 * @hide
442 */
443 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
444
Hall Liue9041242018-02-09 16:40:03 -0800445 /**
446 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
447 * {@link RttCall} object that is used to send and receive text.
448 */
449 public static final int PROPERTY_RTT = 0x00000400;
450
Tyler Gunn5bd90852018-09-21 09:37:07 -0700451 /**
452 * Indicates that the call has been identified as the network as an emergency call. This
453 * property may be set for both incoming and outgoing calls which the network identifies as
454 * emergency calls.
455 */
456 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
457
Andrew Lee2378ea72015-04-29 14:38:11 -0700458 //******************************************************************************************
Tyler Gunn5bd90852018-09-21 09:37:07 -0700459 // Next PROPERTY value: 0x00001000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700460 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800461
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800462 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700463 private final Uri mHandle;
464 private final int mHandlePresentation;
465 private final String mCallerDisplayName;
466 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700467 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700468 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700469 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800470 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700471 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700472 private final long mConnectTimeMillis;
473 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700474 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700475 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700476 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700477 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700478 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700479
480 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800481 * Whether the supplied capabilities supports the specified capability.
482 *
483 * @param capabilities A bit field of capabilities.
484 * @param capability The capability to check capabilities for.
485 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800486 */
487 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800488 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800489 }
490
491 /**
492 * Whether the capabilities of this {@code Details} supports the specified capability.
493 *
494 * @param capability The capability to check capabilities for.
495 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800496 */
497 public boolean can(int capability) {
498 return can(mCallCapabilities, capability);
499 }
500
501 /**
502 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
503 *
504 * @param capabilities A capability bit field.
505 * @return A human readable string representation.
506 */
507 public static String capabilitiesToString(int capabilities) {
508 StringBuilder builder = new StringBuilder();
509 builder.append("[Capabilities:");
510 if (can(capabilities, CAPABILITY_HOLD)) {
511 builder.append(" CAPABILITY_HOLD");
512 }
513 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
514 builder.append(" CAPABILITY_SUPPORT_HOLD");
515 }
516 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
517 builder.append(" CAPABILITY_MERGE_CONFERENCE");
518 }
519 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
520 builder.append(" CAPABILITY_SWAP_CONFERENCE");
521 }
522 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
523 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
524 }
525 if (can(capabilities, CAPABILITY_MUTE)) {
526 builder.append(" CAPABILITY_MUTE");
527 }
528 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
529 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
530 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700531 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
532 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
533 }
534 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
535 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
536 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700537 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
538 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800539 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700540 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
541 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
542 }
543 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
544 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
545 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800546 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
547 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
548 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700549 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
550 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800551 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500552 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700553 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500554 }
Rekha Kumar07366812015-03-24 16:42:31 -0700555 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
556 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
557 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700558 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
559 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
560 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700561 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
562 builder.append(" CAPABILITY_CAN_PULL_CALL");
563 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530564 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
565 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
566 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800567 builder.append("]");
568 return builder.toString();
569 }
570
571 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700572 * Whether the supplied properties includes the specified property.
573 *
574 * @param properties A bit field of properties.
575 * @param property The property to check properties for.
576 * @return Whether the specified property is supported.
577 */
578 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800579 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700580 }
581
582 /**
583 * Whether the properties of this {@code Details} includes the specified property.
584 *
585 * @param property The property to check properties for.
586 * @return Whether the specified property is supported.
587 */
588 public boolean hasProperty(int property) {
589 return hasProperty(mCallProperties, property);
590 }
591
592 /**
593 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
594 *
595 * @param properties A property bit field.
596 * @return A human readable string representation.
597 */
598 public static String propertiesToString(int properties) {
599 StringBuilder builder = new StringBuilder();
600 builder.append("[Properties:");
601 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
602 builder.append(" PROPERTY_CONFERENCE");
603 }
604 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
605 builder.append(" PROPERTY_GENERIC_CONFERENCE");
606 }
607 if (hasProperty(properties, PROPERTY_WIFI)) {
608 builder.append(" PROPERTY_WIFI");
609 }
610 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
611 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
612 }
613 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700614 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700615 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700616 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
617 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
618 }
Brad Ebinger15847072016-05-18 11:08:36 -0700619 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
620 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
621 }
Eric Erfanianec881872017-12-06 16:27:53 -0800622 if(hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
623 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
624 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700625 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
626 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
627 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700628 builder.append("]");
629 return builder.toString();
630 }
631
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800632 /** {@hide} */
633 public String getTelecomCallId() {
634 return mTelecomCallId;
635 }
636
Andrew Lee2378ea72015-04-29 14:38:11 -0700637 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700638 * @return The handle (e.g., phone number) to which the {@code Call} is currently
639 * connected.
640 */
641 public Uri getHandle() {
642 return mHandle;
643 }
644
645 /**
646 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700647 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700648 */
649 public int getHandlePresentation() {
650 return mHandlePresentation;
651 }
652
653 /**
654 * @return The display name for the caller.
655 */
656 public String getCallerDisplayName() {
657 return mCallerDisplayName;
658 }
659
660 /**
661 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700662 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700663 */
664 public int getCallerDisplayNamePresentation() {
665 return mCallerDisplayNamePresentation;
666 }
667
668 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700669 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
670 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700671 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700672 public PhoneAccountHandle getAccountHandle() {
673 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700674 }
675
676 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800677 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
678 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700679 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700680 public int getCallCapabilities() {
681 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700682 }
683
684 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700685 * @return A bitmask of the properties of the {@code Call}, as defined by the various
686 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700687 */
688 public int getCallProperties() {
689 return mCallProperties;
690 }
691
692 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800693 * @return a bitmask of the audio routes available for the call.
694 *
695 * @hide
696 */
697 public int getSupportedAudioRoutes() {
698 return mSupportedAudioRoutes;
699 }
700
701 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700702 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700703 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700704 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700705 public DisconnectCause getDisconnectCause() {
706 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700707 }
708
709 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700710 * Returns the time the {@link Call} connected (i.e. became active). This information is
711 * updated periodically, but user interfaces should not rely on this to display the "call
712 * time clock". For the time when the call was first added to Telecom, see
713 * {@link #getCreationTimeMillis()}.
714 *
715 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700716 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700717 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700718 return mConnectTimeMillis;
719 }
720
721 /**
722 * @return Information about any calling gateway the {@code Call} may be using.
723 */
724 public GatewayInfo getGatewayInfo() {
725 return mGatewayInfo;
726 }
727
Andrew Lee7a341382014-07-15 17:05:08 -0700728 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700729 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700730 */
731 public int getVideoState() {
732 return mVideoState;
733 }
734
Ihab Awad5d0410f2014-07-30 10:07:40 -0700735 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700736 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700737 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700738 */
739 public StatusHints getStatusHints() {
740 return mStatusHints;
741 }
742
Nancy Chen10798dc2014-08-08 14:00:25 -0700743 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700744 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700745 */
746 public Bundle getExtras() {
747 return mExtras;
748 }
749
Santos Cordon6b7f9552015-05-27 17:21:45 -0700750 /**
751 * @return The extras used with the original intent to place this call.
752 */
753 public Bundle getIntentExtras() {
754 return mIntentExtras;
755 }
756
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700757 /**
758 * Returns the time when the call was first created and added to Telecom. This is the same
759 * time that is logged as the start time in the Call Log (see
760 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
761 * (became active), see {@link #getConnectTimeMillis()}.
762 *
763 * @return The creation time of the call, in millis since the epoch.
764 */
765 public long getCreationTimeMillis() {
766 return mCreationTimeMillis;
767 }
768
Ihab Awade63fadb2014-07-09 21:52:04 -0700769 @Override
770 public boolean equals(Object o) {
771 if (o instanceof Details) {
772 Details d = (Details) o;
773 return
774 Objects.equals(mHandle, d.mHandle) &&
775 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
776 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
777 Objects.equals(mCallerDisplayNamePresentation,
778 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700779 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700780 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700781 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700782 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700783 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700784 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700785 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700786 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700787 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700788 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
789 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700790 }
791 return false;
792 }
793
794 @Override
795 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700796 return Objects.hash(mHandle,
797 mHandlePresentation,
798 mCallerDisplayName,
799 mCallerDisplayNamePresentation,
800 mAccountHandle,
801 mCallCapabilities,
802 mCallProperties,
803 mDisconnectCause,
804 mConnectTimeMillis,
805 mGatewayInfo,
806 mVideoState,
807 mStatusHints,
808 mExtras,
809 mIntentExtras,
810 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700811 }
812
813 /** {@hide} */
814 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800815 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700816 Uri handle,
817 int handlePresentation,
818 String callerDisplayName,
819 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700820 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700821 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700822 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700823 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700824 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700825 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700826 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700827 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700828 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700829 Bundle intentExtras,
830 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800831 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700832 mHandle = handle;
833 mHandlePresentation = handlePresentation;
834 mCallerDisplayName = callerDisplayName;
835 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700836 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700837 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700838 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700839 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700840 mConnectTimeMillis = connectTimeMillis;
841 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700842 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700843 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700844 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700845 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700846 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700847 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800848
849 /** {@hide} */
850 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
851 return new Details(
852 parcelableCall.getId(),
853 parcelableCall.getHandle(),
854 parcelableCall.getHandlePresentation(),
855 parcelableCall.getCallerDisplayName(),
856 parcelableCall.getCallerDisplayNamePresentation(),
857 parcelableCall.getAccountHandle(),
858 parcelableCall.getCapabilities(),
859 parcelableCall.getProperties(),
860 parcelableCall.getDisconnectCause(),
861 parcelableCall.getConnectTimeMillis(),
862 parcelableCall.getGatewayInfo(),
863 parcelableCall.getVideoState(),
864 parcelableCall.getStatusHints(),
865 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700866 parcelableCall.getIntentExtras(),
867 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800868 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800869
870 @Override
871 public String toString() {
872 StringBuilder sb = new StringBuilder();
873 sb.append("[pa: ");
874 sb.append(mAccountHandle);
875 sb.append(", hdl: ");
876 sb.append(Log.pii(mHandle));
877 sb.append(", caps: ");
878 sb.append(capabilitiesToString(mCallCapabilities));
879 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700880 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800881 sb.append("]");
882 return sb.toString();
883 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700884 }
885
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700886 /**
887 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
888 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
889 * implementation.
890 * <p>
891 * You can handle these callbacks by extending the {@link Callback} class and overriding the
892 * callbacks that your {@link InCallService} is interested in. The callback methods include the
893 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
894 * {@link Callback} implementation, if desired.
895 * <p>
896 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
897 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
898 * (typically in {@link InCallService#onCallRemoved(Call)}).
899 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
900 * reach your implementation of {@link Callback}, so it is important to register your callback
901 * as soon as your {@link InCallService} is notified of a new call via
902 * {@link InCallService#onCallAdded(Call)}.
903 */
Andrew Leeda80c872015-04-15 14:09:50 -0700904 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700905 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -0700906 * @hide
907 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800908 @IntDef(prefix = { "HANDOVER_" },
909 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -0700910 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -0800911 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -0700912 @Retention(RetentionPolicy.SOURCE)
913 public @interface HandoverFailureErrors {}
914
915 /**
916 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -0800917 * to handover the call to rejects the handover request.
918 * <p>
919 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
920 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
921 * {@code null} {@link Connection} from
922 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
923 * ConnectionRequest)}.
924 * <p>
925 * For more information on call handovers, see
926 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700927 */
928 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
929
930 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800931 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
932 * is initiated but the source or destination app does not support handover.
933 * <p>
934 * Will be returned when a handover is requested via
935 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
936 * {@link PhoneAccountHandle} does not declare
937 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
938 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
939 * {@link Details#getAccountHandle()}) does not declare
940 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
941 * <p>
942 * For more information on call handovers, see
943 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700944 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800945 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700946
947 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800948 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
949 * user rejects the handover request.
950 * <p>
951 * For more information on call handovers, see
952 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700953 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800954 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700955
Sanket Padawe85291f62017-12-01 13:59:27 -0800956 /**
957 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
958 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -0800959 * <p>
960 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
961 * called on an emergency call, or if any other call is an emergency call.
962 * <p>
963 * Handovers are not permitted while there are ongoing emergency calls.
964 * <p>
965 * For more information on call handovers, see
966 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -0800967 */
Tyler Gunn5c60d712018-03-16 09:53:44 -0700968 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -0800969
Tyler Gunn9d127732018-03-02 15:45:51 -0800970 /**
971 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
972 * fails for an unknown reason.
973 * <p>
974 * For more information on call handovers, see
975 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
976 */
977 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700978
979 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700980 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
981 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700982 * @param call The {@code Call} invoking this method.
983 * @param state The new state of the {@code Call}.
984 */
985 public void onStateChanged(Call call, int state) {}
986
987 /**
988 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
989 *
990 * @param call The {@code Call} invoking this method.
991 * @param parent The new parent of the {@code Call}.
992 */
993 public void onParentChanged(Call call, Call parent) {}
994
995 /**
996 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
997 *
998 * @param call The {@code Call} invoking this method.
999 * @param children The new children of the {@code Call}.
1000 */
1001 public void onChildrenChanged(Call call, List<Call> children) {}
1002
1003 /**
1004 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1005 *
1006 * @param call The {@code Call} invoking this method.
1007 * @param details A {@code Details} object describing the {@code Call}.
1008 */
1009 public void onDetailsChanged(Call call, Details details) {}
1010
1011 /**
1012 * Invoked when the text messages that can be used as responses to the incoming
1013 * {@code Call} are loaded from the relevant database.
1014 * See {@link #getCannedTextResponses()}.
1015 *
1016 * @param call The {@code Call} invoking this method.
1017 * @param cannedTextResponses The text messages useable as responses.
1018 */
1019 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1020
1021 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001022 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1023 * character. This causes the post-dial signals to stop pending user confirmation. An
1024 * implementation should present this choice to the user and invoke
1025 * {@link #postDialContinue(boolean)} when the user makes the choice.
1026 *
1027 * @param call The {@code Call} invoking this method.
1028 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1029 */
1030 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1031
1032 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001033 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001034 *
1035 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001036 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001037 */
Andrew Lee50aca232014-07-22 16:41:54 -07001038 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001039
1040 /**
1041 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1042 * up their UI for the {@code Call} in response to state transitions. Specifically,
1043 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1044 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1045 * clients should wait for this method to be invoked.
1046 *
1047 * @param call The {@code Call} being destroyed.
1048 */
1049 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001050
1051 /**
1052 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1053 * conferenced.
1054 *
1055 * @param call The {@code Call} being updated.
1056 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1057 * conferenced.
1058 */
1059 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001060
1061 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001062 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
1063 * <p>
1064 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1065 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1066 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1067 * possible that a {@link ConnectionService} has defined its own Connection events which a
1068 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001069 * <p>
1070 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
1071 *
1072 * @param call The {@code Call} receiving the event.
1073 * @param event The event.
1074 * @param extras Extras associated with the connection event.
1075 */
1076 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001077
1078 /**
1079 * Invoked when the RTT mode changes for this call.
1080 * @param call The call whose RTT mode has changed.
1081 * @param mode the new RTT mode, one of
1082 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1083 * or {@link RttCall#RTT_MODE_VCO}
1084 */
1085 public void onRttModeChanged(Call call, int mode) {}
1086
1087 /**
1088 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1089 * @param call The call whose RTT status has changed.
1090 * @param enabled whether RTT is now enabled or disabled
1091 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1092 * on, null otherwise.
1093 */
1094 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1095
1096 /**
1097 * Invoked when the remote end of the connection has requested that an RTT communication
1098 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1099 * with the same ID that this method is invoked with.
1100 * @param call The call which the RTT request was placed on
1101 * @param id The ID of the request.
1102 */
1103 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001104
1105 /**
1106 * Invoked when the RTT session failed to initiate for some reason, including rejection
1107 * by the remote party.
1108 * @param call The call which the RTT initiation failure occurred on.
1109 * @param reason One of the status codes defined in
1110 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1111 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1112 */
1113 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001114
1115 /**
1116 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1117 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001118 * <p>
1119 * For a full discussion of the handover process and the APIs involved, see
1120 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1121 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001122 * @param call The call which had initiated handover.
1123 */
1124 public void onHandoverComplete(Call call) {}
1125
1126 /**
1127 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1128 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001129 * <p>
1130 * For a full discussion of the handover process and the APIs involved, see
1131 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1132 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001133 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001134 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001135 */
1136 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001137 }
1138
1139 /**
1140 * A class that holds the state that describes the state of the RTT channel to the remote
1141 * party, if it is active.
1142 */
1143 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001144 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001145 @Retention(RetentionPolicy.SOURCE)
1146 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1147 public @interface RttAudioMode {}
1148
1149 /**
1150 * For metrics use. Default value in the proto.
1151 * @hide
1152 */
1153 public static final int RTT_MODE_INVALID = 0;
1154
1155 /**
1156 * Indicates that there should be a bidirectional audio stream between the two parties
1157 * on the call.
1158 */
1159 public static final int RTT_MODE_FULL = 1;
1160
1161 /**
1162 * Indicates that the local user should be able to hear the audio stream from the remote
1163 * user, but not vice versa. Equivalent to muting the microphone.
1164 */
1165 public static final int RTT_MODE_HCO = 2;
1166
1167 /**
1168 * Indicates that the remote user should be able to hear the audio stream from the local
1169 * user, but not vice versa. Equivalent to setting the volume to zero.
1170 */
1171 public static final int RTT_MODE_VCO = 3;
1172
1173 private static final int READ_BUFFER_SIZE = 1000;
1174
1175 private InputStreamReader mReceiveStream;
1176 private OutputStreamWriter mTransmitStream;
1177 private int mRttMode;
1178 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001179 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001180 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1181
1182 /**
1183 * @hide
1184 */
Hall Liu57006aa2017-02-06 10:49:48 -08001185 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1186 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1187 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001188 mReceiveStream = receiveStream;
1189 mTransmitStream = transmitStream;
1190 mRttMode = mode;
1191 mInCallAdapter = inCallAdapter;
1192 }
1193
1194 /**
1195 * Returns the current RTT audio mode.
1196 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1197 * {@link #RTT_MODE_HCO}.
1198 */
1199 public int getRttAudioMode() {
1200 return mRttMode;
1201 }
1202
1203 /**
1204 * Sets the RTT audio mode. The requested mode change will be communicated through
1205 * {@link Callback#onRttModeChanged(Call, int)}.
1206 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1207 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1208 */
1209 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001210 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001211 }
1212
1213 /**
1214 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1215 * RTT transmits text in real-time, this method should be called once for each character
1216 * the user enters into the device.
1217 *
1218 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1219 * lead to interleaved text.
1220 * @param input The message to send to the remote user.
1221 */
1222 public void write(String input) throws IOException {
1223 mTransmitStream.write(input);
1224 mTransmitStream.flush();
1225 }
1226
1227 /**
1228 * Reads a string from the remote user, blocking if there is no data available. Returns
1229 * {@code null} if the RTT conversation has been terminated and there is no further data
1230 * to read.
1231 *
1232 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1233 * lead to interleaved text.
1234 * @return A string containing text sent by the remote user, or {@code null} if the
1235 * conversation has been terminated or if there was an error while reading.
1236 */
Hall Liub1c8a772017-07-17 17:04:41 -07001237 public String read() {
1238 try {
1239 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1240 if (numRead < 0) {
1241 return null;
1242 }
1243 return new String(mReadBuffer, 0, numRead);
1244 } catch (IOException e) {
1245 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001246 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001247 }
Hall Liuffa4a812017-03-02 16:11:00 -08001248 }
1249
1250 /**
1251 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1252 * be read.
1253 * @return A string containing text entered by the user, or {@code null} if the user has
1254 * not entered any new text yet.
1255 */
1256 public String readImmediately() throws IOException {
1257 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001258 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1259 if (numRead < 0) {
1260 return null;
1261 }
1262 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001263 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001264 return null;
1265 }
1266 }
Hall Liue9041242018-02-09 16:40:03 -08001267
1268 /**
1269 * Closes the underlying file descriptors
1270 * @hide
1271 */
1272 public void close() {
1273 try {
1274 mReceiveStream.close();
1275 } catch (IOException e) {
1276 // ignore
1277 }
1278 try {
1279 mTransmitStream.close();
1280 } catch (IOException e) {
1281 // ignore
1282 }
1283 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001284 }
1285
Andrew Leeda80c872015-04-15 14:09:50 -07001286 /**
1287 * @deprecated Use {@code Call.Callback} instead.
1288 * @hide
1289 */
1290 @Deprecated
1291 @SystemApi
1292 public static abstract class Listener extends Callback { }
1293
Ihab Awade63fadb2014-07-09 21:52:04 -07001294 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001295 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001296 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001297 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001298 private final List<Call> mChildren = new ArrayList<>();
1299 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001300 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001301 private final List<Call> mConferenceableCalls = new ArrayList<>();
1302 private final List<Call> mUnmodifiableConferenceableCalls =
1303 Collections.unmodifiableList(mConferenceableCalls);
1304
Santos Cordon823fd3c2014-08-07 18:35:18 -07001305 private boolean mChildrenCached;
1306 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001307 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001308 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001309 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001310 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001311 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001312 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001313 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001314 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001315 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001316
1317 /**
1318 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1319 *
1320 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1321 * remaining or this {@code Call} is not in a post-dial state.
1322 */
1323 public String getRemainingPostDialSequence() {
1324 return mRemainingPostDialSequence;
1325 }
1326
1327 /**
1328 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001329 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001330 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001331 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001332 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001333 }
1334
1335 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301336 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1337 *
1338 * @param address The address to which the call will be deflected.
1339 */
1340 public void deflect(Uri address) {
1341 mInCallAdapter.deflectCall(mTelecomCallId, address);
1342 }
1343
1344 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001345 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1346 *
1347 * @param rejectWithMessage Whether to reject with a text message.
1348 * @param textMessage An optional text message with which to respond.
1349 */
1350 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001351 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001352 }
1353
1354 /**
1355 * Instructs this {@code Call} to disconnect.
1356 */
1357 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001358 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001359 }
1360
1361 /**
1362 * Instructs this {@code Call} to go on hold.
1363 */
1364 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001365 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001366 }
1367
1368 /**
1369 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1370 */
1371 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001372 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001373 }
1374
1375 /**
1376 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1377 *
1378 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1379 *
1380 * @param digit A character representing the DTMF digit for which to play the tone. This
1381 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1382 */
1383 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001384 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001385 }
1386
1387 /**
1388 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1389 * currently playing.
1390 *
1391 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1392 * currently playing, this method will do nothing.
1393 */
1394 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001395 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001396 }
1397
1398 /**
1399 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1400 *
1401 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1402 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001403 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001404 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001405 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1406 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001407 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001408 * {@code Call} will pause playing the tones and notify callbacks via
1409 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001410 * should display to the user an indication of this state and an affordance to continue
1411 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1412 * app should invoke the {@link #postDialContinue(boolean)} method.
1413 *
1414 * @param proceed Whether or not to continue with the post-dial sequence.
1415 */
1416 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001417 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001418 }
1419
1420 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001421 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001422 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001423 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001424 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1425 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001426
1427 }
1428
1429 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001430 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001431 *
1432 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001433 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001434 public void conference(Call callToConferenceWith) {
1435 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001436 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001437 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001438 }
1439
1440 /**
1441 * Instructs this {@code Call} to split from any conference call with which it may be
1442 * connected.
1443 */
1444 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001445 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001446 }
1447
1448 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001449 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001450 */
1451 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001452 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001453 }
1454
1455 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001456 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001457 */
1458 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001459 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001460 }
1461
1462 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001463 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1464 * device.
1465 * <p>
1466 * Calls to this method are ignored if the call does not have the
1467 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1468 * <p>
1469 * An {@link InCallService} will only see calls which support this method if it has the
1470 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1471 * in its manifest.
1472 */
1473 public void pullExternalCall() {
1474 // If this isn't an external call, ignore the request.
1475 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1476 return;
1477 }
1478
1479 mInCallAdapter.pullExternalCall(mTelecomCallId);
1480 }
1481
1482 /**
1483 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1484 * the {@link ConnectionService}.
1485 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001486 * Call events are used to communicate point in time information from an {@link InCallService}
1487 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1488 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1489 * {@link ConnectionService}.
1490 * <p>
1491 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1492 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1493 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001494 * Events are exposed to {@link ConnectionService} implementations via
1495 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1496 * <p>
1497 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001498 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1499 * ignore some events altogether.
1500 * <p>
1501 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1502 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1503 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1504 * they define their own event types in this namespace. When defining a custom event type,
1505 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1506 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1507 * <p>
1508 * When defining events and the associated extras, it is important to keep their behavior
1509 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1510 * events/extras should me maintained to ensure backwards compatibility with older
1511 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001512 *
1513 * @param event The connection event.
1514 * @param extras Bundle containing extra information associated with the event.
1515 */
1516 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001517 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001518 }
1519
1520 /**
Hall Liu95d55872017-01-25 17:12:49 -08001521 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1522 * guaranteed, and notification of success will be via the
1523 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1524 */
1525 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001526 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001527 }
1528
1529 /**
1530 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1531 * callback.
1532 * The ID used here should be the same as the ID that was received via the callback.
1533 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1534 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1535 */
1536 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001537 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001538 }
1539
1540 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001541 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1542 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1543 * handover.
1544 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001545 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1546 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1547 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1548 * is referred to as the source of the handover, and the video calling app is referred to as the
1549 * destination.
1550 * <p>
1551 * When considering a handover scenario the device this method is called on is considered the
1552 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1553 * other device is considered the <em>receiving</em> device.
1554 * <p>
1555 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1556 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1557 * and invoke
1558 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1559 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1560 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1561 * At this point the app should display UI to indicate to the user that a call
1562 * handover is in process.
1563 * <p>
1564 * The destination app is responsible for communicating the handover request from the
1565 * <em>initiating</em> device to the <em>receiving</em> device.
1566 * <p>
1567 * When the app on the <em>receiving</em> device receives the handover request, it calls
1568 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1569 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1570 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1571 * choose whether they want to continue their call in the destination app.
1572 * <p>
1573 * When the destination app on the <em>receiving</em> device calls
1574 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1575 * {@link ConnectionService} and call
1576 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1577 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1578 * {@link Connection} to represent the handover call.
1579 * <p>
1580 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1581 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1582 * original call. If the user rejects the handover, the app calls
1583 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1584 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1585 * <p>
1586 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1587 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1588 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1589 * <p>
1590 * Errors in the handover process are reported to the {@link InCallService} via
1591 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1592 * the involved {@link ConnectionService}s via
1593 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001594 *
1595 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1596 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001597 * @param videoState Indicates the video state desired after the handover (see the
1598 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001599 * @param extras Bundle containing extra information to be passed to the
1600 * {@link ConnectionService}
1601 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001602 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1603 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001604 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1605 }
1606
1607 /**
Hall Liu95d55872017-01-25 17:12:49 -08001608 * Terminate the RTT session on this call. The resulting state change will be notified via
1609 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1610 */
1611 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001612 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001613 }
1614
1615 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001616 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1617 * added.
1618 * <p>
1619 * No assumptions should be made as to how an In-Call UI or service will handle these
1620 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1621 *
1622 * @param extras The extras to add.
1623 */
1624 public final void putExtras(Bundle extras) {
1625 if (extras == null) {
1626 return;
1627 }
1628
1629 if (mExtras == null) {
1630 mExtras = new Bundle();
1631 }
1632 mExtras.putAll(extras);
1633 mInCallAdapter.putExtras(mTelecomCallId, extras);
1634 }
1635
1636 /**
1637 * Adds a boolean extra to this {@link Call}.
1638 *
1639 * @param key The extra key.
1640 * @param value The value.
1641 * @hide
1642 */
1643 public final void putExtra(String key, boolean value) {
1644 if (mExtras == null) {
1645 mExtras = new Bundle();
1646 }
1647 mExtras.putBoolean(key, value);
1648 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1649 }
1650
1651 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001652 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001653 *
1654 * @param key The extra key.
1655 * @param value The value.
1656 * @hide
1657 */
1658 public final void putExtra(String key, int value) {
1659 if (mExtras == null) {
1660 mExtras = new Bundle();
1661 }
1662 mExtras.putInt(key, value);
1663 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1664 }
1665
1666 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001667 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001668 *
1669 * @param key The extra key.
1670 * @param value The value.
1671 * @hide
1672 */
1673 public final void putExtra(String key, String value) {
1674 if (mExtras == null) {
1675 mExtras = new Bundle();
1676 }
1677 mExtras.putString(key, value);
1678 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1679 }
1680
1681 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001682 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001683 *
1684 * @param keys The keys of the extras to remove.
1685 */
1686 public final void removeExtras(List<String> keys) {
1687 if (mExtras != null) {
1688 for (String key : keys) {
1689 mExtras.remove(key);
1690 }
1691 if (mExtras.size() == 0) {
1692 mExtras = null;
1693 }
1694 }
1695 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1696 }
1697
1698 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001699 * Removes extras from this {@link Call}.
1700 *
1701 * @param keys The keys of the extras to remove.
1702 */
1703 public final void removeExtras(String ... keys) {
1704 removeExtras(Arrays.asList(keys));
1705 }
1706
1707 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001708 * Obtains the parent of this {@code Call} in a conference, if any.
1709 *
1710 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1711 * child of any conference {@code Call}s.
1712 */
1713 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001714 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001715 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001716 }
1717 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001718 }
1719
1720 /**
1721 * Obtains the children of this conference {@code Call}, if any.
1722 *
1723 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1724 * {@code List} otherwise.
1725 */
1726 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001727 if (!mChildrenCached) {
1728 mChildrenCached = true;
1729 mChildren.clear();
1730
1731 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001732 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001733 if (call == null) {
1734 // At least one child was still not found, so do not save true for "cached"
1735 mChildrenCached = false;
1736 } else {
1737 mChildren.add(call);
1738 }
1739 }
1740 }
1741
Ihab Awade63fadb2014-07-09 21:52:04 -07001742 return mUnmodifiableChildren;
1743 }
1744
1745 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001746 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1747 *
1748 * @return The list of conferenceable {@code Call}s.
1749 */
1750 public List<Call> getConferenceableCalls() {
1751 return mUnmodifiableConferenceableCalls;
1752 }
1753
1754 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001755 * Obtains the state of this {@code Call}.
1756 *
1757 * @return A state value, chosen from the {@code STATE_*} constants.
1758 */
1759 public int getState() {
1760 return mState;
1761 }
1762
1763 /**
1764 * Obtains a list of canned, pre-configured message responses to present to the user as
1765 * ways of rejecting this {@code Call} using via a text message.
1766 *
1767 * @see #reject(boolean, String)
1768 *
1769 * @return A list of canned text message responses.
1770 */
1771 public List<String> getCannedTextResponses() {
1772 return mCannedTextResponses;
1773 }
1774
1775 /**
1776 * Obtains an object that can be used to display video from this {@code Call}.
1777 *
Andrew Lee50aca232014-07-22 16:41:54 -07001778 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001779 */
Andrew Lee50aca232014-07-22 16:41:54 -07001780 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001781 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001782 }
1783
1784 /**
1785 * Obtains an object containing call details.
1786 *
1787 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1788 * result may be {@code null}.
1789 */
1790 public Details getDetails() {
1791 return mDetails;
1792 }
1793
1794 /**
Hall Liu95d55872017-01-25 17:12:49 -08001795 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1796 * receive RTT text data, as well as to change the RTT mode.
1797 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1798 */
1799 public @Nullable RttCall getRttCall() {
1800 return mRttCall;
1801 }
1802
1803 /**
1804 * Returns whether this call has an active RTT connection.
1805 * @return true if there is a connection, false otherwise.
1806 */
1807 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08001808 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08001809 }
1810
1811 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001812 * Registers a callback to this {@code Call}.
1813 *
1814 * @param callback A {@code Callback}.
1815 */
1816 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001817 registerCallback(callback, new Handler());
1818 }
1819
1820 /**
1821 * Registers a callback to this {@code Call}.
1822 *
1823 * @param callback A {@code Callback}.
1824 * @param handler A handler which command and status changes will be delivered to.
1825 */
1826 public void registerCallback(Callback callback, Handler handler) {
1827 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001828 // Don't allow new callback registration if the call is already being destroyed.
1829 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001830 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1831 }
Andrew Leeda80c872015-04-15 14:09:50 -07001832 }
1833
1834 /**
1835 * Unregisters a callback from this {@code Call}.
1836 *
1837 * @param callback A {@code Callback}.
1838 */
1839 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001840 // Don't allow callback deregistration if the call is already being destroyed.
1841 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001842 for (CallbackRecord<Callback> record : mCallbackRecords) {
1843 if (record.getCallback() == callback) {
1844 mCallbackRecords.remove(record);
1845 break;
1846 }
1847 }
Andrew Leeda80c872015-04-15 14:09:50 -07001848 }
1849 }
1850
Santos Cordon3c20d632016-02-25 16:12:35 -08001851 @Override
1852 public String toString() {
1853 return new StringBuilder().
1854 append("Call [id: ").
1855 append(mTelecomCallId).
1856 append(", state: ").
1857 append(stateToString(mState)).
1858 append(", details: ").
1859 append(mDetails).
1860 append("]").toString();
1861 }
1862
1863 /**
1864 * @param state An integer value of a {@code STATE_*} constant.
1865 * @return A string representation of the value.
1866 */
1867 private static String stateToString(int state) {
1868 switch (state) {
1869 case STATE_NEW:
1870 return "NEW";
1871 case STATE_RINGING:
1872 return "RINGING";
1873 case STATE_DIALING:
1874 return "DIALING";
1875 case STATE_ACTIVE:
1876 return "ACTIVE";
1877 case STATE_HOLDING:
1878 return "HOLDING";
1879 case STATE_DISCONNECTED:
1880 return "DISCONNECTED";
1881 case STATE_CONNECTING:
1882 return "CONNECTING";
1883 case STATE_DISCONNECTING:
1884 return "DISCONNECTING";
1885 case STATE_SELECT_PHONE_ACCOUNT:
1886 return "SELECT_PHONE_ACCOUNT";
1887 default:
1888 Log.w(Call.class, "Unknown state %d", state);
1889 return "UNKNOWN";
1890 }
1891 }
1892
Andrew Leeda80c872015-04-15 14:09:50 -07001893 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001894 * Adds a listener to this {@code Call}.
1895 *
1896 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001897 * @deprecated Use {@link #registerCallback} instead.
1898 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001899 */
Andrew Leeda80c872015-04-15 14:09:50 -07001900 @Deprecated
1901 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001902 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001903 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001904 }
1905
1906 /**
1907 * Removes a listener from this {@code Call}.
1908 *
1909 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001910 * @deprecated Use {@link #unregisterCallback} instead.
1911 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001912 */
Andrew Leeda80c872015-04-15 14:09:50 -07001913 @Deprecated
1914 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001915 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001916 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001917 }
1918
1919 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001920 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1921 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001922 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001923 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001924 mInCallAdapter = inCallAdapter;
1925 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001926 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001927 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001928 }
1929
1930 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001931 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001932 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001933 mPhone = phone;
1934 mTelecomCallId = telecomCallId;
1935 mInCallAdapter = inCallAdapter;
1936 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001937 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001938 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001939 }
1940
1941 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001942 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001943 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001944 }
1945
1946 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001947 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001948
Ihab Awade63fadb2014-07-09 21:52:04 -07001949 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001950 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001951 boolean detailsChanged = !Objects.equals(mDetails, details);
1952 if (detailsChanged) {
1953 mDetails = details;
1954 }
1955
1956 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001957 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1958 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1959 mCannedTextResponses =
1960 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001961 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001962 }
1963
Tyler Gunn159f35c2017-03-02 09:28:37 -08001964 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1965 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001966 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001967 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001968 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001969 mVideoCallImpl = newVideoCallImpl;
1970 }
1971 if (mVideoCallImpl != null) {
1972 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001973 }
1974
Santos Cordone3c507b2015-04-23 14:44:19 -07001975 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001976 boolean stateChanged = mState != state;
1977 if (stateChanged) {
1978 mState = state;
1979 }
1980
Santos Cordon823fd3c2014-08-07 18:35:18 -07001981 String parentId = parcelableCall.getParentCallId();
1982 boolean parentChanged = !Objects.equals(mParentId, parentId);
1983 if (parentChanged) {
1984 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001985 }
1986
Santos Cordon823fd3c2014-08-07 18:35:18 -07001987 List<String> childCallIds = parcelableCall.getChildCallIds();
1988 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1989 if (childrenChanged) {
1990 mChildrenIds.clear();
1991 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1992 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001993 }
1994
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001995 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1996 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1997 for (String otherId : conferenceableCallIds) {
1998 if (callIdMap.containsKey(otherId)) {
1999 conferenceableCalls.add(callIdMap.get(otherId));
2000 }
2001 }
2002
2003 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2004 mConferenceableCalls.clear();
2005 mConferenceableCalls.addAll(conferenceableCalls);
2006 fireConferenceableCallsChanged();
2007 }
2008
Hall Liu95d55872017-01-25 17:12:49 -08002009 boolean isRttChanged = false;
2010 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002011 if (parcelableCall.getIsRttCallChanged()
2012 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002013 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2014 InputStreamReader receiveStream = new InputStreamReader(
2015 new ParcelFileDescriptor.AutoCloseInputStream(
2016 parcelableRttCall.getReceiveStream()),
2017 StandardCharsets.UTF_8);
2018 OutputStreamWriter transmitStream = new OutputStreamWriter(
2019 new ParcelFileDescriptor.AutoCloseOutputStream(
2020 parcelableRttCall.getTransmitStream()),
2021 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002022 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002023 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2024 if (mRttCall == null) {
2025 isRttChanged = true;
2026 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2027 rttModeChanged = true;
2028 }
2029 mRttCall = newRttCall;
2030 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2031 && parcelableCall.getIsRttCallChanged()) {
2032 isRttChanged = true;
2033 mRttCall = null;
2034 }
2035
Ihab Awade63fadb2014-07-09 21:52:04 -07002036 // Now we fire updates, ensuring that any client who listens to any of these notifications
2037 // gets the most up-to-date state.
2038
2039 if (stateChanged) {
2040 fireStateChanged(mState);
2041 }
2042 if (detailsChanged) {
2043 fireDetailsChanged(mDetails);
2044 }
2045 if (cannedTextResponsesChanged) {
2046 fireCannedTextResponsesLoaded(mCannedTextResponses);
2047 }
Andrew Lee50aca232014-07-22 16:41:54 -07002048 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002049 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002050 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002051 if (parentChanged) {
2052 fireParentChanged(getParent());
2053 }
2054 if (childrenChanged) {
2055 fireChildrenChanged(getChildren());
2056 }
Hall Liu95d55872017-01-25 17:12:49 -08002057 if (isRttChanged) {
2058 fireOnIsRttChanged(mRttCall != null, mRttCall);
2059 }
2060 if (rttModeChanged) {
2061 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2062 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002063
2064 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2065 // remove ourselves from the Phone. Note that we do this after completing all state updates
2066 // so a client can cleanly transition all their UI to the state appropriate for a
2067 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2068 if (mState == STATE_DISCONNECTED) {
2069 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002070 }
2071 }
2072
2073 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002074 final void internalSetPostDialWait(String remaining) {
2075 mRemainingPostDialSequence = remaining;
2076 firePostDialWait(mRemainingPostDialSequence);
2077 }
2078
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002079 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002080 final void internalSetDisconnected() {
2081 if (mState != Call.STATE_DISCONNECTED) {
2082 mState = Call.STATE_DISCONNECTED;
2083 fireStateChanged(mState);
2084 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002085 }
2086 }
2087
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002088 /** {@hide} */
2089 final void internalOnConnectionEvent(String event, Bundle extras) {
2090 fireOnConnectionEvent(event, extras);
2091 }
2092
Hall Liu95d55872017-01-25 17:12:49 -08002093 /** {@hide} */
2094 final void internalOnRttUpgradeRequest(final int requestId) {
2095 for (CallbackRecord<Callback> record : mCallbackRecords) {
2096 final Call call = this;
2097 final Callback callback = record.getCallback();
2098 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2099 }
2100 }
2101
Hall Liu57006aa2017-02-06 10:49:48 -08002102 /** @hide */
2103 final void internalOnRttInitiationFailure(int reason) {
2104 for (CallbackRecord<Callback> record : mCallbackRecords) {
2105 final Call call = this;
2106 final Callback callback = record.getCallback();
2107 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2108 }
2109 }
2110
Sanket Padawe85291f62017-12-01 13:59:27 -08002111 /** {@hide} */
2112 final void internalOnHandoverFailed(int error) {
2113 for (CallbackRecord<Callback> record : mCallbackRecords) {
2114 final Call call = this;
2115 final Callback callback = record.getCallback();
2116 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2117 }
2118 }
2119
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002120 /** {@hide} */
2121 final void internalOnHandoverComplete() {
2122 for (CallbackRecord<Callback> record : mCallbackRecords) {
2123 final Call call = this;
2124 final Callback callback = record.getCallback();
2125 record.getHandler().post(() -> callback.onHandoverComplete(call));
2126 }
2127 }
2128
Andrew Lee011728f2015-04-23 15:47:06 -07002129 private void fireStateChanged(final int newState) {
2130 for (CallbackRecord<Callback> record : mCallbackRecords) {
2131 final Call call = this;
2132 final Callback callback = record.getCallback();
2133 record.getHandler().post(new Runnable() {
2134 @Override
2135 public void run() {
2136 callback.onStateChanged(call, newState);
2137 }
2138 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002139 }
2140 }
2141
Andrew Lee011728f2015-04-23 15:47:06 -07002142 private void fireParentChanged(final Call newParent) {
2143 for (CallbackRecord<Callback> record : mCallbackRecords) {
2144 final Call call = this;
2145 final Callback callback = record.getCallback();
2146 record.getHandler().post(new Runnable() {
2147 @Override
2148 public void run() {
2149 callback.onParentChanged(call, newParent);
2150 }
2151 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002152 }
2153 }
2154
Andrew Lee011728f2015-04-23 15:47:06 -07002155 private void fireChildrenChanged(final List<Call> children) {
2156 for (CallbackRecord<Callback> record : mCallbackRecords) {
2157 final Call call = this;
2158 final Callback callback = record.getCallback();
2159 record.getHandler().post(new Runnable() {
2160 @Override
2161 public void run() {
2162 callback.onChildrenChanged(call, children);
2163 }
2164 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002165 }
2166 }
2167
Andrew Lee011728f2015-04-23 15:47:06 -07002168 private void fireDetailsChanged(final Details details) {
2169 for (CallbackRecord<Callback> record : mCallbackRecords) {
2170 final Call call = this;
2171 final Callback callback = record.getCallback();
2172 record.getHandler().post(new Runnable() {
2173 @Override
2174 public void run() {
2175 callback.onDetailsChanged(call, details);
2176 }
2177 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002178 }
2179 }
2180
Andrew Lee011728f2015-04-23 15:47:06 -07002181 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2182 for (CallbackRecord<Callback> record : mCallbackRecords) {
2183 final Call call = this;
2184 final Callback callback = record.getCallback();
2185 record.getHandler().post(new Runnable() {
2186 @Override
2187 public void run() {
2188 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2189 }
2190 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002191 }
2192 }
2193
Andrew Lee011728f2015-04-23 15:47:06 -07002194 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2195 for (CallbackRecord<Callback> record : mCallbackRecords) {
2196 final Call call = this;
2197 final Callback callback = record.getCallback();
2198 record.getHandler().post(new Runnable() {
2199 @Override
2200 public void run() {
2201 callback.onVideoCallChanged(call, videoCall);
2202 }
2203 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002204 }
2205 }
2206
Andrew Lee011728f2015-04-23 15:47:06 -07002207 private void firePostDialWait(final String remainingPostDialSequence) {
2208 for (CallbackRecord<Callback> record : mCallbackRecords) {
2209 final Call call = this;
2210 final Callback callback = record.getCallback();
2211 record.getHandler().post(new Runnable() {
2212 @Override
2213 public void run() {
2214 callback.onPostDialWait(call, remainingPostDialSequence);
2215 }
2216 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002217 }
2218 }
2219
2220 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002221 /**
2222 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2223 * onCallRemoved callback, we remove this call from the Phone's record
2224 * only once all of the registered onCallDestroyed callbacks are executed.
2225 * All the callbacks get removed from our records as a part of this operation
2226 * since onCallDestroyed is the final callback.
2227 */
2228 final Call call = this;
2229 if (mCallbackRecords.isEmpty()) {
2230 // No callbacks registered, remove the call from Phone's record.
2231 mPhone.internalRemoveCall(call);
2232 }
2233 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002234 final Callback callback = record.getCallback();
2235 record.getHandler().post(new Runnable() {
2236 @Override
2237 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002238 boolean isFinalRemoval = false;
2239 RuntimeException toThrow = null;
2240 try {
2241 callback.onCallDestroyed(call);
2242 } catch (RuntimeException e) {
2243 toThrow = e;
2244 }
2245 synchronized(Call.this) {
2246 mCallbackRecords.remove(record);
2247 if (mCallbackRecords.isEmpty()) {
2248 isFinalRemoval = true;
2249 }
2250 }
2251 if (isFinalRemoval) {
2252 mPhone.internalRemoveCall(call);
2253 }
2254 if (toThrow != null) {
2255 throw toThrow;
2256 }
Andrew Lee011728f2015-04-23 15:47:06 -07002257 }
2258 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002259 }
2260 }
2261
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002262 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002263 for (CallbackRecord<Callback> record : mCallbackRecords) {
2264 final Call call = this;
2265 final Callback callback = record.getCallback();
2266 record.getHandler().post(new Runnable() {
2267 @Override
2268 public void run() {
2269 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2270 }
2271 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002272 }
2273 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002274
2275 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002276 * Notifies listeners of an incoming connection event.
2277 * <p>
2278 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2279 *
2280 * @param event
2281 * @param extras
2282 */
2283 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2284 for (CallbackRecord<Callback> record : mCallbackRecords) {
2285 final Call call = this;
2286 final Callback callback = record.getCallback();
2287 record.getHandler().post(new Runnable() {
2288 @Override
2289 public void run() {
2290 callback.onConnectionEvent(call, event, extras);
2291 }
2292 });
2293 }
2294 }
2295
2296 /**
Hall Liu95d55872017-01-25 17:12:49 -08002297 * Notifies listeners of an RTT on/off change
2298 *
2299 * @param enabled True if RTT is now enabled, false otherwise
2300 */
2301 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2302 for (CallbackRecord<Callback> record : mCallbackRecords) {
2303 final Call call = this;
2304 final Callback callback = record.getCallback();
2305 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2306 }
2307 }
2308
2309 /**
2310 * Notifies listeners of a RTT mode change
2311 *
2312 * @param mode The new RTT mode
2313 */
2314 private void fireOnRttModeChanged(final int mode) {
2315 for (CallbackRecord<Callback> record : mCallbackRecords) {
2316 final Call call = this;
2317 final Callback callback = record.getCallback();
2318 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2319 }
2320 }
2321
2322 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002323 * Determines if two bundles are equal.
2324 *
2325 * @param bundle The original bundle.
2326 * @param newBundle The bundle to compare with.
2327 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2328 */
2329 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2330 if (bundle == null || newBundle == null) {
2331 return bundle == newBundle;
2332 }
2333
2334 if (bundle.size() != newBundle.size()) {
2335 return false;
2336 }
2337
2338 for(String key : bundle.keySet()) {
2339 if (key != null) {
2340 final Object value = bundle.get(key);
2341 final Object newValue = newBundle.get(key);
2342 if (!Objects.equals(value, newValue)) {
2343 return false;
2344 }
2345 }
2346 }
2347 return true;
2348 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002349}