blob: daa09f5746519b78983781032b60f8661c8e64b3 [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 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700400 * When set, the UI should indicate to the user that a call is using high definition
401 * audio.
402 * <p>
403 * The underlying {@link ConnectionService} is responsible for reporting this
404 * property. It is important to note that this property is not intended to report the
405 * actual audio codec being used for a Call, but whether the call should be indicated
406 * to the user as high definition.
407 * <p>
408 * The Android Telephony stack reports this property for calls based on a number
409 * of factors, including which audio codec is used and whether a call is using an HD
410 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
411 * and in these cases this property will not be set for a call even if the underlying audio
412 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700413 */
414 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
415
Tony Maka68dcce2015-12-17 09:31:18 +0000416 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100417 * Whether the call is associated with the work profile.
418 */
419 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
420
421 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700422 * When set, indicates that this {@code Call} does not actually exist locally for the
423 * {@link ConnectionService}.
424 * <p>
425 * Consider, for example, a scenario where a user has two phones with the same phone number.
426 * When a user places a call on one device, the telephony stack can represent that call on
427 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700428 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700429 * <p>
430 * An {@link InCallService} will only see calls with this property if it has the
431 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
432 * in its manifest.
433 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700434 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700435 */
436 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
437
Brad Ebinger15847072016-05-18 11:08:36 -0700438 /**
439 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
440 */
441 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
442
Tyler Gunn24e18332017-02-10 09:42:49 -0800443 /**
444 * Indicates that the call is from a self-managed {@link ConnectionService}.
445 * <p>
446 * See also {@link Connection#PROPERTY_SELF_MANAGED}
447 */
448 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
449
Eric Erfanianec881872017-12-06 16:27:53 -0800450 /**
451 * Indicates the call used Assisted Dialing.
452 * See also {@link Connection#PROPERTY_ASSISTED_DIALING_USED}
453 * @hide
454 */
455 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
456
Hall Liue9041242018-02-09 16:40:03 -0800457 /**
458 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
459 * {@link RttCall} object that is used to send and receive text.
460 */
461 public static final int PROPERTY_RTT = 0x00000400;
462
Tyler Gunn5bd90852018-09-21 09:37:07 -0700463 /**
464 * Indicates that the call has been identified as the network as an emergency call. This
465 * property may be set for both incoming and outgoing calls which the network identifies as
466 * emergency calls.
467 */
468 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
469
Andrew Lee2378ea72015-04-29 14:38:11 -0700470 //******************************************************************************************
Tyler Gunn5bd90852018-09-21 09:37:07 -0700471 // Next PROPERTY value: 0x00001000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700472 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800473
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800474 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700475 private final Uri mHandle;
476 private final int mHandlePresentation;
477 private final String mCallerDisplayName;
478 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700479 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700480 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700481 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800482 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700483 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700484 private final long mConnectTimeMillis;
485 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700486 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700487 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700488 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700489 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700490 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700491
492 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800493 * Whether the supplied capabilities supports the specified capability.
494 *
495 * @param capabilities A bit field of capabilities.
496 * @param capability The capability to check capabilities for.
497 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800498 */
499 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800500 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800501 }
502
503 /**
504 * Whether the capabilities of this {@code Details} supports the specified capability.
505 *
506 * @param capability The capability to check capabilities for.
507 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800508 */
509 public boolean can(int capability) {
510 return can(mCallCapabilities, capability);
511 }
512
513 /**
514 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
515 *
516 * @param capabilities A capability bit field.
517 * @return A human readable string representation.
518 */
519 public static String capabilitiesToString(int capabilities) {
520 StringBuilder builder = new StringBuilder();
521 builder.append("[Capabilities:");
522 if (can(capabilities, CAPABILITY_HOLD)) {
523 builder.append(" CAPABILITY_HOLD");
524 }
525 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
526 builder.append(" CAPABILITY_SUPPORT_HOLD");
527 }
528 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
529 builder.append(" CAPABILITY_MERGE_CONFERENCE");
530 }
531 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
532 builder.append(" CAPABILITY_SWAP_CONFERENCE");
533 }
534 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
535 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
536 }
537 if (can(capabilities, CAPABILITY_MUTE)) {
538 builder.append(" CAPABILITY_MUTE");
539 }
540 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
541 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
542 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700543 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
544 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
545 }
546 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
547 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
548 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700549 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
550 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800551 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700552 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
553 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
554 }
555 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
556 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
557 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800558 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
559 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
560 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700561 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
562 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800563 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500564 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700565 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500566 }
Rekha Kumar07366812015-03-24 16:42:31 -0700567 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
568 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
569 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700570 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
571 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
572 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700573 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
574 builder.append(" CAPABILITY_CAN_PULL_CALL");
575 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530576 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
577 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
578 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800579 builder.append("]");
580 return builder.toString();
581 }
582
583 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700584 * Whether the supplied properties includes the specified property.
585 *
586 * @param properties A bit field of properties.
587 * @param property The property to check properties for.
588 * @return Whether the specified property is supported.
589 */
590 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800591 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700592 }
593
594 /**
595 * Whether the properties of this {@code Details} includes the specified property.
596 *
597 * @param property The property to check properties for.
598 * @return Whether the specified property is supported.
599 */
600 public boolean hasProperty(int property) {
601 return hasProperty(mCallProperties, property);
602 }
603
604 /**
605 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
606 *
607 * @param properties A property bit field.
608 * @return A human readable string representation.
609 */
610 public static String propertiesToString(int properties) {
611 StringBuilder builder = new StringBuilder();
612 builder.append("[Properties:");
613 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
614 builder.append(" PROPERTY_CONFERENCE");
615 }
616 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
617 builder.append(" PROPERTY_GENERIC_CONFERENCE");
618 }
619 if (hasProperty(properties, PROPERTY_WIFI)) {
620 builder.append(" PROPERTY_WIFI");
621 }
622 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
623 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
624 }
625 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700626 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700627 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700628 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
629 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
630 }
Brad Ebinger15847072016-05-18 11:08:36 -0700631 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
632 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
633 }
Eric Erfanianec881872017-12-06 16:27:53 -0800634 if(hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
635 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
636 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700637 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
638 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
639 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700640 builder.append("]");
641 return builder.toString();
642 }
643
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800644 /** {@hide} */
645 public String getTelecomCallId() {
646 return mTelecomCallId;
647 }
648
Andrew Lee2378ea72015-04-29 14:38:11 -0700649 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700650 * @return The handle (e.g., phone number) to which the {@code Call} is currently
651 * connected.
652 */
653 public Uri getHandle() {
654 return mHandle;
655 }
656
657 /**
658 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700659 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700660 */
661 public int getHandlePresentation() {
662 return mHandlePresentation;
663 }
664
665 /**
666 * @return The display name for the caller.
667 */
668 public String getCallerDisplayName() {
669 return mCallerDisplayName;
670 }
671
672 /**
673 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700674 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700675 */
676 public int getCallerDisplayNamePresentation() {
677 return mCallerDisplayNamePresentation;
678 }
679
680 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700681 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
682 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700683 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700684 public PhoneAccountHandle getAccountHandle() {
685 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700686 }
687
688 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800689 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
690 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700691 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700692 public int getCallCapabilities() {
693 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700694 }
695
696 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700697 * @return A bitmask of the properties of the {@code Call}, as defined by the various
698 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700699 */
700 public int getCallProperties() {
701 return mCallProperties;
702 }
703
704 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800705 * @return a bitmask of the audio routes available for the call.
706 *
707 * @hide
708 */
709 public int getSupportedAudioRoutes() {
710 return mSupportedAudioRoutes;
711 }
712
713 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700714 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700715 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700716 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700717 public DisconnectCause getDisconnectCause() {
718 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700719 }
720
721 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700722 * Returns the time the {@link Call} connected (i.e. became active). This information is
723 * updated periodically, but user interfaces should not rely on this to display the "call
724 * time clock". For the time when the call was first added to Telecom, see
725 * {@link #getCreationTimeMillis()}.
726 *
727 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700728 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700729 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700730 return mConnectTimeMillis;
731 }
732
733 /**
734 * @return Information about any calling gateway the {@code Call} may be using.
735 */
736 public GatewayInfo getGatewayInfo() {
737 return mGatewayInfo;
738 }
739
Andrew Lee7a341382014-07-15 17:05:08 -0700740 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700741 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700742 */
743 public int getVideoState() {
744 return mVideoState;
745 }
746
Ihab Awad5d0410f2014-07-30 10:07:40 -0700747 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700748 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700749 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700750 */
751 public StatusHints getStatusHints() {
752 return mStatusHints;
753 }
754
Nancy Chen10798dc2014-08-08 14:00:25 -0700755 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700756 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700757 */
758 public Bundle getExtras() {
759 return mExtras;
760 }
761
Santos Cordon6b7f9552015-05-27 17:21:45 -0700762 /**
763 * @return The extras used with the original intent to place this call.
764 */
765 public Bundle getIntentExtras() {
766 return mIntentExtras;
767 }
768
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700769 /**
770 * Returns the time when the call was first created and added to Telecom. This is the same
771 * time that is logged as the start time in the Call Log (see
772 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
773 * (became active), see {@link #getConnectTimeMillis()}.
774 *
775 * @return The creation time of the call, in millis since the epoch.
776 */
777 public long getCreationTimeMillis() {
778 return mCreationTimeMillis;
779 }
780
Ihab Awade63fadb2014-07-09 21:52:04 -0700781 @Override
782 public boolean equals(Object o) {
783 if (o instanceof Details) {
784 Details d = (Details) o;
785 return
786 Objects.equals(mHandle, d.mHandle) &&
787 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
788 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
789 Objects.equals(mCallerDisplayNamePresentation,
790 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700791 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700792 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700793 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700794 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700795 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700796 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700797 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700798 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700799 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700800 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
801 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700802 }
803 return false;
804 }
805
806 @Override
807 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700808 return Objects.hash(mHandle,
809 mHandlePresentation,
810 mCallerDisplayName,
811 mCallerDisplayNamePresentation,
812 mAccountHandle,
813 mCallCapabilities,
814 mCallProperties,
815 mDisconnectCause,
816 mConnectTimeMillis,
817 mGatewayInfo,
818 mVideoState,
819 mStatusHints,
820 mExtras,
821 mIntentExtras,
822 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700823 }
824
825 /** {@hide} */
826 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800827 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700828 Uri handle,
829 int handlePresentation,
830 String callerDisplayName,
831 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700832 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700833 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700834 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700835 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700836 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700837 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700838 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700839 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700840 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700841 Bundle intentExtras,
842 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800843 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700844 mHandle = handle;
845 mHandlePresentation = handlePresentation;
846 mCallerDisplayName = callerDisplayName;
847 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700848 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700849 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700850 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700851 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700852 mConnectTimeMillis = connectTimeMillis;
853 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700854 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700855 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700856 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700857 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700858 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700859 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800860
861 /** {@hide} */
862 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
863 return new Details(
864 parcelableCall.getId(),
865 parcelableCall.getHandle(),
866 parcelableCall.getHandlePresentation(),
867 parcelableCall.getCallerDisplayName(),
868 parcelableCall.getCallerDisplayNamePresentation(),
869 parcelableCall.getAccountHandle(),
870 parcelableCall.getCapabilities(),
871 parcelableCall.getProperties(),
872 parcelableCall.getDisconnectCause(),
873 parcelableCall.getConnectTimeMillis(),
874 parcelableCall.getGatewayInfo(),
875 parcelableCall.getVideoState(),
876 parcelableCall.getStatusHints(),
877 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700878 parcelableCall.getIntentExtras(),
879 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800880 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800881
882 @Override
883 public String toString() {
884 StringBuilder sb = new StringBuilder();
885 sb.append("[pa: ");
886 sb.append(mAccountHandle);
887 sb.append(", hdl: ");
888 sb.append(Log.pii(mHandle));
889 sb.append(", caps: ");
890 sb.append(capabilitiesToString(mCallCapabilities));
891 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700892 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800893 sb.append("]");
894 return sb.toString();
895 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700896 }
897
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700898 /**
899 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
900 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
901 * implementation.
902 * <p>
903 * You can handle these callbacks by extending the {@link Callback} class and overriding the
904 * callbacks that your {@link InCallService} is interested in. The callback methods include the
905 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
906 * {@link Callback} implementation, if desired.
907 * <p>
908 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
909 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
910 * (typically in {@link InCallService#onCallRemoved(Call)}).
911 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
912 * reach your implementation of {@link Callback}, so it is important to register your callback
913 * as soon as your {@link InCallService} is notified of a new call via
914 * {@link InCallService#onCallAdded(Call)}.
915 */
Andrew Leeda80c872015-04-15 14:09:50 -0700916 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700917 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -0700918 * @hide
919 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800920 @IntDef(prefix = { "HANDOVER_" },
921 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -0700922 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -0800923 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -0700924 @Retention(RetentionPolicy.SOURCE)
925 public @interface HandoverFailureErrors {}
926
927 /**
928 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -0800929 * to handover the call to rejects the handover request.
930 * <p>
931 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
932 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
933 * {@code null} {@link Connection} from
934 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
935 * ConnectionRequest)}.
936 * <p>
937 * For more information on call handovers, see
938 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700939 */
940 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
941
942 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800943 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
944 * is initiated but the source or destination app does not support handover.
945 * <p>
946 * Will be returned when a handover is requested via
947 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
948 * {@link PhoneAccountHandle} does not declare
949 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
950 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
951 * {@link Details#getAccountHandle()}) does not declare
952 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
953 * <p>
954 * For more information on call handovers, see
955 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700956 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800957 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700958
959 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800960 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
961 * user rejects the handover request.
962 * <p>
963 * For more information on call handovers, see
964 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700965 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800966 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700967
Sanket Padawe85291f62017-12-01 13:59:27 -0800968 /**
969 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
970 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -0800971 * <p>
972 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
973 * called on an emergency call, or if any other call is an emergency call.
974 * <p>
975 * Handovers are not permitted while there are ongoing emergency calls.
976 * <p>
977 * For more information on call handovers, see
978 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -0800979 */
Tyler Gunn5c60d712018-03-16 09:53:44 -0700980 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -0800981
Tyler Gunn9d127732018-03-02 15:45:51 -0800982 /**
983 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
984 * fails for an unknown reason.
985 * <p>
986 * For more information on call handovers, see
987 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
988 */
989 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700990
991 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700992 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
993 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700994 * @param call The {@code Call} invoking this method.
995 * @param state The new state of the {@code Call}.
996 */
997 public void onStateChanged(Call call, int state) {}
998
999 /**
1000 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1001 *
1002 * @param call The {@code Call} invoking this method.
1003 * @param parent The new parent of the {@code Call}.
1004 */
1005 public void onParentChanged(Call call, Call parent) {}
1006
1007 /**
1008 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1009 *
1010 * @param call The {@code Call} invoking this method.
1011 * @param children The new children of the {@code Call}.
1012 */
1013 public void onChildrenChanged(Call call, List<Call> children) {}
1014
1015 /**
1016 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1017 *
1018 * @param call The {@code Call} invoking this method.
1019 * @param details A {@code Details} object describing the {@code Call}.
1020 */
1021 public void onDetailsChanged(Call call, Details details) {}
1022
1023 /**
1024 * Invoked when the text messages that can be used as responses to the incoming
1025 * {@code Call} are loaded from the relevant database.
1026 * See {@link #getCannedTextResponses()}.
1027 *
1028 * @param call The {@code Call} invoking this method.
1029 * @param cannedTextResponses The text messages useable as responses.
1030 */
1031 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1032
1033 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001034 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1035 * character. This causes the post-dial signals to stop pending user confirmation. An
1036 * implementation should present this choice to the user and invoke
1037 * {@link #postDialContinue(boolean)} when the user makes the choice.
1038 *
1039 * @param call The {@code Call} invoking this method.
1040 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1041 */
1042 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1043
1044 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001045 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001046 *
1047 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001048 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001049 */
Andrew Lee50aca232014-07-22 16:41:54 -07001050 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001051
1052 /**
1053 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1054 * up their UI for the {@code Call} in response to state transitions. Specifically,
1055 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1056 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1057 * clients should wait for this method to be invoked.
1058 *
1059 * @param call The {@code Call} being destroyed.
1060 */
1061 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001062
1063 /**
1064 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1065 * conferenced.
1066 *
1067 * @param call The {@code Call} being updated.
1068 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1069 * conferenced.
1070 */
1071 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001072
1073 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001074 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
1075 * <p>
1076 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1077 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1078 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1079 * possible that a {@link ConnectionService} has defined its own Connection events which a
1080 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001081 * <p>
1082 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
1083 *
1084 * @param call The {@code Call} receiving the event.
1085 * @param event The event.
1086 * @param extras Extras associated with the connection event.
1087 */
1088 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001089
1090 /**
1091 * Invoked when the RTT mode changes for this call.
1092 * @param call The call whose RTT mode has changed.
1093 * @param mode the new RTT mode, one of
1094 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1095 * or {@link RttCall#RTT_MODE_VCO}
1096 */
1097 public void onRttModeChanged(Call call, int mode) {}
1098
1099 /**
1100 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1101 * @param call The call whose RTT status has changed.
1102 * @param enabled whether RTT is now enabled or disabled
1103 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1104 * on, null otherwise.
1105 */
1106 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1107
1108 /**
1109 * Invoked when the remote end of the connection has requested that an RTT communication
1110 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1111 * with the same ID that this method is invoked with.
1112 * @param call The call which the RTT request was placed on
1113 * @param id The ID of the request.
1114 */
1115 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001116
1117 /**
1118 * Invoked when the RTT session failed to initiate for some reason, including rejection
1119 * by the remote party.
1120 * @param call The call which the RTT initiation failure occurred on.
1121 * @param reason One of the status codes defined in
1122 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1123 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1124 */
1125 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001126
1127 /**
1128 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1129 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001130 * <p>
1131 * For a full discussion of the handover process and the APIs involved, see
1132 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1133 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001134 * @param call The call which had initiated handover.
1135 */
1136 public void onHandoverComplete(Call call) {}
1137
1138 /**
1139 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1140 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001141 * <p>
1142 * For a full discussion of the handover process and the APIs involved, see
1143 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1144 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001145 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001146 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001147 */
1148 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001149 }
1150
1151 /**
1152 * A class that holds the state that describes the state of the RTT channel to the remote
1153 * party, if it is active.
1154 */
1155 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001156 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001157 @Retention(RetentionPolicy.SOURCE)
1158 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1159 public @interface RttAudioMode {}
1160
1161 /**
1162 * For metrics use. Default value in the proto.
1163 * @hide
1164 */
1165 public static final int RTT_MODE_INVALID = 0;
1166
1167 /**
1168 * Indicates that there should be a bidirectional audio stream between the two parties
1169 * on the call.
1170 */
1171 public static final int RTT_MODE_FULL = 1;
1172
1173 /**
1174 * Indicates that the local user should be able to hear the audio stream from the remote
1175 * user, but not vice versa. Equivalent to muting the microphone.
1176 */
1177 public static final int RTT_MODE_HCO = 2;
1178
1179 /**
1180 * Indicates that the remote user should be able to hear the audio stream from the local
1181 * user, but not vice versa. Equivalent to setting the volume to zero.
1182 */
1183 public static final int RTT_MODE_VCO = 3;
1184
1185 private static final int READ_BUFFER_SIZE = 1000;
1186
1187 private InputStreamReader mReceiveStream;
1188 private OutputStreamWriter mTransmitStream;
1189 private int mRttMode;
1190 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001191 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001192 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1193
1194 /**
1195 * @hide
1196 */
Hall Liu57006aa2017-02-06 10:49:48 -08001197 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1198 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1199 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001200 mReceiveStream = receiveStream;
1201 mTransmitStream = transmitStream;
1202 mRttMode = mode;
1203 mInCallAdapter = inCallAdapter;
1204 }
1205
1206 /**
1207 * Returns the current RTT audio mode.
1208 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1209 * {@link #RTT_MODE_HCO}.
1210 */
1211 public int getRttAudioMode() {
1212 return mRttMode;
1213 }
1214
1215 /**
1216 * Sets the RTT audio mode. The requested mode change will be communicated through
1217 * {@link Callback#onRttModeChanged(Call, int)}.
1218 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1219 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1220 */
1221 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001222 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001223 }
1224
1225 /**
1226 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1227 * RTT transmits text in real-time, this method should be called once for each character
1228 * the user enters into the device.
1229 *
1230 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1231 * lead to interleaved text.
1232 * @param input The message to send to the remote user.
1233 */
1234 public void write(String input) throws IOException {
1235 mTransmitStream.write(input);
1236 mTransmitStream.flush();
1237 }
1238
1239 /**
1240 * Reads a string from the remote user, blocking if there is no data available. Returns
1241 * {@code null} if the RTT conversation has been terminated and there is no further data
1242 * to read.
1243 *
1244 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1245 * lead to interleaved text.
1246 * @return A string containing text sent by the remote user, or {@code null} if the
1247 * conversation has been terminated or if there was an error while reading.
1248 */
Hall Liub1c8a772017-07-17 17:04:41 -07001249 public String read() {
1250 try {
1251 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1252 if (numRead < 0) {
1253 return null;
1254 }
1255 return new String(mReadBuffer, 0, numRead);
1256 } catch (IOException e) {
1257 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001258 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001259 }
Hall Liuffa4a812017-03-02 16:11:00 -08001260 }
1261
1262 /**
1263 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1264 * be read.
1265 * @return A string containing text entered by the user, or {@code null} if the user has
1266 * not entered any new text yet.
1267 */
1268 public String readImmediately() throws IOException {
1269 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001270 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1271 if (numRead < 0) {
1272 return null;
1273 }
1274 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001275 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001276 return null;
1277 }
1278 }
Hall Liue9041242018-02-09 16:40:03 -08001279
1280 /**
1281 * Closes the underlying file descriptors
1282 * @hide
1283 */
1284 public void close() {
1285 try {
1286 mReceiveStream.close();
1287 } catch (IOException e) {
1288 // ignore
1289 }
1290 try {
1291 mTransmitStream.close();
1292 } catch (IOException e) {
1293 // ignore
1294 }
1295 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001296 }
1297
Andrew Leeda80c872015-04-15 14:09:50 -07001298 /**
1299 * @deprecated Use {@code Call.Callback} instead.
1300 * @hide
1301 */
1302 @Deprecated
1303 @SystemApi
1304 public static abstract class Listener extends Callback { }
1305
Ihab Awade63fadb2014-07-09 21:52:04 -07001306 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001307 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001308 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001309 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001310 private final List<Call> mChildren = new ArrayList<>();
1311 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001312 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001313 private final List<Call> mConferenceableCalls = new ArrayList<>();
1314 private final List<Call> mUnmodifiableConferenceableCalls =
1315 Collections.unmodifiableList(mConferenceableCalls);
1316
Santos Cordon823fd3c2014-08-07 18:35:18 -07001317 private boolean mChildrenCached;
1318 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001319 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001320 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001321 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001322 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001323 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001324 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001325 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001326 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001327 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001328
1329 /**
1330 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1331 *
1332 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1333 * remaining or this {@code Call} is not in a post-dial state.
1334 */
1335 public String getRemainingPostDialSequence() {
1336 return mRemainingPostDialSequence;
1337 }
1338
1339 /**
1340 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001341 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001342 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001343 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001344 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001345 }
1346
1347 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301348 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1349 *
1350 * @param address The address to which the call will be deflected.
1351 */
1352 public void deflect(Uri address) {
1353 mInCallAdapter.deflectCall(mTelecomCallId, address);
1354 }
1355
1356 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001357 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1358 *
1359 * @param rejectWithMessage Whether to reject with a text message.
1360 * @param textMessage An optional text message with which to respond.
1361 */
1362 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001363 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001364 }
1365
1366 /**
1367 * Instructs this {@code Call} to disconnect.
1368 */
1369 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001370 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001371 }
1372
1373 /**
1374 * Instructs this {@code Call} to go on hold.
1375 */
1376 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001377 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001378 }
1379
1380 /**
1381 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1382 */
1383 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001384 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001385 }
1386
1387 /**
1388 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1389 *
1390 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1391 *
1392 * @param digit A character representing the DTMF digit for which to play the tone. This
1393 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1394 */
1395 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001396 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001397 }
1398
1399 /**
1400 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1401 * currently playing.
1402 *
1403 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1404 * currently playing, this method will do nothing.
1405 */
1406 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001407 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001408 }
1409
1410 /**
1411 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1412 *
1413 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1414 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001415 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001416 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001417 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1418 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001419 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001420 * {@code Call} will pause playing the tones and notify callbacks via
1421 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001422 * should display to the user an indication of this state and an affordance to continue
1423 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1424 * app should invoke the {@link #postDialContinue(boolean)} method.
1425 *
1426 * @param proceed Whether or not to continue with the post-dial sequence.
1427 */
1428 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001429 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001430 }
1431
1432 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001433 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001434 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001435 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001436 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1437 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001438
1439 }
1440
1441 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001442 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001443 *
1444 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001445 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001446 public void conference(Call callToConferenceWith) {
1447 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001448 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001449 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001450 }
1451
1452 /**
1453 * Instructs this {@code Call} to split from any conference call with which it may be
1454 * connected.
1455 */
1456 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001457 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001458 }
1459
1460 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001461 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001462 */
1463 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001464 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001465 }
1466
1467 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001468 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001469 */
1470 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001471 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001472 }
1473
1474 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001475 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1476 * device.
1477 * <p>
1478 * Calls to this method are ignored if the call does not have the
1479 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1480 * <p>
1481 * An {@link InCallService} will only see calls which support this method if it has the
1482 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1483 * in its manifest.
1484 */
1485 public void pullExternalCall() {
1486 // If this isn't an external call, ignore the request.
1487 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1488 return;
1489 }
1490
1491 mInCallAdapter.pullExternalCall(mTelecomCallId);
1492 }
1493
1494 /**
1495 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1496 * the {@link ConnectionService}.
1497 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001498 * Call events are used to communicate point in time information from an {@link InCallService}
1499 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1500 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1501 * {@link ConnectionService}.
1502 * <p>
1503 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1504 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1505 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001506 * Events are exposed to {@link ConnectionService} implementations via
1507 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1508 * <p>
1509 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001510 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1511 * ignore some events altogether.
1512 * <p>
1513 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1514 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1515 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1516 * they define their own event types in this namespace. When defining a custom event type,
1517 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1518 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1519 * <p>
1520 * When defining events and the associated extras, it is important to keep their behavior
1521 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1522 * events/extras should me maintained to ensure backwards compatibility with older
1523 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001524 *
1525 * @param event The connection event.
1526 * @param extras Bundle containing extra information associated with the event.
1527 */
1528 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001529 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001530 }
1531
1532 /**
Hall Liu95d55872017-01-25 17:12:49 -08001533 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1534 * guaranteed, and notification of success will be via the
1535 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1536 */
1537 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001538 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001539 }
1540
1541 /**
1542 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1543 * callback.
1544 * The ID used here should be the same as the ID that was received via the callback.
1545 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1546 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1547 */
1548 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001549 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001550 }
1551
1552 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001553 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1554 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1555 * handover.
1556 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001557 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1558 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1559 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1560 * is referred to as the source of the handover, and the video calling app is referred to as the
1561 * destination.
1562 * <p>
1563 * When considering a handover scenario the device this method is called on is considered the
1564 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1565 * other device is considered the <em>receiving</em> device.
1566 * <p>
1567 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1568 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1569 * and invoke
1570 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1571 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1572 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1573 * At this point the app should display UI to indicate to the user that a call
1574 * handover is in process.
1575 * <p>
1576 * The destination app is responsible for communicating the handover request from the
1577 * <em>initiating</em> device to the <em>receiving</em> device.
1578 * <p>
1579 * When the app on the <em>receiving</em> device receives the handover request, it calls
1580 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1581 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1582 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1583 * choose whether they want to continue their call in the destination app.
1584 * <p>
1585 * When the destination app on the <em>receiving</em> device calls
1586 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1587 * {@link ConnectionService} and call
1588 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1589 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1590 * {@link Connection} to represent the handover call.
1591 * <p>
1592 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1593 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1594 * original call. If the user rejects the handover, the app calls
1595 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1596 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1597 * <p>
1598 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1599 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1600 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1601 * <p>
1602 * Errors in the handover process are reported to the {@link InCallService} via
1603 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1604 * the involved {@link ConnectionService}s via
1605 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001606 *
1607 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1608 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001609 * @param videoState Indicates the video state desired after the handover (see the
1610 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001611 * @param extras Bundle containing extra information to be passed to the
1612 * {@link ConnectionService}
1613 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001614 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1615 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001616 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1617 }
1618
1619 /**
Hall Liu95d55872017-01-25 17:12:49 -08001620 * Terminate the RTT session on this call. The resulting state change will be notified via
1621 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1622 */
1623 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001624 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001625 }
1626
1627 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001628 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1629 * added.
1630 * <p>
1631 * No assumptions should be made as to how an In-Call UI or service will handle these
1632 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1633 *
1634 * @param extras The extras to add.
1635 */
1636 public final void putExtras(Bundle extras) {
1637 if (extras == null) {
1638 return;
1639 }
1640
1641 if (mExtras == null) {
1642 mExtras = new Bundle();
1643 }
1644 mExtras.putAll(extras);
1645 mInCallAdapter.putExtras(mTelecomCallId, extras);
1646 }
1647
1648 /**
1649 * Adds a boolean extra to this {@link Call}.
1650 *
1651 * @param key The extra key.
1652 * @param value The value.
1653 * @hide
1654 */
1655 public final void putExtra(String key, boolean value) {
1656 if (mExtras == null) {
1657 mExtras = new Bundle();
1658 }
1659 mExtras.putBoolean(key, value);
1660 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1661 }
1662
1663 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001664 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001665 *
1666 * @param key The extra key.
1667 * @param value The value.
1668 * @hide
1669 */
1670 public final void putExtra(String key, int value) {
1671 if (mExtras == null) {
1672 mExtras = new Bundle();
1673 }
1674 mExtras.putInt(key, value);
1675 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1676 }
1677
1678 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001679 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001680 *
1681 * @param key The extra key.
1682 * @param value The value.
1683 * @hide
1684 */
1685 public final void putExtra(String key, String value) {
1686 if (mExtras == null) {
1687 mExtras = new Bundle();
1688 }
1689 mExtras.putString(key, value);
1690 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1691 }
1692
1693 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001694 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001695 *
1696 * @param keys The keys of the extras to remove.
1697 */
1698 public final void removeExtras(List<String> keys) {
1699 if (mExtras != null) {
1700 for (String key : keys) {
1701 mExtras.remove(key);
1702 }
1703 if (mExtras.size() == 0) {
1704 mExtras = null;
1705 }
1706 }
1707 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1708 }
1709
1710 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001711 * Removes extras from this {@link Call}.
1712 *
1713 * @param keys The keys of the extras to remove.
1714 */
1715 public final void removeExtras(String ... keys) {
1716 removeExtras(Arrays.asList(keys));
1717 }
1718
1719 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001720 * Obtains the parent of this {@code Call} in a conference, if any.
1721 *
1722 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1723 * child of any conference {@code Call}s.
1724 */
1725 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001726 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001727 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001728 }
1729 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001730 }
1731
1732 /**
1733 * Obtains the children of this conference {@code Call}, if any.
1734 *
1735 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1736 * {@code List} otherwise.
1737 */
1738 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001739 if (!mChildrenCached) {
1740 mChildrenCached = true;
1741 mChildren.clear();
1742
1743 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001744 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001745 if (call == null) {
1746 // At least one child was still not found, so do not save true for "cached"
1747 mChildrenCached = false;
1748 } else {
1749 mChildren.add(call);
1750 }
1751 }
1752 }
1753
Ihab Awade63fadb2014-07-09 21:52:04 -07001754 return mUnmodifiableChildren;
1755 }
1756
1757 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001758 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1759 *
1760 * @return The list of conferenceable {@code Call}s.
1761 */
1762 public List<Call> getConferenceableCalls() {
1763 return mUnmodifiableConferenceableCalls;
1764 }
1765
1766 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001767 * Obtains the state of this {@code Call}.
1768 *
1769 * @return A state value, chosen from the {@code STATE_*} constants.
1770 */
1771 public int getState() {
1772 return mState;
1773 }
1774
1775 /**
1776 * Obtains a list of canned, pre-configured message responses to present to the user as
1777 * ways of rejecting this {@code Call} using via a text message.
1778 *
1779 * @see #reject(boolean, String)
1780 *
1781 * @return A list of canned text message responses.
1782 */
1783 public List<String> getCannedTextResponses() {
1784 return mCannedTextResponses;
1785 }
1786
1787 /**
1788 * Obtains an object that can be used to display video from this {@code Call}.
1789 *
Andrew Lee50aca232014-07-22 16:41:54 -07001790 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001791 */
Andrew Lee50aca232014-07-22 16:41:54 -07001792 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001793 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001794 }
1795
1796 /**
1797 * Obtains an object containing call details.
1798 *
1799 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1800 * result may be {@code null}.
1801 */
1802 public Details getDetails() {
1803 return mDetails;
1804 }
1805
1806 /**
Hall Liu95d55872017-01-25 17:12:49 -08001807 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1808 * receive RTT text data, as well as to change the RTT mode.
1809 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1810 */
1811 public @Nullable RttCall getRttCall() {
1812 return mRttCall;
1813 }
1814
1815 /**
1816 * Returns whether this call has an active RTT connection.
1817 * @return true if there is a connection, false otherwise.
1818 */
1819 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08001820 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08001821 }
1822
1823 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001824 * Registers a callback to this {@code Call}.
1825 *
1826 * @param callback A {@code Callback}.
1827 */
1828 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001829 registerCallback(callback, new Handler());
1830 }
1831
1832 /**
1833 * Registers a callback to this {@code Call}.
1834 *
1835 * @param callback A {@code Callback}.
1836 * @param handler A handler which command and status changes will be delivered to.
1837 */
1838 public void registerCallback(Callback callback, Handler handler) {
1839 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001840 // Don't allow new callback registration if the call is already being destroyed.
1841 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001842 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1843 }
Andrew Leeda80c872015-04-15 14:09:50 -07001844 }
1845
1846 /**
1847 * Unregisters a callback from this {@code Call}.
1848 *
1849 * @param callback A {@code Callback}.
1850 */
1851 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001852 // Don't allow callback deregistration if the call is already being destroyed.
1853 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001854 for (CallbackRecord<Callback> record : mCallbackRecords) {
1855 if (record.getCallback() == callback) {
1856 mCallbackRecords.remove(record);
1857 break;
1858 }
1859 }
Andrew Leeda80c872015-04-15 14:09:50 -07001860 }
1861 }
1862
Santos Cordon3c20d632016-02-25 16:12:35 -08001863 @Override
1864 public String toString() {
1865 return new StringBuilder().
1866 append("Call [id: ").
1867 append(mTelecomCallId).
1868 append(", state: ").
1869 append(stateToString(mState)).
1870 append(", details: ").
1871 append(mDetails).
1872 append("]").toString();
1873 }
1874
1875 /**
1876 * @param state An integer value of a {@code STATE_*} constant.
1877 * @return A string representation of the value.
1878 */
1879 private static String stateToString(int state) {
1880 switch (state) {
1881 case STATE_NEW:
1882 return "NEW";
1883 case STATE_RINGING:
1884 return "RINGING";
1885 case STATE_DIALING:
1886 return "DIALING";
1887 case STATE_ACTIVE:
1888 return "ACTIVE";
1889 case STATE_HOLDING:
1890 return "HOLDING";
1891 case STATE_DISCONNECTED:
1892 return "DISCONNECTED";
1893 case STATE_CONNECTING:
1894 return "CONNECTING";
1895 case STATE_DISCONNECTING:
1896 return "DISCONNECTING";
1897 case STATE_SELECT_PHONE_ACCOUNT:
1898 return "SELECT_PHONE_ACCOUNT";
1899 default:
1900 Log.w(Call.class, "Unknown state %d", state);
1901 return "UNKNOWN";
1902 }
1903 }
1904
Andrew Leeda80c872015-04-15 14:09:50 -07001905 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001906 * Adds a listener to this {@code Call}.
1907 *
1908 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001909 * @deprecated Use {@link #registerCallback} instead.
1910 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001911 */
Andrew Leeda80c872015-04-15 14:09:50 -07001912 @Deprecated
1913 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001914 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001915 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001916 }
1917
1918 /**
1919 * Removes a listener from this {@code Call}.
1920 *
1921 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001922 * @deprecated Use {@link #unregisterCallback} instead.
1923 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001924 */
Andrew Leeda80c872015-04-15 14:09:50 -07001925 @Deprecated
1926 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001927 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001928 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001929 }
1930
1931 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001932 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1933 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001934 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001935 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001936 mInCallAdapter = inCallAdapter;
1937 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001938 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001939 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001940 }
1941
1942 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001943 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001944 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001945 mPhone = phone;
1946 mTelecomCallId = telecomCallId;
1947 mInCallAdapter = inCallAdapter;
1948 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001949 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001950 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001951 }
1952
1953 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001954 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001955 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001956 }
1957
1958 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001959 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001960
Ihab Awade63fadb2014-07-09 21:52:04 -07001961 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001962 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001963 boolean detailsChanged = !Objects.equals(mDetails, details);
1964 if (detailsChanged) {
1965 mDetails = details;
1966 }
1967
1968 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001969 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1970 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1971 mCannedTextResponses =
1972 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001973 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001974 }
1975
Tyler Gunn159f35c2017-03-02 09:28:37 -08001976 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1977 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001978 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001979 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001980 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001981 mVideoCallImpl = newVideoCallImpl;
1982 }
1983 if (mVideoCallImpl != null) {
1984 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001985 }
1986
Santos Cordone3c507b2015-04-23 14:44:19 -07001987 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001988 boolean stateChanged = mState != state;
1989 if (stateChanged) {
1990 mState = state;
1991 }
1992
Santos Cordon823fd3c2014-08-07 18:35:18 -07001993 String parentId = parcelableCall.getParentCallId();
1994 boolean parentChanged = !Objects.equals(mParentId, parentId);
1995 if (parentChanged) {
1996 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001997 }
1998
Santos Cordon823fd3c2014-08-07 18:35:18 -07001999 List<String> childCallIds = parcelableCall.getChildCallIds();
2000 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2001 if (childrenChanged) {
2002 mChildrenIds.clear();
2003 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2004 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002005 }
2006
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002007 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2008 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2009 for (String otherId : conferenceableCallIds) {
2010 if (callIdMap.containsKey(otherId)) {
2011 conferenceableCalls.add(callIdMap.get(otherId));
2012 }
2013 }
2014
2015 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2016 mConferenceableCalls.clear();
2017 mConferenceableCalls.addAll(conferenceableCalls);
2018 fireConferenceableCallsChanged();
2019 }
2020
Hall Liu95d55872017-01-25 17:12:49 -08002021 boolean isRttChanged = false;
2022 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002023 if (parcelableCall.getIsRttCallChanged()
2024 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002025 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2026 InputStreamReader receiveStream = new InputStreamReader(
2027 new ParcelFileDescriptor.AutoCloseInputStream(
2028 parcelableRttCall.getReceiveStream()),
2029 StandardCharsets.UTF_8);
2030 OutputStreamWriter transmitStream = new OutputStreamWriter(
2031 new ParcelFileDescriptor.AutoCloseOutputStream(
2032 parcelableRttCall.getTransmitStream()),
2033 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002034 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002035 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2036 if (mRttCall == null) {
2037 isRttChanged = true;
2038 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2039 rttModeChanged = true;
2040 }
2041 mRttCall = newRttCall;
2042 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2043 && parcelableCall.getIsRttCallChanged()) {
2044 isRttChanged = true;
2045 mRttCall = null;
2046 }
2047
Ihab Awade63fadb2014-07-09 21:52:04 -07002048 // Now we fire updates, ensuring that any client who listens to any of these notifications
2049 // gets the most up-to-date state.
2050
2051 if (stateChanged) {
2052 fireStateChanged(mState);
2053 }
2054 if (detailsChanged) {
2055 fireDetailsChanged(mDetails);
2056 }
2057 if (cannedTextResponsesChanged) {
2058 fireCannedTextResponsesLoaded(mCannedTextResponses);
2059 }
Andrew Lee50aca232014-07-22 16:41:54 -07002060 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002061 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002062 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002063 if (parentChanged) {
2064 fireParentChanged(getParent());
2065 }
2066 if (childrenChanged) {
2067 fireChildrenChanged(getChildren());
2068 }
Hall Liu95d55872017-01-25 17:12:49 -08002069 if (isRttChanged) {
2070 fireOnIsRttChanged(mRttCall != null, mRttCall);
2071 }
2072 if (rttModeChanged) {
2073 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2074 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002075
2076 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2077 // remove ourselves from the Phone. Note that we do this after completing all state updates
2078 // so a client can cleanly transition all their UI to the state appropriate for a
2079 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2080 if (mState == STATE_DISCONNECTED) {
2081 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002082 }
2083 }
2084
2085 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002086 final void internalSetPostDialWait(String remaining) {
2087 mRemainingPostDialSequence = remaining;
2088 firePostDialWait(mRemainingPostDialSequence);
2089 }
2090
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002091 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002092 final void internalSetDisconnected() {
2093 if (mState != Call.STATE_DISCONNECTED) {
2094 mState = Call.STATE_DISCONNECTED;
2095 fireStateChanged(mState);
2096 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002097 }
2098 }
2099
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002100 /** {@hide} */
2101 final void internalOnConnectionEvent(String event, Bundle extras) {
2102 fireOnConnectionEvent(event, extras);
2103 }
2104
Hall Liu95d55872017-01-25 17:12:49 -08002105 /** {@hide} */
2106 final void internalOnRttUpgradeRequest(final int requestId) {
2107 for (CallbackRecord<Callback> record : mCallbackRecords) {
2108 final Call call = this;
2109 final Callback callback = record.getCallback();
2110 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2111 }
2112 }
2113
Hall Liu57006aa2017-02-06 10:49:48 -08002114 /** @hide */
2115 final void internalOnRttInitiationFailure(int reason) {
2116 for (CallbackRecord<Callback> record : mCallbackRecords) {
2117 final Call call = this;
2118 final Callback callback = record.getCallback();
2119 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2120 }
2121 }
2122
Sanket Padawe85291f62017-12-01 13:59:27 -08002123 /** {@hide} */
2124 final void internalOnHandoverFailed(int error) {
2125 for (CallbackRecord<Callback> record : mCallbackRecords) {
2126 final Call call = this;
2127 final Callback callback = record.getCallback();
2128 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2129 }
2130 }
2131
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002132 /** {@hide} */
2133 final void internalOnHandoverComplete() {
2134 for (CallbackRecord<Callback> record : mCallbackRecords) {
2135 final Call call = this;
2136 final Callback callback = record.getCallback();
2137 record.getHandler().post(() -> callback.onHandoverComplete(call));
2138 }
2139 }
2140
Andrew Lee011728f2015-04-23 15:47:06 -07002141 private void fireStateChanged(final int newState) {
2142 for (CallbackRecord<Callback> record : mCallbackRecords) {
2143 final Call call = this;
2144 final Callback callback = record.getCallback();
2145 record.getHandler().post(new Runnable() {
2146 @Override
2147 public void run() {
2148 callback.onStateChanged(call, newState);
2149 }
2150 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002151 }
2152 }
2153
Andrew Lee011728f2015-04-23 15:47:06 -07002154 private void fireParentChanged(final Call newParent) {
2155 for (CallbackRecord<Callback> record : mCallbackRecords) {
2156 final Call call = this;
2157 final Callback callback = record.getCallback();
2158 record.getHandler().post(new Runnable() {
2159 @Override
2160 public void run() {
2161 callback.onParentChanged(call, newParent);
2162 }
2163 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002164 }
2165 }
2166
Andrew Lee011728f2015-04-23 15:47:06 -07002167 private void fireChildrenChanged(final List<Call> children) {
2168 for (CallbackRecord<Callback> record : mCallbackRecords) {
2169 final Call call = this;
2170 final Callback callback = record.getCallback();
2171 record.getHandler().post(new Runnable() {
2172 @Override
2173 public void run() {
2174 callback.onChildrenChanged(call, children);
2175 }
2176 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002177 }
2178 }
2179
Andrew Lee011728f2015-04-23 15:47:06 -07002180 private void fireDetailsChanged(final Details details) {
2181 for (CallbackRecord<Callback> record : mCallbackRecords) {
2182 final Call call = this;
2183 final Callback callback = record.getCallback();
2184 record.getHandler().post(new Runnable() {
2185 @Override
2186 public void run() {
2187 callback.onDetailsChanged(call, details);
2188 }
2189 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002190 }
2191 }
2192
Andrew Lee011728f2015-04-23 15:47:06 -07002193 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2194 for (CallbackRecord<Callback> record : mCallbackRecords) {
2195 final Call call = this;
2196 final Callback callback = record.getCallback();
2197 record.getHandler().post(new Runnable() {
2198 @Override
2199 public void run() {
2200 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2201 }
2202 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002203 }
2204 }
2205
Andrew Lee011728f2015-04-23 15:47:06 -07002206 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2207 for (CallbackRecord<Callback> record : mCallbackRecords) {
2208 final Call call = this;
2209 final Callback callback = record.getCallback();
2210 record.getHandler().post(new Runnable() {
2211 @Override
2212 public void run() {
2213 callback.onVideoCallChanged(call, videoCall);
2214 }
2215 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002216 }
2217 }
2218
Andrew Lee011728f2015-04-23 15:47:06 -07002219 private void firePostDialWait(final String remainingPostDialSequence) {
2220 for (CallbackRecord<Callback> record : mCallbackRecords) {
2221 final Call call = this;
2222 final Callback callback = record.getCallback();
2223 record.getHandler().post(new Runnable() {
2224 @Override
2225 public void run() {
2226 callback.onPostDialWait(call, remainingPostDialSequence);
2227 }
2228 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002229 }
2230 }
2231
2232 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002233 /**
2234 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2235 * onCallRemoved callback, we remove this call from the Phone's record
2236 * only once all of the registered onCallDestroyed callbacks are executed.
2237 * All the callbacks get removed from our records as a part of this operation
2238 * since onCallDestroyed is the final callback.
2239 */
2240 final Call call = this;
2241 if (mCallbackRecords.isEmpty()) {
2242 // No callbacks registered, remove the call from Phone's record.
2243 mPhone.internalRemoveCall(call);
2244 }
2245 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002246 final Callback callback = record.getCallback();
2247 record.getHandler().post(new Runnable() {
2248 @Override
2249 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002250 boolean isFinalRemoval = false;
2251 RuntimeException toThrow = null;
2252 try {
2253 callback.onCallDestroyed(call);
2254 } catch (RuntimeException e) {
2255 toThrow = e;
2256 }
2257 synchronized(Call.this) {
2258 mCallbackRecords.remove(record);
2259 if (mCallbackRecords.isEmpty()) {
2260 isFinalRemoval = true;
2261 }
2262 }
2263 if (isFinalRemoval) {
2264 mPhone.internalRemoveCall(call);
2265 }
2266 if (toThrow != null) {
2267 throw toThrow;
2268 }
Andrew Lee011728f2015-04-23 15:47:06 -07002269 }
2270 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002271 }
2272 }
2273
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002274 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002275 for (CallbackRecord<Callback> record : mCallbackRecords) {
2276 final Call call = this;
2277 final Callback callback = record.getCallback();
2278 record.getHandler().post(new Runnable() {
2279 @Override
2280 public void run() {
2281 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2282 }
2283 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002284 }
2285 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002286
2287 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002288 * Notifies listeners of an incoming connection event.
2289 * <p>
2290 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2291 *
2292 * @param event
2293 * @param extras
2294 */
2295 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2296 for (CallbackRecord<Callback> record : mCallbackRecords) {
2297 final Call call = this;
2298 final Callback callback = record.getCallback();
2299 record.getHandler().post(new Runnable() {
2300 @Override
2301 public void run() {
2302 callback.onConnectionEvent(call, event, extras);
2303 }
2304 });
2305 }
2306 }
2307
2308 /**
Hall Liu95d55872017-01-25 17:12:49 -08002309 * Notifies listeners of an RTT on/off change
2310 *
2311 * @param enabled True if RTT is now enabled, false otherwise
2312 */
2313 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2314 for (CallbackRecord<Callback> record : mCallbackRecords) {
2315 final Call call = this;
2316 final Callback callback = record.getCallback();
2317 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2318 }
2319 }
2320
2321 /**
2322 * Notifies listeners of a RTT mode change
2323 *
2324 * @param mode The new RTT mode
2325 */
2326 private void fireOnRttModeChanged(final int mode) {
2327 for (CallbackRecord<Callback> record : mCallbackRecords) {
2328 final Call call = this;
2329 final Callback callback = record.getCallback();
2330 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2331 }
2332 }
2333
2334 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002335 * Determines if two bundles are equal.
2336 *
2337 * @param bundle The original bundle.
2338 * @param newBundle The bundle to compare with.
2339 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2340 */
2341 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2342 if (bundle == null || newBundle == null) {
2343 return bundle == newBundle;
2344 }
2345
2346 if (bundle.size() != newBundle.size()) {
2347 return false;
2348 }
2349
2350 for(String key : bundle.keySet()) {
2351 if (key != null) {
2352 final Object value = bundle.get(key);
2353 final Object newValue = newBundle.get(key);
2354 if (!Objects.equals(value, newValue)) {
2355 return false;
2356 }
2357 }
2358 }
2359 return true;
2360 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002361}