blob: bf0ffb94b252e7182211d45e1b894f24d9139bd0 [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;
Andrew Lee50aca232014-07-22 16:41:54 -070032import java.lang.String;
Hall Liu95d55872017-01-25 17:12:49 -080033import java.lang.annotation.Retention;
34import java.lang.annotation.RetentionPolicy;
35import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070036import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070037import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070038import java.util.Collections;
39import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070040import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070041import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070042import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070043
44/**
45 * Represents an ongoing phone call that the in-call app should present to the user.
46 */
47public final class Call {
48 /**
49 * The state of a {@code Call} when newly created.
50 */
51 public static final int STATE_NEW = 0;
52
53 /**
54 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
55 */
56 public static final int STATE_DIALING = 1;
57
58 /**
59 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
60 */
61 public static final int STATE_RINGING = 2;
62
63 /**
64 * The state of a {@code Call} when in a holding state.
65 */
66 public static final int STATE_HOLDING = 3;
67
68 /**
69 * The state of a {@code Call} when actively supporting conversation.
70 */
71 public static final int STATE_ACTIVE = 4;
72
73 /**
74 * The state of a {@code Call} when no further voice or other communication is being
75 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
76 * is no longer active, and the local data transport has or inevitably will release resources
77 * associated with this {@code Call}.
78 */
79 public static final int STATE_DISCONNECTED = 7;
80
Nancy Chen5da0fd52014-07-08 14:16:17 -070081 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070082 * The state of an outgoing {@code Call} when waiting on user to select a
83 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070084 */
Santos Cordone3c507b2015-04-23 14:44:19 -070085 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
86
87 /**
88 * @hide
89 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
90 */
91 @Deprecated
92 @SystemApi
93 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070094
Nancy Chene20930f2014-08-07 16:17:21 -070095 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070096 * The initial state of an outgoing {@code Call}.
97 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
98 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070099 */
100 public static final int STATE_CONNECTING = 9;
101
Nancy Chen513c8922014-09-17 14:47:20 -0700102 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700103 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
104 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
105 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
106 */
107 public static final int STATE_DISCONNECTING = 10;
108
109 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700110 * The state of an external call which is in the process of being pulled from a remote device to
111 * the local device.
112 * <p>
113 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
114 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
115 * <p>
116 * An {@link InCallService} will only see this state if it has the
117 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
118 * manifest.
119 */
120 public static final int STATE_PULLING_CALL = 11;
121
122 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700123 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
124 * extras. Used to pass the phone accounts to display on the front end to the user in order to
125 * select phone accounts to (for example) place a call.
Hall Liu34d9e242018-11-21 17:05:58 -0800126 * @deprecated Use the list from {@link #EXTRA_SUGGESTED_PHONE_ACCOUNTS} instead.
Nancy Chen513c8922014-09-17 14:47:20 -0700127 */
Hall Liu34d9e242018-11-21 17:05:58 -0800128 @Deprecated
Nancy Chen513c8922014-09-17 14:47:20 -0700129 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
130
mike dooley4af561f2016-12-20 08:55:17 -0800131 /**
Hall Liu34d9e242018-11-21 17:05:58 -0800132 * Key for extra used to pass along a list of {@link PhoneAccountSuggestion}s to the in-call
133 * UI when a call enters the {@link #STATE_SELECT_PHONE_ACCOUNT} state. The list included here
134 * will have the same length and be in the same order as the list passed with
135 * {@link #AVAILABLE_PHONE_ACCOUNTS}.
136 */
137 public static final String EXTRA_SUGGESTED_PHONE_ACCOUNTS =
138 "android.telecom.extra.SUGGESTED_PHONE_ACCOUNTS";
139
140 /**
mike dooley91217422017-03-09 12:58:42 -0800141 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
142 * when the last outgoing emergency call was made. This is used to identify potential emergency
143 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800144 */
145 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
146 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
147
Tyler Gunn8bf76572017-04-06 15:30:08 -0700148 /**
149 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
150 * Telecom that the user has requested that the current {@link Call} should be handed over
151 * to another {@link ConnectionService}.
152 * <p>
153 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
154 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
155 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700156 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
157 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700158 */
159 public static final String EVENT_REQUEST_HANDOVER =
160 "android.telecom.event.REQUEST_HANDOVER";
161
162 /**
163 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
164 * {@link PhoneAccountHandle} to which a call should be handed over to.
165 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700166 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
167 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700168 */
169 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
170 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
171
172 /**
173 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
174 * video state of the call when it is handed over to the new {@link PhoneAccount}.
175 * <p>
176 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
177 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
178 * {@link VideoProfile#STATE_TX_ENABLED}.
179 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700180 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
181 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700182 */
183 public static final String EXTRA_HANDOVER_VIDEO_STATE =
184 "android.telecom.extra.HANDOVER_VIDEO_STATE";
185
186 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700187 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
188 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
189 * information to the handover {@link ConnectionService} specified by
190 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
191 * <p>
192 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
193 * {@link ConnectionService} via the request extras when
194 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
195 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700196 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700197 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
198 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700199 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700200 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700201
202 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700203 * Call event sent from Telecom to the handover {@link ConnectionService} via
204 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
205 * to the {@link ConnectionService} has completed successfully.
206 * <p>
207 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700208 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700209 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
210 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700211 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700212 public static final String EVENT_HANDOVER_COMPLETE =
213 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700214
215 /**
216 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
217 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
218 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
219 * {@code null}.
220 * <p>
221 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
222 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700223 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
224 * APIs instead.
Tyler Gunn34a2b312017-06-23 08:32:00 -0700225 */
226 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
227 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
228
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700229 /**
230 * Call event sent from Telecom to the handover {@link ConnectionService} via
231 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
232 * to the {@link ConnectionService} has failed.
233 * <p>
234 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
235 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700236 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
237 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700238 */
239 public static final String EVENT_HANDOVER_FAILED =
240 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700241
Ihab Awade63fadb2014-07-09 21:52:04 -0700242 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800243
244 /** Call can currently be put on hold or unheld. */
245 public static final int CAPABILITY_HOLD = 0x00000001;
246
247 /** Call supports the hold feature. */
248 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
249
250 /**
251 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
252 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
253 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
254 * capability allows a merge button to be shown while the conference call is in the foreground
255 * of the in-call UI.
256 * <p>
257 * This is only intended for use by a {@link Conference}.
258 */
259 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
260
261 /**
262 * Calls within a conference can be swapped between foreground and background.
263 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
264 * <p>
265 * This is only intended for use by a {@link Conference}.
266 */
267 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
268
269 /**
270 * @hide
271 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700272 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800273
274 /** Call supports responding via text option. */
275 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
276
277 /** Call can be muted. */
278 public static final int CAPABILITY_MUTE = 0x00000040;
279
280 /**
281 * Call supports conference call management. This capability only applies to {@link Conference}
282 * calls which can have {@link Connection}s as children.
283 */
284 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
285
286 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700287 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800288 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700289 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800290
291 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700292 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800293 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700294 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800295
296 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700297 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800298 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700299 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700300 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800301
302 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700303 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800304 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700305 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
306
307 /**
308 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700309 */
310 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
311
312 /**
313 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700314 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700315 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700316 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800317
318 /**
319 * Call is able to be separated from its parent {@code Conference}, if any.
320 */
321 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
322
323 /**
324 * Call is able to be individually disconnected when in a {@code Conference}.
325 */
326 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
327
328 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500329 * Speed up audio setup for MT call.
330 * @hide
331 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700332 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
333
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700334 /**
335 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700336 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800337 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
338 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
339 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700340 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800341 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700342 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
343
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700344 /**
345 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700346 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700347 */
348 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
349
Bryce Lee81901682015-08-28 16:38:02 -0700350 /**
351 * Call sends responses through connection.
352 * @hide
353 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800354 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
355
356 /**
357 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
358 * <p>
359 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
360 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
361 * downgraded from a video call back to a VideoState of
362 * {@link VideoProfile#STATE_AUDIO_ONLY}.
363 * <p>
364 * Intuitively, a call which can be downgraded to audio should also have local and remote
365 * video
366 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
367 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
368 */
369 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700370
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700371 /**
372 * When set for an external call, indicates that this {@code Call} can be pulled from a
373 * remote device to the current device.
374 * <p>
375 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
376 * <p>
377 * An {@link InCallService} will only see calls with this capability if it has the
378 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
379 * in its manifest.
380 * <p>
381 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700382 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700383 */
384 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
385
Pooja Jaind34698d2017-12-28 14:15:31 +0530386 /** Call supports the deflect feature. */
387 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
388
Tyler Gunnd11a3152015-03-18 13:09:14 -0700389 //******************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530390 // Next CAPABILITY value: 0x02000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700391 //******************************************************************************************
392
393 /**
394 * Whether the call is currently a conference.
395 */
396 public static final int PROPERTY_CONFERENCE = 0x00000001;
397
398 /**
399 * Whether the call is a generic conference, where we do not know the precise state of
400 * participants in the conference (eg. on CDMA).
401 */
402 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
403
404 /**
405 * Whether the call is made while the device is in emergency callback mode.
406 */
407 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
408
409 /**
410 * Connection is using WIFI.
411 */
412 public static final int PROPERTY_WIFI = 0x00000008;
413
414 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700415 * When set, the UI should indicate to the user that a call is using high definition
416 * audio.
417 * <p>
418 * The underlying {@link ConnectionService} is responsible for reporting this
419 * property. It is important to note that this property is not intended to report the
420 * actual audio codec being used for a Call, but whether the call should be indicated
421 * to the user as high definition.
422 * <p>
423 * The Android Telephony stack reports this property for calls based on a number
424 * of factors, including which audio codec is used and whether a call is using an HD
425 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
426 * and in these cases this property will not be set for a call even if the underlying audio
427 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700428 */
429 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
430
Tony Maka68dcce2015-12-17 09:31:18 +0000431 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100432 * Whether the call is associated with the work profile.
433 */
434 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
435
436 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700437 * When set, indicates that this {@code Call} does not actually exist locally for the
438 * {@link ConnectionService}.
439 * <p>
440 * Consider, for example, a scenario where a user has two phones with the same phone number.
441 * When a user places a call on one device, the telephony stack can represent that call on
442 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700443 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700444 * <p>
445 * An {@link InCallService} will only see calls with this property if it has the
446 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
447 * in its manifest.
448 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700449 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700450 */
451 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
452
Brad Ebinger15847072016-05-18 11:08:36 -0700453 /**
454 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
455 */
456 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
457
Tyler Gunn24e18332017-02-10 09:42:49 -0800458 /**
459 * Indicates that the call is from a self-managed {@link ConnectionService}.
460 * <p>
461 * See also {@link Connection#PROPERTY_SELF_MANAGED}
462 */
463 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
464
Eric Erfanianec881872017-12-06 16:27:53 -0800465 /**
466 * Indicates the call used Assisted Dialing.
467 * See also {@link Connection#PROPERTY_ASSISTED_DIALING_USED}
468 * @hide
469 */
470 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
471
Hall Liue9041242018-02-09 16:40:03 -0800472 /**
473 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
474 * {@link RttCall} object that is used to send and receive text.
475 */
476 public static final int PROPERTY_RTT = 0x00000400;
477
Tyler Gunn5bd90852018-09-21 09:37:07 -0700478 /**
479 * Indicates that the call has been identified as the network as an emergency call. This
480 * property may be set for both incoming and outgoing calls which the network identifies as
481 * emergency calls.
482 */
483 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
484
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700485 /**
486 * Indicates that the call is using VoIP audio mode.
487 * <p>
488 * When this property is set, the {@link android.media.AudioManager} audio mode for this
489 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
490 * property is not set, the audio mode for this call will be
491 * {@link android.media.AudioManager#MODE_IN_CALL}.
492 * <p>
493 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
494 * <p>
495 * You can use this property to determine whether an un-answered incoming call or a held
496 * call will use VoIP audio mode (if the call does not currently have focus, the system
497 * audio mode may not reflect the mode the call will use).
498 */
499 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
500
Andrew Lee2378ea72015-04-29 14:38:11 -0700501 //******************************************************************************************
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700502 // Next PROPERTY value: 0x00002000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700503 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800504
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800505 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700506 private final Uri mHandle;
507 private final int mHandlePresentation;
508 private final String mCallerDisplayName;
509 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700510 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700511 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700512 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800513 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700514 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700515 private final long mConnectTimeMillis;
516 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700517 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700518 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700519 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700520 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700521 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700522
523 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800524 * Whether the supplied capabilities supports the specified capability.
525 *
526 * @param capabilities A bit field of capabilities.
527 * @param capability The capability to check capabilities for.
528 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800529 */
530 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800531 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800532 }
533
534 /**
535 * Whether the capabilities of this {@code Details} supports the specified capability.
536 *
537 * @param capability The capability to check capabilities for.
538 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800539 */
540 public boolean can(int capability) {
541 return can(mCallCapabilities, capability);
542 }
543
544 /**
545 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
546 *
547 * @param capabilities A capability bit field.
548 * @return A human readable string representation.
549 */
550 public static String capabilitiesToString(int capabilities) {
551 StringBuilder builder = new StringBuilder();
552 builder.append("[Capabilities:");
553 if (can(capabilities, CAPABILITY_HOLD)) {
554 builder.append(" CAPABILITY_HOLD");
555 }
556 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
557 builder.append(" CAPABILITY_SUPPORT_HOLD");
558 }
559 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
560 builder.append(" CAPABILITY_MERGE_CONFERENCE");
561 }
562 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
563 builder.append(" CAPABILITY_SWAP_CONFERENCE");
564 }
565 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
566 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
567 }
568 if (can(capabilities, CAPABILITY_MUTE)) {
569 builder.append(" CAPABILITY_MUTE");
570 }
571 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
572 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
573 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700574 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
575 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
576 }
577 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
578 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
579 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700580 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
581 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800582 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700583 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
584 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
585 }
586 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
587 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
588 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800589 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
590 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
591 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700592 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
593 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800594 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500595 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700596 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500597 }
Rekha Kumar07366812015-03-24 16:42:31 -0700598 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
599 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
600 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700601 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
602 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
603 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700604 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
605 builder.append(" CAPABILITY_CAN_PULL_CALL");
606 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530607 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
608 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
609 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800610 builder.append("]");
611 return builder.toString();
612 }
613
614 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700615 * Whether the supplied properties includes the specified property.
616 *
617 * @param properties A bit field of properties.
618 * @param property The property to check properties for.
619 * @return Whether the specified property is supported.
620 */
621 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800622 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700623 }
624
625 /**
626 * Whether the properties of this {@code Details} includes the specified property.
627 *
628 * @param property The property to check properties for.
629 * @return Whether the specified property is supported.
630 */
631 public boolean hasProperty(int property) {
632 return hasProperty(mCallProperties, property);
633 }
634
635 /**
636 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
637 *
638 * @param properties A property bit field.
639 * @return A human readable string representation.
640 */
641 public static String propertiesToString(int properties) {
642 StringBuilder builder = new StringBuilder();
643 builder.append("[Properties:");
644 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
645 builder.append(" PROPERTY_CONFERENCE");
646 }
647 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
648 builder.append(" PROPERTY_GENERIC_CONFERENCE");
649 }
650 if (hasProperty(properties, PROPERTY_WIFI)) {
651 builder.append(" PROPERTY_WIFI");
652 }
653 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
654 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
655 }
656 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700657 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700658 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700659 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
660 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
661 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700662 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700663 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
664 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700665 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800666 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
667 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700668 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
669 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
670 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700671 if (hasProperty(properties, PROPERTY_RTT)) {
672 builder.append(" PROPERTY_RTT");
673 }
674 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
675 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
676 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700677 builder.append("]");
678 return builder.toString();
679 }
680
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800681 /** {@hide} */
682 public String getTelecomCallId() {
683 return mTelecomCallId;
684 }
685
Andrew Lee2378ea72015-04-29 14:38:11 -0700686 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700687 * @return The handle (e.g., phone number) to which the {@code Call} is currently
688 * connected.
689 */
690 public Uri getHandle() {
691 return mHandle;
692 }
693
694 /**
695 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700696 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700697 */
698 public int getHandlePresentation() {
699 return mHandlePresentation;
700 }
701
702 /**
703 * @return The display name for the caller.
704 */
705 public String getCallerDisplayName() {
706 return mCallerDisplayName;
707 }
708
709 /**
710 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700711 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700712 */
713 public int getCallerDisplayNamePresentation() {
714 return mCallerDisplayNamePresentation;
715 }
716
717 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700718 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
719 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700720 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700721 public PhoneAccountHandle getAccountHandle() {
722 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700723 }
724
725 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800726 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
727 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700728 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700729 public int getCallCapabilities() {
730 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700731 }
732
733 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700734 * @return A bitmask of the properties of the {@code Call}, as defined by the various
735 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700736 */
737 public int getCallProperties() {
738 return mCallProperties;
739 }
740
741 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800742 * @return a bitmask of the audio routes available for the call.
743 *
744 * @hide
745 */
746 public int getSupportedAudioRoutes() {
747 return mSupportedAudioRoutes;
748 }
749
750 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700751 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700752 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700753 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700754 public DisconnectCause getDisconnectCause() {
755 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700756 }
757
758 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700759 * Returns the time the {@link Call} connected (i.e. became active). This information is
760 * updated periodically, but user interfaces should not rely on this to display the "call
761 * time clock". For the time when the call was first added to Telecom, see
762 * {@link #getCreationTimeMillis()}.
763 *
764 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700765 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700766 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700767 return mConnectTimeMillis;
768 }
769
770 /**
771 * @return Information about any calling gateway the {@code Call} may be using.
772 */
773 public GatewayInfo getGatewayInfo() {
774 return mGatewayInfo;
775 }
776
Andrew Lee7a341382014-07-15 17:05:08 -0700777 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700778 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700779 */
780 public int getVideoState() {
781 return mVideoState;
782 }
783
Ihab Awad5d0410f2014-07-30 10:07:40 -0700784 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700785 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700786 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700787 */
788 public StatusHints getStatusHints() {
789 return mStatusHints;
790 }
791
Nancy Chen10798dc2014-08-08 14:00:25 -0700792 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700793 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700794 */
795 public Bundle getExtras() {
796 return mExtras;
797 }
798
Santos Cordon6b7f9552015-05-27 17:21:45 -0700799 /**
800 * @return The extras used with the original intent to place this call.
801 */
802 public Bundle getIntentExtras() {
803 return mIntentExtras;
804 }
805
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700806 /**
807 * Returns the time when the call was first created and added to Telecom. This is the same
808 * time that is logged as the start time in the Call Log (see
809 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
810 * (became active), see {@link #getConnectTimeMillis()}.
811 *
812 * @return The creation time of the call, in millis since the epoch.
813 */
814 public long getCreationTimeMillis() {
815 return mCreationTimeMillis;
816 }
817
Ihab Awade63fadb2014-07-09 21:52:04 -0700818 @Override
819 public boolean equals(Object o) {
820 if (o instanceof Details) {
821 Details d = (Details) o;
822 return
823 Objects.equals(mHandle, d.mHandle) &&
824 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
825 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
826 Objects.equals(mCallerDisplayNamePresentation,
827 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700828 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700829 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700830 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700831 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700832 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700833 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700834 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700835 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700836 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700837 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
838 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700839 }
840 return false;
841 }
842
843 @Override
844 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700845 return Objects.hash(mHandle,
846 mHandlePresentation,
847 mCallerDisplayName,
848 mCallerDisplayNamePresentation,
849 mAccountHandle,
850 mCallCapabilities,
851 mCallProperties,
852 mDisconnectCause,
853 mConnectTimeMillis,
854 mGatewayInfo,
855 mVideoState,
856 mStatusHints,
857 mExtras,
858 mIntentExtras,
859 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700860 }
861
862 /** {@hide} */
863 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800864 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700865 Uri handle,
866 int handlePresentation,
867 String callerDisplayName,
868 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700869 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700870 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700871 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700872 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700873 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700874 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700875 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700876 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700877 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700878 Bundle intentExtras,
879 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800880 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700881 mHandle = handle;
882 mHandlePresentation = handlePresentation;
883 mCallerDisplayName = callerDisplayName;
884 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700885 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700886 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700887 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700888 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700889 mConnectTimeMillis = connectTimeMillis;
890 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700891 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700892 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700893 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700894 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700895 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700896 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800897
898 /** {@hide} */
899 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
900 return new Details(
901 parcelableCall.getId(),
902 parcelableCall.getHandle(),
903 parcelableCall.getHandlePresentation(),
904 parcelableCall.getCallerDisplayName(),
905 parcelableCall.getCallerDisplayNamePresentation(),
906 parcelableCall.getAccountHandle(),
907 parcelableCall.getCapabilities(),
908 parcelableCall.getProperties(),
909 parcelableCall.getDisconnectCause(),
910 parcelableCall.getConnectTimeMillis(),
911 parcelableCall.getGatewayInfo(),
912 parcelableCall.getVideoState(),
913 parcelableCall.getStatusHints(),
914 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700915 parcelableCall.getIntentExtras(),
916 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800917 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800918
919 @Override
920 public String toString() {
921 StringBuilder sb = new StringBuilder();
922 sb.append("[pa: ");
923 sb.append(mAccountHandle);
924 sb.append(", hdl: ");
925 sb.append(Log.pii(mHandle));
926 sb.append(", caps: ");
927 sb.append(capabilitiesToString(mCallCapabilities));
928 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700929 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800930 sb.append("]");
931 return sb.toString();
932 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700933 }
934
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700935 /**
936 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
937 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
938 * implementation.
939 * <p>
940 * You can handle these callbacks by extending the {@link Callback} class and overriding the
941 * callbacks that your {@link InCallService} is interested in. The callback methods include the
942 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
943 * {@link Callback} implementation, if desired.
944 * <p>
945 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
946 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
947 * (typically in {@link InCallService#onCallRemoved(Call)}).
948 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
949 * reach your implementation of {@link Callback}, so it is important to register your callback
950 * as soon as your {@link InCallService} is notified of a new call via
951 * {@link InCallService#onCallAdded(Call)}.
952 */
Andrew Leeda80c872015-04-15 14:09:50 -0700953 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700954 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -0700955 * @hide
956 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800957 @IntDef(prefix = { "HANDOVER_" },
958 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -0700959 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -0800960 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -0700961 @Retention(RetentionPolicy.SOURCE)
962 public @interface HandoverFailureErrors {}
963
964 /**
965 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -0800966 * to handover the call to rejects the handover request.
967 * <p>
968 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
969 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
970 * {@code null} {@link Connection} from
971 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
972 * ConnectionRequest)}.
973 * <p>
974 * For more information on call handovers, see
975 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700976 */
977 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
978
979 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800980 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
981 * is initiated but the source or destination app does not support handover.
982 * <p>
983 * Will be returned when a handover is requested via
984 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
985 * {@link PhoneAccountHandle} does not declare
986 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
987 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
988 * {@link Details#getAccountHandle()}) does not declare
989 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
990 * <p>
991 * For more information on call handovers, see
992 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700993 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800994 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700995
996 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800997 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
998 * user rejects the handover request.
999 * <p>
1000 * For more information on call handovers, see
1001 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001002 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001003 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001004
Sanket Padawe85291f62017-12-01 13:59:27 -08001005 /**
1006 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1007 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001008 * <p>
1009 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1010 * called on an emergency call, or if any other call is an emergency call.
1011 * <p>
1012 * Handovers are not permitted while there are ongoing emergency calls.
1013 * <p>
1014 * For more information on call handovers, see
1015 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001016 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001017 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001018
Tyler Gunn9d127732018-03-02 15:45:51 -08001019 /**
1020 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1021 * fails for an unknown reason.
1022 * <p>
1023 * For more information on call handovers, see
1024 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1025 */
1026 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001027
1028 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001029 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1030 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001031 * @param call The {@code Call} invoking this method.
1032 * @param state The new state of the {@code Call}.
1033 */
1034 public void onStateChanged(Call call, int state) {}
1035
1036 /**
1037 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1038 *
1039 * @param call The {@code Call} invoking this method.
1040 * @param parent The new parent of the {@code Call}.
1041 */
1042 public void onParentChanged(Call call, Call parent) {}
1043
1044 /**
1045 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1046 *
1047 * @param call The {@code Call} invoking this method.
1048 * @param children The new children of the {@code Call}.
1049 */
1050 public void onChildrenChanged(Call call, List<Call> children) {}
1051
1052 /**
1053 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1054 *
1055 * @param call The {@code Call} invoking this method.
1056 * @param details A {@code Details} object describing the {@code Call}.
1057 */
1058 public void onDetailsChanged(Call call, Details details) {}
1059
1060 /**
1061 * Invoked when the text messages that can be used as responses to the incoming
1062 * {@code Call} are loaded from the relevant database.
1063 * See {@link #getCannedTextResponses()}.
1064 *
1065 * @param call The {@code Call} invoking this method.
1066 * @param cannedTextResponses The text messages useable as responses.
1067 */
1068 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1069
1070 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001071 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1072 * character. This causes the post-dial signals to stop pending user confirmation. An
1073 * implementation should present this choice to the user and invoke
1074 * {@link #postDialContinue(boolean)} when the user makes the choice.
1075 *
1076 * @param call The {@code Call} invoking this method.
1077 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1078 */
1079 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1080
1081 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001082 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001083 *
1084 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001085 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001086 */
Andrew Lee50aca232014-07-22 16:41:54 -07001087 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001088
1089 /**
1090 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1091 * up their UI for the {@code Call} in response to state transitions. Specifically,
1092 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1093 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1094 * clients should wait for this method to be invoked.
1095 *
1096 * @param call The {@code Call} being destroyed.
1097 */
1098 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001099
1100 /**
1101 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1102 * conferenced.
1103 *
1104 * @param call The {@code Call} being updated.
1105 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1106 * conferenced.
1107 */
1108 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001109
1110 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001111 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
1112 * <p>
1113 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1114 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1115 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1116 * possible that a {@link ConnectionService} has defined its own Connection events which a
1117 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001118 * <p>
1119 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
1120 *
1121 * @param call The {@code Call} receiving the event.
1122 * @param event The event.
1123 * @param extras Extras associated with the connection event.
1124 */
1125 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001126
1127 /**
1128 * Invoked when the RTT mode changes for this call.
1129 * @param call The call whose RTT mode has changed.
1130 * @param mode the new RTT mode, one of
1131 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1132 * or {@link RttCall#RTT_MODE_VCO}
1133 */
1134 public void onRttModeChanged(Call call, int mode) {}
1135
1136 /**
1137 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1138 * @param call The call whose RTT status has changed.
1139 * @param enabled whether RTT is now enabled or disabled
1140 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1141 * on, null otherwise.
1142 */
1143 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1144
1145 /**
1146 * Invoked when the remote end of the connection has requested that an RTT communication
1147 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1148 * with the same ID that this method is invoked with.
1149 * @param call The call which the RTT request was placed on
1150 * @param id The ID of the request.
1151 */
1152 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001153
1154 /**
1155 * Invoked when the RTT session failed to initiate for some reason, including rejection
1156 * by the remote party.
1157 * @param call The call which the RTT initiation failure occurred on.
1158 * @param reason One of the status codes defined in
1159 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1160 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1161 */
1162 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001163
1164 /**
1165 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1166 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001167 * <p>
1168 * For a full discussion of the handover process and the APIs involved, see
1169 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1170 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001171 * @param call The call which had initiated handover.
1172 */
1173 public void onHandoverComplete(Call call) {}
1174
1175 /**
1176 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1177 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001178 * <p>
1179 * For a full discussion of the handover process and the APIs involved, see
1180 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1181 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001182 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001183 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001184 */
1185 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001186 }
1187
1188 /**
1189 * A class that holds the state that describes the state of the RTT channel to the remote
1190 * party, if it is active.
1191 */
1192 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001193 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001194 @Retention(RetentionPolicy.SOURCE)
1195 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1196 public @interface RttAudioMode {}
1197
1198 /**
1199 * For metrics use. Default value in the proto.
1200 * @hide
1201 */
1202 public static final int RTT_MODE_INVALID = 0;
1203
1204 /**
1205 * Indicates that there should be a bidirectional audio stream between the two parties
1206 * on the call.
1207 */
1208 public static final int RTT_MODE_FULL = 1;
1209
1210 /**
1211 * Indicates that the local user should be able to hear the audio stream from the remote
1212 * user, but not vice versa. Equivalent to muting the microphone.
1213 */
1214 public static final int RTT_MODE_HCO = 2;
1215
1216 /**
1217 * Indicates that the remote user should be able to hear the audio stream from the local
1218 * user, but not vice versa. Equivalent to setting the volume to zero.
1219 */
1220 public static final int RTT_MODE_VCO = 3;
1221
1222 private static final int READ_BUFFER_SIZE = 1000;
1223
1224 private InputStreamReader mReceiveStream;
1225 private OutputStreamWriter mTransmitStream;
1226 private int mRttMode;
1227 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001228 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001229 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1230
1231 /**
1232 * @hide
1233 */
Hall Liu57006aa2017-02-06 10:49:48 -08001234 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1235 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1236 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001237 mReceiveStream = receiveStream;
1238 mTransmitStream = transmitStream;
1239 mRttMode = mode;
1240 mInCallAdapter = inCallAdapter;
1241 }
1242
1243 /**
1244 * Returns the current RTT audio mode.
1245 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1246 * {@link #RTT_MODE_HCO}.
1247 */
1248 public int getRttAudioMode() {
1249 return mRttMode;
1250 }
1251
1252 /**
1253 * Sets the RTT audio mode. The requested mode change will be communicated through
1254 * {@link Callback#onRttModeChanged(Call, int)}.
1255 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1256 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1257 */
1258 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001259 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001260 }
1261
1262 /**
1263 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1264 * RTT transmits text in real-time, this method should be called once for each character
1265 * the user enters into the device.
1266 *
1267 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1268 * lead to interleaved text.
1269 * @param input The message to send to the remote user.
1270 */
1271 public void write(String input) throws IOException {
1272 mTransmitStream.write(input);
1273 mTransmitStream.flush();
1274 }
1275
1276 /**
1277 * Reads a string from the remote user, blocking if there is no data available. Returns
1278 * {@code null} if the RTT conversation has been terminated and there is no further data
1279 * to read.
1280 *
1281 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1282 * lead to interleaved text.
1283 * @return A string containing text sent by the remote user, or {@code null} if the
1284 * conversation has been terminated or if there was an error while reading.
1285 */
Hall Liub1c8a772017-07-17 17:04:41 -07001286 public String read() {
1287 try {
1288 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1289 if (numRead < 0) {
1290 return null;
1291 }
1292 return new String(mReadBuffer, 0, numRead);
1293 } catch (IOException e) {
1294 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001295 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001296 }
Hall Liuffa4a812017-03-02 16:11:00 -08001297 }
1298
1299 /**
1300 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1301 * be read.
1302 * @return A string containing text entered by the user, or {@code null} if the user has
1303 * not entered any new text yet.
1304 */
1305 public String readImmediately() throws IOException {
1306 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001307 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1308 if (numRead < 0) {
1309 return null;
1310 }
1311 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001312 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001313 return null;
1314 }
1315 }
Hall Liue9041242018-02-09 16:40:03 -08001316
1317 /**
1318 * Closes the underlying file descriptors
1319 * @hide
1320 */
1321 public void close() {
1322 try {
1323 mReceiveStream.close();
1324 } catch (IOException e) {
1325 // ignore
1326 }
1327 try {
1328 mTransmitStream.close();
1329 } catch (IOException e) {
1330 // ignore
1331 }
1332 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001333 }
1334
Andrew Leeda80c872015-04-15 14:09:50 -07001335 /**
1336 * @deprecated Use {@code Call.Callback} instead.
1337 * @hide
1338 */
1339 @Deprecated
1340 @SystemApi
1341 public static abstract class Listener extends Callback { }
1342
Ihab Awade63fadb2014-07-09 21:52:04 -07001343 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001344 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001345 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001346 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001347 private final List<Call> mChildren = new ArrayList<>();
1348 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001349 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001350 private final List<Call> mConferenceableCalls = new ArrayList<>();
1351 private final List<Call> mUnmodifiableConferenceableCalls =
1352 Collections.unmodifiableList(mConferenceableCalls);
1353
Santos Cordon823fd3c2014-08-07 18:35:18 -07001354 private boolean mChildrenCached;
1355 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001356 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001357 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001358 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001359 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001360 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001361 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001362 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001363 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001364 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001365
1366 /**
1367 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1368 *
1369 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1370 * remaining or this {@code Call} is not in a post-dial state.
1371 */
1372 public String getRemainingPostDialSequence() {
1373 return mRemainingPostDialSequence;
1374 }
1375
1376 /**
1377 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001378 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001379 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001380 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001381 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001382 }
1383
1384 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301385 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1386 *
1387 * @param address The address to which the call will be deflected.
1388 */
1389 public void deflect(Uri address) {
1390 mInCallAdapter.deflectCall(mTelecomCallId, address);
1391 }
1392
1393 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001394 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1395 *
1396 * @param rejectWithMessage Whether to reject with a text message.
1397 * @param textMessage An optional text message with which to respond.
1398 */
1399 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001400 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001401 }
1402
1403 /**
1404 * Instructs this {@code Call} to disconnect.
1405 */
1406 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001407 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001408 }
1409
1410 /**
1411 * Instructs this {@code Call} to go on hold.
1412 */
1413 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001414 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001415 }
1416
1417 /**
1418 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1419 */
1420 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001421 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001422 }
1423
1424 /**
1425 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1426 *
1427 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1428 *
1429 * @param digit A character representing the DTMF digit for which to play the tone. This
1430 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1431 */
1432 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001433 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001434 }
1435
1436 /**
1437 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1438 * currently playing.
1439 *
1440 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1441 * currently playing, this method will do nothing.
1442 */
1443 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001444 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001445 }
1446
1447 /**
1448 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1449 *
1450 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1451 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001452 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001453 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001454 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1455 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001456 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001457 * {@code Call} will pause playing the tones and notify callbacks via
1458 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001459 * should display to the user an indication of this state and an affordance to continue
1460 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1461 * app should invoke the {@link #postDialContinue(boolean)} method.
1462 *
1463 * @param proceed Whether or not to continue with the post-dial sequence.
1464 */
1465 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001466 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001467 }
1468
1469 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001470 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001471 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001472 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001473 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1474 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001475
1476 }
1477
1478 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001479 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001480 *
1481 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001482 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001483 public void conference(Call callToConferenceWith) {
1484 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001485 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001486 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001487 }
1488
1489 /**
1490 * Instructs this {@code Call} to split from any conference call with which it may be
1491 * connected.
1492 */
1493 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001494 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001495 }
1496
1497 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001498 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001499 */
1500 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001501 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001502 }
1503
1504 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001505 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001506 */
1507 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001508 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001509 }
1510
1511 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001512 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1513 * device.
1514 * <p>
1515 * Calls to this method are ignored if the call does not have the
1516 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1517 * <p>
1518 * An {@link InCallService} will only see calls which support this method if it has the
1519 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1520 * in its manifest.
1521 */
1522 public void pullExternalCall() {
1523 // If this isn't an external call, ignore the request.
1524 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1525 return;
1526 }
1527
1528 mInCallAdapter.pullExternalCall(mTelecomCallId);
1529 }
1530
1531 /**
1532 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1533 * the {@link ConnectionService}.
1534 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001535 * Call events are used to communicate point in time information from an {@link InCallService}
1536 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1537 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1538 * {@link ConnectionService}.
1539 * <p>
1540 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1541 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1542 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001543 * Events are exposed to {@link ConnectionService} implementations via
1544 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1545 * <p>
1546 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001547 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1548 * ignore some events altogether.
1549 * <p>
1550 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1551 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1552 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1553 * they define their own event types in this namespace. When defining a custom event type,
1554 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1555 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1556 * <p>
1557 * When defining events and the associated extras, it is important to keep their behavior
1558 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1559 * events/extras should me maintained to ensure backwards compatibility with older
1560 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001561 *
1562 * @param event The connection event.
1563 * @param extras Bundle containing extra information associated with the event.
1564 */
1565 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001566 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001567 }
1568
1569 /**
Hall Liu95d55872017-01-25 17:12:49 -08001570 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1571 * guaranteed, and notification of success will be via the
1572 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1573 */
1574 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001575 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001576 }
1577
1578 /**
1579 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1580 * callback.
1581 * The ID used here should be the same as the ID that was received via the callback.
1582 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1583 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1584 */
1585 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001586 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001587 }
1588
1589 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001590 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1591 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1592 * handover.
1593 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001594 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1595 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1596 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1597 * is referred to as the source of the handover, and the video calling app is referred to as the
1598 * destination.
1599 * <p>
1600 * When considering a handover scenario the device this method is called on is considered the
1601 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1602 * other device is considered the <em>receiving</em> device.
1603 * <p>
1604 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1605 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1606 * and invoke
1607 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1608 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1609 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1610 * At this point the app should display UI to indicate to the user that a call
1611 * handover is in process.
1612 * <p>
1613 * The destination app is responsible for communicating the handover request from the
1614 * <em>initiating</em> device to the <em>receiving</em> device.
1615 * <p>
1616 * When the app on the <em>receiving</em> device receives the handover request, it calls
1617 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1618 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1619 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1620 * choose whether they want to continue their call in the destination app.
1621 * <p>
1622 * When the destination app on the <em>receiving</em> device calls
1623 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1624 * {@link ConnectionService} and call
1625 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1626 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1627 * {@link Connection} to represent the handover call.
1628 * <p>
1629 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1630 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1631 * original call. If the user rejects the handover, the app calls
1632 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1633 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1634 * <p>
1635 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1636 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1637 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1638 * <p>
1639 * Errors in the handover process are reported to the {@link InCallService} via
1640 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1641 * the involved {@link ConnectionService}s via
1642 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001643 *
1644 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1645 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001646 * @param videoState Indicates the video state desired after the handover (see the
1647 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001648 * @param extras Bundle containing extra information to be passed to the
1649 * {@link ConnectionService}
1650 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001651 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1652 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001653 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1654 }
1655
1656 /**
Hall Liu95d55872017-01-25 17:12:49 -08001657 * Terminate the RTT session on this call. The resulting state change will be notified via
1658 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1659 */
1660 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001661 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001662 }
1663
1664 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001665 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1666 * added.
1667 * <p>
1668 * No assumptions should be made as to how an In-Call UI or service will handle these
1669 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1670 *
1671 * @param extras The extras to add.
1672 */
1673 public final void putExtras(Bundle extras) {
1674 if (extras == null) {
1675 return;
1676 }
1677
1678 if (mExtras == null) {
1679 mExtras = new Bundle();
1680 }
1681 mExtras.putAll(extras);
1682 mInCallAdapter.putExtras(mTelecomCallId, extras);
1683 }
1684
1685 /**
1686 * Adds a boolean extra to this {@link Call}.
1687 *
1688 * @param key The extra key.
1689 * @param value The value.
1690 * @hide
1691 */
1692 public final void putExtra(String key, boolean value) {
1693 if (mExtras == null) {
1694 mExtras = new Bundle();
1695 }
1696 mExtras.putBoolean(key, value);
1697 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1698 }
1699
1700 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001701 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001702 *
1703 * @param key The extra key.
1704 * @param value The value.
1705 * @hide
1706 */
1707 public final void putExtra(String key, int value) {
1708 if (mExtras == null) {
1709 mExtras = new Bundle();
1710 }
1711 mExtras.putInt(key, value);
1712 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1713 }
1714
1715 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001716 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001717 *
1718 * @param key The extra key.
1719 * @param value The value.
1720 * @hide
1721 */
1722 public final void putExtra(String key, String value) {
1723 if (mExtras == null) {
1724 mExtras = new Bundle();
1725 }
1726 mExtras.putString(key, value);
1727 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1728 }
1729
1730 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001731 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001732 *
1733 * @param keys The keys of the extras to remove.
1734 */
1735 public final void removeExtras(List<String> keys) {
1736 if (mExtras != null) {
1737 for (String key : keys) {
1738 mExtras.remove(key);
1739 }
1740 if (mExtras.size() == 0) {
1741 mExtras = null;
1742 }
1743 }
1744 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1745 }
1746
1747 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001748 * Removes extras from this {@link Call}.
1749 *
1750 * @param keys The keys of the extras to remove.
1751 */
1752 public final void removeExtras(String ... keys) {
1753 removeExtras(Arrays.asList(keys));
1754 }
1755
1756 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001757 * Obtains the parent of this {@code Call} in a conference, if any.
1758 *
1759 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1760 * child of any conference {@code Call}s.
1761 */
1762 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001763 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001764 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001765 }
1766 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001767 }
1768
1769 /**
1770 * Obtains the children of this conference {@code Call}, if any.
1771 *
1772 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1773 * {@code List} otherwise.
1774 */
1775 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001776 if (!mChildrenCached) {
1777 mChildrenCached = true;
1778 mChildren.clear();
1779
1780 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001781 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001782 if (call == null) {
1783 // At least one child was still not found, so do not save true for "cached"
1784 mChildrenCached = false;
1785 } else {
1786 mChildren.add(call);
1787 }
1788 }
1789 }
1790
Ihab Awade63fadb2014-07-09 21:52:04 -07001791 return mUnmodifiableChildren;
1792 }
1793
1794 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001795 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1796 *
1797 * @return The list of conferenceable {@code Call}s.
1798 */
1799 public List<Call> getConferenceableCalls() {
1800 return mUnmodifiableConferenceableCalls;
1801 }
1802
1803 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001804 * Obtains the state of this {@code Call}.
1805 *
1806 * @return A state value, chosen from the {@code STATE_*} constants.
1807 */
1808 public int getState() {
1809 return mState;
1810 }
1811
1812 /**
1813 * Obtains a list of canned, pre-configured message responses to present to the user as
1814 * ways of rejecting this {@code Call} using via a text message.
1815 *
1816 * @see #reject(boolean, String)
1817 *
1818 * @return A list of canned text message responses.
1819 */
1820 public List<String> getCannedTextResponses() {
1821 return mCannedTextResponses;
1822 }
1823
1824 /**
1825 * Obtains an object that can be used to display video from this {@code Call}.
1826 *
Andrew Lee50aca232014-07-22 16:41:54 -07001827 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001828 */
Andrew Lee50aca232014-07-22 16:41:54 -07001829 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001830 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001831 }
1832
1833 /**
1834 * Obtains an object containing call details.
1835 *
1836 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1837 * result may be {@code null}.
1838 */
1839 public Details getDetails() {
1840 return mDetails;
1841 }
1842
1843 /**
Hall Liu95d55872017-01-25 17:12:49 -08001844 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1845 * receive RTT text data, as well as to change the RTT mode.
1846 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1847 */
1848 public @Nullable RttCall getRttCall() {
1849 return mRttCall;
1850 }
1851
1852 /**
1853 * Returns whether this call has an active RTT connection.
1854 * @return true if there is a connection, false otherwise.
1855 */
1856 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08001857 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08001858 }
1859
1860 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001861 * Registers a callback to this {@code Call}.
1862 *
1863 * @param callback A {@code Callback}.
1864 */
1865 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001866 registerCallback(callback, new Handler());
1867 }
1868
1869 /**
1870 * Registers a callback to this {@code Call}.
1871 *
1872 * @param callback A {@code Callback}.
1873 * @param handler A handler which command and status changes will be delivered to.
1874 */
1875 public void registerCallback(Callback callback, Handler handler) {
1876 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001877 // Don't allow new callback registration if the call is already being destroyed.
1878 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001879 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1880 }
Andrew Leeda80c872015-04-15 14:09:50 -07001881 }
1882
1883 /**
1884 * Unregisters a callback from this {@code Call}.
1885 *
1886 * @param callback A {@code Callback}.
1887 */
1888 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001889 // Don't allow callback deregistration if the call is already being destroyed.
1890 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001891 for (CallbackRecord<Callback> record : mCallbackRecords) {
1892 if (record.getCallback() == callback) {
1893 mCallbackRecords.remove(record);
1894 break;
1895 }
1896 }
Andrew Leeda80c872015-04-15 14:09:50 -07001897 }
1898 }
1899
Santos Cordon3c20d632016-02-25 16:12:35 -08001900 @Override
1901 public String toString() {
1902 return new StringBuilder().
1903 append("Call [id: ").
1904 append(mTelecomCallId).
1905 append(", state: ").
1906 append(stateToString(mState)).
1907 append(", details: ").
1908 append(mDetails).
1909 append("]").toString();
1910 }
1911
1912 /**
1913 * @param state An integer value of a {@code STATE_*} constant.
1914 * @return A string representation of the value.
1915 */
1916 private static String stateToString(int state) {
1917 switch (state) {
1918 case STATE_NEW:
1919 return "NEW";
1920 case STATE_RINGING:
1921 return "RINGING";
1922 case STATE_DIALING:
1923 return "DIALING";
1924 case STATE_ACTIVE:
1925 return "ACTIVE";
1926 case STATE_HOLDING:
1927 return "HOLDING";
1928 case STATE_DISCONNECTED:
1929 return "DISCONNECTED";
1930 case STATE_CONNECTING:
1931 return "CONNECTING";
1932 case STATE_DISCONNECTING:
1933 return "DISCONNECTING";
1934 case STATE_SELECT_PHONE_ACCOUNT:
1935 return "SELECT_PHONE_ACCOUNT";
1936 default:
1937 Log.w(Call.class, "Unknown state %d", state);
1938 return "UNKNOWN";
1939 }
1940 }
1941
Andrew Leeda80c872015-04-15 14:09:50 -07001942 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001943 * Adds a listener to this {@code Call}.
1944 *
1945 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001946 * @deprecated Use {@link #registerCallback} instead.
1947 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001948 */
Andrew Leeda80c872015-04-15 14:09:50 -07001949 @Deprecated
1950 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001951 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001952 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001953 }
1954
1955 /**
1956 * Removes a listener from this {@code Call}.
1957 *
1958 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001959 * @deprecated Use {@link #unregisterCallback} instead.
1960 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001961 */
Andrew Leeda80c872015-04-15 14:09:50 -07001962 @Deprecated
1963 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001964 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001965 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001966 }
1967
1968 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001969 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1970 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001971 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001972 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001973 mInCallAdapter = inCallAdapter;
1974 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001975 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001976 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001977 }
1978
1979 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001980 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001981 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001982 mPhone = phone;
1983 mTelecomCallId = telecomCallId;
1984 mInCallAdapter = inCallAdapter;
1985 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001986 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001987 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001988 }
1989
1990 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001991 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001992 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001993 }
1994
1995 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001996 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001997
Ihab Awade63fadb2014-07-09 21:52:04 -07001998 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001999 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002000 boolean detailsChanged = !Objects.equals(mDetails, details);
2001 if (detailsChanged) {
2002 mDetails = details;
2003 }
2004
2005 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002006 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2007 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2008 mCannedTextResponses =
2009 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002010 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002011 }
2012
Tyler Gunn159f35c2017-03-02 09:28:37 -08002013 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
2014 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07002015 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002016 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07002017 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002018 mVideoCallImpl = newVideoCallImpl;
2019 }
2020 if (mVideoCallImpl != null) {
2021 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002022 }
2023
Santos Cordone3c507b2015-04-23 14:44:19 -07002024 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07002025 boolean stateChanged = mState != state;
2026 if (stateChanged) {
2027 mState = state;
2028 }
2029
Santos Cordon823fd3c2014-08-07 18:35:18 -07002030 String parentId = parcelableCall.getParentCallId();
2031 boolean parentChanged = !Objects.equals(mParentId, parentId);
2032 if (parentChanged) {
2033 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002034 }
2035
Santos Cordon823fd3c2014-08-07 18:35:18 -07002036 List<String> childCallIds = parcelableCall.getChildCallIds();
2037 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2038 if (childrenChanged) {
2039 mChildrenIds.clear();
2040 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2041 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002042 }
2043
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002044 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2045 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2046 for (String otherId : conferenceableCallIds) {
2047 if (callIdMap.containsKey(otherId)) {
2048 conferenceableCalls.add(callIdMap.get(otherId));
2049 }
2050 }
2051
2052 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2053 mConferenceableCalls.clear();
2054 mConferenceableCalls.addAll(conferenceableCalls);
2055 fireConferenceableCallsChanged();
2056 }
2057
Hall Liu95d55872017-01-25 17:12:49 -08002058 boolean isRttChanged = false;
2059 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002060 if (parcelableCall.getIsRttCallChanged()
2061 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002062 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2063 InputStreamReader receiveStream = new InputStreamReader(
2064 new ParcelFileDescriptor.AutoCloseInputStream(
2065 parcelableRttCall.getReceiveStream()),
2066 StandardCharsets.UTF_8);
2067 OutputStreamWriter transmitStream = new OutputStreamWriter(
2068 new ParcelFileDescriptor.AutoCloseOutputStream(
2069 parcelableRttCall.getTransmitStream()),
2070 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002071 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002072 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2073 if (mRttCall == null) {
2074 isRttChanged = true;
2075 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2076 rttModeChanged = true;
2077 }
2078 mRttCall = newRttCall;
2079 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2080 && parcelableCall.getIsRttCallChanged()) {
2081 isRttChanged = true;
2082 mRttCall = null;
2083 }
2084
Ihab Awade63fadb2014-07-09 21:52:04 -07002085 // Now we fire updates, ensuring that any client who listens to any of these notifications
2086 // gets the most up-to-date state.
2087
2088 if (stateChanged) {
2089 fireStateChanged(mState);
2090 }
2091 if (detailsChanged) {
2092 fireDetailsChanged(mDetails);
2093 }
2094 if (cannedTextResponsesChanged) {
2095 fireCannedTextResponsesLoaded(mCannedTextResponses);
2096 }
Andrew Lee50aca232014-07-22 16:41:54 -07002097 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002098 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002099 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002100 if (parentChanged) {
2101 fireParentChanged(getParent());
2102 }
2103 if (childrenChanged) {
2104 fireChildrenChanged(getChildren());
2105 }
Hall Liu95d55872017-01-25 17:12:49 -08002106 if (isRttChanged) {
2107 fireOnIsRttChanged(mRttCall != null, mRttCall);
2108 }
2109 if (rttModeChanged) {
2110 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2111 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002112
2113 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2114 // remove ourselves from the Phone. Note that we do this after completing all state updates
2115 // so a client can cleanly transition all their UI to the state appropriate for a
2116 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2117 if (mState == STATE_DISCONNECTED) {
2118 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002119 }
2120 }
2121
2122 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002123 final void internalSetPostDialWait(String remaining) {
2124 mRemainingPostDialSequence = remaining;
2125 firePostDialWait(mRemainingPostDialSequence);
2126 }
2127
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002128 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002129 final void internalSetDisconnected() {
2130 if (mState != Call.STATE_DISCONNECTED) {
2131 mState = Call.STATE_DISCONNECTED;
2132 fireStateChanged(mState);
2133 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002134 }
2135 }
2136
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002137 /** {@hide} */
2138 final void internalOnConnectionEvent(String event, Bundle extras) {
2139 fireOnConnectionEvent(event, extras);
2140 }
2141
Hall Liu95d55872017-01-25 17:12:49 -08002142 /** {@hide} */
2143 final void internalOnRttUpgradeRequest(final int requestId) {
2144 for (CallbackRecord<Callback> record : mCallbackRecords) {
2145 final Call call = this;
2146 final Callback callback = record.getCallback();
2147 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2148 }
2149 }
2150
Hall Liu57006aa2017-02-06 10:49:48 -08002151 /** @hide */
2152 final void internalOnRttInitiationFailure(int reason) {
2153 for (CallbackRecord<Callback> record : mCallbackRecords) {
2154 final Call call = this;
2155 final Callback callback = record.getCallback();
2156 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2157 }
2158 }
2159
Sanket Padawe85291f62017-12-01 13:59:27 -08002160 /** {@hide} */
2161 final void internalOnHandoverFailed(int error) {
2162 for (CallbackRecord<Callback> record : mCallbackRecords) {
2163 final Call call = this;
2164 final Callback callback = record.getCallback();
2165 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2166 }
2167 }
2168
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002169 /** {@hide} */
2170 final void internalOnHandoverComplete() {
2171 for (CallbackRecord<Callback> record : mCallbackRecords) {
2172 final Call call = this;
2173 final Callback callback = record.getCallback();
2174 record.getHandler().post(() -> callback.onHandoverComplete(call));
2175 }
2176 }
2177
Andrew Lee011728f2015-04-23 15:47:06 -07002178 private void fireStateChanged(final int newState) {
2179 for (CallbackRecord<Callback> record : mCallbackRecords) {
2180 final Call call = this;
2181 final Callback callback = record.getCallback();
2182 record.getHandler().post(new Runnable() {
2183 @Override
2184 public void run() {
2185 callback.onStateChanged(call, newState);
2186 }
2187 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002188 }
2189 }
2190
Andrew Lee011728f2015-04-23 15:47:06 -07002191 private void fireParentChanged(final Call newParent) {
2192 for (CallbackRecord<Callback> record : mCallbackRecords) {
2193 final Call call = this;
2194 final Callback callback = record.getCallback();
2195 record.getHandler().post(new Runnable() {
2196 @Override
2197 public void run() {
2198 callback.onParentChanged(call, newParent);
2199 }
2200 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002201 }
2202 }
2203
Andrew Lee011728f2015-04-23 15:47:06 -07002204 private void fireChildrenChanged(final List<Call> children) {
2205 for (CallbackRecord<Callback> record : mCallbackRecords) {
2206 final Call call = this;
2207 final Callback callback = record.getCallback();
2208 record.getHandler().post(new Runnable() {
2209 @Override
2210 public void run() {
2211 callback.onChildrenChanged(call, children);
2212 }
2213 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002214 }
2215 }
2216
Andrew Lee011728f2015-04-23 15:47:06 -07002217 private void fireDetailsChanged(final Details details) {
2218 for (CallbackRecord<Callback> record : mCallbackRecords) {
2219 final Call call = this;
2220 final Callback callback = record.getCallback();
2221 record.getHandler().post(new Runnable() {
2222 @Override
2223 public void run() {
2224 callback.onDetailsChanged(call, details);
2225 }
2226 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002227 }
2228 }
2229
Andrew Lee011728f2015-04-23 15:47:06 -07002230 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2231 for (CallbackRecord<Callback> record : mCallbackRecords) {
2232 final Call call = this;
2233 final Callback callback = record.getCallback();
2234 record.getHandler().post(new Runnable() {
2235 @Override
2236 public void run() {
2237 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2238 }
2239 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002240 }
2241 }
2242
Andrew Lee011728f2015-04-23 15:47:06 -07002243 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2244 for (CallbackRecord<Callback> record : mCallbackRecords) {
2245 final Call call = this;
2246 final Callback callback = record.getCallback();
2247 record.getHandler().post(new Runnable() {
2248 @Override
2249 public void run() {
2250 callback.onVideoCallChanged(call, videoCall);
2251 }
2252 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002253 }
2254 }
2255
Andrew Lee011728f2015-04-23 15:47:06 -07002256 private void firePostDialWait(final String remainingPostDialSequence) {
2257 for (CallbackRecord<Callback> record : mCallbackRecords) {
2258 final Call call = this;
2259 final Callback callback = record.getCallback();
2260 record.getHandler().post(new Runnable() {
2261 @Override
2262 public void run() {
2263 callback.onPostDialWait(call, remainingPostDialSequence);
2264 }
2265 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002266 }
2267 }
2268
2269 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002270 /**
2271 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2272 * onCallRemoved callback, we remove this call from the Phone's record
2273 * only once all of the registered onCallDestroyed callbacks are executed.
2274 * All the callbacks get removed from our records as a part of this operation
2275 * since onCallDestroyed is the final callback.
2276 */
2277 final Call call = this;
2278 if (mCallbackRecords.isEmpty()) {
2279 // No callbacks registered, remove the call from Phone's record.
2280 mPhone.internalRemoveCall(call);
2281 }
2282 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002283 final Callback callback = record.getCallback();
2284 record.getHandler().post(new Runnable() {
2285 @Override
2286 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002287 boolean isFinalRemoval = false;
2288 RuntimeException toThrow = null;
2289 try {
2290 callback.onCallDestroyed(call);
2291 } catch (RuntimeException e) {
2292 toThrow = e;
2293 }
2294 synchronized(Call.this) {
2295 mCallbackRecords.remove(record);
2296 if (mCallbackRecords.isEmpty()) {
2297 isFinalRemoval = true;
2298 }
2299 }
2300 if (isFinalRemoval) {
2301 mPhone.internalRemoveCall(call);
2302 }
2303 if (toThrow != null) {
2304 throw toThrow;
2305 }
Andrew Lee011728f2015-04-23 15:47:06 -07002306 }
2307 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002308 }
2309 }
2310
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002311 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002312 for (CallbackRecord<Callback> record : mCallbackRecords) {
2313 final Call call = this;
2314 final Callback callback = record.getCallback();
2315 record.getHandler().post(new Runnable() {
2316 @Override
2317 public void run() {
2318 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2319 }
2320 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002321 }
2322 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002323
2324 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002325 * Notifies listeners of an incoming connection event.
2326 * <p>
2327 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2328 *
2329 * @param event
2330 * @param extras
2331 */
2332 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2333 for (CallbackRecord<Callback> record : mCallbackRecords) {
2334 final Call call = this;
2335 final Callback callback = record.getCallback();
2336 record.getHandler().post(new Runnable() {
2337 @Override
2338 public void run() {
2339 callback.onConnectionEvent(call, event, extras);
2340 }
2341 });
2342 }
2343 }
2344
2345 /**
Hall Liu95d55872017-01-25 17:12:49 -08002346 * Notifies listeners of an RTT on/off change
2347 *
2348 * @param enabled True if RTT is now enabled, false otherwise
2349 */
2350 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2351 for (CallbackRecord<Callback> record : mCallbackRecords) {
2352 final Call call = this;
2353 final Callback callback = record.getCallback();
2354 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2355 }
2356 }
2357
2358 /**
2359 * Notifies listeners of a RTT mode change
2360 *
2361 * @param mode The new RTT mode
2362 */
2363 private void fireOnRttModeChanged(final int mode) {
2364 for (CallbackRecord<Callback> record : mCallbackRecords) {
2365 final Call call = this;
2366 final Callback callback = record.getCallback();
2367 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2368 }
2369 }
2370
2371 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002372 * Determines if two bundles are equal.
2373 *
2374 * @param bundle The original bundle.
2375 * @param newBundle The bundle to compare with.
2376 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2377 */
2378 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2379 if (bundle == null || newBundle == null) {
2380 return bundle == newBundle;
2381 }
2382
2383 if (bundle.size() != newBundle.size()) {
2384 return false;
2385 }
2386
2387 for(String key : bundle.keySet()) {
2388 if (key != null) {
2389 final Object value = bundle.get(key);
2390 final Object newValue = newBundle.get(key);
2391 if (!Objects.equals(value, newValue)) {
2392 return false;
2393 }
2394 }
2395 }
2396 return true;
2397 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002398}