blob: 36d0188048c30e7093c484bea85cc221a5be13c3 [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;
Tyler Gunn6e3ecc42018-11-12 11:30:56 -080024import android.os.Build;
Nancy Chen10798dc2014-08-08 14:00:25 -070025import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070026import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080027import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070028
Hall Liu95d55872017-01-25 17:12:49 -080029import java.io.IOException;
30import java.io.InputStreamReader;
31import java.io.OutputStreamWriter;
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.
Hall Liu34d9e242018-11-21 17:05:58 -0800125 * @deprecated Use the list from {@link #EXTRA_SUGGESTED_PHONE_ACCOUNTS} instead.
Nancy Chen513c8922014-09-17 14:47:20 -0700126 */
Hall Liu34d9e242018-11-21 17:05:58 -0800127 @Deprecated
Nancy Chen513c8922014-09-17 14:47:20 -0700128 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
129
mike dooley4af561f2016-12-20 08:55:17 -0800130 /**
Hall Liu34d9e242018-11-21 17:05:58 -0800131 * Key for extra used to pass along a list of {@link PhoneAccountSuggestion}s to the in-call
132 * UI when a call enters the {@link #STATE_SELECT_PHONE_ACCOUNT} state. The list included here
133 * will have the same length and be in the same order as the list passed with
134 * {@link #AVAILABLE_PHONE_ACCOUNTS}.
135 */
136 public static final String EXTRA_SUGGESTED_PHONE_ACCOUNTS =
137 "android.telecom.extra.SUGGESTED_PHONE_ACCOUNTS";
138
139 /**
mike dooley91217422017-03-09 12:58:42 -0800140 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
141 * when the last outgoing emergency call was made. This is used to identify potential emergency
142 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800143 */
144 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
145 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
146
Tyler Gunn8bf76572017-04-06 15:30:08 -0700147 /**
148 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
149 * Telecom that the user has requested that the current {@link Call} should be handed over
150 * to another {@link ConnectionService}.
151 * <p>
152 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
153 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
154 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700155 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
156 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700157 */
158 public static final String EVENT_REQUEST_HANDOVER =
159 "android.telecom.event.REQUEST_HANDOVER";
160
161 /**
162 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
163 * {@link PhoneAccountHandle} to which a call should be handed over to.
164 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700165 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
166 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700167 */
168 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
169 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
170
171 /**
172 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
173 * video state of the call when it is handed over to the new {@link PhoneAccount}.
174 * <p>
175 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
176 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
177 * {@link VideoProfile#STATE_TX_ENABLED}.
178 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700179 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
180 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700181 */
182 public static final String EXTRA_HANDOVER_VIDEO_STATE =
183 "android.telecom.extra.HANDOVER_VIDEO_STATE";
184
185 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700186 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
187 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
188 * information to the handover {@link ConnectionService} specified by
189 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
190 * <p>
191 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
192 * {@link ConnectionService} via the request extras when
193 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
194 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700195 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700196 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
197 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700198 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700199 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700200
201 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700202 * Call event sent from Telecom to the handover {@link ConnectionService} via
203 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
204 * to the {@link ConnectionService} has completed successfully.
205 * <p>
206 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700207 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700208 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
209 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700210 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700211 public static final String EVENT_HANDOVER_COMPLETE =
212 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700213
214 /**
215 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
216 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
217 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
218 * {@code null}.
219 * <p>
220 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
221 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700222 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
223 * APIs instead.
Tyler Gunn34a2b312017-06-23 08:32:00 -0700224 */
225 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
226 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
227
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700228 /**
229 * Call event sent from Telecom to the handover {@link ConnectionService} via
230 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
231 * to the {@link ConnectionService} has failed.
232 * <p>
233 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
234 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700235 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
236 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700237 */
238 public static final String EVENT_HANDOVER_FAILED =
239 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700240
Ihab Awade63fadb2014-07-09 21:52:04 -0700241 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800242
243 /** Call can currently be put on hold or unheld. */
244 public static final int CAPABILITY_HOLD = 0x00000001;
245
246 /** Call supports the hold feature. */
247 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
248
249 /**
250 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
251 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
252 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
253 * capability allows a merge button to be shown while the conference call is in the foreground
254 * of the in-call UI.
255 * <p>
256 * This is only intended for use by a {@link Conference}.
257 */
258 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
259
260 /**
261 * Calls within a conference can be swapped between foreground and background.
262 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
263 * <p>
264 * This is only intended for use by a {@link Conference}.
265 */
266 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
267
268 /**
269 * @hide
270 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700271 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800272
273 /** Call supports responding via text option. */
274 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
275
276 /** Call can be muted. */
277 public static final int CAPABILITY_MUTE = 0x00000040;
278
279 /**
280 * Call supports conference call management. This capability only applies to {@link Conference}
281 * calls which can have {@link Connection}s as children.
282 */
283 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
284
285 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700286 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800287 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700288 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800289
290 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700291 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800292 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700293 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800294
295 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700296 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800297 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700298 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700299 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800300
301 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700302 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800303 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700304 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
305
306 /**
307 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700308 */
309 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
310
311 /**
312 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700313 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700314 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700315 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800316
317 /**
318 * Call is able to be separated from its parent {@code Conference}, if any.
319 */
320 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
321
322 /**
323 * Call is able to be individually disconnected when in a {@code Conference}.
324 */
325 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
326
327 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500328 * Speed up audio setup for MT call.
329 * @hide
330 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700331 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
332
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700333 /**
334 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700335 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800336 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
337 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
338 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700339 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800340 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700341 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
342
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700343 /**
344 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700345 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700346 */
347 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
348
Bryce Lee81901682015-08-28 16:38:02 -0700349 /**
350 * Call sends responses through connection.
351 * @hide
352 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800353 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
354
355 /**
356 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
357 * <p>
358 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
359 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
360 * downgraded from a video call back to a VideoState of
361 * {@link VideoProfile#STATE_AUDIO_ONLY}.
362 * <p>
363 * Intuitively, a call which can be downgraded to audio should also have local and remote
364 * video
365 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
366 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
367 */
368 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700369
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700370 /**
371 * When set for an external call, indicates that this {@code Call} can be pulled from a
372 * remote device to the current device.
373 * <p>
374 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
375 * <p>
376 * An {@link InCallService} will only see calls with this capability if it has the
377 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
378 * in its manifest.
379 * <p>
380 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700381 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700382 */
383 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
384
Pooja Jaind34698d2017-12-28 14:15:31 +0530385 /** Call supports the deflect feature. */
386 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
387
Tyler Gunnd11a3152015-03-18 13:09:14 -0700388 //******************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530389 // Next CAPABILITY value: 0x02000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700390 //******************************************************************************************
391
392 /**
393 * Whether the call is currently a conference.
394 */
395 public static final int PROPERTY_CONFERENCE = 0x00000001;
396
397 /**
398 * Whether the call is a generic conference, where we do not know the precise state of
399 * participants in the conference (eg. on CDMA).
400 */
401 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
402
403 /**
404 * Whether the call is made while the device is in emergency callback mode.
405 */
406 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
407
408 /**
409 * Connection is using WIFI.
410 */
411 public static final int PROPERTY_WIFI = 0x00000008;
412
413 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700414 * When set, the UI should indicate to the user that a call is using high definition
415 * audio.
416 * <p>
417 * The underlying {@link ConnectionService} is responsible for reporting this
418 * property. It is important to note that this property is not intended to report the
419 * actual audio codec being used for a Call, but whether the call should be indicated
420 * to the user as high definition.
421 * <p>
422 * The Android Telephony stack reports this property for calls based on a number
423 * of factors, including which audio codec is used and whether a call is using an HD
424 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
425 * and in these cases this property will not be set for a call even if the underlying audio
426 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700427 */
428 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
429
Tony Maka68dcce2015-12-17 09:31:18 +0000430 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100431 * Whether the call is associated with the work profile.
432 */
433 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
434
435 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700436 * When set, indicates that this {@code Call} does not actually exist locally for the
437 * {@link ConnectionService}.
438 * <p>
439 * Consider, for example, a scenario where a user has two phones with the same phone number.
440 * When a user places a call on one device, the telephony stack can represent that call on
441 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700442 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700443 * <p>
444 * An {@link InCallService} will only see calls with this property if it has the
445 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
446 * in its manifest.
447 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700448 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700449 */
450 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
451
Brad Ebinger15847072016-05-18 11:08:36 -0700452 /**
453 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
454 */
455 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
456
Tyler Gunn24e18332017-02-10 09:42:49 -0800457 /**
458 * Indicates that the call is from a self-managed {@link ConnectionService}.
459 * <p>
460 * See also {@link Connection#PROPERTY_SELF_MANAGED}
461 */
462 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
463
Eric Erfanianec881872017-12-06 16:27:53 -0800464 /**
465 * Indicates the call used Assisted Dialing.
466 * See also {@link Connection#PROPERTY_ASSISTED_DIALING_USED}
467 * @hide
468 */
469 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
470
Hall Liue9041242018-02-09 16:40:03 -0800471 /**
472 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
473 * {@link RttCall} object that is used to send and receive text.
474 */
475 public static final int PROPERTY_RTT = 0x00000400;
476
Tyler Gunn5bd90852018-09-21 09:37:07 -0700477 /**
478 * Indicates that the call has been identified as the network as an emergency call. This
479 * property may be set for both incoming and outgoing calls which the network identifies as
480 * emergency calls.
481 */
482 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
483
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700484 /**
485 * Indicates that the call is using VoIP audio mode.
486 * <p>
487 * When this property is set, the {@link android.media.AudioManager} audio mode for this
488 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
489 * property is not set, the audio mode for this call will be
490 * {@link android.media.AudioManager#MODE_IN_CALL}.
491 * <p>
492 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
493 * <p>
494 * You can use this property to determine whether an un-answered incoming call or a held
495 * call will use VoIP audio mode (if the call does not currently have focus, the system
496 * audio mode may not reflect the mode the call will use).
497 */
498 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
499
Andrew Lee2378ea72015-04-29 14:38:11 -0700500 //******************************************************************************************
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700501 // Next PROPERTY value: 0x00002000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700502 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800503
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800504 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700505 private final Uri mHandle;
506 private final int mHandlePresentation;
507 private final String mCallerDisplayName;
508 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700509 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700510 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700511 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800512 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700513 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700514 private final long mConnectTimeMillis;
515 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700516 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700517 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700518 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700519 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700520 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700521
522 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800523 * Whether the supplied capabilities supports the specified capability.
524 *
525 * @param capabilities A bit field of capabilities.
526 * @param capability The capability to check capabilities for.
527 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800528 */
529 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800530 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800531 }
532
533 /**
534 * Whether the capabilities of this {@code Details} supports the specified capability.
535 *
536 * @param capability The capability to check capabilities for.
537 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800538 */
539 public boolean can(int capability) {
540 return can(mCallCapabilities, capability);
541 }
542
543 /**
544 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
545 *
546 * @param capabilities A capability bit field.
547 * @return A human readable string representation.
548 */
549 public static String capabilitiesToString(int capabilities) {
550 StringBuilder builder = new StringBuilder();
551 builder.append("[Capabilities:");
552 if (can(capabilities, CAPABILITY_HOLD)) {
553 builder.append(" CAPABILITY_HOLD");
554 }
555 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
556 builder.append(" CAPABILITY_SUPPORT_HOLD");
557 }
558 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
559 builder.append(" CAPABILITY_MERGE_CONFERENCE");
560 }
561 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
562 builder.append(" CAPABILITY_SWAP_CONFERENCE");
563 }
564 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
565 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
566 }
567 if (can(capabilities, CAPABILITY_MUTE)) {
568 builder.append(" CAPABILITY_MUTE");
569 }
570 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
571 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
572 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700573 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
574 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
575 }
576 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
577 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
578 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700579 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
580 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800581 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700582 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
583 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
584 }
585 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
586 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
587 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800588 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
589 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
590 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700591 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
592 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800593 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500594 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700595 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500596 }
Rekha Kumar07366812015-03-24 16:42:31 -0700597 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
598 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
599 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700600 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
601 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
602 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700603 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
604 builder.append(" CAPABILITY_CAN_PULL_CALL");
605 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530606 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
607 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
608 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800609 builder.append("]");
610 return builder.toString();
611 }
612
613 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700614 * Whether the supplied properties includes the specified property.
615 *
616 * @param properties A bit field of properties.
617 * @param property The property to check properties for.
618 * @return Whether the specified property is supported.
619 */
620 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800621 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700622 }
623
624 /**
625 * Whether the properties of this {@code Details} includes the specified property.
626 *
627 * @param property The property to check properties for.
628 * @return Whether the specified property is supported.
629 */
630 public boolean hasProperty(int property) {
631 return hasProperty(mCallProperties, property);
632 }
633
634 /**
635 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
636 *
637 * @param properties A property bit field.
638 * @return A human readable string representation.
639 */
640 public static String propertiesToString(int properties) {
641 StringBuilder builder = new StringBuilder();
642 builder.append("[Properties:");
643 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
644 builder.append(" PROPERTY_CONFERENCE");
645 }
646 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
647 builder.append(" PROPERTY_GENERIC_CONFERENCE");
648 }
649 if (hasProperty(properties, PROPERTY_WIFI)) {
650 builder.append(" PROPERTY_WIFI");
651 }
652 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
653 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
654 }
655 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700656 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700657 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700658 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
659 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
660 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700661 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700662 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
663 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700664 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800665 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
666 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700667 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
668 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
669 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700670 if (hasProperty(properties, PROPERTY_RTT)) {
671 builder.append(" PROPERTY_RTT");
672 }
673 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
674 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
675 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700676 builder.append("]");
677 return builder.toString();
678 }
679
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800680 /** {@hide} */
681 public String getTelecomCallId() {
682 return mTelecomCallId;
683 }
684
Andrew Lee2378ea72015-04-29 14:38:11 -0700685 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700686 * @return The handle (e.g., phone number) to which the {@code Call} is currently
687 * connected.
688 */
689 public Uri getHandle() {
690 return mHandle;
691 }
692
693 /**
694 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700695 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700696 */
697 public int getHandlePresentation() {
698 return mHandlePresentation;
699 }
700
701 /**
702 * @return The display name for the caller.
703 */
704 public String getCallerDisplayName() {
705 return mCallerDisplayName;
706 }
707
708 /**
709 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700710 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700711 */
712 public int getCallerDisplayNamePresentation() {
713 return mCallerDisplayNamePresentation;
714 }
715
716 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700717 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
718 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700719 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700720 public PhoneAccountHandle getAccountHandle() {
721 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700722 }
723
724 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800725 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
726 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700727 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700728 public int getCallCapabilities() {
729 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700730 }
731
732 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700733 * @return A bitmask of the properties of the {@code Call}, as defined by the various
734 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700735 */
736 public int getCallProperties() {
737 return mCallProperties;
738 }
739
740 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800741 * @return a bitmask of the audio routes available for the call.
742 *
743 * @hide
744 */
745 public int getSupportedAudioRoutes() {
746 return mSupportedAudioRoutes;
747 }
748
749 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700750 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700751 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700752 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700753 public DisconnectCause getDisconnectCause() {
754 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700755 }
756
757 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700758 * Returns the time the {@link Call} connected (i.e. became active). This information is
759 * updated periodically, but user interfaces should not rely on this to display the "call
760 * time clock". For the time when the call was first added to Telecom, see
761 * {@link #getCreationTimeMillis()}.
762 *
763 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700764 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700765 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700766 return mConnectTimeMillis;
767 }
768
769 /**
770 * @return Information about any calling gateway the {@code Call} may be using.
771 */
772 public GatewayInfo getGatewayInfo() {
773 return mGatewayInfo;
774 }
775
Andrew Lee7a341382014-07-15 17:05:08 -0700776 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700777 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700778 */
779 public int getVideoState() {
780 return mVideoState;
781 }
782
Ihab Awad5d0410f2014-07-30 10:07:40 -0700783 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700784 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700785 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700786 */
787 public StatusHints getStatusHints() {
788 return mStatusHints;
789 }
790
Nancy Chen10798dc2014-08-08 14:00:25 -0700791 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700792 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700793 */
794 public Bundle getExtras() {
795 return mExtras;
796 }
797
Santos Cordon6b7f9552015-05-27 17:21:45 -0700798 /**
799 * @return The extras used with the original intent to place this call.
800 */
801 public Bundle getIntentExtras() {
802 return mIntentExtras;
803 }
804
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700805 /**
806 * Returns the time when the call was first created and added to Telecom. This is the same
807 * time that is logged as the start time in the Call Log (see
808 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
809 * (became active), see {@link #getConnectTimeMillis()}.
810 *
811 * @return The creation time of the call, in millis since the epoch.
812 */
813 public long getCreationTimeMillis() {
814 return mCreationTimeMillis;
815 }
816
Ihab Awade63fadb2014-07-09 21:52:04 -0700817 @Override
818 public boolean equals(Object o) {
819 if (o instanceof Details) {
820 Details d = (Details) o;
821 return
822 Objects.equals(mHandle, d.mHandle) &&
823 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
824 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
825 Objects.equals(mCallerDisplayNamePresentation,
826 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700827 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700828 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700829 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700830 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700831 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700832 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700833 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700834 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700835 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700836 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
837 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700838 }
839 return false;
840 }
841
842 @Override
843 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700844 return Objects.hash(mHandle,
845 mHandlePresentation,
846 mCallerDisplayName,
847 mCallerDisplayNamePresentation,
848 mAccountHandle,
849 mCallCapabilities,
850 mCallProperties,
851 mDisconnectCause,
852 mConnectTimeMillis,
853 mGatewayInfo,
854 mVideoState,
855 mStatusHints,
856 mExtras,
857 mIntentExtras,
858 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700859 }
860
861 /** {@hide} */
862 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800863 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700864 Uri handle,
865 int handlePresentation,
866 String callerDisplayName,
867 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700868 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700869 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700870 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700871 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700872 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700873 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700874 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700875 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700876 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700877 Bundle intentExtras,
878 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800879 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700880 mHandle = handle;
881 mHandlePresentation = handlePresentation;
882 mCallerDisplayName = callerDisplayName;
883 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700884 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700885 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700886 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700887 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700888 mConnectTimeMillis = connectTimeMillis;
889 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700890 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700891 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700892 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700893 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700894 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700895 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800896
897 /** {@hide} */
898 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
899 return new Details(
900 parcelableCall.getId(),
901 parcelableCall.getHandle(),
902 parcelableCall.getHandlePresentation(),
903 parcelableCall.getCallerDisplayName(),
904 parcelableCall.getCallerDisplayNamePresentation(),
905 parcelableCall.getAccountHandle(),
906 parcelableCall.getCapabilities(),
907 parcelableCall.getProperties(),
908 parcelableCall.getDisconnectCause(),
909 parcelableCall.getConnectTimeMillis(),
910 parcelableCall.getGatewayInfo(),
911 parcelableCall.getVideoState(),
912 parcelableCall.getStatusHints(),
913 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700914 parcelableCall.getIntentExtras(),
915 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800916 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800917
918 @Override
919 public String toString() {
920 StringBuilder sb = new StringBuilder();
Tyler Gunne0caec72018-11-30 14:21:18 -0800921 sb.append("[id: ");
922 sb.append(mTelecomCallId);
923 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -0800924 sb.append(mAccountHandle);
925 sb.append(", hdl: ");
Tyler Gunne0caec72018-11-30 14:21:18 -0800926 sb.append(Log.piiHandle(mHandle));
927 sb.append(", hdlPres: ");
928 sb.append(mHandlePresentation);
929 sb.append(", videoState: ");
930 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -0800931 sb.append(", caps: ");
932 sb.append(capabilitiesToString(mCallCapabilities));
933 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700934 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800935 sb.append("]");
936 return sb.toString();
937 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700938 }
939
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700940 /**
941 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
942 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
943 * implementation.
944 * <p>
945 * You can handle these callbacks by extending the {@link Callback} class and overriding the
946 * callbacks that your {@link InCallService} is interested in. The callback methods include the
947 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
948 * {@link Callback} implementation, if desired.
949 * <p>
950 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
951 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
952 * (typically in {@link InCallService#onCallRemoved(Call)}).
953 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
954 * reach your implementation of {@link Callback}, so it is important to register your callback
955 * as soon as your {@link InCallService} is notified of a new call via
956 * {@link InCallService#onCallAdded(Call)}.
957 */
Andrew Leeda80c872015-04-15 14:09:50 -0700958 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700959 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -0700960 * @hide
961 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800962 @IntDef(prefix = { "HANDOVER_" },
963 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -0700964 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -0800965 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -0700966 @Retention(RetentionPolicy.SOURCE)
967 public @interface HandoverFailureErrors {}
968
969 /**
970 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -0800971 * to handover the call to rejects the handover request.
972 * <p>
973 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
974 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
975 * {@code null} {@link Connection} from
976 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
977 * ConnectionRequest)}.
978 * <p>
979 * For more information on call handovers, see
980 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700981 */
982 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
983
984 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800985 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
986 * is initiated but the source or destination app does not support handover.
987 * <p>
988 * Will be returned when a handover is requested via
989 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
990 * {@link PhoneAccountHandle} does not declare
991 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
992 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
993 * {@link Details#getAccountHandle()}) does not declare
994 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
995 * <p>
996 * For more information on call handovers, see
997 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700998 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800999 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001000
1001 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001002 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1003 * user rejects the handover request.
1004 * <p>
1005 * For more information on call handovers, see
1006 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001007 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001008 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001009
Sanket Padawe85291f62017-12-01 13:59:27 -08001010 /**
1011 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1012 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001013 * <p>
1014 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1015 * called on an emergency call, or if any other call is an emergency call.
1016 * <p>
1017 * Handovers are not permitted while there are ongoing emergency calls.
1018 * <p>
1019 * For more information on call handovers, see
1020 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001021 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001022 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001023
Tyler Gunn9d127732018-03-02 15:45:51 -08001024 /**
1025 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1026 * fails for an unknown reason.
1027 * <p>
1028 * For more information on call handovers, see
1029 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1030 */
1031 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001032
1033 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001034 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1035 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001036 * @param call The {@code Call} invoking this method.
1037 * @param state The new state of the {@code Call}.
1038 */
1039 public void onStateChanged(Call call, int state) {}
1040
1041 /**
1042 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1043 *
1044 * @param call The {@code Call} invoking this method.
1045 * @param parent The new parent of the {@code Call}.
1046 */
1047 public void onParentChanged(Call call, Call parent) {}
1048
1049 /**
1050 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1051 *
1052 * @param call The {@code Call} invoking this method.
1053 * @param children The new children of the {@code Call}.
1054 */
1055 public void onChildrenChanged(Call call, List<Call> children) {}
1056
1057 /**
1058 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1059 *
1060 * @param call The {@code Call} invoking this method.
1061 * @param details A {@code Details} object describing the {@code Call}.
1062 */
1063 public void onDetailsChanged(Call call, Details details) {}
1064
1065 /**
1066 * Invoked when the text messages that can be used as responses to the incoming
1067 * {@code Call} are loaded from the relevant database.
1068 * See {@link #getCannedTextResponses()}.
1069 *
1070 * @param call The {@code Call} invoking this method.
1071 * @param cannedTextResponses The text messages useable as responses.
1072 */
1073 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1074
1075 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001076 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1077 * character. This causes the post-dial signals to stop pending user confirmation. An
1078 * implementation should present this choice to the user and invoke
1079 * {@link #postDialContinue(boolean)} when the user makes the choice.
1080 *
1081 * @param call The {@code Call} invoking this method.
1082 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1083 */
1084 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1085
1086 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001087 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001088 *
1089 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001090 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001091 */
Andrew Lee50aca232014-07-22 16:41:54 -07001092 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001093
1094 /**
1095 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1096 * up their UI for the {@code Call} in response to state transitions. Specifically,
1097 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1098 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1099 * clients should wait for this method to be invoked.
1100 *
1101 * @param call The {@code Call} being destroyed.
1102 */
1103 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001104
1105 /**
1106 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1107 * conferenced.
1108 *
1109 * @param call The {@code Call} being updated.
1110 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1111 * conferenced.
1112 */
1113 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001114
1115 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001116 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
1117 * <p>
1118 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1119 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1120 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1121 * possible that a {@link ConnectionService} has defined its own Connection events which a
1122 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001123 * <p>
1124 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
1125 *
1126 * @param call The {@code Call} receiving the event.
1127 * @param event The event.
1128 * @param extras Extras associated with the connection event.
1129 */
1130 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001131
1132 /**
1133 * Invoked when the RTT mode changes for this call.
1134 * @param call The call whose RTT mode has changed.
1135 * @param mode the new RTT mode, one of
1136 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1137 * or {@link RttCall#RTT_MODE_VCO}
1138 */
1139 public void onRttModeChanged(Call call, int mode) {}
1140
1141 /**
1142 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1143 * @param call The call whose RTT status has changed.
1144 * @param enabled whether RTT is now enabled or disabled
1145 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1146 * on, null otherwise.
1147 */
1148 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1149
1150 /**
1151 * Invoked when the remote end of the connection has requested that an RTT communication
1152 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1153 * with the same ID that this method is invoked with.
1154 * @param call The call which the RTT request was placed on
1155 * @param id The ID of the request.
1156 */
1157 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001158
1159 /**
1160 * Invoked when the RTT session failed to initiate for some reason, including rejection
1161 * by the remote party.
1162 * @param call The call which the RTT initiation failure occurred on.
1163 * @param reason One of the status codes defined in
1164 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1165 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1166 */
1167 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001168
1169 /**
1170 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1171 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001172 * <p>
1173 * For a full discussion of the handover process and the APIs involved, see
1174 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1175 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001176 * @param call The call which had initiated handover.
1177 */
1178 public void onHandoverComplete(Call call) {}
1179
1180 /**
1181 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1182 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001183 * <p>
1184 * For a full discussion of the handover process and the APIs involved, see
1185 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1186 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001187 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001188 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001189 */
1190 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001191 }
1192
1193 /**
1194 * A class that holds the state that describes the state of the RTT channel to the remote
1195 * party, if it is active.
1196 */
1197 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001198 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001199 @Retention(RetentionPolicy.SOURCE)
1200 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1201 public @interface RttAudioMode {}
1202
1203 /**
1204 * For metrics use. Default value in the proto.
1205 * @hide
1206 */
1207 public static final int RTT_MODE_INVALID = 0;
1208
1209 /**
1210 * Indicates that there should be a bidirectional audio stream between the two parties
1211 * on the call.
1212 */
1213 public static final int RTT_MODE_FULL = 1;
1214
1215 /**
1216 * Indicates that the local user should be able to hear the audio stream from the remote
1217 * user, but not vice versa. Equivalent to muting the microphone.
1218 */
1219 public static final int RTT_MODE_HCO = 2;
1220
1221 /**
1222 * Indicates that the remote user should be able to hear the audio stream from the local
1223 * user, but not vice versa. Equivalent to setting the volume to zero.
1224 */
1225 public static final int RTT_MODE_VCO = 3;
1226
1227 private static final int READ_BUFFER_SIZE = 1000;
1228
1229 private InputStreamReader mReceiveStream;
1230 private OutputStreamWriter mTransmitStream;
1231 private int mRttMode;
1232 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001233 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001234 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1235
1236 /**
1237 * @hide
1238 */
Hall Liu57006aa2017-02-06 10:49:48 -08001239 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1240 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1241 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001242 mReceiveStream = receiveStream;
1243 mTransmitStream = transmitStream;
1244 mRttMode = mode;
1245 mInCallAdapter = inCallAdapter;
1246 }
1247
1248 /**
1249 * Returns the current RTT audio mode.
1250 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1251 * {@link #RTT_MODE_HCO}.
1252 */
1253 public int getRttAudioMode() {
1254 return mRttMode;
1255 }
1256
1257 /**
1258 * Sets the RTT audio mode. The requested mode change will be communicated through
1259 * {@link Callback#onRttModeChanged(Call, int)}.
1260 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1261 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1262 */
1263 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001264 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001265 }
1266
1267 /**
1268 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1269 * RTT transmits text in real-time, this method should be called once for each character
1270 * the user enters into the device.
1271 *
1272 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1273 * lead to interleaved text.
1274 * @param input The message to send to the remote user.
1275 */
1276 public void write(String input) throws IOException {
1277 mTransmitStream.write(input);
1278 mTransmitStream.flush();
1279 }
1280
1281 /**
1282 * Reads a string from the remote user, blocking if there is no data available. Returns
1283 * {@code null} if the RTT conversation has been terminated and there is no further data
1284 * to read.
1285 *
1286 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1287 * lead to interleaved text.
1288 * @return A string containing text sent by the remote user, or {@code null} if the
1289 * conversation has been terminated or if there was an error while reading.
1290 */
Hall Liub1c8a772017-07-17 17:04:41 -07001291 public String read() {
1292 try {
1293 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1294 if (numRead < 0) {
1295 return null;
1296 }
1297 return new String(mReadBuffer, 0, numRead);
1298 } catch (IOException e) {
1299 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001300 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001301 }
Hall Liuffa4a812017-03-02 16:11:00 -08001302 }
1303
1304 /**
1305 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1306 * be read.
1307 * @return A string containing text entered by the user, or {@code null} if the user has
1308 * not entered any new text yet.
1309 */
1310 public String readImmediately() throws IOException {
1311 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001312 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1313 if (numRead < 0) {
1314 return null;
1315 }
1316 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001317 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001318 return null;
1319 }
1320 }
Hall Liue9041242018-02-09 16:40:03 -08001321
1322 /**
1323 * Closes the underlying file descriptors
1324 * @hide
1325 */
1326 public void close() {
1327 try {
1328 mReceiveStream.close();
1329 } catch (IOException e) {
1330 // ignore
1331 }
1332 try {
1333 mTransmitStream.close();
1334 } catch (IOException e) {
1335 // ignore
1336 }
1337 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001338 }
1339
Andrew Leeda80c872015-04-15 14:09:50 -07001340 /**
1341 * @deprecated Use {@code Call.Callback} instead.
1342 * @hide
1343 */
1344 @Deprecated
1345 @SystemApi
1346 public static abstract class Listener extends Callback { }
1347
Ihab Awade63fadb2014-07-09 21:52:04 -07001348 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001349 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001350 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001351 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001352 private final List<Call> mChildren = new ArrayList<>();
1353 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001354 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001355 private final List<Call> mConferenceableCalls = new ArrayList<>();
1356 private final List<Call> mUnmodifiableConferenceableCalls =
1357 Collections.unmodifiableList(mConferenceableCalls);
1358
Santos Cordon823fd3c2014-08-07 18:35:18 -07001359 private boolean mChildrenCached;
1360 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001361 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001362 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001363 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001364 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001365 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001366 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001367 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001368 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001369 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001370
1371 /**
1372 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1373 *
1374 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1375 * remaining or this {@code Call} is not in a post-dial state.
1376 */
1377 public String getRemainingPostDialSequence() {
1378 return mRemainingPostDialSequence;
1379 }
1380
1381 /**
1382 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001383 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001384 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001385 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001386 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001387 }
1388
1389 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301390 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1391 *
1392 * @param address The address to which the call will be deflected.
1393 */
1394 public void deflect(Uri address) {
1395 mInCallAdapter.deflectCall(mTelecomCallId, address);
1396 }
1397
1398 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001399 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1400 *
1401 * @param rejectWithMessage Whether to reject with a text message.
1402 * @param textMessage An optional text message with which to respond.
1403 */
1404 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001405 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001406 }
1407
1408 /**
1409 * Instructs this {@code Call} to disconnect.
1410 */
1411 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001412 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001413 }
1414
1415 /**
1416 * Instructs this {@code Call} to go on hold.
1417 */
1418 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001419 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001420 }
1421
1422 /**
1423 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1424 */
1425 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001426 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001427 }
1428
1429 /**
1430 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1431 *
1432 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1433 *
1434 * @param digit A character representing the DTMF digit for which to play the tone. This
1435 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1436 */
1437 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001438 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001439 }
1440
1441 /**
1442 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1443 * currently playing.
1444 *
1445 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1446 * currently playing, this method will do nothing.
1447 */
1448 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001449 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001450 }
1451
1452 /**
1453 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1454 *
1455 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1456 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001457 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001458 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001459 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1460 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001461 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001462 * {@code Call} will pause playing the tones and notify callbacks via
1463 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001464 * should display to the user an indication of this state and an affordance to continue
1465 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1466 * app should invoke the {@link #postDialContinue(boolean)} method.
1467 *
1468 * @param proceed Whether or not to continue with the post-dial sequence.
1469 */
1470 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001471 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001472 }
1473
1474 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001475 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001476 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001477 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001478 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1479 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001480
1481 }
1482
1483 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001484 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001485 *
1486 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001487 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001488 public void conference(Call callToConferenceWith) {
1489 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001490 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001491 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001492 }
1493
1494 /**
1495 * Instructs this {@code Call} to split from any conference call with which it may be
1496 * connected.
1497 */
1498 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001499 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001500 }
1501
1502 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001503 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001504 */
1505 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001506 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001507 }
1508
1509 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001510 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001511 */
1512 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001513 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001514 }
1515
1516 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001517 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1518 * device.
1519 * <p>
1520 * Calls to this method are ignored if the call does not have the
1521 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1522 * <p>
1523 * An {@link InCallService} will only see calls which support this method if it has the
1524 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1525 * in its manifest.
1526 */
1527 public void pullExternalCall() {
1528 // If this isn't an external call, ignore the request.
1529 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1530 return;
1531 }
1532
1533 mInCallAdapter.pullExternalCall(mTelecomCallId);
1534 }
1535
1536 /**
1537 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1538 * the {@link ConnectionService}.
1539 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001540 * Call events are used to communicate point in time information from an {@link InCallService}
1541 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1542 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1543 * {@link ConnectionService}.
1544 * <p>
1545 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1546 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1547 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001548 * Events are exposed to {@link ConnectionService} implementations via
1549 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1550 * <p>
1551 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001552 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1553 * ignore some events altogether.
1554 * <p>
1555 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1556 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1557 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1558 * they define their own event types in this namespace. When defining a custom event type,
1559 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1560 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1561 * <p>
1562 * When defining events and the associated extras, it is important to keep their behavior
1563 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1564 * events/extras should me maintained to ensure backwards compatibility with older
1565 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001566 *
1567 * @param event The connection event.
1568 * @param extras Bundle containing extra information associated with the event.
1569 */
1570 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001571 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001572 }
1573
1574 /**
Hall Liu95d55872017-01-25 17:12:49 -08001575 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1576 * guaranteed, and notification of success will be via the
1577 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1578 */
1579 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001580 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001581 }
1582
1583 /**
1584 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1585 * callback.
1586 * The ID used here should be the same as the ID that was received via the callback.
1587 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1588 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1589 */
1590 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001591 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001592 }
1593
1594 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001595 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1596 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1597 * handover.
1598 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001599 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1600 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1601 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1602 * is referred to as the source of the handover, and the video calling app is referred to as the
1603 * destination.
1604 * <p>
1605 * When considering a handover scenario the device this method is called on is considered the
1606 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1607 * other device is considered the <em>receiving</em> device.
1608 * <p>
1609 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1610 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1611 * and invoke
1612 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1613 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1614 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1615 * At this point the app should display UI to indicate to the user that a call
1616 * handover is in process.
1617 * <p>
1618 * The destination app is responsible for communicating the handover request from the
1619 * <em>initiating</em> device to the <em>receiving</em> device.
1620 * <p>
1621 * When the app on the <em>receiving</em> device receives the handover request, it calls
1622 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1623 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1624 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1625 * choose whether they want to continue their call in the destination app.
1626 * <p>
1627 * When the destination app on the <em>receiving</em> device calls
1628 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1629 * {@link ConnectionService} and call
1630 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1631 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1632 * {@link Connection} to represent the handover call.
1633 * <p>
1634 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1635 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1636 * original call. If the user rejects the handover, the app calls
1637 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1638 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1639 * <p>
1640 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1641 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1642 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1643 * <p>
1644 * Errors in the handover process are reported to the {@link InCallService} via
1645 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1646 * the involved {@link ConnectionService}s via
1647 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001648 *
1649 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1650 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001651 * @param videoState Indicates the video state desired after the handover (see the
1652 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001653 * @param extras Bundle containing extra information to be passed to the
1654 * {@link ConnectionService}
1655 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001656 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1657 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001658 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1659 }
1660
1661 /**
Hall Liu95d55872017-01-25 17:12:49 -08001662 * Terminate the RTT session on this call. The resulting state change will be notified via
1663 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1664 */
1665 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001666 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001667 }
1668
1669 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001670 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1671 * added.
1672 * <p>
1673 * No assumptions should be made as to how an In-Call UI or service will handle these
1674 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1675 *
1676 * @param extras The extras to add.
1677 */
1678 public final void putExtras(Bundle extras) {
1679 if (extras == null) {
1680 return;
1681 }
1682
1683 if (mExtras == null) {
1684 mExtras = new Bundle();
1685 }
1686 mExtras.putAll(extras);
1687 mInCallAdapter.putExtras(mTelecomCallId, extras);
1688 }
1689
1690 /**
1691 * Adds a boolean extra to this {@link Call}.
1692 *
1693 * @param key The extra key.
1694 * @param value The value.
1695 * @hide
1696 */
1697 public final void putExtra(String key, boolean value) {
1698 if (mExtras == null) {
1699 mExtras = new Bundle();
1700 }
1701 mExtras.putBoolean(key, value);
1702 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1703 }
1704
1705 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001706 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001707 *
1708 * @param key The extra key.
1709 * @param value The value.
1710 * @hide
1711 */
1712 public final void putExtra(String key, int value) {
1713 if (mExtras == null) {
1714 mExtras = new Bundle();
1715 }
1716 mExtras.putInt(key, value);
1717 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1718 }
1719
1720 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001721 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001722 *
1723 * @param key The extra key.
1724 * @param value The value.
1725 * @hide
1726 */
1727 public final void putExtra(String key, String value) {
1728 if (mExtras == null) {
1729 mExtras = new Bundle();
1730 }
1731 mExtras.putString(key, value);
1732 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1733 }
1734
1735 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001736 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001737 *
1738 * @param keys The keys of the extras to remove.
1739 */
1740 public final void removeExtras(List<String> keys) {
1741 if (mExtras != null) {
1742 for (String key : keys) {
1743 mExtras.remove(key);
1744 }
1745 if (mExtras.size() == 0) {
1746 mExtras = null;
1747 }
1748 }
1749 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1750 }
1751
1752 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001753 * Removes extras from this {@link Call}.
1754 *
1755 * @param keys The keys of the extras to remove.
1756 */
1757 public final void removeExtras(String ... keys) {
1758 removeExtras(Arrays.asList(keys));
1759 }
1760
1761 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001762 * Obtains the parent of this {@code Call} in a conference, if any.
1763 *
1764 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1765 * child of any conference {@code Call}s.
1766 */
1767 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001768 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001769 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001770 }
1771 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001772 }
1773
1774 /**
1775 * Obtains the children of this conference {@code Call}, if any.
1776 *
1777 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1778 * {@code List} otherwise.
1779 */
1780 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001781 if (!mChildrenCached) {
1782 mChildrenCached = true;
1783 mChildren.clear();
1784
1785 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001786 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001787 if (call == null) {
1788 // At least one child was still not found, so do not save true for "cached"
1789 mChildrenCached = false;
1790 } else {
1791 mChildren.add(call);
1792 }
1793 }
1794 }
1795
Ihab Awade63fadb2014-07-09 21:52:04 -07001796 return mUnmodifiableChildren;
1797 }
1798
1799 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001800 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1801 *
1802 * @return The list of conferenceable {@code Call}s.
1803 */
1804 public List<Call> getConferenceableCalls() {
1805 return mUnmodifiableConferenceableCalls;
1806 }
1807
1808 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001809 * Obtains the state of this {@code Call}.
1810 *
1811 * @return A state value, chosen from the {@code STATE_*} constants.
1812 */
1813 public int getState() {
1814 return mState;
1815 }
1816
1817 /**
1818 * Obtains a list of canned, pre-configured message responses to present to the user as
1819 * ways of rejecting this {@code Call} using via a text message.
1820 *
1821 * @see #reject(boolean, String)
1822 *
1823 * @return A list of canned text message responses.
1824 */
1825 public List<String> getCannedTextResponses() {
1826 return mCannedTextResponses;
1827 }
1828
1829 /**
1830 * Obtains an object that can be used to display video from this {@code Call}.
1831 *
Andrew Lee50aca232014-07-22 16:41:54 -07001832 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001833 */
Andrew Lee50aca232014-07-22 16:41:54 -07001834 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001835 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001836 }
1837
1838 /**
1839 * Obtains an object containing call details.
1840 *
1841 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1842 * result may be {@code null}.
1843 */
1844 public Details getDetails() {
1845 return mDetails;
1846 }
1847
1848 /**
Hall Liu95d55872017-01-25 17:12:49 -08001849 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1850 * receive RTT text data, as well as to change the RTT mode.
1851 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1852 */
1853 public @Nullable RttCall getRttCall() {
1854 return mRttCall;
1855 }
1856
1857 /**
1858 * Returns whether this call has an active RTT connection.
1859 * @return true if there is a connection, false otherwise.
1860 */
1861 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08001862 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08001863 }
1864
1865 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001866 * Registers a callback to this {@code Call}.
1867 *
1868 * @param callback A {@code Callback}.
1869 */
1870 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001871 registerCallback(callback, new Handler());
1872 }
1873
1874 /**
1875 * Registers a callback to this {@code Call}.
1876 *
1877 * @param callback A {@code Callback}.
1878 * @param handler A handler which command and status changes will be delivered to.
1879 */
1880 public void registerCallback(Callback callback, Handler handler) {
1881 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001882 // Don't allow new callback registration if the call is already being destroyed.
1883 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001884 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1885 }
Andrew Leeda80c872015-04-15 14:09:50 -07001886 }
1887
1888 /**
1889 * Unregisters a callback from this {@code Call}.
1890 *
1891 * @param callback A {@code Callback}.
1892 */
1893 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001894 // Don't allow callback deregistration if the call is already being destroyed.
1895 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001896 for (CallbackRecord<Callback> record : mCallbackRecords) {
1897 if (record.getCallback() == callback) {
1898 mCallbackRecords.remove(record);
1899 break;
1900 }
1901 }
Andrew Leeda80c872015-04-15 14:09:50 -07001902 }
1903 }
1904
Santos Cordon3c20d632016-02-25 16:12:35 -08001905 @Override
1906 public String toString() {
1907 return new StringBuilder().
1908 append("Call [id: ").
1909 append(mTelecomCallId).
1910 append(", state: ").
1911 append(stateToString(mState)).
1912 append(", details: ").
1913 append(mDetails).
1914 append("]").toString();
1915 }
1916
1917 /**
1918 * @param state An integer value of a {@code STATE_*} constant.
1919 * @return A string representation of the value.
1920 */
1921 private static String stateToString(int state) {
1922 switch (state) {
1923 case STATE_NEW:
1924 return "NEW";
1925 case STATE_RINGING:
1926 return "RINGING";
1927 case STATE_DIALING:
1928 return "DIALING";
1929 case STATE_ACTIVE:
1930 return "ACTIVE";
1931 case STATE_HOLDING:
1932 return "HOLDING";
1933 case STATE_DISCONNECTED:
1934 return "DISCONNECTED";
1935 case STATE_CONNECTING:
1936 return "CONNECTING";
1937 case STATE_DISCONNECTING:
1938 return "DISCONNECTING";
1939 case STATE_SELECT_PHONE_ACCOUNT:
1940 return "SELECT_PHONE_ACCOUNT";
1941 default:
1942 Log.w(Call.class, "Unknown state %d", state);
1943 return "UNKNOWN";
1944 }
1945 }
1946
Andrew Leeda80c872015-04-15 14:09:50 -07001947 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001948 * Adds a listener to this {@code Call}.
1949 *
1950 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001951 * @deprecated Use {@link #registerCallback} instead.
1952 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001953 */
Andrew Leeda80c872015-04-15 14:09:50 -07001954 @Deprecated
1955 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001956 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001957 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001958 }
1959
1960 /**
1961 * Removes a listener from this {@code Call}.
1962 *
1963 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001964 * @deprecated Use {@link #unregisterCallback} instead.
1965 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001966 */
Andrew Leeda80c872015-04-15 14:09:50 -07001967 @Deprecated
1968 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001969 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001970 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001971 }
1972
1973 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001974 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1975 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001976 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001977 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001978 mInCallAdapter = inCallAdapter;
1979 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001980 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001981 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001982 }
1983
1984 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001985 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001986 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001987 mPhone = phone;
1988 mTelecomCallId = telecomCallId;
1989 mInCallAdapter = inCallAdapter;
1990 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001991 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001992 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001993 }
1994
1995 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001996 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001997 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001998 }
1999
2000 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002001 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002002
Ihab Awade63fadb2014-07-09 21:52:04 -07002003 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002004 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002005 boolean detailsChanged = !Objects.equals(mDetails, details);
2006 if (detailsChanged) {
2007 mDetails = details;
2008 }
2009
2010 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002011 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2012 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2013 mCannedTextResponses =
2014 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002015 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002016 }
2017
Tyler Gunn159f35c2017-03-02 09:28:37 -08002018 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
2019 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07002020 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002021 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07002022 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002023 mVideoCallImpl = newVideoCallImpl;
2024 }
2025 if (mVideoCallImpl != null) {
2026 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002027 }
2028
Santos Cordone3c507b2015-04-23 14:44:19 -07002029 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07002030 boolean stateChanged = mState != state;
2031 if (stateChanged) {
2032 mState = state;
2033 }
2034
Santos Cordon823fd3c2014-08-07 18:35:18 -07002035 String parentId = parcelableCall.getParentCallId();
2036 boolean parentChanged = !Objects.equals(mParentId, parentId);
2037 if (parentChanged) {
2038 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002039 }
2040
Santos Cordon823fd3c2014-08-07 18:35:18 -07002041 List<String> childCallIds = parcelableCall.getChildCallIds();
2042 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2043 if (childrenChanged) {
2044 mChildrenIds.clear();
2045 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2046 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002047 }
2048
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002049 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2050 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2051 for (String otherId : conferenceableCallIds) {
2052 if (callIdMap.containsKey(otherId)) {
2053 conferenceableCalls.add(callIdMap.get(otherId));
2054 }
2055 }
2056
2057 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2058 mConferenceableCalls.clear();
2059 mConferenceableCalls.addAll(conferenceableCalls);
2060 fireConferenceableCallsChanged();
2061 }
2062
Hall Liu95d55872017-01-25 17:12:49 -08002063 boolean isRttChanged = false;
2064 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002065 if (parcelableCall.getIsRttCallChanged()
2066 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002067 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2068 InputStreamReader receiveStream = new InputStreamReader(
2069 new ParcelFileDescriptor.AutoCloseInputStream(
2070 parcelableRttCall.getReceiveStream()),
2071 StandardCharsets.UTF_8);
2072 OutputStreamWriter transmitStream = new OutputStreamWriter(
2073 new ParcelFileDescriptor.AutoCloseOutputStream(
2074 parcelableRttCall.getTransmitStream()),
2075 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002076 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002077 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2078 if (mRttCall == null) {
2079 isRttChanged = true;
2080 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2081 rttModeChanged = true;
2082 }
2083 mRttCall = newRttCall;
2084 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2085 && parcelableCall.getIsRttCallChanged()) {
2086 isRttChanged = true;
2087 mRttCall = null;
2088 }
2089
Ihab Awade63fadb2014-07-09 21:52:04 -07002090 // Now we fire updates, ensuring that any client who listens to any of these notifications
2091 // gets the most up-to-date state.
2092
2093 if (stateChanged) {
2094 fireStateChanged(mState);
2095 }
2096 if (detailsChanged) {
2097 fireDetailsChanged(mDetails);
2098 }
2099 if (cannedTextResponsesChanged) {
2100 fireCannedTextResponsesLoaded(mCannedTextResponses);
2101 }
Andrew Lee50aca232014-07-22 16:41:54 -07002102 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002103 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002104 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002105 if (parentChanged) {
2106 fireParentChanged(getParent());
2107 }
2108 if (childrenChanged) {
2109 fireChildrenChanged(getChildren());
2110 }
Hall Liu95d55872017-01-25 17:12:49 -08002111 if (isRttChanged) {
2112 fireOnIsRttChanged(mRttCall != null, mRttCall);
2113 }
2114 if (rttModeChanged) {
2115 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2116 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002117
2118 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2119 // remove ourselves from the Phone. Note that we do this after completing all state updates
2120 // so a client can cleanly transition all their UI to the state appropriate for a
2121 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2122 if (mState == STATE_DISCONNECTED) {
2123 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002124 }
2125 }
2126
2127 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002128 final void internalSetPostDialWait(String remaining) {
2129 mRemainingPostDialSequence = remaining;
2130 firePostDialWait(mRemainingPostDialSequence);
2131 }
2132
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002133 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002134 final void internalSetDisconnected() {
2135 if (mState != Call.STATE_DISCONNECTED) {
2136 mState = Call.STATE_DISCONNECTED;
2137 fireStateChanged(mState);
2138 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002139 }
2140 }
2141
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002142 /** {@hide} */
2143 final void internalOnConnectionEvent(String event, Bundle extras) {
2144 fireOnConnectionEvent(event, extras);
2145 }
2146
Hall Liu95d55872017-01-25 17:12:49 -08002147 /** {@hide} */
2148 final void internalOnRttUpgradeRequest(final int requestId) {
2149 for (CallbackRecord<Callback> record : mCallbackRecords) {
2150 final Call call = this;
2151 final Callback callback = record.getCallback();
2152 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2153 }
2154 }
2155
Hall Liu57006aa2017-02-06 10:49:48 -08002156 /** @hide */
2157 final void internalOnRttInitiationFailure(int reason) {
2158 for (CallbackRecord<Callback> record : mCallbackRecords) {
2159 final Call call = this;
2160 final Callback callback = record.getCallback();
2161 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2162 }
2163 }
2164
Sanket Padawe85291f62017-12-01 13:59:27 -08002165 /** {@hide} */
2166 final void internalOnHandoverFailed(int error) {
2167 for (CallbackRecord<Callback> record : mCallbackRecords) {
2168 final Call call = this;
2169 final Callback callback = record.getCallback();
2170 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2171 }
2172 }
2173
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002174 /** {@hide} */
2175 final void internalOnHandoverComplete() {
2176 for (CallbackRecord<Callback> record : mCallbackRecords) {
2177 final Call call = this;
2178 final Callback callback = record.getCallback();
2179 record.getHandler().post(() -> callback.onHandoverComplete(call));
2180 }
2181 }
2182
Andrew Lee011728f2015-04-23 15:47:06 -07002183 private void fireStateChanged(final int newState) {
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.onStateChanged(call, newState);
2191 }
2192 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002193 }
2194 }
2195
Andrew Lee011728f2015-04-23 15:47:06 -07002196 private void fireParentChanged(final Call newParent) {
2197 for (CallbackRecord<Callback> record : mCallbackRecords) {
2198 final Call call = this;
2199 final Callback callback = record.getCallback();
2200 record.getHandler().post(new Runnable() {
2201 @Override
2202 public void run() {
2203 callback.onParentChanged(call, newParent);
2204 }
2205 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002206 }
2207 }
2208
Andrew Lee011728f2015-04-23 15:47:06 -07002209 private void fireChildrenChanged(final List<Call> children) {
2210 for (CallbackRecord<Callback> record : mCallbackRecords) {
2211 final Call call = this;
2212 final Callback callback = record.getCallback();
2213 record.getHandler().post(new Runnable() {
2214 @Override
2215 public void run() {
2216 callback.onChildrenChanged(call, children);
2217 }
2218 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002219 }
2220 }
2221
Andrew Lee011728f2015-04-23 15:47:06 -07002222 private void fireDetailsChanged(final Details details) {
2223 for (CallbackRecord<Callback> record : mCallbackRecords) {
2224 final Call call = this;
2225 final Callback callback = record.getCallback();
2226 record.getHandler().post(new Runnable() {
2227 @Override
2228 public void run() {
2229 callback.onDetailsChanged(call, details);
2230 }
2231 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002232 }
2233 }
2234
Andrew Lee011728f2015-04-23 15:47:06 -07002235 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2236 for (CallbackRecord<Callback> record : mCallbackRecords) {
2237 final Call call = this;
2238 final Callback callback = record.getCallback();
2239 record.getHandler().post(new Runnable() {
2240 @Override
2241 public void run() {
2242 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2243 }
2244 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002245 }
2246 }
2247
Andrew Lee011728f2015-04-23 15:47:06 -07002248 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2249 for (CallbackRecord<Callback> record : mCallbackRecords) {
2250 final Call call = this;
2251 final Callback callback = record.getCallback();
2252 record.getHandler().post(new Runnable() {
2253 @Override
2254 public void run() {
2255 callback.onVideoCallChanged(call, videoCall);
2256 }
2257 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002258 }
2259 }
2260
Andrew Lee011728f2015-04-23 15:47:06 -07002261 private void firePostDialWait(final String remainingPostDialSequence) {
2262 for (CallbackRecord<Callback> record : mCallbackRecords) {
2263 final Call call = this;
2264 final Callback callback = record.getCallback();
2265 record.getHandler().post(new Runnable() {
2266 @Override
2267 public void run() {
2268 callback.onPostDialWait(call, remainingPostDialSequence);
2269 }
2270 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002271 }
2272 }
2273
2274 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002275 /**
2276 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2277 * onCallRemoved callback, we remove this call from the Phone's record
2278 * only once all of the registered onCallDestroyed callbacks are executed.
2279 * All the callbacks get removed from our records as a part of this operation
2280 * since onCallDestroyed is the final callback.
2281 */
2282 final Call call = this;
2283 if (mCallbackRecords.isEmpty()) {
2284 // No callbacks registered, remove the call from Phone's record.
2285 mPhone.internalRemoveCall(call);
2286 }
2287 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002288 final Callback callback = record.getCallback();
2289 record.getHandler().post(new Runnable() {
2290 @Override
2291 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002292 boolean isFinalRemoval = false;
2293 RuntimeException toThrow = null;
2294 try {
2295 callback.onCallDestroyed(call);
2296 } catch (RuntimeException e) {
2297 toThrow = e;
2298 }
2299 synchronized(Call.this) {
2300 mCallbackRecords.remove(record);
2301 if (mCallbackRecords.isEmpty()) {
2302 isFinalRemoval = true;
2303 }
2304 }
2305 if (isFinalRemoval) {
2306 mPhone.internalRemoveCall(call);
2307 }
2308 if (toThrow != null) {
2309 throw toThrow;
2310 }
Andrew Lee011728f2015-04-23 15:47:06 -07002311 }
2312 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002313 }
2314 }
2315
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002316 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002317 for (CallbackRecord<Callback> record : mCallbackRecords) {
2318 final Call call = this;
2319 final Callback callback = record.getCallback();
2320 record.getHandler().post(new Runnable() {
2321 @Override
2322 public void run() {
2323 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2324 }
2325 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002326 }
2327 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002328
2329 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002330 * Notifies listeners of an incoming connection event.
2331 * <p>
2332 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2333 *
2334 * @param event
2335 * @param extras
2336 */
2337 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2338 for (CallbackRecord<Callback> record : mCallbackRecords) {
2339 final Call call = this;
2340 final Callback callback = record.getCallback();
2341 record.getHandler().post(new Runnable() {
2342 @Override
2343 public void run() {
2344 callback.onConnectionEvent(call, event, extras);
2345 }
2346 });
2347 }
2348 }
2349
2350 /**
Hall Liu95d55872017-01-25 17:12:49 -08002351 * Notifies listeners of an RTT on/off change
2352 *
2353 * @param enabled True if RTT is now enabled, false otherwise
2354 */
2355 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2356 for (CallbackRecord<Callback> record : mCallbackRecords) {
2357 final Call call = this;
2358 final Callback callback = record.getCallback();
2359 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2360 }
2361 }
2362
2363 /**
2364 * Notifies listeners of a RTT mode change
2365 *
2366 * @param mode The new RTT mode
2367 */
2368 private void fireOnRttModeChanged(final int mode) {
2369 for (CallbackRecord<Callback> record : mCallbackRecords) {
2370 final Call call = this;
2371 final Callback callback = record.getCallback();
2372 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2373 }
2374 }
2375
2376 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002377 * Determines if two bundles are equal.
2378 *
2379 * @param bundle The original bundle.
2380 * @param newBundle The bundle to compare with.
2381 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2382 */
2383 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2384 if (bundle == null || newBundle == null) {
2385 return bundle == newBundle;
2386 }
2387
2388 if (bundle.size() != newBundle.size()) {
2389 return false;
2390 }
2391
2392 for(String key : bundle.keySet()) {
2393 if (key != null) {
2394 final Object value = bundle.get(key);
2395 final Object newValue = newBundle.get(key);
2396 if (!Objects.equals(value, newValue)) {
2397 return false;
2398 }
2399 }
2400 }
2401 return true;
2402 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002403}