blob: 096cf37d4c65f3fd43998bc7713bb95d8b1688ed [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
Andrew Lee2378ea72015-04-29 14:38:11 -0700437 //******************************************************************************************
Hall Liue9041242018-02-09 16:40:03 -0800438 // Next PROPERTY value: 0x00000800
Tyler Gunnd11a3152015-03-18 13:09:14 -0700439 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800440
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800441 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700442 private final Uri mHandle;
443 private final int mHandlePresentation;
444 private final String mCallerDisplayName;
445 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700446 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700447 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700448 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800449 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700450 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700451 private final long mConnectTimeMillis;
452 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700453 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700454 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700455 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700456 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700457 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700458
459 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800460 * Whether the supplied capabilities supports the specified capability.
461 *
462 * @param capabilities A bit field of capabilities.
463 * @param capability The capability to check capabilities for.
464 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800465 */
466 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800467 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800468 }
469
470 /**
471 * Whether the capabilities of this {@code Details} supports the specified capability.
472 *
473 * @param capability The capability to check capabilities for.
474 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800475 */
476 public boolean can(int capability) {
477 return can(mCallCapabilities, capability);
478 }
479
480 /**
481 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
482 *
483 * @param capabilities A capability bit field.
484 * @return A human readable string representation.
485 */
486 public static String capabilitiesToString(int capabilities) {
487 StringBuilder builder = new StringBuilder();
488 builder.append("[Capabilities:");
489 if (can(capabilities, CAPABILITY_HOLD)) {
490 builder.append(" CAPABILITY_HOLD");
491 }
492 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
493 builder.append(" CAPABILITY_SUPPORT_HOLD");
494 }
495 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
496 builder.append(" CAPABILITY_MERGE_CONFERENCE");
497 }
498 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
499 builder.append(" CAPABILITY_SWAP_CONFERENCE");
500 }
501 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
502 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
503 }
504 if (can(capabilities, CAPABILITY_MUTE)) {
505 builder.append(" CAPABILITY_MUTE");
506 }
507 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
508 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
509 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700510 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
511 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
512 }
513 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
514 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
515 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700516 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
517 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800518 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700519 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
520 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
521 }
522 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
523 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
524 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800525 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
526 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
527 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700528 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
529 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800530 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500531 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700532 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500533 }
Rekha Kumar07366812015-03-24 16:42:31 -0700534 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
535 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
536 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700537 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
538 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
539 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700540 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
541 builder.append(" CAPABILITY_CAN_PULL_CALL");
542 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530543 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
544 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
545 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800546 builder.append("]");
547 return builder.toString();
548 }
549
550 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700551 * Whether the supplied properties includes the specified property.
552 *
553 * @param properties A bit field of properties.
554 * @param property The property to check properties for.
555 * @return Whether the specified property is supported.
556 */
557 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800558 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700559 }
560
561 /**
562 * Whether the properties of this {@code Details} includes the specified property.
563 *
564 * @param property The property to check properties for.
565 * @return Whether the specified property is supported.
566 */
567 public boolean hasProperty(int property) {
568 return hasProperty(mCallProperties, property);
569 }
570
571 /**
572 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
573 *
574 * @param properties A property bit field.
575 * @return A human readable string representation.
576 */
577 public static String propertiesToString(int properties) {
578 StringBuilder builder = new StringBuilder();
579 builder.append("[Properties:");
580 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
581 builder.append(" PROPERTY_CONFERENCE");
582 }
583 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
584 builder.append(" PROPERTY_GENERIC_CONFERENCE");
585 }
586 if (hasProperty(properties, PROPERTY_WIFI)) {
587 builder.append(" PROPERTY_WIFI");
588 }
589 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
590 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
591 }
592 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700593 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700594 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700595 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
596 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
597 }
Brad Ebinger15847072016-05-18 11:08:36 -0700598 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
599 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
600 }
Eric Erfanianec881872017-12-06 16:27:53 -0800601 if(hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
602 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
603 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700604 builder.append("]");
605 return builder.toString();
606 }
607
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800608 /** {@hide} */
609 public String getTelecomCallId() {
610 return mTelecomCallId;
611 }
612
Andrew Lee2378ea72015-04-29 14:38:11 -0700613 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700614 * @return The handle (e.g., phone number) to which the {@code Call} is currently
615 * connected.
616 */
617 public Uri getHandle() {
618 return mHandle;
619 }
620
621 /**
622 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700623 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700624 */
625 public int getHandlePresentation() {
626 return mHandlePresentation;
627 }
628
629 /**
630 * @return The display name for the caller.
631 */
632 public String getCallerDisplayName() {
633 return mCallerDisplayName;
634 }
635
636 /**
637 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700638 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700639 */
640 public int getCallerDisplayNamePresentation() {
641 return mCallerDisplayNamePresentation;
642 }
643
644 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700645 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
646 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700647 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700648 public PhoneAccountHandle getAccountHandle() {
649 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700650 }
651
652 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800653 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
654 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700655 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700656 public int getCallCapabilities() {
657 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700658 }
659
660 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700661 * @return A bitmask of the properties of the {@code Call}, as defined by the various
662 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700663 */
664 public int getCallProperties() {
665 return mCallProperties;
666 }
667
668 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800669 * @return a bitmask of the audio routes available for the call.
670 *
671 * @hide
672 */
673 public int getSupportedAudioRoutes() {
674 return mSupportedAudioRoutes;
675 }
676
677 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700678 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700679 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700680 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700681 public DisconnectCause getDisconnectCause() {
682 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700683 }
684
685 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700686 * Returns the time the {@link Call} connected (i.e. became active). This information is
687 * updated periodically, but user interfaces should not rely on this to display the "call
688 * time clock". For the time when the call was first added to Telecom, see
689 * {@link #getCreationTimeMillis()}.
690 *
691 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700692 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700693 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700694 return mConnectTimeMillis;
695 }
696
697 /**
698 * @return Information about any calling gateway the {@code Call} may be using.
699 */
700 public GatewayInfo getGatewayInfo() {
701 return mGatewayInfo;
702 }
703
Andrew Lee7a341382014-07-15 17:05:08 -0700704 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700705 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700706 */
707 public int getVideoState() {
708 return mVideoState;
709 }
710
Ihab Awad5d0410f2014-07-30 10:07:40 -0700711 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700712 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700713 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700714 */
715 public StatusHints getStatusHints() {
716 return mStatusHints;
717 }
718
Nancy Chen10798dc2014-08-08 14:00:25 -0700719 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700720 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700721 */
722 public Bundle getExtras() {
723 return mExtras;
724 }
725
Santos Cordon6b7f9552015-05-27 17:21:45 -0700726 /**
727 * @return The extras used with the original intent to place this call.
728 */
729 public Bundle getIntentExtras() {
730 return mIntentExtras;
731 }
732
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700733 /**
734 * Returns the time when the call was first created and added to Telecom. This is the same
735 * time that is logged as the start time in the Call Log (see
736 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
737 * (became active), see {@link #getConnectTimeMillis()}.
738 *
739 * @return The creation time of the call, in millis since the epoch.
740 */
741 public long getCreationTimeMillis() {
742 return mCreationTimeMillis;
743 }
744
Ihab Awade63fadb2014-07-09 21:52:04 -0700745 @Override
746 public boolean equals(Object o) {
747 if (o instanceof Details) {
748 Details d = (Details) o;
749 return
750 Objects.equals(mHandle, d.mHandle) &&
751 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
752 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
753 Objects.equals(mCallerDisplayNamePresentation,
754 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700755 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700756 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700757 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700758 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700759 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700760 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700761 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700762 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700763 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700764 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
765 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700766 }
767 return false;
768 }
769
770 @Override
771 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700772 return Objects.hash(mHandle,
773 mHandlePresentation,
774 mCallerDisplayName,
775 mCallerDisplayNamePresentation,
776 mAccountHandle,
777 mCallCapabilities,
778 mCallProperties,
779 mDisconnectCause,
780 mConnectTimeMillis,
781 mGatewayInfo,
782 mVideoState,
783 mStatusHints,
784 mExtras,
785 mIntentExtras,
786 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700787 }
788
789 /** {@hide} */
790 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800791 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700792 Uri handle,
793 int handlePresentation,
794 String callerDisplayName,
795 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700796 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700797 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700798 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700799 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700800 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700801 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700802 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700803 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700804 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700805 Bundle intentExtras,
806 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800807 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700808 mHandle = handle;
809 mHandlePresentation = handlePresentation;
810 mCallerDisplayName = callerDisplayName;
811 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700812 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700813 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700814 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700815 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700816 mConnectTimeMillis = connectTimeMillis;
817 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700818 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700819 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700820 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700821 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700822 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700823 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800824
825 /** {@hide} */
826 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
827 return new Details(
828 parcelableCall.getId(),
829 parcelableCall.getHandle(),
830 parcelableCall.getHandlePresentation(),
831 parcelableCall.getCallerDisplayName(),
832 parcelableCall.getCallerDisplayNamePresentation(),
833 parcelableCall.getAccountHandle(),
834 parcelableCall.getCapabilities(),
835 parcelableCall.getProperties(),
836 parcelableCall.getDisconnectCause(),
837 parcelableCall.getConnectTimeMillis(),
838 parcelableCall.getGatewayInfo(),
839 parcelableCall.getVideoState(),
840 parcelableCall.getStatusHints(),
841 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700842 parcelableCall.getIntentExtras(),
843 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800844 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800845
846 @Override
847 public String toString() {
848 StringBuilder sb = new StringBuilder();
849 sb.append("[pa: ");
850 sb.append(mAccountHandle);
851 sb.append(", hdl: ");
852 sb.append(Log.pii(mHandle));
853 sb.append(", caps: ");
854 sb.append(capabilitiesToString(mCallCapabilities));
855 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700856 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800857 sb.append("]");
858 return sb.toString();
859 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700860 }
861
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700862 /**
863 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
864 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
865 * implementation.
866 * <p>
867 * You can handle these callbacks by extending the {@link Callback} class and overriding the
868 * callbacks that your {@link InCallService} is interested in. The callback methods include the
869 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
870 * {@link Callback} implementation, if desired.
871 * <p>
872 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
873 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
874 * (typically in {@link InCallService#onCallRemoved(Call)}).
875 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
876 * reach your implementation of {@link Callback}, so it is important to register your callback
877 * as soon as your {@link InCallService} is notified of a new call via
878 * {@link InCallService#onCallAdded(Call)}.
879 */
Andrew Leeda80c872015-04-15 14:09:50 -0700880 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700881 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -0700882 * @hide
883 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800884 @IntDef(prefix = { "HANDOVER_" },
885 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -0700886 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -0800887 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -0700888 @Retention(RetentionPolicy.SOURCE)
889 public @interface HandoverFailureErrors {}
890
891 /**
892 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -0800893 * to handover the call to rejects the handover request.
894 * <p>
895 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
896 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
897 * {@code null} {@link Connection} from
898 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
899 * ConnectionRequest)}.
900 * <p>
901 * For more information on call handovers, see
902 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700903 */
904 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
905
906 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800907 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
908 * is initiated but the source or destination app does not support handover.
909 * <p>
910 * Will be returned when a handover is requested via
911 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
912 * {@link PhoneAccountHandle} does not declare
913 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
914 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
915 * {@link Details#getAccountHandle()}) does not declare
916 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
917 * <p>
918 * For more information on call handovers, see
919 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700920 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800921 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700922
923 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800924 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
925 * user rejects the handover request.
926 * <p>
927 * For more information on call handovers, see
928 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700929 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800930 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700931
Sanket Padawe85291f62017-12-01 13:59:27 -0800932 /**
933 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
934 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -0800935 * <p>
936 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
937 * called on an emergency call, or if any other call is an emergency call.
938 * <p>
939 * Handovers are not permitted while there are ongoing emergency calls.
940 * <p>
941 * For more information on call handovers, see
942 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -0800943 */
Tyler Gunn5c60d712018-03-16 09:53:44 -0700944 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -0800945
Tyler Gunn9d127732018-03-02 15:45:51 -0800946 /**
947 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
948 * fails for an unknown reason.
949 * <p>
950 * For more information on call handovers, see
951 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
952 */
953 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700954
955 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700956 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
957 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700958 * @param call The {@code Call} invoking this method.
959 * @param state The new state of the {@code Call}.
960 */
961 public void onStateChanged(Call call, int state) {}
962
963 /**
964 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
965 *
966 * @param call The {@code Call} invoking this method.
967 * @param parent The new parent of the {@code Call}.
968 */
969 public void onParentChanged(Call call, Call parent) {}
970
971 /**
972 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
973 *
974 * @param call The {@code Call} invoking this method.
975 * @param children The new children of the {@code Call}.
976 */
977 public void onChildrenChanged(Call call, List<Call> children) {}
978
979 /**
980 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
981 *
982 * @param call The {@code Call} invoking this method.
983 * @param details A {@code Details} object describing the {@code Call}.
984 */
985 public void onDetailsChanged(Call call, Details details) {}
986
987 /**
988 * Invoked when the text messages that can be used as responses to the incoming
989 * {@code Call} are loaded from the relevant database.
990 * See {@link #getCannedTextResponses()}.
991 *
992 * @param call The {@code Call} invoking this method.
993 * @param cannedTextResponses The text messages useable as responses.
994 */
995 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
996
997 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700998 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
999 * character. This causes the post-dial signals to stop pending user confirmation. An
1000 * implementation should present this choice to the user and invoke
1001 * {@link #postDialContinue(boolean)} when the user makes the choice.
1002 *
1003 * @param call The {@code Call} invoking this method.
1004 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1005 */
1006 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1007
1008 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001009 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001010 *
1011 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001012 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001013 */
Andrew Lee50aca232014-07-22 16:41:54 -07001014 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001015
1016 /**
1017 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1018 * up their UI for the {@code Call} in response to state transitions. Specifically,
1019 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1020 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1021 * clients should wait for this method to be invoked.
1022 *
1023 * @param call The {@code Call} being destroyed.
1024 */
1025 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001026
1027 /**
1028 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1029 * conferenced.
1030 *
1031 * @param call The {@code Call} being updated.
1032 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1033 * conferenced.
1034 */
1035 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001036
1037 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001038 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
1039 * <p>
1040 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1041 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1042 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1043 * possible that a {@link ConnectionService} has defined its own Connection events which a
1044 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001045 * <p>
1046 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
1047 *
1048 * @param call The {@code Call} receiving the event.
1049 * @param event The event.
1050 * @param extras Extras associated with the connection event.
1051 */
1052 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001053
1054 /**
1055 * Invoked when the RTT mode changes for this call.
1056 * @param call The call whose RTT mode has changed.
1057 * @param mode the new RTT mode, one of
1058 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1059 * or {@link RttCall#RTT_MODE_VCO}
1060 */
1061 public void onRttModeChanged(Call call, int mode) {}
1062
1063 /**
1064 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1065 * @param call The call whose RTT status has changed.
1066 * @param enabled whether RTT is now enabled or disabled
1067 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1068 * on, null otherwise.
1069 */
1070 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1071
1072 /**
1073 * Invoked when the remote end of the connection has requested that an RTT communication
1074 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1075 * with the same ID that this method is invoked with.
1076 * @param call The call which the RTT request was placed on
1077 * @param id The ID of the request.
1078 */
1079 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001080
1081 /**
1082 * Invoked when the RTT session failed to initiate for some reason, including rejection
1083 * by the remote party.
1084 * @param call The call which the RTT initiation failure occurred on.
1085 * @param reason One of the status codes defined in
1086 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1087 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1088 */
1089 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001090
1091 /**
1092 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1093 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001094 * <p>
1095 * For a full discussion of the handover process and the APIs involved, see
1096 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1097 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001098 * @param call The call which had initiated handover.
1099 */
1100 public void onHandoverComplete(Call call) {}
1101
1102 /**
1103 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1104 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001105 * <p>
1106 * For a full discussion of the handover process and the APIs involved, see
1107 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1108 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001109 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001110 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001111 */
1112 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001113 }
1114
1115 /**
1116 * A class that holds the state that describes the state of the RTT channel to the remote
1117 * party, if it is active.
1118 */
1119 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001120 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001121 @Retention(RetentionPolicy.SOURCE)
1122 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1123 public @interface RttAudioMode {}
1124
1125 /**
1126 * For metrics use. Default value in the proto.
1127 * @hide
1128 */
1129 public static final int RTT_MODE_INVALID = 0;
1130
1131 /**
1132 * Indicates that there should be a bidirectional audio stream between the two parties
1133 * on the call.
1134 */
1135 public static final int RTT_MODE_FULL = 1;
1136
1137 /**
1138 * Indicates that the local user should be able to hear the audio stream from the remote
1139 * user, but not vice versa. Equivalent to muting the microphone.
1140 */
1141 public static final int RTT_MODE_HCO = 2;
1142
1143 /**
1144 * Indicates that the remote user should be able to hear the audio stream from the local
1145 * user, but not vice versa. Equivalent to setting the volume to zero.
1146 */
1147 public static final int RTT_MODE_VCO = 3;
1148
1149 private static final int READ_BUFFER_SIZE = 1000;
1150
1151 private InputStreamReader mReceiveStream;
1152 private OutputStreamWriter mTransmitStream;
1153 private int mRttMode;
1154 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001155 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001156 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1157
1158 /**
1159 * @hide
1160 */
Hall Liu57006aa2017-02-06 10:49:48 -08001161 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1162 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1163 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001164 mReceiveStream = receiveStream;
1165 mTransmitStream = transmitStream;
1166 mRttMode = mode;
1167 mInCallAdapter = inCallAdapter;
1168 }
1169
1170 /**
1171 * Returns the current RTT audio mode.
1172 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1173 * {@link #RTT_MODE_HCO}.
1174 */
1175 public int getRttAudioMode() {
1176 return mRttMode;
1177 }
1178
1179 /**
1180 * Sets the RTT audio mode. The requested mode change will be communicated through
1181 * {@link Callback#onRttModeChanged(Call, int)}.
1182 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1183 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1184 */
1185 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001186 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001187 }
1188
1189 /**
1190 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1191 * RTT transmits text in real-time, this method should be called once for each character
1192 * the user enters into the device.
1193 *
1194 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1195 * lead to interleaved text.
1196 * @param input The message to send to the remote user.
1197 */
1198 public void write(String input) throws IOException {
1199 mTransmitStream.write(input);
1200 mTransmitStream.flush();
1201 }
1202
1203 /**
1204 * Reads a string from the remote user, blocking if there is no data available. Returns
1205 * {@code null} if the RTT conversation has been terminated and there is no further data
1206 * to read.
1207 *
1208 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1209 * lead to interleaved text.
1210 * @return A string containing text sent by the remote user, or {@code null} if the
1211 * conversation has been terminated or if there was an error while reading.
1212 */
Hall Liub1c8a772017-07-17 17:04:41 -07001213 public String read() {
1214 try {
1215 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1216 if (numRead < 0) {
1217 return null;
1218 }
1219 return new String(mReadBuffer, 0, numRead);
1220 } catch (IOException e) {
1221 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001222 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001223 }
Hall Liuffa4a812017-03-02 16:11:00 -08001224 }
1225
1226 /**
1227 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1228 * be read.
1229 * @return A string containing text entered by the user, or {@code null} if the user has
1230 * not entered any new text yet.
1231 */
1232 public String readImmediately() throws IOException {
1233 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001234 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1235 if (numRead < 0) {
1236 return null;
1237 }
1238 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001239 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001240 return null;
1241 }
1242 }
Hall Liue9041242018-02-09 16:40:03 -08001243
1244 /**
1245 * Closes the underlying file descriptors
1246 * @hide
1247 */
1248 public void close() {
1249 try {
1250 mReceiveStream.close();
1251 } catch (IOException e) {
1252 // ignore
1253 }
1254 try {
1255 mTransmitStream.close();
1256 } catch (IOException e) {
1257 // ignore
1258 }
1259 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001260 }
1261
Andrew Leeda80c872015-04-15 14:09:50 -07001262 /**
1263 * @deprecated Use {@code Call.Callback} instead.
1264 * @hide
1265 */
1266 @Deprecated
1267 @SystemApi
1268 public static abstract class Listener extends Callback { }
1269
Ihab Awade63fadb2014-07-09 21:52:04 -07001270 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001271 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001272 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001273 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001274 private final List<Call> mChildren = new ArrayList<>();
1275 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001276 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001277 private final List<Call> mConferenceableCalls = new ArrayList<>();
1278 private final List<Call> mUnmodifiableConferenceableCalls =
1279 Collections.unmodifiableList(mConferenceableCalls);
1280
Santos Cordon823fd3c2014-08-07 18:35:18 -07001281 private boolean mChildrenCached;
1282 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001283 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001284 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001285 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001286 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001287 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001288 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001289 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001290 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001291 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001292
1293 /**
1294 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1295 *
1296 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1297 * remaining or this {@code Call} is not in a post-dial state.
1298 */
1299 public String getRemainingPostDialSequence() {
1300 return mRemainingPostDialSequence;
1301 }
1302
1303 /**
1304 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001305 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001306 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001307 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001308 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001309 }
1310
1311 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301312 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1313 *
1314 * @param address The address to which the call will be deflected.
1315 */
1316 public void deflect(Uri address) {
1317 mInCallAdapter.deflectCall(mTelecomCallId, address);
1318 }
1319
1320 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001321 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1322 *
1323 * @param rejectWithMessage Whether to reject with a text message.
1324 * @param textMessage An optional text message with which to respond.
1325 */
1326 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001327 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001328 }
1329
1330 /**
1331 * Instructs this {@code Call} to disconnect.
1332 */
1333 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001334 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001335 }
1336
1337 /**
1338 * Instructs this {@code Call} to go on hold.
1339 */
1340 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001341 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001342 }
1343
1344 /**
1345 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1346 */
1347 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001348 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001349 }
1350
1351 /**
1352 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1353 *
1354 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1355 *
1356 * @param digit A character representing the DTMF digit for which to play the tone. This
1357 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1358 */
1359 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001360 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001361 }
1362
1363 /**
1364 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1365 * currently playing.
1366 *
1367 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1368 * currently playing, this method will do nothing.
1369 */
1370 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001371 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001372 }
1373
1374 /**
1375 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1376 *
1377 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1378 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001379 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001380 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001381 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1382 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001383 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001384 * {@code Call} will pause playing the tones and notify callbacks via
1385 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001386 * should display to the user an indication of this state and an affordance to continue
1387 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1388 * app should invoke the {@link #postDialContinue(boolean)} method.
1389 *
1390 * @param proceed Whether or not to continue with the post-dial sequence.
1391 */
1392 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001393 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001394 }
1395
1396 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001397 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001398 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001399 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001400 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1401 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001402
1403 }
1404
1405 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001406 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001407 *
1408 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001409 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001410 public void conference(Call callToConferenceWith) {
1411 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001412 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001413 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001414 }
1415
1416 /**
1417 * Instructs this {@code Call} to split from any conference call with which it may be
1418 * connected.
1419 */
1420 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001421 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001422 }
1423
1424 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001425 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001426 */
1427 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001428 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001429 }
1430
1431 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001432 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001433 */
1434 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001435 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001436 }
1437
1438 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001439 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1440 * device.
1441 * <p>
1442 * Calls to this method are ignored if the call does not have the
1443 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1444 * <p>
1445 * An {@link InCallService} will only see calls which support this method if it has the
1446 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1447 * in its manifest.
1448 */
1449 public void pullExternalCall() {
1450 // If this isn't an external call, ignore the request.
1451 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1452 return;
1453 }
1454
1455 mInCallAdapter.pullExternalCall(mTelecomCallId);
1456 }
1457
1458 /**
1459 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1460 * the {@link ConnectionService}.
1461 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001462 * Call events are used to communicate point in time information from an {@link InCallService}
1463 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1464 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1465 * {@link ConnectionService}.
1466 * <p>
1467 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1468 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1469 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001470 * Events are exposed to {@link ConnectionService} implementations via
1471 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1472 * <p>
1473 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001474 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1475 * ignore some events altogether.
1476 * <p>
1477 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1478 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1479 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1480 * they define their own event types in this namespace. When defining a custom event type,
1481 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1482 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1483 * <p>
1484 * When defining events and the associated extras, it is important to keep their behavior
1485 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1486 * events/extras should me maintained to ensure backwards compatibility with older
1487 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001488 *
1489 * @param event The connection event.
1490 * @param extras Bundle containing extra information associated with the event.
1491 */
1492 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001493 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001494 }
1495
1496 /**
Hall Liu95d55872017-01-25 17:12:49 -08001497 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1498 * guaranteed, and notification of success will be via the
1499 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1500 */
1501 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001502 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001503 }
1504
1505 /**
1506 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1507 * callback.
1508 * The ID used here should be the same as the ID that was received via the callback.
1509 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1510 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1511 */
1512 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001513 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001514 }
1515
1516 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001517 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1518 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1519 * handover.
1520 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001521 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1522 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1523 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1524 * is referred to as the source of the handover, and the video calling app is referred to as the
1525 * destination.
1526 * <p>
1527 * When considering a handover scenario the device this method is called on is considered the
1528 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1529 * other device is considered the <em>receiving</em> device.
1530 * <p>
1531 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1532 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1533 * and invoke
1534 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1535 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1536 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1537 * At this point the app should display UI to indicate to the user that a call
1538 * handover is in process.
1539 * <p>
1540 * The destination app is responsible for communicating the handover request from the
1541 * <em>initiating</em> device to the <em>receiving</em> device.
1542 * <p>
1543 * When the app on the <em>receiving</em> device receives the handover request, it calls
1544 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1545 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1546 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1547 * choose whether they want to continue their call in the destination app.
1548 * <p>
1549 * When the destination app on the <em>receiving</em> device calls
1550 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1551 * {@link ConnectionService} and call
1552 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1553 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1554 * {@link Connection} to represent the handover call.
1555 * <p>
1556 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1557 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1558 * original call. If the user rejects the handover, the app calls
1559 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1560 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1561 * <p>
1562 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1563 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1564 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1565 * <p>
1566 * Errors in the handover process are reported to the {@link InCallService} via
1567 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1568 * the involved {@link ConnectionService}s via
1569 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001570 *
1571 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1572 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001573 * @param videoState Indicates the video state desired after the handover (see the
1574 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001575 * @param extras Bundle containing extra information to be passed to the
1576 * {@link ConnectionService}
1577 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001578 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1579 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001580 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1581 }
1582
1583 /**
Hall Liu95d55872017-01-25 17:12:49 -08001584 * Terminate the RTT session on this call. The resulting state change will be notified via
1585 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1586 */
1587 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001588 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001589 }
1590
1591 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001592 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1593 * added.
1594 * <p>
1595 * No assumptions should be made as to how an In-Call UI or service will handle these
1596 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1597 *
1598 * @param extras The extras to add.
1599 */
1600 public final void putExtras(Bundle extras) {
1601 if (extras == null) {
1602 return;
1603 }
1604
1605 if (mExtras == null) {
1606 mExtras = new Bundle();
1607 }
1608 mExtras.putAll(extras);
1609 mInCallAdapter.putExtras(mTelecomCallId, extras);
1610 }
1611
1612 /**
1613 * Adds a boolean extra to this {@link Call}.
1614 *
1615 * @param key The extra key.
1616 * @param value The value.
1617 * @hide
1618 */
1619 public final void putExtra(String key, boolean value) {
1620 if (mExtras == null) {
1621 mExtras = new Bundle();
1622 }
1623 mExtras.putBoolean(key, value);
1624 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1625 }
1626
1627 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001628 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001629 *
1630 * @param key The extra key.
1631 * @param value The value.
1632 * @hide
1633 */
1634 public final void putExtra(String key, int value) {
1635 if (mExtras == null) {
1636 mExtras = new Bundle();
1637 }
1638 mExtras.putInt(key, value);
1639 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1640 }
1641
1642 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001643 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001644 *
1645 * @param key The extra key.
1646 * @param value The value.
1647 * @hide
1648 */
1649 public final void putExtra(String key, String value) {
1650 if (mExtras == null) {
1651 mExtras = new Bundle();
1652 }
1653 mExtras.putString(key, value);
1654 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1655 }
1656
1657 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001658 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001659 *
1660 * @param keys The keys of the extras to remove.
1661 */
1662 public final void removeExtras(List<String> keys) {
1663 if (mExtras != null) {
1664 for (String key : keys) {
1665 mExtras.remove(key);
1666 }
1667 if (mExtras.size() == 0) {
1668 mExtras = null;
1669 }
1670 }
1671 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1672 }
1673
1674 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001675 * Removes extras from this {@link Call}.
1676 *
1677 * @param keys The keys of the extras to remove.
1678 */
1679 public final void removeExtras(String ... keys) {
1680 removeExtras(Arrays.asList(keys));
1681 }
1682
1683 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001684 * Obtains the parent of this {@code Call} in a conference, if any.
1685 *
1686 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1687 * child of any conference {@code Call}s.
1688 */
1689 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001690 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001691 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001692 }
1693 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001694 }
1695
1696 /**
1697 * Obtains the children of this conference {@code Call}, if any.
1698 *
1699 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1700 * {@code List} otherwise.
1701 */
1702 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001703 if (!mChildrenCached) {
1704 mChildrenCached = true;
1705 mChildren.clear();
1706
1707 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001708 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001709 if (call == null) {
1710 // At least one child was still not found, so do not save true for "cached"
1711 mChildrenCached = false;
1712 } else {
1713 mChildren.add(call);
1714 }
1715 }
1716 }
1717
Ihab Awade63fadb2014-07-09 21:52:04 -07001718 return mUnmodifiableChildren;
1719 }
1720
1721 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001722 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1723 *
1724 * @return The list of conferenceable {@code Call}s.
1725 */
1726 public List<Call> getConferenceableCalls() {
1727 return mUnmodifiableConferenceableCalls;
1728 }
1729
1730 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001731 * Obtains the state of this {@code Call}.
1732 *
1733 * @return A state value, chosen from the {@code STATE_*} constants.
1734 */
1735 public int getState() {
1736 return mState;
1737 }
1738
1739 /**
1740 * Obtains a list of canned, pre-configured message responses to present to the user as
1741 * ways of rejecting this {@code Call} using via a text message.
1742 *
1743 * @see #reject(boolean, String)
1744 *
1745 * @return A list of canned text message responses.
1746 */
1747 public List<String> getCannedTextResponses() {
1748 return mCannedTextResponses;
1749 }
1750
1751 /**
1752 * Obtains an object that can be used to display video from this {@code Call}.
1753 *
Andrew Lee50aca232014-07-22 16:41:54 -07001754 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001755 */
Andrew Lee50aca232014-07-22 16:41:54 -07001756 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001757 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001758 }
1759
1760 /**
1761 * Obtains an object containing call details.
1762 *
1763 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1764 * result may be {@code null}.
1765 */
1766 public Details getDetails() {
1767 return mDetails;
1768 }
1769
1770 /**
Hall Liu95d55872017-01-25 17:12:49 -08001771 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1772 * receive RTT text data, as well as to change the RTT mode.
1773 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1774 */
1775 public @Nullable RttCall getRttCall() {
1776 return mRttCall;
1777 }
1778
1779 /**
1780 * Returns whether this call has an active RTT connection.
1781 * @return true if there is a connection, false otherwise.
1782 */
1783 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08001784 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08001785 }
1786
1787 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001788 * Registers a callback to this {@code Call}.
1789 *
1790 * @param callback A {@code Callback}.
1791 */
1792 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001793 registerCallback(callback, new Handler());
1794 }
1795
1796 /**
1797 * Registers a callback to this {@code Call}.
1798 *
1799 * @param callback A {@code Callback}.
1800 * @param handler A handler which command and status changes will be delivered to.
1801 */
1802 public void registerCallback(Callback callback, Handler handler) {
1803 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001804 // Don't allow new callback registration if the call is already being destroyed.
1805 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001806 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1807 }
Andrew Leeda80c872015-04-15 14:09:50 -07001808 }
1809
1810 /**
1811 * Unregisters a callback from this {@code Call}.
1812 *
1813 * @param callback A {@code Callback}.
1814 */
1815 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001816 // Don't allow callback deregistration if the call is already being destroyed.
1817 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001818 for (CallbackRecord<Callback> record : mCallbackRecords) {
1819 if (record.getCallback() == callback) {
1820 mCallbackRecords.remove(record);
1821 break;
1822 }
1823 }
Andrew Leeda80c872015-04-15 14:09:50 -07001824 }
1825 }
1826
Santos Cordon3c20d632016-02-25 16:12:35 -08001827 @Override
1828 public String toString() {
1829 return new StringBuilder().
1830 append("Call [id: ").
1831 append(mTelecomCallId).
1832 append(", state: ").
1833 append(stateToString(mState)).
1834 append(", details: ").
1835 append(mDetails).
1836 append("]").toString();
1837 }
1838
1839 /**
1840 * @param state An integer value of a {@code STATE_*} constant.
1841 * @return A string representation of the value.
1842 */
1843 private static String stateToString(int state) {
1844 switch (state) {
1845 case STATE_NEW:
1846 return "NEW";
1847 case STATE_RINGING:
1848 return "RINGING";
1849 case STATE_DIALING:
1850 return "DIALING";
1851 case STATE_ACTIVE:
1852 return "ACTIVE";
1853 case STATE_HOLDING:
1854 return "HOLDING";
1855 case STATE_DISCONNECTED:
1856 return "DISCONNECTED";
1857 case STATE_CONNECTING:
1858 return "CONNECTING";
1859 case STATE_DISCONNECTING:
1860 return "DISCONNECTING";
1861 case STATE_SELECT_PHONE_ACCOUNT:
1862 return "SELECT_PHONE_ACCOUNT";
1863 default:
1864 Log.w(Call.class, "Unknown state %d", state);
1865 return "UNKNOWN";
1866 }
1867 }
1868
Andrew Leeda80c872015-04-15 14:09:50 -07001869 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001870 * Adds a listener to this {@code Call}.
1871 *
1872 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001873 * @deprecated Use {@link #registerCallback} instead.
1874 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001875 */
Andrew Leeda80c872015-04-15 14:09:50 -07001876 @Deprecated
1877 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001878 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001879 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001880 }
1881
1882 /**
1883 * Removes a listener from this {@code Call}.
1884 *
1885 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001886 * @deprecated Use {@link #unregisterCallback} instead.
1887 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001888 */
Andrew Leeda80c872015-04-15 14:09:50 -07001889 @Deprecated
1890 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001891 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001892 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001893 }
1894
1895 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001896 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1897 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001898 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001899 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001900 mInCallAdapter = inCallAdapter;
1901 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001902 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001903 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001904 }
1905
1906 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001907 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001908 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001909 mPhone = phone;
1910 mTelecomCallId = telecomCallId;
1911 mInCallAdapter = inCallAdapter;
1912 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001913 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001914 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001915 }
1916
1917 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001918 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001919 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001920 }
1921
1922 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001923 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001924
Ihab Awade63fadb2014-07-09 21:52:04 -07001925 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001926 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001927 boolean detailsChanged = !Objects.equals(mDetails, details);
1928 if (detailsChanged) {
1929 mDetails = details;
1930 }
1931
1932 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001933 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1934 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1935 mCannedTextResponses =
1936 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001937 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001938 }
1939
Tyler Gunn159f35c2017-03-02 09:28:37 -08001940 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1941 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001942 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001943 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001944 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001945 mVideoCallImpl = newVideoCallImpl;
1946 }
1947 if (mVideoCallImpl != null) {
1948 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001949 }
1950
Santos Cordone3c507b2015-04-23 14:44:19 -07001951 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001952 boolean stateChanged = mState != state;
1953 if (stateChanged) {
1954 mState = state;
1955 }
1956
Santos Cordon823fd3c2014-08-07 18:35:18 -07001957 String parentId = parcelableCall.getParentCallId();
1958 boolean parentChanged = !Objects.equals(mParentId, parentId);
1959 if (parentChanged) {
1960 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001961 }
1962
Santos Cordon823fd3c2014-08-07 18:35:18 -07001963 List<String> childCallIds = parcelableCall.getChildCallIds();
1964 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1965 if (childrenChanged) {
1966 mChildrenIds.clear();
1967 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1968 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001969 }
1970
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001971 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1972 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1973 for (String otherId : conferenceableCallIds) {
1974 if (callIdMap.containsKey(otherId)) {
1975 conferenceableCalls.add(callIdMap.get(otherId));
1976 }
1977 }
1978
1979 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1980 mConferenceableCalls.clear();
1981 mConferenceableCalls.addAll(conferenceableCalls);
1982 fireConferenceableCallsChanged();
1983 }
1984
Hall Liu95d55872017-01-25 17:12:49 -08001985 boolean isRttChanged = false;
1986 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08001987 if (parcelableCall.getIsRttCallChanged()
1988 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08001989 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1990 InputStreamReader receiveStream = new InputStreamReader(
1991 new ParcelFileDescriptor.AutoCloseInputStream(
1992 parcelableRttCall.getReceiveStream()),
1993 StandardCharsets.UTF_8);
1994 OutputStreamWriter transmitStream = new OutputStreamWriter(
1995 new ParcelFileDescriptor.AutoCloseOutputStream(
1996 parcelableRttCall.getTransmitStream()),
1997 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08001998 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08001999 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2000 if (mRttCall == null) {
2001 isRttChanged = true;
2002 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2003 rttModeChanged = true;
2004 }
2005 mRttCall = newRttCall;
2006 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2007 && parcelableCall.getIsRttCallChanged()) {
2008 isRttChanged = true;
2009 mRttCall = null;
2010 }
2011
Ihab Awade63fadb2014-07-09 21:52:04 -07002012 // Now we fire updates, ensuring that any client who listens to any of these notifications
2013 // gets the most up-to-date state.
2014
2015 if (stateChanged) {
2016 fireStateChanged(mState);
2017 }
2018 if (detailsChanged) {
2019 fireDetailsChanged(mDetails);
2020 }
2021 if (cannedTextResponsesChanged) {
2022 fireCannedTextResponsesLoaded(mCannedTextResponses);
2023 }
Andrew Lee50aca232014-07-22 16:41:54 -07002024 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002025 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002026 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002027 if (parentChanged) {
2028 fireParentChanged(getParent());
2029 }
2030 if (childrenChanged) {
2031 fireChildrenChanged(getChildren());
2032 }
Hall Liu95d55872017-01-25 17:12:49 -08002033 if (isRttChanged) {
2034 fireOnIsRttChanged(mRttCall != null, mRttCall);
2035 }
2036 if (rttModeChanged) {
2037 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2038 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002039
2040 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2041 // remove ourselves from the Phone. Note that we do this after completing all state updates
2042 // so a client can cleanly transition all their UI to the state appropriate for a
2043 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2044 if (mState == STATE_DISCONNECTED) {
2045 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002046 }
2047 }
2048
2049 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002050 final void internalSetPostDialWait(String remaining) {
2051 mRemainingPostDialSequence = remaining;
2052 firePostDialWait(mRemainingPostDialSequence);
2053 }
2054
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002055 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002056 final void internalSetDisconnected() {
2057 if (mState != Call.STATE_DISCONNECTED) {
2058 mState = Call.STATE_DISCONNECTED;
2059 fireStateChanged(mState);
2060 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002061 }
2062 }
2063
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002064 /** {@hide} */
2065 final void internalOnConnectionEvent(String event, Bundle extras) {
2066 fireOnConnectionEvent(event, extras);
2067 }
2068
Hall Liu95d55872017-01-25 17:12:49 -08002069 /** {@hide} */
2070 final void internalOnRttUpgradeRequest(final int requestId) {
2071 for (CallbackRecord<Callback> record : mCallbackRecords) {
2072 final Call call = this;
2073 final Callback callback = record.getCallback();
2074 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2075 }
2076 }
2077
Hall Liu57006aa2017-02-06 10:49:48 -08002078 /** @hide */
2079 final void internalOnRttInitiationFailure(int reason) {
2080 for (CallbackRecord<Callback> record : mCallbackRecords) {
2081 final Call call = this;
2082 final Callback callback = record.getCallback();
2083 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2084 }
2085 }
2086
Sanket Padawe85291f62017-12-01 13:59:27 -08002087 /** {@hide} */
2088 final void internalOnHandoverFailed(int error) {
2089 for (CallbackRecord<Callback> record : mCallbackRecords) {
2090 final Call call = this;
2091 final Callback callback = record.getCallback();
2092 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2093 }
2094 }
2095
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002096 /** {@hide} */
2097 final void internalOnHandoverComplete() {
2098 for (CallbackRecord<Callback> record : mCallbackRecords) {
2099 final Call call = this;
2100 final Callback callback = record.getCallback();
2101 record.getHandler().post(() -> callback.onHandoverComplete(call));
2102 }
2103 }
2104
Andrew Lee011728f2015-04-23 15:47:06 -07002105 private void fireStateChanged(final int newState) {
2106 for (CallbackRecord<Callback> record : mCallbackRecords) {
2107 final Call call = this;
2108 final Callback callback = record.getCallback();
2109 record.getHandler().post(new Runnable() {
2110 @Override
2111 public void run() {
2112 callback.onStateChanged(call, newState);
2113 }
2114 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002115 }
2116 }
2117
Andrew Lee011728f2015-04-23 15:47:06 -07002118 private void fireParentChanged(final Call newParent) {
2119 for (CallbackRecord<Callback> record : mCallbackRecords) {
2120 final Call call = this;
2121 final Callback callback = record.getCallback();
2122 record.getHandler().post(new Runnable() {
2123 @Override
2124 public void run() {
2125 callback.onParentChanged(call, newParent);
2126 }
2127 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002128 }
2129 }
2130
Andrew Lee011728f2015-04-23 15:47:06 -07002131 private void fireChildrenChanged(final List<Call> children) {
2132 for (CallbackRecord<Callback> record : mCallbackRecords) {
2133 final Call call = this;
2134 final Callback callback = record.getCallback();
2135 record.getHandler().post(new Runnable() {
2136 @Override
2137 public void run() {
2138 callback.onChildrenChanged(call, children);
2139 }
2140 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002141 }
2142 }
2143
Andrew Lee011728f2015-04-23 15:47:06 -07002144 private void fireDetailsChanged(final Details details) {
2145 for (CallbackRecord<Callback> record : mCallbackRecords) {
2146 final Call call = this;
2147 final Callback callback = record.getCallback();
2148 record.getHandler().post(new Runnable() {
2149 @Override
2150 public void run() {
2151 callback.onDetailsChanged(call, details);
2152 }
2153 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002154 }
2155 }
2156
Andrew Lee011728f2015-04-23 15:47:06 -07002157 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2158 for (CallbackRecord<Callback> record : mCallbackRecords) {
2159 final Call call = this;
2160 final Callback callback = record.getCallback();
2161 record.getHandler().post(new Runnable() {
2162 @Override
2163 public void run() {
2164 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2165 }
2166 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002167 }
2168 }
2169
Andrew Lee011728f2015-04-23 15:47:06 -07002170 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2171 for (CallbackRecord<Callback> record : mCallbackRecords) {
2172 final Call call = this;
2173 final Callback callback = record.getCallback();
2174 record.getHandler().post(new Runnable() {
2175 @Override
2176 public void run() {
2177 callback.onVideoCallChanged(call, videoCall);
2178 }
2179 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002180 }
2181 }
2182
Andrew Lee011728f2015-04-23 15:47:06 -07002183 private void firePostDialWait(final String remainingPostDialSequence) {
2184 for (CallbackRecord<Callback> record : mCallbackRecords) {
2185 final Call call = this;
2186 final Callback callback = record.getCallback();
2187 record.getHandler().post(new Runnable() {
2188 @Override
2189 public void run() {
2190 callback.onPostDialWait(call, remainingPostDialSequence);
2191 }
2192 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002193 }
2194 }
2195
2196 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002197 /**
2198 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2199 * onCallRemoved callback, we remove this call from the Phone's record
2200 * only once all of the registered onCallDestroyed callbacks are executed.
2201 * All the callbacks get removed from our records as a part of this operation
2202 * since onCallDestroyed is the final callback.
2203 */
2204 final Call call = this;
2205 if (mCallbackRecords.isEmpty()) {
2206 // No callbacks registered, remove the call from Phone's record.
2207 mPhone.internalRemoveCall(call);
2208 }
2209 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002210 final Callback callback = record.getCallback();
2211 record.getHandler().post(new Runnable() {
2212 @Override
2213 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002214 boolean isFinalRemoval = false;
2215 RuntimeException toThrow = null;
2216 try {
2217 callback.onCallDestroyed(call);
2218 } catch (RuntimeException e) {
2219 toThrow = e;
2220 }
2221 synchronized(Call.this) {
2222 mCallbackRecords.remove(record);
2223 if (mCallbackRecords.isEmpty()) {
2224 isFinalRemoval = true;
2225 }
2226 }
2227 if (isFinalRemoval) {
2228 mPhone.internalRemoveCall(call);
2229 }
2230 if (toThrow != null) {
2231 throw toThrow;
2232 }
Andrew Lee011728f2015-04-23 15:47:06 -07002233 }
2234 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002235 }
2236 }
2237
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002238 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002239 for (CallbackRecord<Callback> record : mCallbackRecords) {
2240 final Call call = this;
2241 final Callback callback = record.getCallback();
2242 record.getHandler().post(new Runnable() {
2243 @Override
2244 public void run() {
2245 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2246 }
2247 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002248 }
2249 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002250
2251 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002252 * Notifies listeners of an incoming connection event.
2253 * <p>
2254 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2255 *
2256 * @param event
2257 * @param extras
2258 */
2259 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2260 for (CallbackRecord<Callback> record : mCallbackRecords) {
2261 final Call call = this;
2262 final Callback callback = record.getCallback();
2263 record.getHandler().post(new Runnable() {
2264 @Override
2265 public void run() {
2266 callback.onConnectionEvent(call, event, extras);
2267 }
2268 });
2269 }
2270 }
2271
2272 /**
Hall Liu95d55872017-01-25 17:12:49 -08002273 * Notifies listeners of an RTT on/off change
2274 *
2275 * @param enabled True if RTT is now enabled, false otherwise
2276 */
2277 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2278 for (CallbackRecord<Callback> record : mCallbackRecords) {
2279 final Call call = this;
2280 final Callback callback = record.getCallback();
2281 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2282 }
2283 }
2284
2285 /**
2286 * Notifies listeners of a RTT mode change
2287 *
2288 * @param mode The new RTT mode
2289 */
2290 private void fireOnRttModeChanged(final int mode) {
2291 for (CallbackRecord<Callback> record : mCallbackRecords) {
2292 final Call call = this;
2293 final Callback callback = record.getCallback();
2294 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2295 }
2296 }
2297
2298 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002299 * Determines if two bundles are equal.
2300 *
2301 * @param bundle The original bundle.
2302 * @param newBundle The bundle to compare with.
2303 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2304 */
2305 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2306 if (bundle == null || newBundle == null) {
2307 return bundle == newBundle;
2308 }
2309
2310 if (bundle.size() != newBundle.size()) {
2311 return false;
2312 }
2313
2314 for(String key : bundle.keySet()) {
2315 if (key != null) {
2316 final Object value = bundle.get(key);
2317 final Object newValue = newBundle.get(key);
2318 if (!Objects.equals(value, newValue)) {
2319 return false;
2320 }
2321 }
2322 }
2323 return true;
2324 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002325}