blob: 26bd4a106ca63125fa733a3e3457c341cb1f7d22 [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
144 */
145 public static final String EVENT_REQUEST_HANDOVER =
146 "android.telecom.event.REQUEST_HANDOVER";
147
148 /**
149 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
150 * {@link PhoneAccountHandle} to which a call should be handed over to.
151 * @hide
152 */
153 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
154 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
155
156 /**
157 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
158 * video state of the call when it is handed over to the new {@link PhoneAccount}.
159 * <p>
160 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
161 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
162 * {@link VideoProfile#STATE_TX_ENABLED}.
163 * @hide
164 */
165 public static final String EXTRA_HANDOVER_VIDEO_STATE =
166 "android.telecom.extra.HANDOVER_VIDEO_STATE";
167
168 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700169 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
170 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
171 * information to the handover {@link ConnectionService} specified by
172 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
173 * <p>
174 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
175 * {@link ConnectionService} via the request extras when
176 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
177 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700178 * @hide
179 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700180 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700181
182 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700183 * Call event sent from Telecom to the handover {@link ConnectionService} via
184 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
185 * to the {@link ConnectionService} has completed successfully.
186 * <p>
187 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700188 * @hide
189 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700190 public static final String EVENT_HANDOVER_COMPLETE =
191 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700192
193 /**
194 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
195 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
196 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
197 * {@code null}.
198 * <p>
199 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
200 * @hide
201 */
202 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
203 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
204
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700205 /**
206 * Call event sent from Telecom to the handover {@link ConnectionService} via
207 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
208 * to the {@link ConnectionService} has failed.
209 * <p>
210 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
211 * @hide
212 */
213 public static final String EVENT_HANDOVER_FAILED =
214 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700215
Ihab Awade63fadb2014-07-09 21:52:04 -0700216 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800217
218 /** Call can currently be put on hold or unheld. */
219 public static final int CAPABILITY_HOLD = 0x00000001;
220
221 /** Call supports the hold feature. */
222 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
223
224 /**
225 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
226 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
227 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
228 * capability allows a merge button to be shown while the conference call is in the foreground
229 * of the in-call UI.
230 * <p>
231 * This is only intended for use by a {@link Conference}.
232 */
233 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
234
235 /**
236 * Calls within a conference can be swapped between foreground and background.
237 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
238 * <p>
239 * This is only intended for use by a {@link Conference}.
240 */
241 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
242
243 /**
244 * @hide
245 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700246 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800247
248 /** Call supports responding via text option. */
249 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
250
251 /** Call can be muted. */
252 public static final int CAPABILITY_MUTE = 0x00000040;
253
254 /**
255 * Call supports conference call management. This capability only applies to {@link Conference}
256 * calls which can have {@link Connection}s as children.
257 */
258 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
259
260 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700261 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800262 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700263 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800264
265 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700266 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800267 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700268 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800269
270 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700271 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800272 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700273 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700274 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800275
276 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700277 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800278 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700279 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
280
281 /**
282 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700283 */
284 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
285
286 /**
287 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700288 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700289 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700290 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800291
292 /**
293 * Call is able to be separated from its parent {@code Conference}, if any.
294 */
295 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
296
297 /**
298 * Call is able to be individually disconnected when in a {@code Conference}.
299 */
300 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
301
302 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500303 * Speed up audio setup for MT call.
304 * @hide
305 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700306 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
307
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700308 /**
309 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700310 * @hide
311 */
Mathew Inwood42346d12018-08-01 11:33:05 +0100312 @UnsupportedAppUsage
Rekha Kumar07366812015-03-24 16:42:31 -0700313 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
314
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700315 /**
316 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700317 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700318 */
319 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
320
Bryce Lee81901682015-08-28 16:38:02 -0700321 /**
322 * Call sends responses through connection.
323 * @hide
324 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800325 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
326
327 /**
328 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
329 * <p>
330 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
331 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
332 * downgraded from a video call back to a VideoState of
333 * {@link VideoProfile#STATE_AUDIO_ONLY}.
334 * <p>
335 * Intuitively, a call which can be downgraded to audio should also have local and remote
336 * video
337 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
338 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
339 */
340 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700341
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700342 /**
343 * When set for an external call, indicates that this {@code Call} can be pulled from a
344 * remote device to the current device.
345 * <p>
346 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
347 * <p>
348 * An {@link InCallService} will only see calls with this capability if it has the
349 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
350 * in its manifest.
351 * <p>
352 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700353 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700354 */
355 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
356
Pooja Jaind34698d2017-12-28 14:15:31 +0530357 /** Call supports the deflect feature. */
358 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
359
Tyler Gunnd11a3152015-03-18 13:09:14 -0700360 //******************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530361 // Next CAPABILITY value: 0x02000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700362 //******************************************************************************************
363
364 /**
365 * Whether the call is currently a conference.
366 */
367 public static final int PROPERTY_CONFERENCE = 0x00000001;
368
369 /**
370 * Whether the call is a generic conference, where we do not know the precise state of
371 * participants in the conference (eg. on CDMA).
372 */
373 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
374
375 /**
376 * Whether the call is made while the device is in emergency callback mode.
377 */
378 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
379
380 /**
381 * Connection is using WIFI.
382 */
383 public static final int PROPERTY_WIFI = 0x00000008;
384
385 /**
386 * Call is using high definition audio.
387 */
388 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
389
Tony Maka68dcce2015-12-17 09:31:18 +0000390 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100391 * Whether the call is associated with the work profile.
392 */
393 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
394
395 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700396 * When set, indicates that this {@code Call} does not actually exist locally for the
397 * {@link ConnectionService}.
398 * <p>
399 * Consider, for example, a scenario where a user has two phones with the same phone number.
400 * When a user places a call on one device, the telephony stack can represent that call on
401 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700402 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700403 * <p>
404 * An {@link InCallService} will only see calls with this property if it has the
405 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
406 * in its manifest.
407 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700408 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700409 */
410 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
411
Brad Ebinger15847072016-05-18 11:08:36 -0700412 /**
413 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
414 */
415 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
416
Tyler Gunn24e18332017-02-10 09:42:49 -0800417 /**
418 * Indicates that the call is from a self-managed {@link ConnectionService}.
419 * <p>
420 * See also {@link Connection#PROPERTY_SELF_MANAGED}
421 */
422 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
423
Eric Erfanianec881872017-12-06 16:27:53 -0800424 /**
425 * Indicates the call used Assisted Dialing.
426 * See also {@link Connection#PROPERTY_ASSISTED_DIALING_USED}
427 * @hide
428 */
429 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
430
Hall Liue9041242018-02-09 16:40:03 -0800431 /**
432 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
433 * {@link RttCall} object that is used to send and receive text.
434 */
435 public static final int PROPERTY_RTT = 0x00000400;
436
Tyler Gunn5bd90852018-09-21 09:37:07 -0700437 /**
438 * Indicates that the call has been identified as the network as an emergency call. This
439 * property may be set for both incoming and outgoing calls which the network identifies as
440 * emergency calls.
441 */
442 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
443
Andrew Lee2378ea72015-04-29 14:38:11 -0700444 //******************************************************************************************
Tyler Gunn5bd90852018-09-21 09:37:07 -0700445 // Next PROPERTY value: 0x00001000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700446 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800447
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800448 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700449 private final Uri mHandle;
450 private final int mHandlePresentation;
451 private final String mCallerDisplayName;
452 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700453 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700454 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700455 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800456 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700457 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700458 private final long mConnectTimeMillis;
459 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700460 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700461 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700462 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700463 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700464 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700465
466 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800467 * Whether the supplied capabilities supports the specified capability.
468 *
469 * @param capabilities A bit field of capabilities.
470 * @param capability The capability to check capabilities for.
471 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800472 */
473 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800474 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800475 }
476
477 /**
478 * Whether the capabilities of this {@code Details} supports the specified capability.
479 *
480 * @param capability The capability to check capabilities for.
481 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800482 */
483 public boolean can(int capability) {
484 return can(mCallCapabilities, capability);
485 }
486
487 /**
488 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
489 *
490 * @param capabilities A capability bit field.
491 * @return A human readable string representation.
492 */
493 public static String capabilitiesToString(int capabilities) {
494 StringBuilder builder = new StringBuilder();
495 builder.append("[Capabilities:");
496 if (can(capabilities, CAPABILITY_HOLD)) {
497 builder.append(" CAPABILITY_HOLD");
498 }
499 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
500 builder.append(" CAPABILITY_SUPPORT_HOLD");
501 }
502 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
503 builder.append(" CAPABILITY_MERGE_CONFERENCE");
504 }
505 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
506 builder.append(" CAPABILITY_SWAP_CONFERENCE");
507 }
508 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
509 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
510 }
511 if (can(capabilities, CAPABILITY_MUTE)) {
512 builder.append(" CAPABILITY_MUTE");
513 }
514 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
515 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
516 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700517 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
518 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
519 }
520 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
521 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
522 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700523 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
524 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800525 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700526 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
527 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
528 }
529 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
530 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
531 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800532 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
533 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
534 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700535 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
536 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800537 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500538 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700539 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500540 }
Rekha Kumar07366812015-03-24 16:42:31 -0700541 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
542 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
543 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700544 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
545 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
546 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700547 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
548 builder.append(" CAPABILITY_CAN_PULL_CALL");
549 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530550 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
551 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
552 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800553 builder.append("]");
554 return builder.toString();
555 }
556
557 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700558 * Whether the supplied properties includes the specified property.
559 *
560 * @param properties A bit field of properties.
561 * @param property The property to check properties for.
562 * @return Whether the specified property is supported.
563 */
564 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800565 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700566 }
567
568 /**
569 * Whether the properties of this {@code Details} includes the specified property.
570 *
571 * @param property The property to check properties for.
572 * @return Whether the specified property is supported.
573 */
574 public boolean hasProperty(int property) {
575 return hasProperty(mCallProperties, property);
576 }
577
578 /**
579 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
580 *
581 * @param properties A property bit field.
582 * @return A human readable string representation.
583 */
584 public static String propertiesToString(int properties) {
585 StringBuilder builder = new StringBuilder();
586 builder.append("[Properties:");
587 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
588 builder.append(" PROPERTY_CONFERENCE");
589 }
590 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
591 builder.append(" PROPERTY_GENERIC_CONFERENCE");
592 }
593 if (hasProperty(properties, PROPERTY_WIFI)) {
594 builder.append(" PROPERTY_WIFI");
595 }
596 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
597 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
598 }
599 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700600 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700601 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700602 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
603 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
604 }
Brad Ebinger15847072016-05-18 11:08:36 -0700605 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
606 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
607 }
Eric Erfanianec881872017-12-06 16:27:53 -0800608 if(hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
609 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
610 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700611 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
612 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
613 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700614 builder.append("]");
615 return builder.toString();
616 }
617
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800618 /** {@hide} */
619 public String getTelecomCallId() {
620 return mTelecomCallId;
621 }
622
Andrew Lee2378ea72015-04-29 14:38:11 -0700623 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700624 * @return The handle (e.g., phone number) to which the {@code Call} is currently
625 * connected.
626 */
627 public Uri getHandle() {
628 return mHandle;
629 }
630
631 /**
632 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700633 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700634 */
635 public int getHandlePresentation() {
636 return mHandlePresentation;
637 }
638
639 /**
640 * @return The display name for the caller.
641 */
642 public String getCallerDisplayName() {
643 return mCallerDisplayName;
644 }
645
646 /**
647 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700648 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700649 */
650 public int getCallerDisplayNamePresentation() {
651 return mCallerDisplayNamePresentation;
652 }
653
654 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700655 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
656 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700657 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700658 public PhoneAccountHandle getAccountHandle() {
659 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700660 }
661
662 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800663 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
664 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700665 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700666 public int getCallCapabilities() {
667 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700668 }
669
670 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700671 * @return A bitmask of the properties of the {@code Call}, as defined by the various
672 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700673 */
674 public int getCallProperties() {
675 return mCallProperties;
676 }
677
678 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800679 * @return a bitmask of the audio routes available for the call.
680 *
681 * @hide
682 */
683 public int getSupportedAudioRoutes() {
684 return mSupportedAudioRoutes;
685 }
686
687 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700688 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700689 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700690 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700691 public DisconnectCause getDisconnectCause() {
692 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700693 }
694
695 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700696 * Returns the time the {@link Call} connected (i.e. became active). This information is
697 * updated periodically, but user interfaces should not rely on this to display the "call
698 * time clock". For the time when the call was first added to Telecom, see
699 * {@link #getCreationTimeMillis()}.
700 *
701 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700702 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700703 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700704 return mConnectTimeMillis;
705 }
706
707 /**
708 * @return Information about any calling gateway the {@code Call} may be using.
709 */
710 public GatewayInfo getGatewayInfo() {
711 return mGatewayInfo;
712 }
713
Andrew Lee7a341382014-07-15 17:05:08 -0700714 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700715 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700716 */
717 public int getVideoState() {
718 return mVideoState;
719 }
720
Ihab Awad5d0410f2014-07-30 10:07:40 -0700721 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700722 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700723 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700724 */
725 public StatusHints getStatusHints() {
726 return mStatusHints;
727 }
728
Nancy Chen10798dc2014-08-08 14:00:25 -0700729 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700730 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700731 */
732 public Bundle getExtras() {
733 return mExtras;
734 }
735
Santos Cordon6b7f9552015-05-27 17:21:45 -0700736 /**
737 * @return The extras used with the original intent to place this call.
738 */
739 public Bundle getIntentExtras() {
740 return mIntentExtras;
741 }
742
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700743 /**
744 * Returns the time when the call was first created and added to Telecom. This is the same
745 * time that is logged as the start time in the Call Log (see
746 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
747 * (became active), see {@link #getConnectTimeMillis()}.
748 *
749 * @return The creation time of the call, in millis since the epoch.
750 */
751 public long getCreationTimeMillis() {
752 return mCreationTimeMillis;
753 }
754
Ihab Awade63fadb2014-07-09 21:52:04 -0700755 @Override
756 public boolean equals(Object o) {
757 if (o instanceof Details) {
758 Details d = (Details) o;
759 return
760 Objects.equals(mHandle, d.mHandle) &&
761 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
762 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
763 Objects.equals(mCallerDisplayNamePresentation,
764 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700765 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700766 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700767 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700768 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700769 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700770 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700771 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700772 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700773 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700774 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
775 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700776 }
777 return false;
778 }
779
780 @Override
781 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700782 return Objects.hash(mHandle,
783 mHandlePresentation,
784 mCallerDisplayName,
785 mCallerDisplayNamePresentation,
786 mAccountHandle,
787 mCallCapabilities,
788 mCallProperties,
789 mDisconnectCause,
790 mConnectTimeMillis,
791 mGatewayInfo,
792 mVideoState,
793 mStatusHints,
794 mExtras,
795 mIntentExtras,
796 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700797 }
798
799 /** {@hide} */
800 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800801 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700802 Uri handle,
803 int handlePresentation,
804 String callerDisplayName,
805 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700806 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700807 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700808 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700809 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700810 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700811 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700812 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700813 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700814 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700815 Bundle intentExtras,
816 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800817 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700818 mHandle = handle;
819 mHandlePresentation = handlePresentation;
820 mCallerDisplayName = callerDisplayName;
821 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700822 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700823 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700824 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700825 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700826 mConnectTimeMillis = connectTimeMillis;
827 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700828 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700829 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700830 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700831 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700832 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700833 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800834
835 /** {@hide} */
836 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
837 return new Details(
838 parcelableCall.getId(),
839 parcelableCall.getHandle(),
840 parcelableCall.getHandlePresentation(),
841 parcelableCall.getCallerDisplayName(),
842 parcelableCall.getCallerDisplayNamePresentation(),
843 parcelableCall.getAccountHandle(),
844 parcelableCall.getCapabilities(),
845 parcelableCall.getProperties(),
846 parcelableCall.getDisconnectCause(),
847 parcelableCall.getConnectTimeMillis(),
848 parcelableCall.getGatewayInfo(),
849 parcelableCall.getVideoState(),
850 parcelableCall.getStatusHints(),
851 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700852 parcelableCall.getIntentExtras(),
853 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800854 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800855
856 @Override
857 public String toString() {
858 StringBuilder sb = new StringBuilder();
859 sb.append("[pa: ");
860 sb.append(mAccountHandle);
861 sb.append(", hdl: ");
862 sb.append(Log.pii(mHandle));
863 sb.append(", caps: ");
864 sb.append(capabilitiesToString(mCallCapabilities));
865 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700866 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800867 sb.append("]");
868 return sb.toString();
869 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700870 }
871
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700872 /**
873 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
874 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
875 * implementation.
876 * <p>
877 * You can handle these callbacks by extending the {@link Callback} class and overriding the
878 * callbacks that your {@link InCallService} is interested in. The callback methods include the
879 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
880 * {@link Callback} implementation, if desired.
881 * <p>
882 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
883 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
884 * (typically in {@link InCallService#onCallRemoved(Call)}).
885 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
886 * reach your implementation of {@link Callback}, so it is important to register your callback
887 * as soon as your {@link InCallService} is notified of a new call via
888 * {@link InCallService#onCallAdded(Call)}.
889 */
Andrew Leeda80c872015-04-15 14:09:50 -0700890 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700891 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -0700892 * @hide
893 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800894 @IntDef(prefix = { "HANDOVER_" },
895 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -0700896 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -0800897 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -0700898 @Retention(RetentionPolicy.SOURCE)
899 public @interface HandoverFailureErrors {}
900
901 /**
902 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -0800903 * to handover the call to rejects the handover request.
904 * <p>
905 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
906 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
907 * {@code null} {@link Connection} from
908 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
909 * ConnectionRequest)}.
910 * <p>
911 * For more information on call handovers, see
912 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700913 */
914 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
915
916 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800917 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
918 * is initiated but the source or destination app does not support handover.
919 * <p>
920 * Will be returned when a handover is requested via
921 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
922 * {@link PhoneAccountHandle} does not declare
923 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
924 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
925 * {@link Details#getAccountHandle()}) does not declare
926 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
927 * <p>
928 * For more information on call handovers, see
929 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700930 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800931 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700932
933 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800934 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
935 * user rejects the handover request.
936 * <p>
937 * For more information on call handovers, see
938 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700939 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800940 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700941
Sanket Padawe85291f62017-12-01 13:59:27 -0800942 /**
943 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
944 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -0800945 * <p>
946 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
947 * called on an emergency call, or if any other call is an emergency call.
948 * <p>
949 * Handovers are not permitted while there are ongoing emergency calls.
950 * <p>
951 * For more information on call handovers, see
952 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -0800953 */
Tyler Gunn5c60d712018-03-16 09:53:44 -0700954 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -0800955
Tyler Gunn9d127732018-03-02 15:45:51 -0800956 /**
957 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
958 * fails for an unknown reason.
959 * <p>
960 * For more information on call handovers, see
961 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
962 */
963 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700964
965 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700966 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
967 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700968 * @param call The {@code Call} invoking this method.
969 * @param state The new state of the {@code Call}.
970 */
971 public void onStateChanged(Call call, int state) {}
972
973 /**
974 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
975 *
976 * @param call The {@code Call} invoking this method.
977 * @param parent The new parent of the {@code Call}.
978 */
979 public void onParentChanged(Call call, Call parent) {}
980
981 /**
982 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
983 *
984 * @param call The {@code Call} invoking this method.
985 * @param children The new children of the {@code Call}.
986 */
987 public void onChildrenChanged(Call call, List<Call> children) {}
988
989 /**
990 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
991 *
992 * @param call The {@code Call} invoking this method.
993 * @param details A {@code Details} object describing the {@code Call}.
994 */
995 public void onDetailsChanged(Call call, Details details) {}
996
997 /**
998 * Invoked when the text messages that can be used as responses to the incoming
999 * {@code Call} are loaded from the relevant database.
1000 * See {@link #getCannedTextResponses()}.
1001 *
1002 * @param call The {@code Call} invoking this method.
1003 * @param cannedTextResponses The text messages useable as responses.
1004 */
1005 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1006
1007 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001008 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1009 * character. This causes the post-dial signals to stop pending user confirmation. An
1010 * implementation should present this choice to the user and invoke
1011 * {@link #postDialContinue(boolean)} when the user makes the choice.
1012 *
1013 * @param call The {@code Call} invoking this method.
1014 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1015 */
1016 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1017
1018 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001019 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001020 *
1021 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001022 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001023 */
Andrew Lee50aca232014-07-22 16:41:54 -07001024 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001025
1026 /**
1027 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1028 * up their UI for the {@code Call} in response to state transitions. Specifically,
1029 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1030 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1031 * clients should wait for this method to be invoked.
1032 *
1033 * @param call The {@code Call} being destroyed.
1034 */
1035 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001036
1037 /**
1038 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1039 * conferenced.
1040 *
1041 * @param call The {@code Call} being updated.
1042 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1043 * conferenced.
1044 */
1045 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001046
1047 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001048 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
1049 * <p>
1050 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1051 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1052 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1053 * possible that a {@link ConnectionService} has defined its own Connection events which a
1054 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001055 * <p>
1056 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
1057 *
1058 * @param call The {@code Call} receiving the event.
1059 * @param event The event.
1060 * @param extras Extras associated with the connection event.
1061 */
1062 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001063
1064 /**
1065 * Invoked when the RTT mode changes for this call.
1066 * @param call The call whose RTT mode has changed.
1067 * @param mode the new RTT mode, one of
1068 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1069 * or {@link RttCall#RTT_MODE_VCO}
1070 */
1071 public void onRttModeChanged(Call call, int mode) {}
1072
1073 /**
1074 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1075 * @param call The call whose RTT status has changed.
1076 * @param enabled whether RTT is now enabled or disabled
1077 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1078 * on, null otherwise.
1079 */
1080 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1081
1082 /**
1083 * Invoked when the remote end of the connection has requested that an RTT communication
1084 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1085 * with the same ID that this method is invoked with.
1086 * @param call The call which the RTT request was placed on
1087 * @param id The ID of the request.
1088 */
1089 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001090
1091 /**
1092 * Invoked when the RTT session failed to initiate for some reason, including rejection
1093 * by the remote party.
1094 * @param call The call which the RTT initiation failure occurred on.
1095 * @param reason One of the status codes defined in
1096 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1097 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1098 */
1099 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001100
1101 /**
1102 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1103 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001104 * <p>
1105 * For a full discussion of the handover process and the APIs involved, see
1106 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1107 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001108 * @param call The call which had initiated handover.
1109 */
1110 public void onHandoverComplete(Call call) {}
1111
1112 /**
1113 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1114 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001115 * <p>
1116 * For a full discussion of the handover process and the APIs involved, see
1117 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1118 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001119 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001120 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001121 */
1122 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001123 }
1124
1125 /**
1126 * A class that holds the state that describes the state of the RTT channel to the remote
1127 * party, if it is active.
1128 */
1129 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001130 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001131 @Retention(RetentionPolicy.SOURCE)
1132 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1133 public @interface RttAudioMode {}
1134
1135 /**
1136 * For metrics use. Default value in the proto.
1137 * @hide
1138 */
1139 public static final int RTT_MODE_INVALID = 0;
1140
1141 /**
1142 * Indicates that there should be a bidirectional audio stream between the two parties
1143 * on the call.
1144 */
1145 public static final int RTT_MODE_FULL = 1;
1146
1147 /**
1148 * Indicates that the local user should be able to hear the audio stream from the remote
1149 * user, but not vice versa. Equivalent to muting the microphone.
1150 */
1151 public static final int RTT_MODE_HCO = 2;
1152
1153 /**
1154 * Indicates that the remote user should be able to hear the audio stream from the local
1155 * user, but not vice versa. Equivalent to setting the volume to zero.
1156 */
1157 public static final int RTT_MODE_VCO = 3;
1158
1159 private static final int READ_BUFFER_SIZE = 1000;
1160
1161 private InputStreamReader mReceiveStream;
1162 private OutputStreamWriter mTransmitStream;
1163 private int mRttMode;
1164 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001165 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001166 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1167
1168 /**
1169 * @hide
1170 */
Hall Liu57006aa2017-02-06 10:49:48 -08001171 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1172 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1173 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001174 mReceiveStream = receiveStream;
1175 mTransmitStream = transmitStream;
1176 mRttMode = mode;
1177 mInCallAdapter = inCallAdapter;
1178 }
1179
1180 /**
1181 * Returns the current RTT audio mode.
1182 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1183 * {@link #RTT_MODE_HCO}.
1184 */
1185 public int getRttAudioMode() {
1186 return mRttMode;
1187 }
1188
1189 /**
1190 * Sets the RTT audio mode. The requested mode change will be communicated through
1191 * {@link Callback#onRttModeChanged(Call, int)}.
1192 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1193 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1194 */
1195 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001196 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001197 }
1198
1199 /**
1200 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1201 * RTT transmits text in real-time, this method should be called once for each character
1202 * the user enters into the device.
1203 *
1204 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1205 * lead to interleaved text.
1206 * @param input The message to send to the remote user.
1207 */
1208 public void write(String input) throws IOException {
1209 mTransmitStream.write(input);
1210 mTransmitStream.flush();
1211 }
1212
1213 /**
1214 * Reads a string from the remote user, blocking if there is no data available. Returns
1215 * {@code null} if the RTT conversation has been terminated and there is no further data
1216 * to read.
1217 *
1218 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1219 * lead to interleaved text.
1220 * @return A string containing text sent by the remote user, or {@code null} if the
1221 * conversation has been terminated or if there was an error while reading.
1222 */
Hall Liub1c8a772017-07-17 17:04:41 -07001223 public String read() {
1224 try {
1225 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1226 if (numRead < 0) {
1227 return null;
1228 }
1229 return new String(mReadBuffer, 0, numRead);
1230 } catch (IOException e) {
1231 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001232 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001233 }
Hall Liuffa4a812017-03-02 16:11:00 -08001234 }
1235
1236 /**
1237 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1238 * be read.
1239 * @return A string containing text entered by the user, or {@code null} if the user has
1240 * not entered any new text yet.
1241 */
1242 public String readImmediately() throws IOException {
1243 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001244 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1245 if (numRead < 0) {
1246 return null;
1247 }
1248 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001249 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001250 return null;
1251 }
1252 }
Hall Liue9041242018-02-09 16:40:03 -08001253
1254 /**
1255 * Closes the underlying file descriptors
1256 * @hide
1257 */
1258 public void close() {
1259 try {
1260 mReceiveStream.close();
1261 } catch (IOException e) {
1262 // ignore
1263 }
1264 try {
1265 mTransmitStream.close();
1266 } catch (IOException e) {
1267 // ignore
1268 }
1269 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001270 }
1271
Andrew Leeda80c872015-04-15 14:09:50 -07001272 /**
1273 * @deprecated Use {@code Call.Callback} instead.
1274 * @hide
1275 */
1276 @Deprecated
1277 @SystemApi
1278 public static abstract class Listener extends Callback { }
1279
Ihab Awade63fadb2014-07-09 21:52:04 -07001280 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001281 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001282 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001283 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001284 private final List<Call> mChildren = new ArrayList<>();
1285 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001286 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001287 private final List<Call> mConferenceableCalls = new ArrayList<>();
1288 private final List<Call> mUnmodifiableConferenceableCalls =
1289 Collections.unmodifiableList(mConferenceableCalls);
1290
Santos Cordon823fd3c2014-08-07 18:35:18 -07001291 private boolean mChildrenCached;
1292 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001293 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001294 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001295 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001296 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001297 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001298 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001299 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001300 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001301 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001302
1303 /**
1304 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1305 *
1306 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1307 * remaining or this {@code Call} is not in a post-dial state.
1308 */
1309 public String getRemainingPostDialSequence() {
1310 return mRemainingPostDialSequence;
1311 }
1312
1313 /**
1314 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001315 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001316 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001317 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001318 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001319 }
1320
1321 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301322 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1323 *
1324 * @param address The address to which the call will be deflected.
1325 */
1326 public void deflect(Uri address) {
1327 mInCallAdapter.deflectCall(mTelecomCallId, address);
1328 }
1329
1330 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001331 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1332 *
1333 * @param rejectWithMessage Whether to reject with a text message.
1334 * @param textMessage An optional text message with which to respond.
1335 */
1336 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001337 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001338 }
1339
1340 /**
1341 * Instructs this {@code Call} to disconnect.
1342 */
1343 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001344 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001345 }
1346
1347 /**
1348 * Instructs this {@code Call} to go on hold.
1349 */
1350 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001351 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001352 }
1353
1354 /**
1355 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1356 */
1357 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001358 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001359 }
1360
1361 /**
1362 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1363 *
1364 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1365 *
1366 * @param digit A character representing the DTMF digit for which to play the tone. This
1367 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1368 */
1369 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001370 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001371 }
1372
1373 /**
1374 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1375 * currently playing.
1376 *
1377 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1378 * currently playing, this method will do nothing.
1379 */
1380 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001381 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001382 }
1383
1384 /**
1385 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1386 *
1387 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1388 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001389 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001390 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001391 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1392 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001393 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001394 * {@code Call} will pause playing the tones and notify callbacks via
1395 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001396 * should display to the user an indication of this state and an affordance to continue
1397 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1398 * app should invoke the {@link #postDialContinue(boolean)} method.
1399 *
1400 * @param proceed Whether or not to continue with the post-dial sequence.
1401 */
1402 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001403 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001404 }
1405
1406 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001407 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001408 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001409 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001410 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1411 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001412
1413 }
1414
1415 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001416 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001417 *
1418 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001419 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001420 public void conference(Call callToConferenceWith) {
1421 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001422 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001423 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001424 }
1425
1426 /**
1427 * Instructs this {@code Call} to split from any conference call with which it may be
1428 * connected.
1429 */
1430 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001431 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001432 }
1433
1434 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001435 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001436 */
1437 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001438 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001439 }
1440
1441 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001442 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001443 */
1444 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001445 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001446 }
1447
1448 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001449 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1450 * device.
1451 * <p>
1452 * Calls to this method are ignored if the call does not have the
1453 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1454 * <p>
1455 * An {@link InCallService} will only see calls which support this method if it has the
1456 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1457 * in its manifest.
1458 */
1459 public void pullExternalCall() {
1460 // If this isn't an external call, ignore the request.
1461 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1462 return;
1463 }
1464
1465 mInCallAdapter.pullExternalCall(mTelecomCallId);
1466 }
1467
1468 /**
1469 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1470 * the {@link ConnectionService}.
1471 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001472 * Call events are used to communicate point in time information from an {@link InCallService}
1473 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1474 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1475 * {@link ConnectionService}.
1476 * <p>
1477 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1478 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1479 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001480 * Events are exposed to {@link ConnectionService} implementations via
1481 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1482 * <p>
1483 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001484 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1485 * ignore some events altogether.
1486 * <p>
1487 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1488 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1489 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1490 * they define their own event types in this namespace. When defining a custom event type,
1491 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1492 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1493 * <p>
1494 * When defining events and the associated extras, it is important to keep their behavior
1495 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1496 * events/extras should me maintained to ensure backwards compatibility with older
1497 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001498 *
1499 * @param event The connection event.
1500 * @param extras Bundle containing extra information associated with the event.
1501 */
1502 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001503 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001504 }
1505
1506 /**
Hall Liu95d55872017-01-25 17:12:49 -08001507 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1508 * guaranteed, and notification of success will be via the
1509 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1510 */
1511 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001512 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001513 }
1514
1515 /**
1516 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1517 * callback.
1518 * The ID used here should be the same as the ID that was received via the callback.
1519 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1520 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1521 */
1522 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001523 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001524 }
1525
1526 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001527 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1528 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1529 * handover.
1530 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001531 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1532 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1533 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1534 * is referred to as the source of the handover, and the video calling app is referred to as the
1535 * destination.
1536 * <p>
1537 * When considering a handover scenario the device this method is called on is considered the
1538 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1539 * other device is considered the <em>receiving</em> device.
1540 * <p>
1541 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1542 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1543 * and invoke
1544 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1545 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1546 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1547 * At this point the app should display UI to indicate to the user that a call
1548 * handover is in process.
1549 * <p>
1550 * The destination app is responsible for communicating the handover request from the
1551 * <em>initiating</em> device to the <em>receiving</em> device.
1552 * <p>
1553 * When the app on the <em>receiving</em> device receives the handover request, it calls
1554 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1555 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1556 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1557 * choose whether they want to continue their call in the destination app.
1558 * <p>
1559 * When the destination app on the <em>receiving</em> device calls
1560 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1561 * {@link ConnectionService} and call
1562 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1563 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1564 * {@link Connection} to represent the handover call.
1565 * <p>
1566 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1567 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1568 * original call. If the user rejects the handover, the app calls
1569 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1570 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1571 * <p>
1572 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1573 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1574 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1575 * <p>
1576 * Errors in the handover process are reported to the {@link InCallService} via
1577 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1578 * the involved {@link ConnectionService}s via
1579 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001580 *
1581 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1582 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001583 * @param videoState Indicates the video state desired after the handover (see the
1584 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001585 * @param extras Bundle containing extra information to be passed to the
1586 * {@link ConnectionService}
1587 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001588 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1589 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001590 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1591 }
1592
1593 /**
Hall Liu95d55872017-01-25 17:12:49 -08001594 * Terminate the RTT session on this call. The resulting state change will be notified via
1595 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1596 */
1597 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001598 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001599 }
1600
1601 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001602 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1603 * added.
1604 * <p>
1605 * No assumptions should be made as to how an In-Call UI or service will handle these
1606 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1607 *
1608 * @param extras The extras to add.
1609 */
1610 public final void putExtras(Bundle extras) {
1611 if (extras == null) {
1612 return;
1613 }
1614
1615 if (mExtras == null) {
1616 mExtras = new Bundle();
1617 }
1618 mExtras.putAll(extras);
1619 mInCallAdapter.putExtras(mTelecomCallId, extras);
1620 }
1621
1622 /**
1623 * Adds a boolean extra to this {@link Call}.
1624 *
1625 * @param key The extra key.
1626 * @param value The value.
1627 * @hide
1628 */
1629 public final void putExtra(String key, boolean value) {
1630 if (mExtras == null) {
1631 mExtras = new Bundle();
1632 }
1633 mExtras.putBoolean(key, value);
1634 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1635 }
1636
1637 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001638 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001639 *
1640 * @param key The extra key.
1641 * @param value The value.
1642 * @hide
1643 */
1644 public final void putExtra(String key, int value) {
1645 if (mExtras == null) {
1646 mExtras = new Bundle();
1647 }
1648 mExtras.putInt(key, value);
1649 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1650 }
1651
1652 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001653 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001654 *
1655 * @param key The extra key.
1656 * @param value The value.
1657 * @hide
1658 */
1659 public final void putExtra(String key, String value) {
1660 if (mExtras == null) {
1661 mExtras = new Bundle();
1662 }
1663 mExtras.putString(key, value);
1664 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1665 }
1666
1667 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001668 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001669 *
1670 * @param keys The keys of the extras to remove.
1671 */
1672 public final void removeExtras(List<String> keys) {
1673 if (mExtras != null) {
1674 for (String key : keys) {
1675 mExtras.remove(key);
1676 }
1677 if (mExtras.size() == 0) {
1678 mExtras = null;
1679 }
1680 }
1681 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1682 }
1683
1684 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001685 * Removes extras from this {@link Call}.
1686 *
1687 * @param keys The keys of the extras to remove.
1688 */
1689 public final void removeExtras(String ... keys) {
1690 removeExtras(Arrays.asList(keys));
1691 }
1692
1693 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001694 * Obtains the parent of this {@code Call} in a conference, if any.
1695 *
1696 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1697 * child of any conference {@code Call}s.
1698 */
1699 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001700 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001701 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001702 }
1703 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001704 }
1705
1706 /**
1707 * Obtains the children of this conference {@code Call}, if any.
1708 *
1709 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1710 * {@code List} otherwise.
1711 */
1712 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001713 if (!mChildrenCached) {
1714 mChildrenCached = true;
1715 mChildren.clear();
1716
1717 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001718 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001719 if (call == null) {
1720 // At least one child was still not found, so do not save true for "cached"
1721 mChildrenCached = false;
1722 } else {
1723 mChildren.add(call);
1724 }
1725 }
1726 }
1727
Ihab Awade63fadb2014-07-09 21:52:04 -07001728 return mUnmodifiableChildren;
1729 }
1730
1731 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001732 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1733 *
1734 * @return The list of conferenceable {@code Call}s.
1735 */
1736 public List<Call> getConferenceableCalls() {
1737 return mUnmodifiableConferenceableCalls;
1738 }
1739
1740 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001741 * Obtains the state of this {@code Call}.
1742 *
1743 * @return A state value, chosen from the {@code STATE_*} constants.
1744 */
1745 public int getState() {
1746 return mState;
1747 }
1748
1749 /**
1750 * Obtains a list of canned, pre-configured message responses to present to the user as
1751 * ways of rejecting this {@code Call} using via a text message.
1752 *
1753 * @see #reject(boolean, String)
1754 *
1755 * @return A list of canned text message responses.
1756 */
1757 public List<String> getCannedTextResponses() {
1758 return mCannedTextResponses;
1759 }
1760
1761 /**
1762 * Obtains an object that can be used to display video from this {@code Call}.
1763 *
Andrew Lee50aca232014-07-22 16:41:54 -07001764 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001765 */
Andrew Lee50aca232014-07-22 16:41:54 -07001766 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001767 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001768 }
1769
1770 /**
1771 * Obtains an object containing call details.
1772 *
1773 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1774 * result may be {@code null}.
1775 */
1776 public Details getDetails() {
1777 return mDetails;
1778 }
1779
1780 /**
Hall Liu95d55872017-01-25 17:12:49 -08001781 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1782 * receive RTT text data, as well as to change the RTT mode.
1783 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1784 */
1785 public @Nullable RttCall getRttCall() {
1786 return mRttCall;
1787 }
1788
1789 /**
1790 * Returns whether this call has an active RTT connection.
1791 * @return true if there is a connection, false otherwise.
1792 */
1793 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08001794 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08001795 }
1796
1797 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001798 * Registers a callback to this {@code Call}.
1799 *
1800 * @param callback A {@code Callback}.
1801 */
1802 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001803 registerCallback(callback, new Handler());
1804 }
1805
1806 /**
1807 * Registers a callback to this {@code Call}.
1808 *
1809 * @param callback A {@code Callback}.
1810 * @param handler A handler which command and status changes will be delivered to.
1811 */
1812 public void registerCallback(Callback callback, Handler handler) {
1813 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001814 // Don't allow new callback registration if the call is already being destroyed.
1815 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001816 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1817 }
Andrew Leeda80c872015-04-15 14:09:50 -07001818 }
1819
1820 /**
1821 * Unregisters a callback from this {@code Call}.
1822 *
1823 * @param callback A {@code Callback}.
1824 */
1825 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001826 // Don't allow callback deregistration if the call is already being destroyed.
1827 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001828 for (CallbackRecord<Callback> record : mCallbackRecords) {
1829 if (record.getCallback() == callback) {
1830 mCallbackRecords.remove(record);
1831 break;
1832 }
1833 }
Andrew Leeda80c872015-04-15 14:09:50 -07001834 }
1835 }
1836
Santos Cordon3c20d632016-02-25 16:12:35 -08001837 @Override
1838 public String toString() {
1839 return new StringBuilder().
1840 append("Call [id: ").
1841 append(mTelecomCallId).
1842 append(", state: ").
1843 append(stateToString(mState)).
1844 append(", details: ").
1845 append(mDetails).
1846 append("]").toString();
1847 }
1848
1849 /**
1850 * @param state An integer value of a {@code STATE_*} constant.
1851 * @return A string representation of the value.
1852 */
1853 private static String stateToString(int state) {
1854 switch (state) {
1855 case STATE_NEW:
1856 return "NEW";
1857 case STATE_RINGING:
1858 return "RINGING";
1859 case STATE_DIALING:
1860 return "DIALING";
1861 case STATE_ACTIVE:
1862 return "ACTIVE";
1863 case STATE_HOLDING:
1864 return "HOLDING";
1865 case STATE_DISCONNECTED:
1866 return "DISCONNECTED";
1867 case STATE_CONNECTING:
1868 return "CONNECTING";
1869 case STATE_DISCONNECTING:
1870 return "DISCONNECTING";
1871 case STATE_SELECT_PHONE_ACCOUNT:
1872 return "SELECT_PHONE_ACCOUNT";
1873 default:
1874 Log.w(Call.class, "Unknown state %d", state);
1875 return "UNKNOWN";
1876 }
1877 }
1878
Andrew Leeda80c872015-04-15 14:09:50 -07001879 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001880 * Adds a listener to this {@code Call}.
1881 *
1882 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001883 * @deprecated Use {@link #registerCallback} instead.
1884 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001885 */
Andrew Leeda80c872015-04-15 14:09:50 -07001886 @Deprecated
1887 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001888 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001889 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001890 }
1891
1892 /**
1893 * Removes a listener from this {@code Call}.
1894 *
1895 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001896 * @deprecated Use {@link #unregisterCallback} instead.
1897 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001898 */
Andrew Leeda80c872015-04-15 14:09:50 -07001899 @Deprecated
1900 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001901 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001902 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001903 }
1904
1905 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001906 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1907 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001908 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001909 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001910 mInCallAdapter = inCallAdapter;
1911 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001912 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001913 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001914 }
1915
1916 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001917 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001918 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001919 mPhone = phone;
1920 mTelecomCallId = telecomCallId;
1921 mInCallAdapter = inCallAdapter;
1922 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001923 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001924 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001925 }
1926
1927 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001928 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001929 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001930 }
1931
1932 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001933 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001934
Ihab Awade63fadb2014-07-09 21:52:04 -07001935 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001936 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001937 boolean detailsChanged = !Objects.equals(mDetails, details);
1938 if (detailsChanged) {
1939 mDetails = details;
1940 }
1941
1942 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001943 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1944 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1945 mCannedTextResponses =
1946 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001947 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001948 }
1949
Tyler Gunn159f35c2017-03-02 09:28:37 -08001950 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1951 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001952 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001953 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001954 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001955 mVideoCallImpl = newVideoCallImpl;
1956 }
1957 if (mVideoCallImpl != null) {
1958 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001959 }
1960
Santos Cordone3c507b2015-04-23 14:44:19 -07001961 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001962 boolean stateChanged = mState != state;
1963 if (stateChanged) {
1964 mState = state;
1965 }
1966
Santos Cordon823fd3c2014-08-07 18:35:18 -07001967 String parentId = parcelableCall.getParentCallId();
1968 boolean parentChanged = !Objects.equals(mParentId, parentId);
1969 if (parentChanged) {
1970 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001971 }
1972
Santos Cordon823fd3c2014-08-07 18:35:18 -07001973 List<String> childCallIds = parcelableCall.getChildCallIds();
1974 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1975 if (childrenChanged) {
1976 mChildrenIds.clear();
1977 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1978 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001979 }
1980
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001981 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1982 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1983 for (String otherId : conferenceableCallIds) {
1984 if (callIdMap.containsKey(otherId)) {
1985 conferenceableCalls.add(callIdMap.get(otherId));
1986 }
1987 }
1988
1989 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1990 mConferenceableCalls.clear();
1991 mConferenceableCalls.addAll(conferenceableCalls);
1992 fireConferenceableCallsChanged();
1993 }
1994
Hall Liu95d55872017-01-25 17:12:49 -08001995 boolean isRttChanged = false;
1996 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08001997 if (parcelableCall.getIsRttCallChanged()
1998 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08001999 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2000 InputStreamReader receiveStream = new InputStreamReader(
2001 new ParcelFileDescriptor.AutoCloseInputStream(
2002 parcelableRttCall.getReceiveStream()),
2003 StandardCharsets.UTF_8);
2004 OutputStreamWriter transmitStream = new OutputStreamWriter(
2005 new ParcelFileDescriptor.AutoCloseOutputStream(
2006 parcelableRttCall.getTransmitStream()),
2007 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002008 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002009 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2010 if (mRttCall == null) {
2011 isRttChanged = true;
2012 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2013 rttModeChanged = true;
2014 }
2015 mRttCall = newRttCall;
2016 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2017 && parcelableCall.getIsRttCallChanged()) {
2018 isRttChanged = true;
2019 mRttCall = null;
2020 }
2021
Ihab Awade63fadb2014-07-09 21:52:04 -07002022 // Now we fire updates, ensuring that any client who listens to any of these notifications
2023 // gets the most up-to-date state.
2024
2025 if (stateChanged) {
2026 fireStateChanged(mState);
2027 }
2028 if (detailsChanged) {
2029 fireDetailsChanged(mDetails);
2030 }
2031 if (cannedTextResponsesChanged) {
2032 fireCannedTextResponsesLoaded(mCannedTextResponses);
2033 }
Andrew Lee50aca232014-07-22 16:41:54 -07002034 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002035 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002036 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002037 if (parentChanged) {
2038 fireParentChanged(getParent());
2039 }
2040 if (childrenChanged) {
2041 fireChildrenChanged(getChildren());
2042 }
Hall Liu95d55872017-01-25 17:12:49 -08002043 if (isRttChanged) {
2044 fireOnIsRttChanged(mRttCall != null, mRttCall);
2045 }
2046 if (rttModeChanged) {
2047 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2048 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002049
2050 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2051 // remove ourselves from the Phone. Note that we do this after completing all state updates
2052 // so a client can cleanly transition all their UI to the state appropriate for a
2053 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2054 if (mState == STATE_DISCONNECTED) {
2055 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002056 }
2057 }
2058
2059 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002060 final void internalSetPostDialWait(String remaining) {
2061 mRemainingPostDialSequence = remaining;
2062 firePostDialWait(mRemainingPostDialSequence);
2063 }
2064
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002065 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002066 final void internalSetDisconnected() {
2067 if (mState != Call.STATE_DISCONNECTED) {
2068 mState = Call.STATE_DISCONNECTED;
2069 fireStateChanged(mState);
2070 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002071 }
2072 }
2073
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002074 /** {@hide} */
2075 final void internalOnConnectionEvent(String event, Bundle extras) {
2076 fireOnConnectionEvent(event, extras);
2077 }
2078
Hall Liu95d55872017-01-25 17:12:49 -08002079 /** {@hide} */
2080 final void internalOnRttUpgradeRequest(final int requestId) {
2081 for (CallbackRecord<Callback> record : mCallbackRecords) {
2082 final Call call = this;
2083 final Callback callback = record.getCallback();
2084 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2085 }
2086 }
2087
Hall Liu57006aa2017-02-06 10:49:48 -08002088 /** @hide */
2089 final void internalOnRttInitiationFailure(int reason) {
2090 for (CallbackRecord<Callback> record : mCallbackRecords) {
2091 final Call call = this;
2092 final Callback callback = record.getCallback();
2093 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2094 }
2095 }
2096
Sanket Padawe85291f62017-12-01 13:59:27 -08002097 /** {@hide} */
2098 final void internalOnHandoverFailed(int error) {
2099 for (CallbackRecord<Callback> record : mCallbackRecords) {
2100 final Call call = this;
2101 final Callback callback = record.getCallback();
2102 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2103 }
2104 }
2105
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002106 /** {@hide} */
2107 final void internalOnHandoverComplete() {
2108 for (CallbackRecord<Callback> record : mCallbackRecords) {
2109 final Call call = this;
2110 final Callback callback = record.getCallback();
2111 record.getHandler().post(() -> callback.onHandoverComplete(call));
2112 }
2113 }
2114
Andrew Lee011728f2015-04-23 15:47:06 -07002115 private void fireStateChanged(final int newState) {
2116 for (CallbackRecord<Callback> record : mCallbackRecords) {
2117 final Call call = this;
2118 final Callback callback = record.getCallback();
2119 record.getHandler().post(new Runnable() {
2120 @Override
2121 public void run() {
2122 callback.onStateChanged(call, newState);
2123 }
2124 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002125 }
2126 }
2127
Andrew Lee011728f2015-04-23 15:47:06 -07002128 private void fireParentChanged(final Call newParent) {
2129 for (CallbackRecord<Callback> record : mCallbackRecords) {
2130 final Call call = this;
2131 final Callback callback = record.getCallback();
2132 record.getHandler().post(new Runnable() {
2133 @Override
2134 public void run() {
2135 callback.onParentChanged(call, newParent);
2136 }
2137 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002138 }
2139 }
2140
Andrew Lee011728f2015-04-23 15:47:06 -07002141 private void fireChildrenChanged(final List<Call> children) {
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.onChildrenChanged(call, children);
2149 }
2150 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002151 }
2152 }
2153
Andrew Lee011728f2015-04-23 15:47:06 -07002154 private void fireDetailsChanged(final Details details) {
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.onDetailsChanged(call, details);
2162 }
2163 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002164 }
2165 }
2166
Andrew Lee011728f2015-04-23 15:47:06 -07002167 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
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.onCannedTextResponsesLoaded(call, cannedTextResponses);
2175 }
2176 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002177 }
2178 }
2179
Andrew Lee011728f2015-04-23 15:47:06 -07002180 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
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.onVideoCallChanged(call, videoCall);
2188 }
2189 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002190 }
2191 }
2192
Andrew Lee011728f2015-04-23 15:47:06 -07002193 private void firePostDialWait(final String remainingPostDialSequence) {
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.onPostDialWait(call, remainingPostDialSequence);
2201 }
2202 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002203 }
2204 }
2205
2206 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002207 /**
2208 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2209 * onCallRemoved callback, we remove this call from the Phone's record
2210 * only once all of the registered onCallDestroyed callbacks are executed.
2211 * All the callbacks get removed from our records as a part of this operation
2212 * since onCallDestroyed is the final callback.
2213 */
2214 final Call call = this;
2215 if (mCallbackRecords.isEmpty()) {
2216 // No callbacks registered, remove the call from Phone's record.
2217 mPhone.internalRemoveCall(call);
2218 }
2219 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002220 final Callback callback = record.getCallback();
2221 record.getHandler().post(new Runnable() {
2222 @Override
2223 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002224 boolean isFinalRemoval = false;
2225 RuntimeException toThrow = null;
2226 try {
2227 callback.onCallDestroyed(call);
2228 } catch (RuntimeException e) {
2229 toThrow = e;
2230 }
2231 synchronized(Call.this) {
2232 mCallbackRecords.remove(record);
2233 if (mCallbackRecords.isEmpty()) {
2234 isFinalRemoval = true;
2235 }
2236 }
2237 if (isFinalRemoval) {
2238 mPhone.internalRemoveCall(call);
2239 }
2240 if (toThrow != null) {
2241 throw toThrow;
2242 }
Andrew Lee011728f2015-04-23 15:47:06 -07002243 }
2244 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002245 }
2246 }
2247
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002248 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002249 for (CallbackRecord<Callback> record : mCallbackRecords) {
2250 final Call call = this;
2251 final Callback callback = record.getCallback();
2252 record.getHandler().post(new Runnable() {
2253 @Override
2254 public void run() {
2255 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2256 }
2257 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002258 }
2259 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002260
2261 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002262 * Notifies listeners of an incoming connection event.
2263 * <p>
2264 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2265 *
2266 * @param event
2267 * @param extras
2268 */
2269 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2270 for (CallbackRecord<Callback> record : mCallbackRecords) {
2271 final Call call = this;
2272 final Callback callback = record.getCallback();
2273 record.getHandler().post(new Runnable() {
2274 @Override
2275 public void run() {
2276 callback.onConnectionEvent(call, event, extras);
2277 }
2278 });
2279 }
2280 }
2281
2282 /**
Hall Liu95d55872017-01-25 17:12:49 -08002283 * Notifies listeners of an RTT on/off change
2284 *
2285 * @param enabled True if RTT is now enabled, false otherwise
2286 */
2287 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2288 for (CallbackRecord<Callback> record : mCallbackRecords) {
2289 final Call call = this;
2290 final Callback callback = record.getCallback();
2291 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2292 }
2293 }
2294
2295 /**
2296 * Notifies listeners of a RTT mode change
2297 *
2298 * @param mode The new RTT mode
2299 */
2300 private void fireOnRttModeChanged(final int mode) {
2301 for (CallbackRecord<Callback> record : mCallbackRecords) {
2302 final Call call = this;
2303 final Callback callback = record.getCallback();
2304 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2305 }
2306 }
2307
2308 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002309 * Determines if two bundles are equal.
2310 *
2311 * @param bundle The original bundle.
2312 * @param newBundle The bundle to compare with.
2313 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2314 */
2315 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2316 if (bundle == null || newBundle == null) {
2317 return bundle == newBundle;
2318 }
2319
2320 if (bundle.size() != newBundle.size()) {
2321 return false;
2322 }
2323
2324 for(String key : bundle.keySet()) {
2325 if (key != null) {
2326 final Object value = bundle.get(key);
2327 final Object newValue = newBundle.get(key);
2328 if (!Objects.equals(value, newValue)) {
2329 return false;
2330 }
2331 }
2332 }
2333 return true;
2334 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002335}