blob: d617de0af6a1dca98ee89bcb8af0c514434d3f85 [file] [log] [blame]
Ihab Awade63fadb2014-07-09 21:52:04 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awade63fadb2014-07-09 21:52:04 -070018
Hall Liu95d55872017-01-25 17:12:49 -080019import android.annotation.IntDef;
20import android.annotation.Nullable;
Andrew Leeda80c872015-04-15 14:09:50 -070021import android.annotation.SystemApi;
Mathew Inwood42346d12018-08-01 11:33:05 +010022import android.annotation.UnsupportedAppUsage;
Ihab Awade63fadb2014-07-09 21:52:04 -070023import android.net.Uri;
Tyler Gunn6e3ecc42018-11-12 11:30:56 -080024import android.os.Build;
Nancy Chen10798dc2014-08-08 14:00:25 -070025import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070026import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080027import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070028
Hall Liu95d55872017-01-25 17:12:49 -080029import java.io.IOException;
30import java.io.InputStreamReader;
31import java.io.OutputStreamWriter;
Hall Liu95d55872017-01-25 17:12:49 -080032import java.lang.annotation.Retention;
33import java.lang.annotation.RetentionPolicy;
34import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070035import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070036import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070037import java.util.Collections;
38import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070039import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070040import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070041import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070042
43/**
44 * Represents an ongoing phone call that the in-call app should present to the user.
45 */
46public final class Call {
47 /**
48 * The state of a {@code Call} when newly created.
49 */
50 public static final int STATE_NEW = 0;
51
52 /**
53 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
54 */
55 public static final int STATE_DIALING = 1;
56
57 /**
58 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
59 */
60 public static final int STATE_RINGING = 2;
61
62 /**
63 * The state of a {@code Call} when in a holding state.
64 */
65 public static final int STATE_HOLDING = 3;
66
67 /**
68 * The state of a {@code Call} when actively supporting conversation.
69 */
70 public static final int STATE_ACTIVE = 4;
71
72 /**
73 * The state of a {@code Call} when no further voice or other communication is being
74 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
75 * is no longer active, and the local data transport has or inevitably will release resources
76 * associated with this {@code Call}.
77 */
78 public static final int STATE_DISCONNECTED = 7;
79
Nancy Chen5da0fd52014-07-08 14:16:17 -070080 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070081 * The state of an outgoing {@code Call} when waiting on user to select a
82 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070083 */
Santos Cordone3c507b2015-04-23 14:44:19 -070084 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
85
86 /**
87 * @hide
88 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
89 */
90 @Deprecated
91 @SystemApi
92 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070093
Nancy Chene20930f2014-08-07 16:17:21 -070094 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070095 * The initial state of an outgoing {@code Call}.
96 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
97 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070098 */
99 public static final int STATE_CONNECTING = 9;
100
Nancy Chen513c8922014-09-17 14:47:20 -0700101 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700102 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
103 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
104 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
105 */
106 public static final int STATE_DISCONNECTING = 10;
107
108 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700109 * The state of an external call which is in the process of being pulled from a remote device to
110 * the local device.
111 * <p>
112 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
113 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
114 * <p>
115 * An {@link InCallService} will only see this state if it has the
116 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
117 * manifest.
118 */
119 public static final int STATE_PULLING_CALL = 11;
120
121 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700122 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
123 * extras. Used to pass the phone accounts to display on the front end to the user in order to
124 * select phone accounts to (for example) place a call.
Nancy Chen513c8922014-09-17 14:47:20 -0700125 */
126 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
127
mike dooley4af561f2016-12-20 08:55:17 -0800128 /**
mike dooley91217422017-03-09 12:58:42 -0800129 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
130 * when the last outgoing emergency call was made. This is used to identify potential emergency
131 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800132 */
133 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
134 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
135
Tyler Gunn8bf76572017-04-06 15:30:08 -0700136 /**
137 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
138 * Telecom that the user has requested that the current {@link Call} should be handed over
139 * to another {@link ConnectionService}.
140 * <p>
141 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
142 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
143 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700144 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
145 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700146 */
147 public static final String EVENT_REQUEST_HANDOVER =
148 "android.telecom.event.REQUEST_HANDOVER";
149
150 /**
151 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
152 * {@link PhoneAccountHandle} to which a call should be handed over to.
153 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700154 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
155 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700156 */
157 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
158 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
159
160 /**
161 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
162 * video state of the call when it is handed over to the new {@link PhoneAccount}.
163 * <p>
164 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
165 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
166 * {@link VideoProfile#STATE_TX_ENABLED}.
167 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700168 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
169 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700170 */
171 public static final String EXTRA_HANDOVER_VIDEO_STATE =
172 "android.telecom.extra.HANDOVER_VIDEO_STATE";
173
174 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700175 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
176 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
177 * information to the handover {@link ConnectionService} specified by
178 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
179 * <p>
180 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
181 * {@link ConnectionService} via the request extras when
182 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
183 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700184 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700185 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
186 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700187 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700188 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700189
190 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700191 * Call event sent from Telecom to the handover {@link ConnectionService} via
192 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
193 * to the {@link ConnectionService} has completed successfully.
194 * <p>
195 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700196 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700197 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
198 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700199 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700200 public static final String EVENT_HANDOVER_COMPLETE =
201 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700202
203 /**
204 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
205 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
206 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
207 * {@code null}.
208 * <p>
209 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
210 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700211 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
212 * APIs instead.
Tyler Gunn34a2b312017-06-23 08:32:00 -0700213 */
214 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
215 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
216
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700217 /**
218 * Call event sent from Telecom to the handover {@link ConnectionService} via
219 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
220 * to the {@link ConnectionService} has failed.
221 * <p>
222 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
223 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700224 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
225 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700226 */
227 public static final String EVENT_HANDOVER_FAILED =
228 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700229
Ihab Awade63fadb2014-07-09 21:52:04 -0700230 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800231
232 /** Call can currently be put on hold or unheld. */
233 public static final int CAPABILITY_HOLD = 0x00000001;
234
235 /** Call supports the hold feature. */
236 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
237
238 /**
239 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
240 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
241 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
242 * capability allows a merge button to be shown while the conference call is in the foreground
243 * of the in-call UI.
244 * <p>
245 * This is only intended for use by a {@link Conference}.
246 */
247 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
248
249 /**
250 * Calls within a conference can be swapped between foreground and background.
251 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
252 * <p>
253 * This is only intended for use by a {@link Conference}.
254 */
255 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
256
257 /**
258 * @hide
259 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700260 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800261
262 /** Call supports responding via text option. */
263 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
264
265 /** Call can be muted. */
266 public static final int CAPABILITY_MUTE = 0x00000040;
267
268 /**
269 * Call supports conference call management. This capability only applies to {@link Conference}
270 * calls which can have {@link Connection}s as children.
271 */
272 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
273
274 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700275 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800276 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700277 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800278
279 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700280 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800281 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700282 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800283
284 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700285 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800286 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700287 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700288 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800289
290 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700291 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800292 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700293 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
294
295 /**
296 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700297 */
298 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
299
300 /**
301 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700302 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700303 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700304 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800305
306 /**
307 * Call is able to be separated from its parent {@code Conference}, if any.
308 */
309 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
310
311 /**
312 * Call is able to be individually disconnected when in a {@code Conference}.
313 */
314 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
315
316 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500317 * Speed up audio setup for MT call.
318 * @hide
319 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700320 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
321
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700322 /**
323 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700324 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800325 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
326 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
327 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700328 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800329 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700330 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
331
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700332 /**
333 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700334 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700335 */
336 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
337
Bryce Lee81901682015-08-28 16:38:02 -0700338 /**
339 * Call sends responses through connection.
340 * @hide
341 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800342 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
343
344 /**
345 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
346 * <p>
347 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
348 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
349 * downgraded from a video call back to a VideoState of
350 * {@link VideoProfile#STATE_AUDIO_ONLY}.
351 * <p>
352 * Intuitively, a call which can be downgraded to audio should also have local and remote
353 * video
354 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
355 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
356 */
357 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700358
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700359 /**
360 * When set for an external call, indicates that this {@code Call} can be pulled from a
361 * remote device to the current device.
362 * <p>
363 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
364 * <p>
365 * An {@link InCallService} will only see calls with this capability if it has the
366 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
367 * in its manifest.
368 * <p>
369 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700370 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700371 */
372 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
373
Pooja Jaind34698d2017-12-28 14:15:31 +0530374 /** Call supports the deflect feature. */
375 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
376
Tyler Gunnd11a3152015-03-18 13:09:14 -0700377 //******************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530378 // Next CAPABILITY value: 0x02000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700379 //******************************************************************************************
380
381 /**
382 * Whether the call is currently a conference.
383 */
384 public static final int PROPERTY_CONFERENCE = 0x00000001;
385
386 /**
387 * Whether the call is a generic conference, where we do not know the precise state of
388 * participants in the conference (eg. on CDMA).
389 */
390 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
391
392 /**
393 * Whether the call is made while the device is in emergency callback mode.
394 */
395 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
396
397 /**
398 * Connection is using WIFI.
399 */
400 public static final int PROPERTY_WIFI = 0x00000008;
401
402 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700403 * When set, the UI should indicate to the user that a call is using high definition
404 * audio.
405 * <p>
406 * The underlying {@link ConnectionService} is responsible for reporting this
407 * property. It is important to note that this property is not intended to report the
408 * actual audio codec being used for a Call, but whether the call should be indicated
409 * to the user as high definition.
410 * <p>
411 * The Android Telephony stack reports this property for calls based on a number
412 * of factors, including which audio codec is used and whether a call is using an HD
413 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
414 * and in these cases this property will not be set for a call even if the underlying audio
415 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700416 */
417 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
418
Tony Maka68dcce2015-12-17 09:31:18 +0000419 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100420 * Whether the call is associated with the work profile.
421 */
422 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
423
424 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700425 * When set, indicates that this {@code Call} does not actually exist locally for the
426 * {@link ConnectionService}.
427 * <p>
428 * Consider, for example, a scenario where a user has two phones with the same phone number.
429 * When a user places a call on one device, the telephony stack can represent that call on
430 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700431 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700432 * <p>
433 * An {@link InCallService} will only see calls with this property if it has the
434 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
435 * in its manifest.
436 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700437 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700438 */
439 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
440
Brad Ebinger15847072016-05-18 11:08:36 -0700441 /**
442 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
443 */
444 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
445
Tyler Gunn24e18332017-02-10 09:42:49 -0800446 /**
447 * Indicates that the call is from a self-managed {@link ConnectionService}.
448 * <p>
449 * See also {@link Connection#PROPERTY_SELF_MANAGED}
450 */
451 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
452
Eric Erfanianec881872017-12-06 16:27:53 -0800453 /**
454 * Indicates the call used Assisted Dialing.
455 * See also {@link Connection#PROPERTY_ASSISTED_DIALING_USED}
456 * @hide
457 */
458 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
459
Hall Liue9041242018-02-09 16:40:03 -0800460 /**
461 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
462 * {@link RttCall} object that is used to send and receive text.
463 */
464 public static final int PROPERTY_RTT = 0x00000400;
465
Tyler Gunn5bd90852018-09-21 09:37:07 -0700466 /**
467 * Indicates that the call has been identified as the network as an emergency call. This
468 * property may be set for both incoming and outgoing calls which the network identifies as
469 * emergency calls.
470 */
471 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
472
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700473 /**
474 * Indicates that the call is using VoIP audio mode.
475 * <p>
476 * When this property is set, the {@link android.media.AudioManager} audio mode for this
477 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
478 * property is not set, the audio mode for this call will be
479 * {@link android.media.AudioManager#MODE_IN_CALL}.
480 * <p>
481 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
482 * <p>
483 * You can use this property to determine whether an un-answered incoming call or a held
484 * call will use VoIP audio mode (if the call does not currently have focus, the system
485 * audio mode may not reflect the mode the call will use).
486 */
487 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
488
Andrew Lee2378ea72015-04-29 14:38:11 -0700489 //******************************************************************************************
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700490 // Next PROPERTY value: 0x00002000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700491 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800492
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800493 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700494 private final Uri mHandle;
495 private final int mHandlePresentation;
496 private final String mCallerDisplayName;
497 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700498 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700499 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700500 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800501 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700502 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700503 private final long mConnectTimeMillis;
504 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700505 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700506 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700507 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700508 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700509 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700510
511 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800512 * Whether the supplied capabilities supports the specified capability.
513 *
514 * @param capabilities A bit field of capabilities.
515 * @param capability The capability to check capabilities for.
516 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800517 */
518 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800519 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800520 }
521
522 /**
523 * Whether the capabilities of this {@code Details} supports the specified capability.
524 *
525 * @param capability The capability to check capabilities for.
526 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800527 */
528 public boolean can(int capability) {
529 return can(mCallCapabilities, capability);
530 }
531
532 /**
533 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
534 *
535 * @param capabilities A capability bit field.
536 * @return A human readable string representation.
537 */
538 public static String capabilitiesToString(int capabilities) {
539 StringBuilder builder = new StringBuilder();
540 builder.append("[Capabilities:");
541 if (can(capabilities, CAPABILITY_HOLD)) {
542 builder.append(" CAPABILITY_HOLD");
543 }
544 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
545 builder.append(" CAPABILITY_SUPPORT_HOLD");
546 }
547 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
548 builder.append(" CAPABILITY_MERGE_CONFERENCE");
549 }
550 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
551 builder.append(" CAPABILITY_SWAP_CONFERENCE");
552 }
553 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
554 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
555 }
556 if (can(capabilities, CAPABILITY_MUTE)) {
557 builder.append(" CAPABILITY_MUTE");
558 }
559 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
560 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
561 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700562 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
563 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
564 }
565 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
566 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
567 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700568 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
569 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800570 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700571 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
572 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
573 }
574 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
575 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
576 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800577 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
578 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
579 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700580 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
581 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800582 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500583 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700584 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500585 }
Rekha Kumar07366812015-03-24 16:42:31 -0700586 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
587 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
588 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700589 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
590 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
591 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700592 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
593 builder.append(" CAPABILITY_CAN_PULL_CALL");
594 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530595 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
596 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
597 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800598 builder.append("]");
599 return builder.toString();
600 }
601
602 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700603 * Whether the supplied properties includes the specified property.
604 *
605 * @param properties A bit field of properties.
606 * @param property The property to check properties for.
607 * @return Whether the specified property is supported.
608 */
609 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800610 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700611 }
612
613 /**
614 * Whether the properties of this {@code Details} includes the specified property.
615 *
616 * @param property The property to check properties for.
617 * @return Whether the specified property is supported.
618 */
619 public boolean hasProperty(int property) {
620 return hasProperty(mCallProperties, property);
621 }
622
623 /**
624 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
625 *
626 * @param properties A property bit field.
627 * @return A human readable string representation.
628 */
629 public static String propertiesToString(int properties) {
630 StringBuilder builder = new StringBuilder();
631 builder.append("[Properties:");
632 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
633 builder.append(" PROPERTY_CONFERENCE");
634 }
635 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
636 builder.append(" PROPERTY_GENERIC_CONFERENCE");
637 }
638 if (hasProperty(properties, PROPERTY_WIFI)) {
639 builder.append(" PROPERTY_WIFI");
640 }
641 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
642 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
643 }
644 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700645 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700646 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700647 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
648 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
649 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700650 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700651 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
652 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700653 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800654 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
655 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700656 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
657 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
658 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700659 if (hasProperty(properties, PROPERTY_RTT)) {
660 builder.append(" PROPERTY_RTT");
661 }
662 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
663 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
664 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700665 builder.append("]");
666 return builder.toString();
667 }
668
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800669 /** {@hide} */
670 public String getTelecomCallId() {
671 return mTelecomCallId;
672 }
673
Andrew Lee2378ea72015-04-29 14:38:11 -0700674 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700675 * @return The handle (e.g., phone number) to which the {@code Call} is currently
676 * connected.
677 */
678 public Uri getHandle() {
679 return mHandle;
680 }
681
682 /**
683 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700684 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700685 */
686 public int getHandlePresentation() {
687 return mHandlePresentation;
688 }
689
690 /**
691 * @return The display name for the caller.
692 */
693 public String getCallerDisplayName() {
694 return mCallerDisplayName;
695 }
696
697 /**
698 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700699 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700700 */
701 public int getCallerDisplayNamePresentation() {
702 return mCallerDisplayNamePresentation;
703 }
704
705 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700706 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
707 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700708 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700709 public PhoneAccountHandle getAccountHandle() {
710 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700711 }
712
713 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800714 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
715 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700716 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700717 public int getCallCapabilities() {
718 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700719 }
720
721 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700722 * @return A bitmask of the properties of the {@code Call}, as defined by the various
723 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700724 */
725 public int getCallProperties() {
726 return mCallProperties;
727 }
728
729 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800730 * @return a bitmask of the audio routes available for the call.
731 *
732 * @hide
733 */
734 public int getSupportedAudioRoutes() {
735 return mSupportedAudioRoutes;
736 }
737
738 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700739 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700740 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700741 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700742 public DisconnectCause getDisconnectCause() {
743 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700744 }
745
746 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700747 * Returns the time the {@link Call} connected (i.e. became active). This information is
748 * updated periodically, but user interfaces should not rely on this to display the "call
749 * time clock". For the time when the call was first added to Telecom, see
750 * {@link #getCreationTimeMillis()}.
751 *
752 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700753 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700754 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700755 return mConnectTimeMillis;
756 }
757
758 /**
759 * @return Information about any calling gateway the {@code Call} may be using.
760 */
761 public GatewayInfo getGatewayInfo() {
762 return mGatewayInfo;
763 }
764
Andrew Lee7a341382014-07-15 17:05:08 -0700765 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700766 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700767 */
768 public int getVideoState() {
769 return mVideoState;
770 }
771
Ihab Awad5d0410f2014-07-30 10:07:40 -0700772 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700773 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700774 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700775 */
776 public StatusHints getStatusHints() {
777 return mStatusHints;
778 }
779
Nancy Chen10798dc2014-08-08 14:00:25 -0700780 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700781 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700782 */
783 public Bundle getExtras() {
784 return mExtras;
785 }
786
Santos Cordon6b7f9552015-05-27 17:21:45 -0700787 /**
788 * @return The extras used with the original intent to place this call.
789 */
790 public Bundle getIntentExtras() {
791 return mIntentExtras;
792 }
793
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700794 /**
795 * Returns the time when the call was first created and added to Telecom. This is the same
796 * time that is logged as the start time in the Call Log (see
797 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
798 * (became active), see {@link #getConnectTimeMillis()}.
799 *
800 * @return The creation time of the call, in millis since the epoch.
801 */
802 public long getCreationTimeMillis() {
803 return mCreationTimeMillis;
804 }
805
Ihab Awade63fadb2014-07-09 21:52:04 -0700806 @Override
807 public boolean equals(Object o) {
808 if (o instanceof Details) {
809 Details d = (Details) o;
810 return
811 Objects.equals(mHandle, d.mHandle) &&
812 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
813 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
814 Objects.equals(mCallerDisplayNamePresentation,
815 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700816 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700817 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700818 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700819 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700820 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700821 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700822 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700823 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700824 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700825 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
826 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700827 }
828 return false;
829 }
830
831 @Override
832 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700833 return Objects.hash(mHandle,
834 mHandlePresentation,
835 mCallerDisplayName,
836 mCallerDisplayNamePresentation,
837 mAccountHandle,
838 mCallCapabilities,
839 mCallProperties,
840 mDisconnectCause,
841 mConnectTimeMillis,
842 mGatewayInfo,
843 mVideoState,
844 mStatusHints,
845 mExtras,
846 mIntentExtras,
847 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700848 }
849
850 /** {@hide} */
851 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800852 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700853 Uri handle,
854 int handlePresentation,
855 String callerDisplayName,
856 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700857 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700858 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700859 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700860 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700861 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700862 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700863 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700864 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700865 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700866 Bundle intentExtras,
867 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800868 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700869 mHandle = handle;
870 mHandlePresentation = handlePresentation;
871 mCallerDisplayName = callerDisplayName;
872 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700873 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700874 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700875 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700876 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700877 mConnectTimeMillis = connectTimeMillis;
878 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700879 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700880 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700881 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700882 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700883 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700884 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800885
886 /** {@hide} */
887 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
888 return new Details(
889 parcelableCall.getId(),
890 parcelableCall.getHandle(),
891 parcelableCall.getHandlePresentation(),
892 parcelableCall.getCallerDisplayName(),
893 parcelableCall.getCallerDisplayNamePresentation(),
894 parcelableCall.getAccountHandle(),
895 parcelableCall.getCapabilities(),
896 parcelableCall.getProperties(),
897 parcelableCall.getDisconnectCause(),
898 parcelableCall.getConnectTimeMillis(),
899 parcelableCall.getGatewayInfo(),
900 parcelableCall.getVideoState(),
901 parcelableCall.getStatusHints(),
902 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700903 parcelableCall.getIntentExtras(),
904 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800905 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800906
907 @Override
908 public String toString() {
909 StringBuilder sb = new StringBuilder();
Tyler Gunne0caec72018-11-30 14:21:18 -0800910 sb.append("[id: ");
911 sb.append(mTelecomCallId);
912 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -0800913 sb.append(mAccountHandle);
914 sb.append(", hdl: ");
Tyler Gunne0caec72018-11-30 14:21:18 -0800915 sb.append(Log.piiHandle(mHandle));
916 sb.append(", hdlPres: ");
917 sb.append(mHandlePresentation);
918 sb.append(", videoState: ");
919 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -0800920 sb.append(", caps: ");
921 sb.append(capabilitiesToString(mCallCapabilities));
922 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700923 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800924 sb.append("]");
925 return sb.toString();
926 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700927 }
928
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700929 /**
930 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
931 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
932 * implementation.
933 * <p>
934 * You can handle these callbacks by extending the {@link Callback} class and overriding the
935 * callbacks that your {@link InCallService} is interested in. The callback methods include the
936 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
937 * {@link Callback} implementation, if desired.
938 * <p>
939 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
940 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
941 * (typically in {@link InCallService#onCallRemoved(Call)}).
942 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
943 * reach your implementation of {@link Callback}, so it is important to register your callback
944 * as soon as your {@link InCallService} is notified of a new call via
945 * {@link InCallService#onCallAdded(Call)}.
946 */
Andrew Leeda80c872015-04-15 14:09:50 -0700947 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700948 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -0700949 * @hide
950 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800951 @IntDef(prefix = { "HANDOVER_" },
952 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -0700953 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -0800954 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -0700955 @Retention(RetentionPolicy.SOURCE)
956 public @interface HandoverFailureErrors {}
957
958 /**
959 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -0800960 * to handover the call to rejects the handover request.
961 * <p>
962 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
963 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
964 * {@code null} {@link Connection} from
965 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
966 * ConnectionRequest)}.
967 * <p>
968 * For more information on call handovers, see
969 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700970 */
971 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
972
973 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800974 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
975 * is initiated but the source or destination app does not support handover.
976 * <p>
977 * Will be returned when a handover is requested via
978 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
979 * {@link PhoneAccountHandle} does not declare
980 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
981 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
982 * {@link Details#getAccountHandle()}) does not declare
983 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
984 * <p>
985 * For more information on call handovers, see
986 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700987 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800988 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700989
990 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800991 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
992 * user rejects the handover request.
993 * <p>
994 * For more information on call handovers, see
995 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700996 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800997 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700998
Sanket Padawe85291f62017-12-01 13:59:27 -0800999 /**
1000 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1001 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001002 * <p>
1003 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1004 * called on an emergency call, or if any other call is an emergency call.
1005 * <p>
1006 * Handovers are not permitted while there are ongoing emergency calls.
1007 * <p>
1008 * For more information on call handovers, see
1009 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001010 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001011 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001012
Tyler Gunn9d127732018-03-02 15:45:51 -08001013 /**
1014 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1015 * fails for an unknown reason.
1016 * <p>
1017 * For more information on call handovers, see
1018 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1019 */
1020 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001021
1022 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001023 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1024 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001025 * @param call The {@code Call} invoking this method.
1026 * @param state The new state of the {@code Call}.
1027 */
1028 public void onStateChanged(Call call, int state) {}
1029
1030 /**
1031 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1032 *
1033 * @param call The {@code Call} invoking this method.
1034 * @param parent The new parent of the {@code Call}.
1035 */
1036 public void onParentChanged(Call call, Call parent) {}
1037
1038 /**
1039 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1040 *
1041 * @param call The {@code Call} invoking this method.
1042 * @param children The new children of the {@code Call}.
1043 */
1044 public void onChildrenChanged(Call call, List<Call> children) {}
1045
1046 /**
1047 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1048 *
1049 * @param call The {@code Call} invoking this method.
1050 * @param details A {@code Details} object describing the {@code Call}.
1051 */
1052 public void onDetailsChanged(Call call, Details details) {}
1053
1054 /**
1055 * Invoked when the text messages that can be used as responses to the incoming
1056 * {@code Call} are loaded from the relevant database.
1057 * See {@link #getCannedTextResponses()}.
1058 *
1059 * @param call The {@code Call} invoking this method.
1060 * @param cannedTextResponses The text messages useable as responses.
1061 */
1062 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1063
1064 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001065 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1066 * character. This causes the post-dial signals to stop pending user confirmation. An
1067 * implementation should present this choice to the user and invoke
1068 * {@link #postDialContinue(boolean)} when the user makes the choice.
1069 *
1070 * @param call The {@code Call} invoking this method.
1071 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1072 */
1073 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1074
1075 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001076 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001077 *
1078 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001079 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001080 */
Andrew Lee50aca232014-07-22 16:41:54 -07001081 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001082
1083 /**
1084 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1085 * up their UI for the {@code Call} in response to state transitions. Specifically,
1086 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1087 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1088 * clients should wait for this method to be invoked.
1089 *
1090 * @param call The {@code Call} being destroyed.
1091 */
1092 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001093
1094 /**
1095 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1096 * conferenced.
1097 *
1098 * @param call The {@code Call} being updated.
1099 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1100 * conferenced.
1101 */
1102 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001103
1104 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001105 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
1106 * <p>
1107 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1108 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1109 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1110 * possible that a {@link ConnectionService} has defined its own Connection events which a
1111 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001112 * <p>
1113 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
1114 *
1115 * @param call The {@code Call} receiving the event.
1116 * @param event The event.
1117 * @param extras Extras associated with the connection event.
1118 */
1119 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001120
1121 /**
1122 * Invoked when the RTT mode changes for this call.
1123 * @param call The call whose RTT mode has changed.
1124 * @param mode the new RTT mode, one of
1125 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1126 * or {@link RttCall#RTT_MODE_VCO}
1127 */
1128 public void onRttModeChanged(Call call, int mode) {}
1129
1130 /**
1131 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1132 * @param call The call whose RTT status has changed.
1133 * @param enabled whether RTT is now enabled or disabled
1134 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1135 * on, null otherwise.
1136 */
1137 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1138
1139 /**
1140 * Invoked when the remote end of the connection has requested that an RTT communication
1141 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1142 * with the same ID that this method is invoked with.
1143 * @param call The call which the RTT request was placed on
1144 * @param id The ID of the request.
1145 */
1146 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001147
1148 /**
1149 * Invoked when the RTT session failed to initiate for some reason, including rejection
1150 * by the remote party.
1151 * @param call The call which the RTT initiation failure occurred on.
1152 * @param reason One of the status codes defined in
1153 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1154 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1155 */
1156 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001157
1158 /**
1159 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1160 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001161 * <p>
1162 * For a full discussion of the handover process and the APIs involved, see
1163 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1164 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001165 * @param call The call which had initiated handover.
1166 */
1167 public void onHandoverComplete(Call call) {}
1168
1169 /**
1170 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1171 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001172 * <p>
1173 * For a full discussion of the handover process and the APIs involved, see
1174 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1175 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001176 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001177 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001178 */
1179 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001180 }
1181
1182 /**
1183 * A class that holds the state that describes the state of the RTT channel to the remote
1184 * party, if it is active.
1185 */
1186 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001187 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001188 @Retention(RetentionPolicy.SOURCE)
1189 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1190 public @interface RttAudioMode {}
1191
1192 /**
1193 * For metrics use. Default value in the proto.
1194 * @hide
1195 */
1196 public static final int RTT_MODE_INVALID = 0;
1197
1198 /**
1199 * Indicates that there should be a bidirectional audio stream between the two parties
1200 * on the call.
1201 */
1202 public static final int RTT_MODE_FULL = 1;
1203
1204 /**
1205 * Indicates that the local user should be able to hear the audio stream from the remote
1206 * user, but not vice versa. Equivalent to muting the microphone.
1207 */
1208 public static final int RTT_MODE_HCO = 2;
1209
1210 /**
1211 * Indicates that the remote user should be able to hear the audio stream from the local
1212 * user, but not vice versa. Equivalent to setting the volume to zero.
1213 */
1214 public static final int RTT_MODE_VCO = 3;
1215
1216 private static final int READ_BUFFER_SIZE = 1000;
1217
1218 private InputStreamReader mReceiveStream;
1219 private OutputStreamWriter mTransmitStream;
1220 private int mRttMode;
1221 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001222 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001223 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1224
1225 /**
1226 * @hide
1227 */
Hall Liu57006aa2017-02-06 10:49:48 -08001228 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1229 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1230 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001231 mReceiveStream = receiveStream;
1232 mTransmitStream = transmitStream;
1233 mRttMode = mode;
1234 mInCallAdapter = inCallAdapter;
1235 }
1236
1237 /**
1238 * Returns the current RTT audio mode.
1239 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1240 * {@link #RTT_MODE_HCO}.
1241 */
1242 public int getRttAudioMode() {
1243 return mRttMode;
1244 }
1245
1246 /**
1247 * Sets the RTT audio mode. The requested mode change will be communicated through
1248 * {@link Callback#onRttModeChanged(Call, int)}.
1249 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1250 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1251 */
1252 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001253 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001254 }
1255
1256 /**
1257 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1258 * RTT transmits text in real-time, this method should be called once for each character
1259 * the user enters into the device.
1260 *
1261 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1262 * lead to interleaved text.
1263 * @param input The message to send to the remote user.
1264 */
1265 public void write(String input) throws IOException {
1266 mTransmitStream.write(input);
1267 mTransmitStream.flush();
1268 }
1269
1270 /**
1271 * Reads a string from the remote user, blocking if there is no data available. Returns
1272 * {@code null} if the RTT conversation has been terminated and there is no further data
1273 * to read.
1274 *
1275 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1276 * lead to interleaved text.
1277 * @return A string containing text sent by the remote user, or {@code null} if the
1278 * conversation has been terminated or if there was an error while reading.
1279 */
Hall Liub1c8a772017-07-17 17:04:41 -07001280 public String read() {
1281 try {
1282 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1283 if (numRead < 0) {
1284 return null;
1285 }
1286 return new String(mReadBuffer, 0, numRead);
1287 } catch (IOException e) {
1288 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001289 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001290 }
Hall Liuffa4a812017-03-02 16:11:00 -08001291 }
1292
1293 /**
1294 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1295 * be read.
1296 * @return A string containing text entered by the user, or {@code null} if the user has
1297 * not entered any new text yet.
1298 */
1299 public String readImmediately() throws IOException {
1300 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001301 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1302 if (numRead < 0) {
1303 return null;
1304 }
1305 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001306 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001307 return null;
1308 }
1309 }
Hall Liue9041242018-02-09 16:40:03 -08001310
1311 /**
1312 * Closes the underlying file descriptors
1313 * @hide
1314 */
1315 public void close() {
1316 try {
1317 mReceiveStream.close();
1318 } catch (IOException e) {
1319 // ignore
1320 }
1321 try {
1322 mTransmitStream.close();
1323 } catch (IOException e) {
1324 // ignore
1325 }
1326 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001327 }
1328
Andrew Leeda80c872015-04-15 14:09:50 -07001329 /**
1330 * @deprecated Use {@code Call.Callback} instead.
1331 * @hide
1332 */
1333 @Deprecated
1334 @SystemApi
1335 public static abstract class Listener extends Callback { }
1336
Ihab Awade63fadb2014-07-09 21:52:04 -07001337 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001338 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001339 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001340 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001341 private final List<Call> mChildren = new ArrayList<>();
1342 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001343 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001344 private final List<Call> mConferenceableCalls = new ArrayList<>();
1345 private final List<Call> mUnmodifiableConferenceableCalls =
1346 Collections.unmodifiableList(mConferenceableCalls);
1347
Santos Cordon823fd3c2014-08-07 18:35:18 -07001348 private boolean mChildrenCached;
1349 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001350 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001351 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001352 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001353 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001354 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001355 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001356 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001357 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001358 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001359
1360 /**
1361 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1362 *
1363 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1364 * remaining or this {@code Call} is not in a post-dial state.
1365 */
1366 public String getRemainingPostDialSequence() {
1367 return mRemainingPostDialSequence;
1368 }
1369
1370 /**
1371 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001372 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001373 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001374 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001375 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001376 }
1377
1378 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301379 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1380 *
1381 * @param address The address to which the call will be deflected.
1382 */
1383 public void deflect(Uri address) {
1384 mInCallAdapter.deflectCall(mTelecomCallId, address);
1385 }
1386
1387 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001388 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1389 *
1390 * @param rejectWithMessage Whether to reject with a text message.
1391 * @param textMessage An optional text message with which to respond.
1392 */
1393 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001394 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001395 }
1396
1397 /**
1398 * Instructs this {@code Call} to disconnect.
1399 */
1400 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001401 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001402 }
1403
1404 /**
1405 * Instructs this {@code Call} to go on hold.
1406 */
1407 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001408 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001409 }
1410
1411 /**
1412 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1413 */
1414 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001415 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001416 }
1417
1418 /**
1419 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1420 *
1421 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1422 *
1423 * @param digit A character representing the DTMF digit for which to play the tone. This
1424 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1425 */
1426 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001427 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001428 }
1429
1430 /**
1431 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1432 * currently playing.
1433 *
1434 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1435 * currently playing, this method will do nothing.
1436 */
1437 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001438 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001439 }
1440
1441 /**
1442 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1443 *
1444 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1445 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001446 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001447 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001448 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1449 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001450 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001451 * {@code Call} will pause playing the tones and notify callbacks via
1452 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001453 * should display to the user an indication of this state and an affordance to continue
1454 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1455 * app should invoke the {@link #postDialContinue(boolean)} method.
1456 *
1457 * @param proceed Whether or not to continue with the post-dial sequence.
1458 */
1459 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001460 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001461 }
1462
1463 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001464 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001465 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001466 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001467 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1468 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001469
1470 }
1471
1472 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001473 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001474 *
1475 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001476 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001477 public void conference(Call callToConferenceWith) {
1478 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001479 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001480 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001481 }
1482
1483 /**
1484 * Instructs this {@code Call} to split from any conference call with which it may be
1485 * connected.
1486 */
1487 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001488 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001489 }
1490
1491 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001492 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001493 */
1494 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001495 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001496 }
1497
1498 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001499 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001500 */
1501 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001502 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001503 }
1504
1505 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001506 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1507 * device.
1508 * <p>
1509 * Calls to this method are ignored if the call does not have the
1510 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1511 * <p>
1512 * An {@link InCallService} will only see calls which support this method if it has the
1513 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1514 * in its manifest.
1515 */
1516 public void pullExternalCall() {
1517 // If this isn't an external call, ignore the request.
1518 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1519 return;
1520 }
1521
1522 mInCallAdapter.pullExternalCall(mTelecomCallId);
1523 }
1524
1525 /**
1526 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1527 * the {@link ConnectionService}.
1528 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001529 * Call events are used to communicate point in time information from an {@link InCallService}
1530 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1531 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1532 * {@link ConnectionService}.
1533 * <p>
1534 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1535 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1536 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001537 * Events are exposed to {@link ConnectionService} implementations via
1538 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1539 * <p>
1540 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001541 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1542 * ignore some events altogether.
1543 * <p>
1544 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1545 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1546 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1547 * they define their own event types in this namespace. When defining a custom event type,
1548 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1549 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1550 * <p>
1551 * When defining events and the associated extras, it is important to keep their behavior
1552 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1553 * events/extras should me maintained to ensure backwards compatibility with older
1554 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001555 *
1556 * @param event The connection event.
1557 * @param extras Bundle containing extra information associated with the event.
1558 */
1559 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001560 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001561 }
1562
1563 /**
Hall Liu95d55872017-01-25 17:12:49 -08001564 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1565 * guaranteed, and notification of success will be via the
1566 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1567 */
1568 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001569 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001570 }
1571
1572 /**
1573 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1574 * callback.
1575 * The ID used here should be the same as the ID that was received via the callback.
1576 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1577 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1578 */
1579 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001580 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001581 }
1582
1583 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001584 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1585 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1586 * handover.
1587 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001588 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1589 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1590 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1591 * is referred to as the source of the handover, and the video calling app is referred to as the
1592 * destination.
1593 * <p>
1594 * When considering a handover scenario the device this method is called on is considered the
1595 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1596 * other device is considered the <em>receiving</em> device.
1597 * <p>
1598 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1599 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1600 * and invoke
1601 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1602 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1603 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1604 * At this point the app should display UI to indicate to the user that a call
1605 * handover is in process.
1606 * <p>
1607 * The destination app is responsible for communicating the handover request from the
1608 * <em>initiating</em> device to the <em>receiving</em> device.
1609 * <p>
1610 * When the app on the <em>receiving</em> device receives the handover request, it calls
1611 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1612 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1613 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1614 * choose whether they want to continue their call in the destination app.
1615 * <p>
1616 * When the destination app on the <em>receiving</em> device calls
1617 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1618 * {@link ConnectionService} and call
1619 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1620 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1621 * {@link Connection} to represent the handover call.
1622 * <p>
1623 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1624 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1625 * original call. If the user rejects the handover, the app calls
1626 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1627 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1628 * <p>
1629 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1630 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1631 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1632 * <p>
1633 * Errors in the handover process are reported to the {@link InCallService} via
1634 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1635 * the involved {@link ConnectionService}s via
1636 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001637 *
1638 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1639 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001640 * @param videoState Indicates the video state desired after the handover (see the
1641 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001642 * @param extras Bundle containing extra information to be passed to the
1643 * {@link ConnectionService}
1644 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001645 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1646 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001647 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1648 }
1649
1650 /**
Hall Liu95d55872017-01-25 17:12:49 -08001651 * Terminate the RTT session on this call. The resulting state change will be notified via
1652 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1653 */
1654 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001655 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001656 }
1657
1658 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001659 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1660 * added.
1661 * <p>
1662 * No assumptions should be made as to how an In-Call UI or service will handle these
1663 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1664 *
1665 * @param extras The extras to add.
1666 */
1667 public final void putExtras(Bundle extras) {
1668 if (extras == null) {
1669 return;
1670 }
1671
1672 if (mExtras == null) {
1673 mExtras = new Bundle();
1674 }
1675 mExtras.putAll(extras);
1676 mInCallAdapter.putExtras(mTelecomCallId, extras);
1677 }
1678
1679 /**
1680 * Adds a boolean extra to this {@link Call}.
1681 *
1682 * @param key The extra key.
1683 * @param value The value.
1684 * @hide
1685 */
1686 public final void putExtra(String key, boolean value) {
1687 if (mExtras == null) {
1688 mExtras = new Bundle();
1689 }
1690 mExtras.putBoolean(key, value);
1691 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1692 }
1693
1694 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001695 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001696 *
1697 * @param key The extra key.
1698 * @param value The value.
1699 * @hide
1700 */
1701 public final void putExtra(String key, int value) {
1702 if (mExtras == null) {
1703 mExtras = new Bundle();
1704 }
1705 mExtras.putInt(key, value);
1706 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1707 }
1708
1709 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001710 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001711 *
1712 * @param key The extra key.
1713 * @param value The value.
1714 * @hide
1715 */
1716 public final void putExtra(String key, String value) {
1717 if (mExtras == null) {
1718 mExtras = new Bundle();
1719 }
1720 mExtras.putString(key, value);
1721 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1722 }
1723
1724 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001725 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001726 *
1727 * @param keys The keys of the extras to remove.
1728 */
1729 public final void removeExtras(List<String> keys) {
1730 if (mExtras != null) {
1731 for (String key : keys) {
1732 mExtras.remove(key);
1733 }
1734 if (mExtras.size() == 0) {
1735 mExtras = null;
1736 }
1737 }
1738 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1739 }
1740
1741 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001742 * Removes extras from this {@link Call}.
1743 *
1744 * @param keys The keys of the extras to remove.
1745 */
1746 public final void removeExtras(String ... keys) {
1747 removeExtras(Arrays.asList(keys));
1748 }
1749
1750 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001751 * Obtains the parent of this {@code Call} in a conference, if any.
1752 *
1753 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1754 * child of any conference {@code Call}s.
1755 */
1756 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001757 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001758 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001759 }
1760 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001761 }
1762
1763 /**
1764 * Obtains the children of this conference {@code Call}, if any.
1765 *
1766 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1767 * {@code List} otherwise.
1768 */
1769 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001770 if (!mChildrenCached) {
1771 mChildrenCached = true;
1772 mChildren.clear();
1773
1774 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001775 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001776 if (call == null) {
1777 // At least one child was still not found, so do not save true for "cached"
1778 mChildrenCached = false;
1779 } else {
1780 mChildren.add(call);
1781 }
1782 }
1783 }
1784
Ihab Awade63fadb2014-07-09 21:52:04 -07001785 return mUnmodifiableChildren;
1786 }
1787
1788 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001789 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1790 *
1791 * @return The list of conferenceable {@code Call}s.
1792 */
1793 public List<Call> getConferenceableCalls() {
1794 return mUnmodifiableConferenceableCalls;
1795 }
1796
1797 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001798 * Obtains the state of this {@code Call}.
1799 *
1800 * @return A state value, chosen from the {@code STATE_*} constants.
1801 */
1802 public int getState() {
1803 return mState;
1804 }
1805
1806 /**
1807 * Obtains a list of canned, pre-configured message responses to present to the user as
1808 * ways of rejecting this {@code Call} using via a text message.
1809 *
1810 * @see #reject(boolean, String)
1811 *
1812 * @return A list of canned text message responses.
1813 */
1814 public List<String> getCannedTextResponses() {
1815 return mCannedTextResponses;
1816 }
1817
1818 /**
1819 * Obtains an object that can be used to display video from this {@code Call}.
1820 *
Andrew Lee50aca232014-07-22 16:41:54 -07001821 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001822 */
Andrew Lee50aca232014-07-22 16:41:54 -07001823 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001824 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001825 }
1826
1827 /**
1828 * Obtains an object containing call details.
1829 *
1830 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1831 * result may be {@code null}.
1832 */
1833 public Details getDetails() {
1834 return mDetails;
1835 }
1836
1837 /**
Hall Liu95d55872017-01-25 17:12:49 -08001838 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1839 * receive RTT text data, as well as to change the RTT mode.
1840 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1841 */
1842 public @Nullable RttCall getRttCall() {
1843 return mRttCall;
1844 }
1845
1846 /**
1847 * Returns whether this call has an active RTT connection.
1848 * @return true if there is a connection, false otherwise.
1849 */
1850 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08001851 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08001852 }
1853
1854 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001855 * Registers a callback to this {@code Call}.
1856 *
1857 * @param callback A {@code Callback}.
1858 */
1859 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001860 registerCallback(callback, new Handler());
1861 }
1862
1863 /**
1864 * Registers a callback to this {@code Call}.
1865 *
1866 * @param callback A {@code Callback}.
1867 * @param handler A handler which command and status changes will be delivered to.
1868 */
1869 public void registerCallback(Callback callback, Handler handler) {
1870 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001871 // Don't allow new callback registration if the call is already being destroyed.
1872 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001873 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1874 }
Andrew Leeda80c872015-04-15 14:09:50 -07001875 }
1876
1877 /**
1878 * Unregisters a callback from this {@code Call}.
1879 *
1880 * @param callback A {@code Callback}.
1881 */
1882 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001883 // Don't allow callback deregistration if the call is already being destroyed.
1884 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001885 for (CallbackRecord<Callback> record : mCallbackRecords) {
1886 if (record.getCallback() == callback) {
1887 mCallbackRecords.remove(record);
1888 break;
1889 }
1890 }
Andrew Leeda80c872015-04-15 14:09:50 -07001891 }
1892 }
1893
Santos Cordon3c20d632016-02-25 16:12:35 -08001894 @Override
1895 public String toString() {
1896 return new StringBuilder().
1897 append("Call [id: ").
1898 append(mTelecomCallId).
1899 append(", state: ").
1900 append(stateToString(mState)).
1901 append(", details: ").
1902 append(mDetails).
1903 append("]").toString();
1904 }
1905
1906 /**
1907 * @param state An integer value of a {@code STATE_*} constant.
1908 * @return A string representation of the value.
1909 */
1910 private static String stateToString(int state) {
1911 switch (state) {
1912 case STATE_NEW:
1913 return "NEW";
1914 case STATE_RINGING:
1915 return "RINGING";
1916 case STATE_DIALING:
1917 return "DIALING";
1918 case STATE_ACTIVE:
1919 return "ACTIVE";
1920 case STATE_HOLDING:
1921 return "HOLDING";
1922 case STATE_DISCONNECTED:
1923 return "DISCONNECTED";
1924 case STATE_CONNECTING:
1925 return "CONNECTING";
1926 case STATE_DISCONNECTING:
1927 return "DISCONNECTING";
1928 case STATE_SELECT_PHONE_ACCOUNT:
1929 return "SELECT_PHONE_ACCOUNT";
1930 default:
1931 Log.w(Call.class, "Unknown state %d", state);
1932 return "UNKNOWN";
1933 }
1934 }
1935
Andrew Leeda80c872015-04-15 14:09:50 -07001936 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001937 * Adds a listener to this {@code Call}.
1938 *
1939 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001940 * @deprecated Use {@link #registerCallback} instead.
1941 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001942 */
Andrew Leeda80c872015-04-15 14:09:50 -07001943 @Deprecated
1944 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001945 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001946 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001947 }
1948
1949 /**
1950 * Removes a listener from this {@code Call}.
1951 *
1952 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001953 * @deprecated Use {@link #unregisterCallback} instead.
1954 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001955 */
Andrew Leeda80c872015-04-15 14:09:50 -07001956 @Deprecated
1957 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001958 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001959 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001960 }
1961
1962 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001963 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1964 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001965 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001966 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001967 mInCallAdapter = inCallAdapter;
1968 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001969 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001970 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001971 }
1972
1973 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001974 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001975 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001976 mPhone = phone;
1977 mTelecomCallId = telecomCallId;
1978 mInCallAdapter = inCallAdapter;
1979 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001980 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001981 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001982 }
1983
1984 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001985 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001986 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001987 }
1988
1989 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001990 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001991
Ihab Awade63fadb2014-07-09 21:52:04 -07001992 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001993 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001994 boolean detailsChanged = !Objects.equals(mDetails, details);
1995 if (detailsChanged) {
1996 mDetails = details;
1997 }
1998
1999 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002000 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2001 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2002 mCannedTextResponses =
2003 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002004 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002005 }
2006
Tyler Gunn159f35c2017-03-02 09:28:37 -08002007 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
2008 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07002009 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002010 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07002011 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002012 mVideoCallImpl = newVideoCallImpl;
2013 }
2014 if (mVideoCallImpl != null) {
2015 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002016 }
2017
Santos Cordone3c507b2015-04-23 14:44:19 -07002018 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07002019 boolean stateChanged = mState != state;
2020 if (stateChanged) {
2021 mState = state;
2022 }
2023
Santos Cordon823fd3c2014-08-07 18:35:18 -07002024 String parentId = parcelableCall.getParentCallId();
2025 boolean parentChanged = !Objects.equals(mParentId, parentId);
2026 if (parentChanged) {
2027 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002028 }
2029
Santos Cordon823fd3c2014-08-07 18:35:18 -07002030 List<String> childCallIds = parcelableCall.getChildCallIds();
2031 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2032 if (childrenChanged) {
2033 mChildrenIds.clear();
2034 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2035 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002036 }
2037
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002038 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2039 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2040 for (String otherId : conferenceableCallIds) {
2041 if (callIdMap.containsKey(otherId)) {
2042 conferenceableCalls.add(callIdMap.get(otherId));
2043 }
2044 }
2045
2046 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2047 mConferenceableCalls.clear();
2048 mConferenceableCalls.addAll(conferenceableCalls);
2049 fireConferenceableCallsChanged();
2050 }
2051
Hall Liu95d55872017-01-25 17:12:49 -08002052 boolean isRttChanged = false;
2053 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002054 if (parcelableCall.getIsRttCallChanged()
2055 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002056 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2057 InputStreamReader receiveStream = new InputStreamReader(
2058 new ParcelFileDescriptor.AutoCloseInputStream(
2059 parcelableRttCall.getReceiveStream()),
2060 StandardCharsets.UTF_8);
2061 OutputStreamWriter transmitStream = new OutputStreamWriter(
2062 new ParcelFileDescriptor.AutoCloseOutputStream(
2063 parcelableRttCall.getTransmitStream()),
2064 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002065 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002066 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2067 if (mRttCall == null) {
2068 isRttChanged = true;
2069 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2070 rttModeChanged = true;
2071 }
2072 mRttCall = newRttCall;
2073 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2074 && parcelableCall.getIsRttCallChanged()) {
2075 isRttChanged = true;
2076 mRttCall = null;
2077 }
2078
Ihab Awade63fadb2014-07-09 21:52:04 -07002079 // Now we fire updates, ensuring that any client who listens to any of these notifications
2080 // gets the most up-to-date state.
2081
2082 if (stateChanged) {
2083 fireStateChanged(mState);
2084 }
2085 if (detailsChanged) {
2086 fireDetailsChanged(mDetails);
2087 }
2088 if (cannedTextResponsesChanged) {
2089 fireCannedTextResponsesLoaded(mCannedTextResponses);
2090 }
Andrew Lee50aca232014-07-22 16:41:54 -07002091 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002092 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002093 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002094 if (parentChanged) {
2095 fireParentChanged(getParent());
2096 }
2097 if (childrenChanged) {
2098 fireChildrenChanged(getChildren());
2099 }
Hall Liu95d55872017-01-25 17:12:49 -08002100 if (isRttChanged) {
2101 fireOnIsRttChanged(mRttCall != null, mRttCall);
2102 }
2103 if (rttModeChanged) {
2104 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2105 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002106
2107 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2108 // remove ourselves from the Phone. Note that we do this after completing all state updates
2109 // so a client can cleanly transition all their UI to the state appropriate for a
2110 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2111 if (mState == STATE_DISCONNECTED) {
2112 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002113 }
2114 }
2115
2116 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002117 final void internalSetPostDialWait(String remaining) {
2118 mRemainingPostDialSequence = remaining;
2119 firePostDialWait(mRemainingPostDialSequence);
2120 }
2121
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002122 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002123 final void internalSetDisconnected() {
2124 if (mState != Call.STATE_DISCONNECTED) {
2125 mState = Call.STATE_DISCONNECTED;
2126 fireStateChanged(mState);
2127 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002128 }
2129 }
2130
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002131 /** {@hide} */
2132 final void internalOnConnectionEvent(String event, Bundle extras) {
2133 fireOnConnectionEvent(event, extras);
2134 }
2135
Hall Liu95d55872017-01-25 17:12:49 -08002136 /** {@hide} */
2137 final void internalOnRttUpgradeRequest(final int requestId) {
2138 for (CallbackRecord<Callback> record : mCallbackRecords) {
2139 final Call call = this;
2140 final Callback callback = record.getCallback();
2141 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2142 }
2143 }
2144
Hall Liu57006aa2017-02-06 10:49:48 -08002145 /** @hide */
2146 final void internalOnRttInitiationFailure(int reason) {
2147 for (CallbackRecord<Callback> record : mCallbackRecords) {
2148 final Call call = this;
2149 final Callback callback = record.getCallback();
2150 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2151 }
2152 }
2153
Sanket Padawe85291f62017-12-01 13:59:27 -08002154 /** {@hide} */
2155 final void internalOnHandoverFailed(int error) {
2156 for (CallbackRecord<Callback> record : mCallbackRecords) {
2157 final Call call = this;
2158 final Callback callback = record.getCallback();
2159 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2160 }
2161 }
2162
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002163 /** {@hide} */
2164 final void internalOnHandoverComplete() {
2165 for (CallbackRecord<Callback> record : mCallbackRecords) {
2166 final Call call = this;
2167 final Callback callback = record.getCallback();
2168 record.getHandler().post(() -> callback.onHandoverComplete(call));
2169 }
2170 }
2171
Andrew Lee011728f2015-04-23 15:47:06 -07002172 private void fireStateChanged(final int newState) {
2173 for (CallbackRecord<Callback> record : mCallbackRecords) {
2174 final Call call = this;
2175 final Callback callback = record.getCallback();
2176 record.getHandler().post(new Runnable() {
2177 @Override
2178 public void run() {
2179 callback.onStateChanged(call, newState);
2180 }
2181 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002182 }
2183 }
2184
Andrew Lee011728f2015-04-23 15:47:06 -07002185 private void fireParentChanged(final Call newParent) {
2186 for (CallbackRecord<Callback> record : mCallbackRecords) {
2187 final Call call = this;
2188 final Callback callback = record.getCallback();
2189 record.getHandler().post(new Runnable() {
2190 @Override
2191 public void run() {
2192 callback.onParentChanged(call, newParent);
2193 }
2194 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002195 }
2196 }
2197
Andrew Lee011728f2015-04-23 15:47:06 -07002198 private void fireChildrenChanged(final List<Call> children) {
2199 for (CallbackRecord<Callback> record : mCallbackRecords) {
2200 final Call call = this;
2201 final Callback callback = record.getCallback();
2202 record.getHandler().post(new Runnable() {
2203 @Override
2204 public void run() {
2205 callback.onChildrenChanged(call, children);
2206 }
2207 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002208 }
2209 }
2210
Andrew Lee011728f2015-04-23 15:47:06 -07002211 private void fireDetailsChanged(final Details details) {
2212 for (CallbackRecord<Callback> record : mCallbackRecords) {
2213 final Call call = this;
2214 final Callback callback = record.getCallback();
2215 record.getHandler().post(new Runnable() {
2216 @Override
2217 public void run() {
2218 callback.onDetailsChanged(call, details);
2219 }
2220 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002221 }
2222 }
2223
Andrew Lee011728f2015-04-23 15:47:06 -07002224 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2225 for (CallbackRecord<Callback> record : mCallbackRecords) {
2226 final Call call = this;
2227 final Callback callback = record.getCallback();
2228 record.getHandler().post(new Runnable() {
2229 @Override
2230 public void run() {
2231 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2232 }
2233 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002234 }
2235 }
2236
Andrew Lee011728f2015-04-23 15:47:06 -07002237 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2238 for (CallbackRecord<Callback> record : mCallbackRecords) {
2239 final Call call = this;
2240 final Callback callback = record.getCallback();
2241 record.getHandler().post(new Runnable() {
2242 @Override
2243 public void run() {
2244 callback.onVideoCallChanged(call, videoCall);
2245 }
2246 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002247 }
2248 }
2249
Andrew Lee011728f2015-04-23 15:47:06 -07002250 private void firePostDialWait(final String remainingPostDialSequence) {
2251 for (CallbackRecord<Callback> record : mCallbackRecords) {
2252 final Call call = this;
2253 final Callback callback = record.getCallback();
2254 record.getHandler().post(new Runnable() {
2255 @Override
2256 public void run() {
2257 callback.onPostDialWait(call, remainingPostDialSequence);
2258 }
2259 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002260 }
2261 }
2262
2263 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002264 /**
2265 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2266 * onCallRemoved callback, we remove this call from the Phone's record
2267 * only once all of the registered onCallDestroyed callbacks are executed.
2268 * All the callbacks get removed from our records as a part of this operation
2269 * since onCallDestroyed is the final callback.
2270 */
2271 final Call call = this;
2272 if (mCallbackRecords.isEmpty()) {
2273 // No callbacks registered, remove the call from Phone's record.
2274 mPhone.internalRemoveCall(call);
2275 }
2276 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002277 final Callback callback = record.getCallback();
2278 record.getHandler().post(new Runnable() {
2279 @Override
2280 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002281 boolean isFinalRemoval = false;
2282 RuntimeException toThrow = null;
2283 try {
2284 callback.onCallDestroyed(call);
2285 } catch (RuntimeException e) {
2286 toThrow = e;
2287 }
2288 synchronized(Call.this) {
2289 mCallbackRecords.remove(record);
2290 if (mCallbackRecords.isEmpty()) {
2291 isFinalRemoval = true;
2292 }
2293 }
2294 if (isFinalRemoval) {
2295 mPhone.internalRemoveCall(call);
2296 }
2297 if (toThrow != null) {
2298 throw toThrow;
2299 }
Andrew Lee011728f2015-04-23 15:47:06 -07002300 }
2301 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002302 }
2303 }
2304
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002305 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002306 for (CallbackRecord<Callback> record : mCallbackRecords) {
2307 final Call call = this;
2308 final Callback callback = record.getCallback();
2309 record.getHandler().post(new Runnable() {
2310 @Override
2311 public void run() {
2312 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2313 }
2314 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002315 }
2316 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002317
2318 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002319 * Notifies listeners of an incoming connection event.
2320 * <p>
2321 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2322 *
2323 * @param event
2324 * @param extras
2325 */
2326 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2327 for (CallbackRecord<Callback> record : mCallbackRecords) {
2328 final Call call = this;
2329 final Callback callback = record.getCallback();
2330 record.getHandler().post(new Runnable() {
2331 @Override
2332 public void run() {
2333 callback.onConnectionEvent(call, event, extras);
2334 }
2335 });
2336 }
2337 }
2338
2339 /**
Hall Liu95d55872017-01-25 17:12:49 -08002340 * Notifies listeners of an RTT on/off change
2341 *
2342 * @param enabled True if RTT is now enabled, false otherwise
2343 */
2344 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2345 for (CallbackRecord<Callback> record : mCallbackRecords) {
2346 final Call call = this;
2347 final Callback callback = record.getCallback();
2348 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2349 }
2350 }
2351
2352 /**
2353 * Notifies listeners of a RTT mode change
2354 *
2355 * @param mode The new RTT mode
2356 */
2357 private void fireOnRttModeChanged(final int mode) {
2358 for (CallbackRecord<Callback> record : mCallbackRecords) {
2359 final Call call = this;
2360 final Callback callback = record.getCallback();
2361 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2362 }
2363 }
2364
2365 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002366 * Determines if two bundles are equal.
2367 *
2368 * @param bundle The original bundle.
2369 * @param newBundle The bundle to compare with.
2370 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2371 */
2372 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2373 if (bundle == null || newBundle == null) {
2374 return bundle == newBundle;
2375 }
2376
2377 if (bundle.size() != newBundle.size()) {
2378 return false;
2379 }
2380
2381 for(String key : bundle.keySet()) {
2382 if (key != null) {
2383 final Object value = bundle.get(key);
2384 final Object newValue = newBundle.get(key);
2385 if (!Objects.equals(value, newValue)) {
2386 return false;
2387 }
2388 }
2389 }
2390 return true;
2391 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002392}