blob: c152a41c8694b50e7e6c540551956f3aa5af60f1 [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;
Ravi Paluri404babb2020-01-23 19:02:44 +053020import android.annotation.NonNull;
Hall Liu95d55872017-01-25 17:12:49 -080021import android.annotation.Nullable;
Andrew Leeda80c872015-04-15 14:09:50 -070022import android.annotation.SystemApi;
Hall Liu6dfa2492019-10-01 17:20:39 -070023import android.annotation.TestApi;
Artur Satayev53ada2a2019-12-10 17:47:56 +000024import android.compat.annotation.UnsupportedAppUsage;
Tyler Gunn460b7d42020-05-15 10:19:32 -070025import android.content.pm.ServiceInfo;
Ihab Awade63fadb2014-07-09 21:52:04 -070026import android.net.Uri;
Tyler Gunn6e3ecc42018-11-12 11:30:56 -080027import android.os.Build;
Nancy Chen10798dc2014-08-08 14:00:25 -070028import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070029import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080030import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070031
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -080032import com.android.internal.telecom.IVideoProvider;
33
Hall Liu95d55872017-01-25 17:12:49 -080034import java.io.IOException;
35import java.io.InputStreamReader;
36import java.io.OutputStreamWriter;
Hall Liu95d55872017-01-25 17:12:49 -080037import java.lang.annotation.Retention;
38import java.lang.annotation.RetentionPolicy;
39import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070040import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070041import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070042import java.util.Collections;
43import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070044import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070045import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070046import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070047
48/**
49 * Represents an ongoing phone call that the in-call app should present to the user.
50 */
51public final class Call {
52 /**
53 * The state of a {@code Call} when newly created.
54 */
55 public static final int STATE_NEW = 0;
56
57 /**
58 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
59 */
60 public static final int STATE_DIALING = 1;
61
62 /**
63 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
64 */
65 public static final int STATE_RINGING = 2;
66
67 /**
68 * The state of a {@code Call} when in a holding state.
69 */
70 public static final int STATE_HOLDING = 3;
71
72 /**
73 * The state of a {@code Call} when actively supporting conversation.
74 */
75 public static final int STATE_ACTIVE = 4;
76
77 /**
78 * The state of a {@code Call} when no further voice or other communication is being
79 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
80 * is no longer active, and the local data transport has or inevitably will release resources
81 * associated with this {@code Call}.
82 */
83 public static final int STATE_DISCONNECTED = 7;
84
Nancy Chen5da0fd52014-07-08 14:16:17 -070085 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070086 * The state of an outgoing {@code Call} when waiting on user to select a
87 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070088 */
Santos Cordone3c507b2015-04-23 14:44:19 -070089 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
90
91 /**
92 * @hide
93 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
94 */
95 @Deprecated
96 @SystemApi
97 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070098
Nancy Chene20930f2014-08-07 16:17:21 -070099 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -0700100 * The initial state of an outgoing {@code Call}.
101 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
102 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -0700103 */
104 public static final int STATE_CONNECTING = 9;
105
Nancy Chen513c8922014-09-17 14:47:20 -0700106 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700107 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
108 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
109 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
110 */
111 public static final int STATE_DISCONNECTING = 10;
112
113 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700114 * The state of an external call which is in the process of being pulled from a remote device to
115 * the local device.
116 * <p>
117 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
118 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
119 * <p>
120 * An {@link InCallService} will only see this state if it has the
121 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
122 * manifest.
123 */
124 public static final int STATE_PULLING_CALL = 11;
125
126 /**
Hall Liu6dfa2492019-10-01 17:20:39 -0700127 * The state of a call that is active with the network, but the audio from the call is
128 * being intercepted by an app on the local device. Telecom does not hold audio focus in this
129 * state, and the call will be invisible to the user except for a persistent notification.
130 */
131 public static final int STATE_AUDIO_PROCESSING = 12;
132
133 /**
134 * The state of a call that is being presented to the user after being in
135 * {@link #STATE_AUDIO_PROCESSING}. The call is still active with the network in this case, and
136 * Telecom will hold audio focus and play a ringtone if appropriate.
137 */
138 public static final int STATE_SIMULATED_RINGING = 13;
139
140 /**
Tyler Gunn1e406ca2021-03-18 16:47:14 -0700141 * @hide
142 */
143 @IntDef(prefix = { "STATE_" },
144 value = {
145 STATE_NEW,
146 STATE_DIALING,
147 STATE_RINGING,
148 STATE_HOLDING,
149 STATE_ACTIVE,
150 STATE_DISCONNECTED,
151 STATE_SELECT_PHONE_ACCOUNT,
152 STATE_CONNECTING,
153 STATE_DISCONNECTING,
154 STATE_PULLING_CALL,
155 STATE_AUDIO_PROCESSING,
156 STATE_SIMULATED_RINGING
157 })
158 @Retention(RetentionPolicy.SOURCE)
159 public @interface CallState {};
160
161 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700162 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
163 * extras. Used to pass the phone accounts to display on the front end to the user in order to
164 * select phone accounts to (for example) place a call.
Hall Liu34d9e242018-11-21 17:05:58 -0800165 * @deprecated Use the list from {@link #EXTRA_SUGGESTED_PHONE_ACCOUNTS} instead.
Nancy Chen513c8922014-09-17 14:47:20 -0700166 */
Hall Liu34d9e242018-11-21 17:05:58 -0800167 @Deprecated
Nancy Chen513c8922014-09-17 14:47:20 -0700168 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
169
mike dooley4af561f2016-12-20 08:55:17 -0800170 /**
Thomas Stuart5ca875eb2022-08-03 18:39:57 -0700171 * Extra key intended for {@link InCallService}s that notify the user of an incoming call. When
172 * EXTRA_IS_SUPPRESSED_BY_DO_NOT_DISTURB returns true, the {@link InCallService} should not
173 * interrupt the user of the incoming call because the call is being suppressed by Do Not
174 * Disturb settings.
175 *
176 * This extra will be removed from the {@link Call} object for {@link InCallService}s that do
177 * not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
178 */
179 public static final String EXTRA_IS_SUPPRESSED_BY_DO_NOT_DISTURB =
180 "android.telecom.extra.IS_SUPPRESSED_BY_DO_NOT_DISTURB";
181
182 /**
Hall Liu34d9e242018-11-21 17:05:58 -0800183 * Key for extra used to pass along a list of {@link PhoneAccountSuggestion}s to the in-call
184 * UI when a call enters the {@link #STATE_SELECT_PHONE_ACCOUNT} state. The list included here
185 * will have the same length and be in the same order as the list passed with
186 * {@link #AVAILABLE_PHONE_ACCOUNTS}.
187 */
188 public static final String EXTRA_SUGGESTED_PHONE_ACCOUNTS =
189 "android.telecom.extra.SUGGESTED_PHONE_ACCOUNTS";
190
191 /**
mike dooley91217422017-03-09 12:58:42 -0800192 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
193 * when the last outgoing emergency call was made. This is used to identify potential emergency
194 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800195 */
196 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
197 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
198
Usman Abdullahb0dc29a2019-03-06 15:54:56 -0800199
200 /**
201 * Extra key used to indicate whether a {@link CallScreeningService} has requested to silence
202 * the ringtone for a call. If the {@link InCallService} declares
203 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} in its manifest, it should not
204 * play a ringtone for an incoming call with this extra key set.
205 */
206 public static final String EXTRA_SILENT_RINGING_REQUESTED =
207 "android.telecom.extra.SILENT_RINGING_REQUESTED";
208
Tyler Gunn8bf76572017-04-06 15:30:08 -0700209 /**
210 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
211 * Telecom that the user has requested that the current {@link Call} should be handed over
212 * to another {@link ConnectionService}.
213 * <p>
214 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
215 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
216 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700217 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
218 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700219 */
220 public static final String EVENT_REQUEST_HANDOVER =
221 "android.telecom.event.REQUEST_HANDOVER";
222
223 /**
224 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
225 * {@link PhoneAccountHandle} to which a call should be handed over to.
226 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700227 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
228 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700229 */
230 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
231 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
232
233 /**
234 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
235 * video state of the call when it is handed over to the new {@link PhoneAccount}.
236 * <p>
237 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
238 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
239 * {@link VideoProfile#STATE_TX_ENABLED}.
240 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700241 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
242 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700243 */
244 public static final String EXTRA_HANDOVER_VIDEO_STATE =
245 "android.telecom.extra.HANDOVER_VIDEO_STATE";
246
247 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700248 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
249 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
250 * information to the handover {@link ConnectionService} specified by
251 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
252 * <p>
253 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
254 * {@link ConnectionService} via the request extras when
255 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
256 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700257 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700258 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
259 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700260 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700261 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700262
263 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700264 * Call event sent from Telecom to the handover {@link ConnectionService} via
265 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
266 * to the {@link ConnectionService} has completed successfully.
267 * <p>
268 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700269 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700270 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
271 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700272 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700273 public static final String EVENT_HANDOVER_COMPLETE =
274 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700275
276 /**
277 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
278 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
279 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
280 * {@code null}.
281 * <p>
282 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
283 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700284 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
285 * APIs instead.
Tyler Gunn34a2b312017-06-23 08:32:00 -0700286 */
287 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
288 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
289
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700290 /**
291 * Call event sent from Telecom to the handover {@link ConnectionService} via
292 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
293 * to the {@link ConnectionService} has failed.
294 * <p>
295 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
296 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700297 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
298 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700299 */
300 public static final String EVENT_HANDOVER_FAILED =
301 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700302
Tyler Gunnd5821842021-02-05 11:12:57 -0800303 /**
304 * Event reported from the Telecom stack to report an in-call diagnostic message which the
305 * dialer app may opt to display to the user. A diagnostic message is used to communicate
306 * scenarios the device has detected which may impact the quality of the ongoing call.
307 * <p>
308 * For example a problem with a bluetooth headset may generate a recommendation for the user to
309 * try using the speakerphone instead, or if the device detects it has entered a poor service
310 * area, the user might be warned so that they can finish their call prior to it dropping.
311 * <p>
312 * A diagnostic message is considered persistent in nature. When the user enters a poor service
313 * area, for example, the accompanying diagnostic message persists until they leave the area
314 * of poor service. Each message is accompanied with a {@link #EXTRA_DIAGNOSTIC_MESSAGE_ID}
315 * which uniquely identifies the diagnostic condition being reported. The framework raises a
316 * call event of type {@link #EVENT_CLEAR_DIAGNOSTIC_MESSAGE} when the condition reported has
317 * been cleared. The dialer app should display the diagnostic message until it is cleared.
318 * If multiple diagnostic messages are sent with different IDs (which have not yet been cleared)
319 * the dialer app should prioritize the most recently received message, but still provide the
320 * user with a means to review past messages.
321 * <p>
322 * The text of the message is found in {@link #EXTRA_DIAGNOSTIC_MESSAGE} in the form of a human
323 * readable {@link CharSequence} which is intended for display in the call UX.
324 * <p>
325 * The telecom framework audibly notifies the user of the presence of a diagnostic message, so
326 * the dialer app needs only to concern itself with visually displaying the message.
327 * <p>
328 * The dialer app receives this event via
329 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
330 */
331 public static final String EVENT_DISPLAY_DIAGNOSTIC_MESSAGE =
332 "android.telecom.event.DISPLAY_DIAGNOSTIC_MESSAGE";
333
334 /**
335 * Event reported from the telecom framework when a diagnostic message previously raised with
336 * {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE} has cleared and is no longer pertinent.
337 * <p>
338 * The {@link #EXTRA_DIAGNOSTIC_MESSAGE_ID} indicates the diagnostic message which has been
339 * cleared.
340 * <p>
341 * The dialer app receives this event via
342 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
343 */
344 public static final String EVENT_CLEAR_DIAGNOSTIC_MESSAGE =
345 "android.telecom.event.CLEAR_DIAGNOSTIC_MESSAGE";
346
347 /**
348 * Integer extra representing a message ID for a message posted via
349 * {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE}. Used to ensure that the dialer app knows when
350 * the message in question has cleared via {@link #EVENT_CLEAR_DIAGNOSTIC_MESSAGE}.
351 */
352 public static final String EXTRA_DIAGNOSTIC_MESSAGE_ID =
353 "android.telecom.extra.DIAGNOSTIC_MESSAGE_ID";
354
355 /**
356 * {@link CharSequence} extra used with {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE}. This is the
357 * diagnostic message the dialer app should display.
358 */
359 public static final String EXTRA_DIAGNOSTIC_MESSAGE =
360 "android.telecom.extra.DIAGNOSTIC_MESSAGE";
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800361
362 /**
Thomas Nguyeneb427672023-02-15 15:42:34 -0800363 * Event reported from the Telecom stack to indicate that the {@link Connection} is not able to
364 * find any network and likely will not get connected. Upon receiving this event, the dialer
365 * app should show satellite SOS button if satellite is provisioned.
366 * <p>
367 * The dialer app receives this event via
368 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
369 * @hide
370 */
371 public static final String EVENT_DISPLAY_SOS_MESSAGE =
372 "android.telecom.event.DISPLAY_SOS_MESSAGE";
373
374 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800375 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
376 * call because they have declined to answer it. This typically means that they are unable
377 * to answer the call at this time and would prefer it be sent to voicemail.
378 */
379 public static final int REJECT_REASON_DECLINED = 1;
380
381 /**
382 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
383 * call because it is an unwanted call. This allows the user to indicate that they are
384 * rejecting a call because it is likely a nuisance call.
385 */
386 public static final int REJECT_REASON_UNWANTED = 2;
387
388 /**
389 * @hide
390 */
391 @IntDef(prefix = { "REJECT_REASON_" },
392 value = {REJECT_REASON_DECLINED, REJECT_REASON_UNWANTED})
393 @Retention(RetentionPolicy.SOURCE)
394 public @interface RejectReason {};
395
Ihab Awade63fadb2014-07-09 21:52:04 -0700396 public static class Details {
Tyler Gunn94f8f112018-12-17 09:56:11 -0800397 /** @hide */
398 @Retention(RetentionPolicy.SOURCE)
399 @IntDef(
400 prefix = { "DIRECTION_" },
401 value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
402 public @interface CallDirection {}
403
404 /**
405 * Indicates that the call is neither and incoming nor an outgoing call. This can be the
406 * case for calls reported directly by a {@link ConnectionService} in special cases such as
407 * call handovers.
408 */
409 public static final int DIRECTION_UNKNOWN = -1;
410
411 /**
412 * Indicates that the call is an incoming call.
413 */
414 public static final int DIRECTION_INCOMING = 0;
415
416 /**
417 * Indicates that the call is an outgoing call.
418 */
419 public static final int DIRECTION_OUTGOING = 1;
420
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800421 /** Call can currently be put on hold or unheld. */
422 public static final int CAPABILITY_HOLD = 0x00000001;
423
424 /** Call supports the hold feature. */
425 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
426
427 /**
428 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
429 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
430 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
431 * capability allows a merge button to be shown while the conference call is in the foreground
432 * of the in-call UI.
433 * <p>
434 * This is only intended for use by a {@link Conference}.
435 */
436 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
437
438 /**
439 * Calls within a conference can be swapped between foreground and background.
440 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
441 * <p>
442 * This is only intended for use by a {@link Conference}.
443 */
444 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
445
446 /**
447 * @hide
448 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700449 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800450
451 /** Call supports responding via text option. */
452 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
453
454 /** Call can be muted. */
455 public static final int CAPABILITY_MUTE = 0x00000040;
456
457 /**
458 * Call supports conference call management. This capability only applies to {@link Conference}
459 * calls which can have {@link Connection}s as children.
460 */
461 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
462
463 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700464 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800465 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700466 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800467
468 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700469 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800470 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700471 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800472
473 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700474 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800475 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700476 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700477 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800478
479 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700480 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800481 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700482 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
483
484 /**
485 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700486 */
487 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
488
489 /**
490 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700491 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700492 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700493 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800494
495 /**
496 * Call is able to be separated from its parent {@code Conference}, if any.
497 */
498 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
499
500 /**
501 * Call is able to be individually disconnected when in a {@code Conference}.
502 */
503 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
504
505 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500506 * Speed up audio setup for MT call.
507 * @hide
508 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700509 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
510
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700511 /**
512 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700513 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800514 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
515 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
516 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700517 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800518 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700519 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
520
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700521 /**
522 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700523 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700524 */
525 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
526
Bryce Lee81901682015-08-28 16:38:02 -0700527 /**
528 * Call sends responses through connection.
529 * @hide
530 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800531 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
532
533 /**
534 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
535 * <p>
536 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
537 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
538 * downgraded from a video call back to a VideoState of
539 * {@link VideoProfile#STATE_AUDIO_ONLY}.
540 * <p>
541 * Intuitively, a call which can be downgraded to audio should also have local and remote
542 * video
543 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
544 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
545 */
546 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700547
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700548 /**
549 * When set for an external call, indicates that this {@code Call} can be pulled from a
550 * remote device to the current device.
551 * <p>
552 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
553 * <p>
554 * An {@link InCallService} will only see calls with this capability if it has the
555 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
556 * in its manifest.
557 * <p>
558 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700559 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700560 */
561 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
562
Pooja Jaind34698d2017-12-28 14:15:31 +0530563 /** Call supports the deflect feature. */
564 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
565
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800566 /**
567 * Call supports adding participants to the call via
Grace Jia8587ee52020-07-10 15:42:32 -0700568 * {@link #addConferenceParticipants(List)}. Once participants are added, the call becomes
569 * an adhoc conference call ({@link #PROPERTY_IS_ADHOC_CONFERENCE}).
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800570 */
Ravi Paluri404babb2020-01-23 19:02:44 +0530571 public static final int CAPABILITY_ADD_PARTICIPANT = 0x02000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530572
573 /**
574 * When set for a call, indicates that this {@code Call} can be transferred to another
575 * number.
Tyler Gunn460360d2020-07-29 10:21:45 -0700576 * Call supports the confirmed and unconfirmed call transfer feature.
Ravi Palurif4b38e72020-02-05 12:35:41 +0530577 *
578 * @hide
579 */
580 public static final int CAPABILITY_TRANSFER = 0x04000000;
581
582 /**
583 * When set for a call, indicates that this {@code Call} can be transferred to another
584 * ongoing call.
585 * Call supports the consultative call transfer feature.
586 *
587 * @hide
588 */
589 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x08000000;
590
Alvin Dey2f37d772018-05-18 23:16:10 +0530591 /**
592 * Indicates whether the remote party supports RTT or not to the UI.
593 */
594
595 public static final int CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT = 0x10000000;
596
Tyler Gunnd11a3152015-03-18 13:09:14 -0700597 //******************************************************************************************
Alvin Dey2f37d772018-05-18 23:16:10 +0530598 // Next CAPABILITY value: 0x20000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700599 //******************************************************************************************
600
601 /**
602 * Whether the call is currently a conference.
603 */
604 public static final int PROPERTY_CONFERENCE = 0x00000001;
605
606 /**
607 * Whether the call is a generic conference, where we do not know the precise state of
608 * participants in the conference (eg. on CDMA).
609 */
610 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
611
612 /**
613 * Whether the call is made while the device is in emergency callback mode.
614 */
615 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
616
617 /**
618 * Connection is using WIFI.
619 */
620 public static final int PROPERTY_WIFI = 0x00000008;
621
622 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700623 * When set, the UI should indicate to the user that a call is using high definition
624 * audio.
625 * <p>
626 * The underlying {@link ConnectionService} is responsible for reporting this
627 * property. It is important to note that this property is not intended to report the
628 * actual audio codec being used for a Call, but whether the call should be indicated
629 * to the user as high definition.
630 * <p>
631 * The Android Telephony stack reports this property for calls based on a number
632 * of factors, including which audio codec is used and whether a call is using an HD
633 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
634 * and in these cases this property will not be set for a call even if the underlying audio
635 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700636 */
637 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
638
Tony Maka68dcce2015-12-17 09:31:18 +0000639 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100640 * Whether the call is associated with the work profile.
641 */
642 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
643
644 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700645 * When set, indicates that this {@code Call} does not actually exist locally for the
646 * {@link ConnectionService}.
647 * <p>
648 * Consider, for example, a scenario where a user has two phones with the same phone number.
649 * When a user places a call on one device, the telephony stack can represent that call on
650 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700651 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700652 * <p>
653 * An {@link InCallService} will only see calls with this property if it has the
654 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
655 * in its manifest.
656 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700657 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700658 */
659 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
660
Brad Ebinger15847072016-05-18 11:08:36 -0700661 /**
662 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
663 */
664 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
665
Tyler Gunn24e18332017-02-10 09:42:49 -0800666 /**
667 * Indicates that the call is from a self-managed {@link ConnectionService}.
668 * <p>
669 * See also {@link Connection#PROPERTY_SELF_MANAGED}
670 */
671 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
672
Eric Erfanianec881872017-12-06 16:27:53 -0800673 /**
674 * Indicates the call used Assisted Dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700675 *
676 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanianec881872017-12-06 16:27:53 -0800677 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800678 public static final int PROPERTY_ASSISTED_DIALING = 0x00000200;
Eric Erfanianec881872017-12-06 16:27:53 -0800679
Hall Liue9041242018-02-09 16:40:03 -0800680 /**
681 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
682 * {@link RttCall} object that is used to send and receive text.
683 */
684 public static final int PROPERTY_RTT = 0x00000400;
685
Tyler Gunn5bd90852018-09-21 09:37:07 -0700686 /**
687 * Indicates that the call has been identified as the network as an emergency call. This
688 * property may be set for both incoming and outgoing calls which the network identifies as
689 * emergency calls.
690 */
691 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
692
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700693 /**
694 * Indicates that the call is using VoIP audio mode.
695 * <p>
696 * When this property is set, the {@link android.media.AudioManager} audio mode for this
697 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
698 * property is not set, the audio mode for this call will be
699 * {@link android.media.AudioManager#MODE_IN_CALL}.
700 * <p>
701 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
702 * <p>
703 * You can use this property to determine whether an un-answered incoming call or a held
704 * call will use VoIP audio mode (if the call does not currently have focus, the system
705 * audio mode may not reflect the mode the call will use).
706 */
707 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
708
Ravi Paluri80aa2142019-12-02 11:57:37 +0530709 /**
710 * Indicates that the call is an adhoc conference call. This property can be set for both
Grace Jia8587ee52020-07-10 15:42:32 -0700711 * incoming and outgoing calls. An adhoc conference call is formed using
712 * {@link #addConferenceParticipants(List)},
713 * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}, or
714 * {@link TelecomManager#startConference(List, Bundle)}, rather than by merging existing
715 * call using {@link #conference(Call)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530716 */
717 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 0x00002000;
718
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800719 /**
Sooraj Sasindranfa1e57a2021-03-22 13:44:14 -0700720 * Connection is using cross sim technology.
721 * <p>
722 * Indicates that the {@link Connection} is using a cross sim technology which would
723 * register IMS over internet APN of default data subscription.
724 * <p>
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800725 */
726 public static final int PROPERTY_CROSS_SIM = 0x00004000;
727
Andrew Lee2378ea72015-04-29 14:38:11 -0700728 //******************************************************************************************
Ravi Paluri80aa2142019-12-02 11:57:37 +0530729 // Next PROPERTY value: 0x00004000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700730 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800731
Tyler Gunn1e406ca2021-03-18 16:47:14 -0700732 private final @CallState int mState;
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800733 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700734 private final Uri mHandle;
735 private final int mHandlePresentation;
736 private final String mCallerDisplayName;
737 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700738 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700739 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700740 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800741 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700742 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700743 private final long mConnectTimeMillis;
744 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700745 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700746 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700747 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700748 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700749 private final long mCreationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -0800750 private final String mContactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800751 private final @CallDirection int mCallDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700752 private final @Connection.VerificationStatus int mCallerNumberVerificationStatus;
Edgar Arriagae5bec822022-10-14 14:25:43 -0700753 private final Uri mContactPhotoUri;
Ihab Awade63fadb2014-07-09 21:52:04 -0700754
755 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800756 * Whether the supplied capabilities supports the specified capability.
757 *
758 * @param capabilities A bit field of capabilities.
759 * @param capability The capability to check capabilities for.
760 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800761 */
762 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800763 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800764 }
765
766 /**
767 * Whether the capabilities of this {@code Details} supports the specified capability.
768 *
769 * @param capability The capability to check capabilities for.
770 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800771 */
772 public boolean can(int capability) {
773 return can(mCallCapabilities, capability);
774 }
775
776 /**
777 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
778 *
779 * @param capabilities A capability bit field.
780 * @return A human readable string representation.
781 */
782 public static String capabilitiesToString(int capabilities) {
783 StringBuilder builder = new StringBuilder();
784 builder.append("[Capabilities:");
785 if (can(capabilities, CAPABILITY_HOLD)) {
786 builder.append(" CAPABILITY_HOLD");
787 }
788 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
789 builder.append(" CAPABILITY_SUPPORT_HOLD");
790 }
791 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
792 builder.append(" CAPABILITY_MERGE_CONFERENCE");
793 }
794 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
795 builder.append(" CAPABILITY_SWAP_CONFERENCE");
796 }
797 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
798 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
799 }
800 if (can(capabilities, CAPABILITY_MUTE)) {
801 builder.append(" CAPABILITY_MUTE");
802 }
803 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
804 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
805 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700806 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
807 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
808 }
809 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
810 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
811 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700812 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
813 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800814 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700815 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
816 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
817 }
818 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
819 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
820 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800821 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
822 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
823 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700824 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
825 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800826 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500827 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700828 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500829 }
Rekha Kumar07366812015-03-24 16:42:31 -0700830 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
831 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
832 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700833 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
834 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
835 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700836 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
837 builder.append(" CAPABILITY_CAN_PULL_CALL");
838 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530839 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
840 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
841 }
Ravi Paluri404babb2020-01-23 19:02:44 +0530842 if (can(capabilities, CAPABILITY_ADD_PARTICIPANT)) {
843 builder.append(" CAPABILITY_ADD_PARTICIPANT");
844 }
Ravi Palurif4b38e72020-02-05 12:35:41 +0530845 if (can(capabilities, CAPABILITY_TRANSFER)) {
846 builder.append(" CAPABILITY_TRANSFER");
847 }
848 if (can(capabilities, CAPABILITY_TRANSFER_CONSULTATIVE)) {
849 builder.append(" CAPABILITY_TRANSFER_CONSULTATIVE");
850 }
Alvin Dey2f37d772018-05-18 23:16:10 +0530851 if (can(capabilities, CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT)) {
852 builder.append(" CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT");
853 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800854 builder.append("]");
855 return builder.toString();
856 }
857
858 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700859 * Whether the supplied properties includes the specified property.
860 *
861 * @param properties A bit field of properties.
862 * @param property The property to check properties for.
863 * @return Whether the specified property is supported.
864 */
865 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800866 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700867 }
868
869 /**
870 * Whether the properties of this {@code Details} includes the specified property.
871 *
872 * @param property The property to check properties for.
873 * @return Whether the specified property is supported.
874 */
875 public boolean hasProperty(int property) {
876 return hasProperty(mCallProperties, property);
877 }
878
879 /**
880 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
881 *
882 * @param properties A property bit field.
883 * @return A human readable string representation.
884 */
885 public static String propertiesToString(int properties) {
886 StringBuilder builder = new StringBuilder();
887 builder.append("[Properties:");
888 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
889 builder.append(" PROPERTY_CONFERENCE");
890 }
891 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
892 builder.append(" PROPERTY_GENERIC_CONFERENCE");
893 }
894 if (hasProperty(properties, PROPERTY_WIFI)) {
895 builder.append(" PROPERTY_WIFI");
896 }
897 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
898 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
899 }
900 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700901 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700902 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700903 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
904 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
905 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700906 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700907 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
908 }
Tyler Gunnc9503d62020-01-27 10:30:51 -0800909 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800910 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
911 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700912 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
913 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
914 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700915 if (hasProperty(properties, PROPERTY_RTT)) {
916 builder.append(" PROPERTY_RTT");
917 }
918 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
919 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
920 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530921 if (hasProperty(properties, PROPERTY_IS_ADHOC_CONFERENCE)) {
922 builder.append(" PROPERTY_IS_ADHOC_CONFERENCE");
923 }
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800924 if (hasProperty(properties, PROPERTY_CROSS_SIM)) {
925 builder.append(" PROPERTY_CROSS_SIM");
926 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700927 builder.append("]");
928 return builder.toString();
929 }
930
Tyler Gunn1e406ca2021-03-18 16:47:14 -0700931 /**
932 * @return the state of the {@link Call} represented by this {@link Call.Details}.
933 */
934 public final @CallState int getState() {
935 return mState;
936 }
937
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800938 /** {@hide} */
Hall Liu31de23d2019-10-11 15:38:29 -0700939 @TestApi
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800940 public String getTelecomCallId() {
941 return mTelecomCallId;
942 }
943
Andrew Lee2378ea72015-04-29 14:38:11 -0700944 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700945 * @return The handle (e.g., phone number) to which the {@code Call} is currently
946 * connected.
947 */
948 public Uri getHandle() {
949 return mHandle;
950 }
951
952 /**
953 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700954 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700955 */
956 public int getHandlePresentation() {
957 return mHandlePresentation;
958 }
959
960 /**
Edgar Arriagae5bec822022-10-14 14:25:43 -0700961 * @return The contact photo URI which corresponds to
962 * {@link android.provider.ContactsContract.PhoneLookup#PHOTO_URI}, or {@code null} if the
963 * lookup is not yet complete, if there's no contacts entry for the caller,
964 * or if the {@link InCallService} does not hold the
965 * {@link android.Manifest.permission#READ_CONTACTS} permission.
966 */
967 public @Nullable Uri getContactPhotoUri() {
968 return mContactPhotoUri;
969 }
970
971 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800972 * The display name for the caller.
973 * <p>
974 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800975 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700976 * @return The display name for the caller.
977 */
978 public String getCallerDisplayName() {
979 return mCallerDisplayName;
980 }
981
982 /**
983 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700984 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700985 */
986 public int getCallerDisplayNamePresentation() {
987 return mCallerDisplayNamePresentation;
988 }
989
990 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700991 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
992 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700993 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700994 public PhoneAccountHandle getAccountHandle() {
995 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700996 }
997
998 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800999 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
1000 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -07001001 */
Ihab Awad5d0410f2014-07-30 10:07:40 -07001002 public int getCallCapabilities() {
1003 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -07001004 }
1005
1006 /**
Andrew Lee2378ea72015-04-29 14:38:11 -07001007 * @return A bitmask of the properties of the {@code Call}, as defined by the various
1008 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -07001009 */
1010 public int getCallProperties() {
1011 return mCallProperties;
1012 }
1013
1014 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -08001015 * @return a bitmask of the audio routes available for the call.
1016 *
1017 * @hide
1018 */
1019 public int getSupportedAudioRoutes() {
1020 return mSupportedAudioRoutes;
1021 }
1022
1023 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001024 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -07001025 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001026 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001027 public DisconnectCause getDisconnectCause() {
1028 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -07001029 }
1030
1031 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001032 * Returns the time the {@link Call} connected (i.e. became active). This information is
1033 * updated periodically, but user interfaces should not rely on this to display the "call
1034 * time clock". For the time when the call was first added to Telecom, see
1035 * {@link #getCreationTimeMillis()}.
1036 *
1037 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -07001038 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -07001039 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -07001040 return mConnectTimeMillis;
1041 }
1042
1043 /**
1044 * @return Information about any calling gateway the {@code Call} may be using.
1045 */
1046 public GatewayInfo getGatewayInfo() {
1047 return mGatewayInfo;
1048 }
1049
Andrew Lee7a341382014-07-15 17:05:08 -07001050 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -07001051 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -07001052 */
1053 public int getVideoState() {
1054 return mVideoState;
1055 }
1056
Ihab Awad5d0410f2014-07-30 10:07:40 -07001057 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001058 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -07001059 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -07001060 */
1061 public StatusHints getStatusHints() {
1062 return mStatusHints;
1063 }
1064
Nancy Chen10798dc2014-08-08 14:00:25 -07001065 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001066 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -07001067 */
1068 public Bundle getExtras() {
1069 return mExtras;
1070 }
1071
Santos Cordon6b7f9552015-05-27 17:21:45 -07001072 /**
1073 * @return The extras used with the original intent to place this call.
1074 */
1075 public Bundle getIntentExtras() {
1076 return mIntentExtras;
1077 }
1078
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001079 /**
1080 * Returns the time when the call was first created and added to Telecom. This is the same
1081 * time that is logged as the start time in the Call Log (see
1082 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
1083 * (became active), see {@link #getConnectTimeMillis()}.
1084 *
1085 * @return The creation time of the call, in millis since the epoch.
1086 */
1087 public long getCreationTimeMillis() {
1088 return mCreationTimeMillis;
1089 }
1090
Tyler Gunnd081f042018-12-04 12:56:45 -08001091 /**
Hall Liuef98bf82020-01-09 15:22:44 -08001092 * Returns the name of the caller on the remote end, as derived from a
1093 * {@link android.provider.ContactsContract} lookup of the call's handle.
1094 * @return The name of the caller, or {@code null} if the lookup is not yet complete, if
1095 * there's no contacts entry for the caller, or if the {@link InCallService} does
1096 * not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
1097 */
1098 public @Nullable String getContactDisplayName() {
1099 return mContactDisplayName;
1100 }
1101
1102 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -08001103 * Indicates whether the call is an incoming or outgoing call.
1104 * @return The call's direction.
1105 */
1106 public @CallDirection int getCallDirection() {
1107 return mCallDirection;
1108 }
1109
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001110 /**
1111 * Gets the verification status for the phone number of an incoming call as identified in
1112 * ATIS-1000082.
Tyler Gunn9c642492020-10-08 13:37:03 -07001113 * <p>
1114 * For incoming calls, the number verification status indicates whether the device was
1115 * able to verify the authenticity of the calling number using the STIR process outlined
1116 * in ATIS-1000082. {@link Connection#VERIFICATION_STATUS_NOT_VERIFIED} indicates that
1117 * the network was not able to use STIR to verify the caller's number (i.e. nothing is
1118 * known regarding the authenticity of the number.
1119 * {@link Connection#VERIFICATION_STATUS_PASSED} indicates that the network was able to
1120 * use STIR to verify the caller's number. This indicates that the network has a high
1121 * degree of confidence that the incoming call actually originated from the indicated
1122 * number. {@link Connection#VERIFICATION_STATUS_FAILED} indicates that the network's
1123 * STIR verification did not pass. This indicates that the incoming call may not
1124 * actually be from the indicated number. This could occur if, for example, the caller
1125 * is using an impersonated phone number.
1126 * <p>
1127 * A {@link CallScreeningService} can use this information to help determine if an
1128 * incoming call is potentially an unwanted call. A verification status of
1129 * {@link Connection#VERIFICATION_STATUS_FAILED} indicates that an incoming call may not
1130 * actually be from the number indicated on the call (i.e. impersonated number) and that it
1131 * should potentially be blocked. Likewise,
1132 * {@link Connection#VERIFICATION_STATUS_PASSED} can be used as a positive signal to
1133 * help clarify that the incoming call is originating from the indicated number and it
1134 * is less likely to be an undesirable call.
1135 * <p>
1136 * An {@link InCallService} can use this information to provide a visual indicator to the
1137 * user regarding the verification status of a call and to help identify calls from
1138 * potentially impersonated numbers.
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001139 * @return the verification status.
1140 */
1141 public @Connection.VerificationStatus int getCallerNumberVerificationStatus() {
1142 return mCallerNumberVerificationStatus;
1143 }
1144
Ihab Awade63fadb2014-07-09 21:52:04 -07001145 @Override
1146 public boolean equals(Object o) {
1147 if (o instanceof Details) {
1148 Details d = (Details) o;
1149 return
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001150 Objects.equals(mState, d.mState) &&
Ihab Awade63fadb2014-07-09 21:52:04 -07001151 Objects.equals(mHandle, d.mHandle) &&
1152 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
1153 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
1154 Objects.equals(mCallerDisplayNamePresentation,
1155 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -07001156 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -07001157 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -07001158 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001159 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -07001160 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -07001161 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -07001162 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -07001163 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001164 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001165 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -08001166 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Hall Liuef98bf82020-01-09 15:22:44 -08001167 Objects.equals(mContactDisplayName, d.mContactDisplayName) &&
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001168 Objects.equals(mCallDirection, d.mCallDirection) &&
1169 Objects.equals(mCallerNumberVerificationStatus,
Edgar Arriagae5bec822022-10-14 14:25:43 -07001170 d.mCallerNumberVerificationStatus) &&
1171 Objects.equals(mContactPhotoUri, d.mContactPhotoUri);
Ihab Awade63fadb2014-07-09 21:52:04 -07001172 }
1173 return false;
1174 }
1175
1176 @Override
1177 public int hashCode() {
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001178 return Objects.hash(mState,
1179 mHandle,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001180 mHandlePresentation,
1181 mCallerDisplayName,
1182 mCallerDisplayNamePresentation,
1183 mAccountHandle,
1184 mCallCapabilities,
1185 mCallProperties,
1186 mDisconnectCause,
1187 mConnectTimeMillis,
1188 mGatewayInfo,
1189 mVideoState,
1190 mStatusHints,
1191 mExtras,
1192 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001193 mCreationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001194 mContactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001195 mCallDirection,
Edgar Arriagae5bec822022-10-14 14:25:43 -07001196 mCallerNumberVerificationStatus,
1197 mContactPhotoUri);
Ihab Awade63fadb2014-07-09 21:52:04 -07001198 }
1199
1200 /** {@hide} */
1201 public Details(
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001202 @CallState int state,
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001203 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -07001204 Uri handle,
1205 int handlePresentation,
1206 String callerDisplayName,
1207 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -07001208 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -07001209 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -07001210 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001211 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -07001212 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -07001213 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -07001214 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -07001215 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -07001216 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001217 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001218 long creationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001219 String contactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001220 int callDirection,
Edgar Arriagae5bec822022-10-14 14:25:43 -07001221 int callerNumberVerificationStatus,
1222 Uri contactPhotoUri) {
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001223 mState = state;
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001224 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001225 mHandle = handle;
1226 mHandlePresentation = handlePresentation;
1227 mCallerDisplayName = callerDisplayName;
1228 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -07001229 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -07001230 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -07001231 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001232 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -07001233 mConnectTimeMillis = connectTimeMillis;
1234 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -07001235 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -07001236 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -07001237 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001238 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001239 mCreationTimeMillis = creationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -08001240 mContactDisplayName = contactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -08001241 mCallDirection = callDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001242 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
Edgar Arriagae5bec822022-10-14 14:25:43 -07001243 mContactPhotoUri = contactPhotoUri;
Ihab Awade63fadb2014-07-09 21:52:04 -07001244 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001245
1246 /** {@hide} */
1247 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
1248 return new Details(
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001249 parcelableCall.getState(),
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001250 parcelableCall.getId(),
1251 parcelableCall.getHandle(),
1252 parcelableCall.getHandlePresentation(),
1253 parcelableCall.getCallerDisplayName(),
1254 parcelableCall.getCallerDisplayNamePresentation(),
1255 parcelableCall.getAccountHandle(),
1256 parcelableCall.getCapabilities(),
1257 parcelableCall.getProperties(),
1258 parcelableCall.getDisconnectCause(),
1259 parcelableCall.getConnectTimeMillis(),
1260 parcelableCall.getGatewayInfo(),
1261 parcelableCall.getVideoState(),
1262 parcelableCall.getStatusHints(),
1263 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001264 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -08001265 parcelableCall.getCreationTimeMillis(),
Hall Liuef98bf82020-01-09 15:22:44 -08001266 parcelableCall.getContactDisplayName(),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001267 parcelableCall.getCallDirection(),
Edgar Arriagae5bec822022-10-14 14:25:43 -07001268 parcelableCall.getCallerNumberVerificationStatus(),
1269 parcelableCall.getContactPhotoUri()
1270 );
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001271 }
Santos Cordon3c20d632016-02-25 16:12:35 -08001272
1273 @Override
1274 public String toString() {
1275 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001276 sb.append("[id: ");
1277 sb.append(mTelecomCallId);
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001278 sb.append(", state: ");
1279 sb.append(Call.stateToString(mState));
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001280 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -08001281 sb.append(mAccountHandle);
1282 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001283 sb.append(Log.piiHandle(mHandle));
1284 sb.append(", hdlPres: ");
1285 sb.append(mHandlePresentation);
1286 sb.append(", videoState: ");
1287 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -08001288 sb.append(", caps: ");
1289 sb.append(capabilitiesToString(mCallCapabilities));
1290 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001291 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001292 sb.append("]");
1293 return sb.toString();
1294 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001295 }
1296
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001297 /**
1298 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1299 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1300 * implementation.
1301 * <p>
1302 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1303 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1304 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1305 * {@link Callback} implementation, if desired.
1306 * <p>
1307 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1308 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1309 * (typically in {@link InCallService#onCallRemoved(Call)}).
1310 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1311 * reach your implementation of {@link Callback}, so it is important to register your callback
1312 * as soon as your {@link InCallService} is notified of a new call via
1313 * {@link InCallService#onCallAdded(Call)}.
1314 */
Andrew Leeda80c872015-04-15 14:09:50 -07001315 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001316 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001317 * @hide
1318 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001319 @IntDef(prefix = { "HANDOVER_" },
1320 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001321 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001322 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001323 @Retention(RetentionPolicy.SOURCE)
1324 public @interface HandoverFailureErrors {}
1325
1326 /**
1327 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001328 * to handover the call to rejects the handover request.
1329 * <p>
1330 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1331 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1332 * {@code null} {@link Connection} from
1333 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1334 * ConnectionRequest)}.
1335 * <p>
1336 * For more information on call handovers, see
1337 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001338 */
1339 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1340
1341 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001342 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1343 * is initiated but the source or destination app does not support handover.
1344 * <p>
1345 * Will be returned when a handover is requested via
1346 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1347 * {@link PhoneAccountHandle} does not declare
1348 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1349 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1350 * {@link Details#getAccountHandle()}) does not declare
1351 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1352 * <p>
1353 * For more information on call handovers, see
1354 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001355 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001356 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001357
1358 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001359 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1360 * user rejects the handover request.
1361 * <p>
1362 * For more information on call handovers, see
1363 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001364 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001365 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001366
Sanket Padawe85291f62017-12-01 13:59:27 -08001367 /**
1368 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1369 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001370 * <p>
1371 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1372 * called on an emergency call, or if any other call is an emergency call.
1373 * <p>
1374 * Handovers are not permitted while there are ongoing emergency calls.
1375 * <p>
1376 * For more information on call handovers, see
1377 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001378 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001379 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001380
Tyler Gunn9d127732018-03-02 15:45:51 -08001381 /**
1382 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1383 * fails for an unknown reason.
1384 * <p>
1385 * For more information on call handovers, see
1386 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1387 */
1388 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001389
1390 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001391 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1392 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001393 * @param call The {@code Call} invoking this method.
1394 * @param state The new state of the {@code Call}.
1395 */
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001396 public void onStateChanged(Call call, @CallState int state) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001397
1398 /**
1399 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1400 *
1401 * @param call The {@code Call} invoking this method.
1402 * @param parent The new parent of the {@code Call}.
1403 */
1404 public void onParentChanged(Call call, Call parent) {}
1405
1406 /**
1407 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1408 *
1409 * @param call The {@code Call} invoking this method.
1410 * @param children The new children of the {@code Call}.
1411 */
1412 public void onChildrenChanged(Call call, List<Call> children) {}
1413
1414 /**
1415 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1416 *
1417 * @param call The {@code Call} invoking this method.
1418 * @param details A {@code Details} object describing the {@code Call}.
1419 */
1420 public void onDetailsChanged(Call call, Details details) {}
1421
1422 /**
1423 * Invoked when the text messages that can be used as responses to the incoming
1424 * {@code Call} are loaded from the relevant database.
1425 * See {@link #getCannedTextResponses()}.
1426 *
1427 * @param call The {@code Call} invoking this method.
1428 * @param cannedTextResponses The text messages useable as responses.
1429 */
1430 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1431
1432 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001433 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1434 * character. This causes the post-dial signals to stop pending user confirmation. An
1435 * implementation should present this choice to the user and invoke
1436 * {@link #postDialContinue(boolean)} when the user makes the choice.
1437 *
1438 * @param call The {@code Call} invoking this method.
1439 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1440 */
1441 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1442
1443 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001444 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001445 *
1446 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001447 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001448 */
Andrew Lee50aca232014-07-22 16:41:54 -07001449 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001450
1451 /**
1452 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1453 * up their UI for the {@code Call} in response to state transitions. Specifically,
1454 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1455 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1456 * clients should wait for this method to be invoked.
1457 *
1458 * @param call The {@code Call} being destroyed.
1459 */
1460 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001461
1462 /**
1463 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1464 * conferenced.
1465 *
1466 * @param call The {@code Call} being updated.
1467 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1468 * conferenced.
1469 */
1470 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001471
1472 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001473 * Invoked when a {@link Call} receives an event from its associated {@link Connection} or
1474 * {@link Conference}.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001475 * <p>
1476 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1477 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1478 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1479 * possible that a {@link ConnectionService} has defined its own Connection events which a
1480 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001481 * <p>
Tyler Gunn5567d742019-10-31 13:04:37 -07001482 * See {@link Connection#sendConnectionEvent(String, Bundle)},
1483 * {@link Conference#sendConferenceEvent(String, Bundle)}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001484 *
1485 * @param call The {@code Call} receiving the event.
1486 * @param event The event.
1487 * @param extras Extras associated with the connection event.
1488 */
1489 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001490
1491 /**
1492 * Invoked when the RTT mode changes for this call.
1493 * @param call The call whose RTT mode has changed.
1494 * @param mode the new RTT mode, one of
1495 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1496 * or {@link RttCall#RTT_MODE_VCO}
1497 */
1498 public void onRttModeChanged(Call call, int mode) {}
1499
1500 /**
1501 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1502 * @param call The call whose RTT status has changed.
1503 * @param enabled whether RTT is now enabled or disabled
1504 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1505 * on, null otherwise.
1506 */
1507 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1508
1509 /**
1510 * Invoked when the remote end of the connection has requested that an RTT communication
1511 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1512 * with the same ID that this method is invoked with.
1513 * @param call The call which the RTT request was placed on
1514 * @param id The ID of the request.
1515 */
1516 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001517
1518 /**
1519 * Invoked when the RTT session failed to initiate for some reason, including rejection
1520 * by the remote party.
Tyler Gunnb9a04962022-02-17 08:23:54 -08001521 * <p>
1522 * This callback will ONLY be invoked to report a failure related to a user initiated
1523 * session modification request (i.e. {@link Call#sendRttRequest()}).
1524 * <p>
1525 * If a call is initiated with {@link TelecomManager#EXTRA_START_CALL_WITH_RTT} specified,
1526 * the availability of RTT can be determined by checking {@link Details#PROPERTY_RTT}
1527 * once the call enters state {@link Details#STATE_ACTIVE}.
1528 *
Hall Liu57006aa2017-02-06 10:49:48 -08001529 * @param call The call which the RTT initiation failure occurred on.
1530 * @param reason One of the status codes defined in
Tyler Gunnb9a04962022-02-17 08:23:54 -08001531 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1532 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liu57006aa2017-02-06 10:49:48 -08001533 */
Tyler Gunnb9a04962022-02-17 08:23:54 -08001534 public void onRttInitiationFailure(Call call,
1535 @android.telecom.Connection.RttModifyStatus.RttSessionModifyStatus int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001536
1537 /**
1538 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1539 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001540 * <p>
1541 * For a full discussion of the handover process and the APIs involved, see
1542 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1543 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001544 * @param call The call which had initiated handover.
1545 */
1546 public void onHandoverComplete(Call call) {}
1547
1548 /**
1549 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1550 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001551 * <p>
1552 * For a full discussion of the handover process and the APIs involved, see
1553 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1554 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001555 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001556 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001557 */
1558 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001559 }
1560
1561 /**
1562 * A class that holds the state that describes the state of the RTT channel to the remote
1563 * party, if it is active.
1564 */
1565 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001566 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001567 @Retention(RetentionPolicy.SOURCE)
1568 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1569 public @interface RttAudioMode {}
1570
1571 /**
1572 * For metrics use. Default value in the proto.
1573 * @hide
1574 */
1575 public static final int RTT_MODE_INVALID = 0;
1576
1577 /**
1578 * Indicates that there should be a bidirectional audio stream between the two parties
1579 * on the call.
1580 */
1581 public static final int RTT_MODE_FULL = 1;
1582
1583 /**
1584 * Indicates that the local user should be able to hear the audio stream from the remote
1585 * user, but not vice versa. Equivalent to muting the microphone.
1586 */
1587 public static final int RTT_MODE_HCO = 2;
1588
1589 /**
1590 * Indicates that the remote user should be able to hear the audio stream from the local
1591 * user, but not vice versa. Equivalent to setting the volume to zero.
1592 */
1593 public static final int RTT_MODE_VCO = 3;
1594
1595 private static final int READ_BUFFER_SIZE = 1000;
1596
1597 private InputStreamReader mReceiveStream;
1598 private OutputStreamWriter mTransmitStream;
1599 private int mRttMode;
1600 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001601 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001602 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1603
1604 /**
1605 * @hide
1606 */
Hall Liu57006aa2017-02-06 10:49:48 -08001607 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1608 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1609 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001610 mReceiveStream = receiveStream;
1611 mTransmitStream = transmitStream;
1612 mRttMode = mode;
1613 mInCallAdapter = inCallAdapter;
1614 }
1615
1616 /**
1617 * Returns the current RTT audio mode.
1618 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1619 * {@link #RTT_MODE_HCO}.
1620 */
1621 public int getRttAudioMode() {
1622 return mRttMode;
1623 }
1624
1625 /**
1626 * Sets the RTT audio mode. The requested mode change will be communicated through
1627 * {@link Callback#onRttModeChanged(Call, int)}.
1628 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1629 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1630 */
1631 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001632 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001633 }
1634
1635 /**
1636 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
Hall Liudc46c852020-10-29 16:15:33 -07001637 * RTT transmits text in real-time, this method should be called once for each user action.
1638 * For example, when the user enters text as discrete characters using the keyboard, this
1639 * method should be called once for each character. However, if the user enters text by
1640 * pasting or autocomplete, the entire contents of the pasted or autocompleted text should
1641 * be sent in one call to this method.
Hall Liu95d55872017-01-25 17:12:49 -08001642 *
1643 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1644 * lead to interleaved text.
1645 * @param input The message to send to the remote user.
1646 */
1647 public void write(String input) throws IOException {
1648 mTransmitStream.write(input);
1649 mTransmitStream.flush();
1650 }
1651
1652 /**
1653 * Reads a string from the remote user, blocking if there is no data available. Returns
1654 * {@code null} if the RTT conversation has been terminated and there is no further data
1655 * to read.
1656 *
1657 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1658 * lead to interleaved text.
1659 * @return A string containing text sent by the remote user, or {@code null} if the
1660 * conversation has been terminated or if there was an error while reading.
1661 */
Hall Liub1c8a772017-07-17 17:04:41 -07001662 public String read() {
1663 try {
1664 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1665 if (numRead < 0) {
1666 return null;
1667 }
1668 return new String(mReadBuffer, 0, numRead);
1669 } catch (IOException e) {
1670 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001671 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001672 }
Hall Liuffa4a812017-03-02 16:11:00 -08001673 }
1674
1675 /**
1676 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1677 * be read.
1678 * @return A string containing text entered by the user, or {@code null} if the user has
1679 * not entered any new text yet.
1680 */
1681 public String readImmediately() throws IOException {
1682 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001683 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1684 if (numRead < 0) {
1685 return null;
1686 }
1687 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001688 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001689 return null;
1690 }
1691 }
Hall Liue9041242018-02-09 16:40:03 -08001692
1693 /**
1694 * Closes the underlying file descriptors
1695 * @hide
1696 */
1697 public void close() {
1698 try {
1699 mReceiveStream.close();
1700 } catch (IOException e) {
1701 // ignore
1702 }
1703 try {
1704 mTransmitStream.close();
1705 } catch (IOException e) {
1706 // ignore
1707 }
1708 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001709 }
1710
Andrew Leeda80c872015-04-15 14:09:50 -07001711 /**
1712 * @deprecated Use {@code Call.Callback} instead.
1713 * @hide
1714 */
1715 @Deprecated
1716 @SystemApi
1717 public static abstract class Listener extends Callback { }
1718
Ihab Awade63fadb2014-07-09 21:52:04 -07001719 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001720 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001721 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001722 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001723 private final List<Call> mChildren = new ArrayList<>();
1724 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001725 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001726 private final List<Call> mConferenceableCalls = new ArrayList<>();
1727 private final List<Call> mUnmodifiableConferenceableCalls =
1728 Collections.unmodifiableList(mConferenceableCalls);
1729
Santos Cordon823fd3c2014-08-07 18:35:18 -07001730 private boolean mChildrenCached;
1731 private String mParentId = null;
Hall Liuef98bf82020-01-09 15:22:44 -08001732 private String mActiveGenericConferenceChild = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001733 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001734 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001735 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001736 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001737 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001738 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001739 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001740 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001741 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001742
1743 /**
1744 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1745 *
1746 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1747 * remaining or this {@code Call} is not in a post-dial state.
1748 */
1749 public String getRemainingPostDialSequence() {
1750 return mRemainingPostDialSequence;
1751 }
1752
1753 /**
1754 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001755 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001756 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001757 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001758 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001759 }
1760
1761 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301762 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1763 *
1764 * @param address The address to which the call will be deflected.
1765 */
1766 public void deflect(Uri address) {
1767 mInCallAdapter.deflectCall(mTelecomCallId, address);
1768 }
1769
1770 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001771 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1772 *
1773 * @param rejectWithMessage Whether to reject with a text message.
1774 * @param textMessage An optional text message with which to respond.
1775 */
1776 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001777 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001778 }
1779
1780 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001781 * Instructs the {@link ConnectionService} providing this {@link #STATE_RINGING} call that the
1782 * user has chosen to reject the call and has indicated a reason why the call is being rejected.
1783 *
1784 * @param rejectReason the reason the call is being rejected.
1785 */
1786 public void reject(@RejectReason int rejectReason) {
1787 mInCallAdapter.rejectCall(mTelecomCallId, rejectReason);
1788 }
1789
1790 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05301791 * Instructs this {@code Call} to be transferred to another number.
1792 *
1793 * @param targetNumber The address to which the call will be transferred.
Tyler Gunn460360d2020-07-29 10:21:45 -07001794 * @param isConfirmationRequired if {@code true} it will initiate a confirmed transfer,
1795 * if {@code false}, it will initiate an unconfirmed transfer.
Ravi Palurif4b38e72020-02-05 12:35:41 +05301796 *
1797 * @hide
1798 */
1799 public void transfer(@NonNull Uri targetNumber, boolean isConfirmationRequired) {
1800 mInCallAdapter.transferCall(mTelecomCallId, targetNumber, isConfirmationRequired);
1801 }
1802
1803 /**
1804 * Instructs this {@code Call} to be transferred to another ongoing call.
1805 * This will initiate CONSULTATIVE transfer.
1806 * @param toCall The other ongoing {@code Call} to which this call will be transferred.
1807 *
1808 * @hide
1809 */
1810 public void transfer(@NonNull android.telecom.Call toCall) {
1811 mInCallAdapter.transferCall(mTelecomCallId, toCall.mTelecomCallId);
1812 }
1813
1814 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001815 * Instructs this {@code Call} to disconnect.
1816 */
1817 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001818 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001819 }
1820
1821 /**
1822 * Instructs this {@code Call} to go on hold.
1823 */
1824 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001825 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001826 }
1827
1828 /**
1829 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1830 */
1831 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001832 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001833 }
1834
1835 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001836 * Instructs Telecom to put the call into the background audio processing state.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001837 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001838 * This method can be called either when the call is in {@link #STATE_RINGING} or
1839 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1840 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1841 * order to capture and play audio on the call stream.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001842 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001843 * This method can only be called by the default dialer app.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001844 * <p>
1845 * Apps built with SDK version {@link android.os.Build.VERSION_CODES#R} or later which are using
1846 * the microphone as part of audio processing should specify the foreground service type using
1847 * the attribute {@link android.R.attr#foregroundServiceType} in the {@link InCallService}
1848 * service element of the app's manifest file.
1849 * The {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_MICROPHONE} attribute should be specified.
1850 * @see <a href="https://developer.android.com/preview/privacy/foreground-service-types">
1851 * the Android Developer Site</a> for more information.
Hall Liu6dfa2492019-10-01 17:20:39 -07001852 * @hide
1853 */
1854 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001855 public void enterBackgroundAudioProcessing() {
1856 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1857 throw new IllegalStateException("Call must be active or ringing");
1858 }
1859 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1860 }
1861
1862 /**
1863 * Instructs Telecom to come out of the background audio processing state requested by
1864 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1865 *
1866 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1867 *
1868 * @param shouldRing If true, Telecom will put the call into the
1869 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1870 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1871 * immediately.
1872 * @hide
1873 */
1874 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001875 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1876 if (mState != STATE_AUDIO_PROCESSING) {
1877 throw new IllegalStateException("Call must in the audio processing state");
1878 }
1879 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1880 }
1881
1882 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001883 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
Tyler Gunn2517d032023-02-06 16:34:54 +00001884 * <p>
1885 * Tones are both played locally for the user to hear and sent to the network to be relayed
1886 * to the remote device.
1887 * <p>
1888 * You must ensure that any call to {@link #playDtmfTone(char}) is followed by a matching
1889 * call to {@link #stopDtmfTone()} and that each tone is stopped before a new one is started.
1890 * The play and stop commands are relayed to the underlying
1891 * {@link android.telecom.ConnectionService} as executed; implementations may not correctly
1892 * handle out of order commands.
Ihab Awade63fadb2014-07-09 21:52:04 -07001893 *
1894 * @param digit A character representing the DTMF digit for which to play the tone. This
1895 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1896 */
1897 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001898 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001899 }
1900
1901 /**
1902 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1903 * currently playing.
1904 *
1905 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1906 * currently playing, this method will do nothing.
1907 */
1908 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001909 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001910 }
1911
1912 /**
1913 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1914 *
1915 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1916 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001917 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001918 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001919 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1920 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001921 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001922 * {@code Call} will pause playing the tones and notify callbacks via
1923 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001924 * should display to the user an indication of this state and an affordance to continue
1925 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1926 * app should invoke the {@link #postDialContinue(boolean)} method.
1927 *
1928 * @param proceed Whether or not to continue with the post-dial sequence.
1929 */
1930 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001931 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001932 }
1933
1934 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001935 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001936 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001937 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001938 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1939 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001940
1941 }
1942
1943 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001944 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001945 *
1946 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001947 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001948 public void conference(Call callToConferenceWith) {
1949 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001950 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001951 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001952 }
1953
1954 /**
1955 * Instructs this {@code Call} to split from any conference call with which it may be
1956 * connected.
1957 */
1958 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001959 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001960 }
1961
1962 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001963 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001964 */
1965 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001966 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001967 }
1968
1969 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001970 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001971 */
1972 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001973 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001974 }
1975
1976 /**
Ravi Paluri404babb2020-01-23 19:02:44 +05301977 * Pulls participants to existing call by forming a conference call.
1978 * See {@link Details#CAPABILITY_ADD_PARTICIPANT}.
1979 *
1980 * @param participants participants to be pulled to existing call.
1981 */
1982 public void addConferenceParticipants(@NonNull List<Uri> participants) {
1983 mInCallAdapter.addConferenceParticipants(mTelecomCallId, participants);
1984 }
1985
1986 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001987 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1988 * device.
1989 * <p>
1990 * Calls to this method are ignored if the call does not have the
1991 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1992 * <p>
1993 * An {@link InCallService} will only see calls which support this method if it has the
1994 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1995 * in its manifest.
1996 */
1997 public void pullExternalCall() {
1998 // If this isn't an external call, ignore the request.
1999 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
2000 return;
2001 }
2002
2003 mInCallAdapter.pullExternalCall(mTelecomCallId);
2004 }
2005
2006 /**
2007 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
2008 * the {@link ConnectionService}.
2009 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002010 * Call events are used to communicate point in time information from an {@link InCallService}
2011 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
2012 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
2013 * {@link ConnectionService}.
2014 * <p>
2015 * A {@link ConnectionService} can communicate to the {@link InCallService} using
2016 * {@link Connection#sendConnectionEvent(String, Bundle)}.
2017 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002018 * Events are exposed to {@link ConnectionService} implementations via
2019 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
2020 * <p>
2021 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002022 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
2023 * ignore some events altogether.
2024 * <p>
2025 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
2026 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
2027 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
2028 * they define their own event types in this namespace. When defining a custom event type,
2029 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
2030 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
2031 * <p>
2032 * When defining events and the associated extras, it is important to keep their behavior
2033 * consistent when the associated {@link InCallService} is updated. Support for deprecated
2034 * events/extras should me maintained to ensure backwards compatibility with older
2035 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002036 *
2037 * @param event The connection event.
2038 * @param extras Bundle containing extra information associated with the event.
2039 */
2040 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08002041 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002042 }
2043
2044 /**
Hall Liu95d55872017-01-25 17:12:49 -08002045 * Sends an RTT upgrade request to the remote end of the connection. Success is not
2046 * guaranteed, and notification of success will be via the
2047 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
2048 */
2049 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08002050 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08002051 }
2052
2053 /**
2054 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
2055 * callback.
2056 * The ID used here should be the same as the ID that was received via the callback.
2057 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
2058 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
2059 */
2060 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08002061 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08002062 }
2063
2064 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07002065 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
2066 * by {@code toHandle}. The videoState specified indicates the desired video state after the
2067 * handover.
2068 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08002069 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2070 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2071 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2072 * is referred to as the source of the handover, and the video calling app is referred to as the
2073 * destination.
2074 * <p>
2075 * When considering a handover scenario the device this method is called on is considered the
2076 * <em>initiating</em> device (since the user initiates the handover from this device), and the
2077 * other device is considered the <em>receiving</em> device.
2078 * <p>
2079 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
2080 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
2081 * and invoke
2082 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
2083 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
2084 * call to it. The app returns an instance of {@link Connection} to represent the handover call
2085 * At this point the app should display UI to indicate to the user that a call
2086 * handover is in process.
2087 * <p>
2088 * The destination app is responsible for communicating the handover request from the
2089 * <em>initiating</em> device to the <em>receiving</em> device.
2090 * <p>
2091 * When the app on the <em>receiving</em> device receives the handover request, it calls
2092 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
2093 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
2094 * the destination app on the <em>receiving</em> device should show UI to allow the user to
2095 * choose whether they want to continue their call in the destination app.
2096 * <p>
2097 * When the destination app on the <em>receiving</em> device calls
2098 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
2099 * {@link ConnectionService} and call
2100 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
2101 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
2102 * {@link Connection} to represent the handover call.
2103 * <p>
2104 * If the user of the <em>receiving</em> device accepts the handover, the app calls
2105 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
2106 * original call. If the user rejects the handover, the app calls
2107 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
2108 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
2109 * <p>
2110 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
2111 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
2112 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
2113 * <p>
2114 * Errors in the handover process are reported to the {@link InCallService} via
2115 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
2116 * the involved {@link ConnectionService}s via
2117 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002118 *
2119 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
2120 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08002121 * @param videoState Indicates the video state desired after the handover (see the
2122 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07002123 * @param extras Bundle containing extra information to be passed to the
2124 * {@link ConnectionService}
2125 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002126 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
2127 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002128 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
2129 }
2130
2131 /**
Hall Liu95d55872017-01-25 17:12:49 -08002132 * Terminate the RTT session on this call. The resulting state change will be notified via
2133 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
2134 */
2135 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08002136 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08002137 }
2138
2139 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002140 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
2141 * added.
2142 * <p>
2143 * No assumptions should be made as to how an In-Call UI or service will handle these
2144 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
Tyler Gunn6c100242023-01-09 11:23:18 -08002145 * <p>
2146 * Extras added using this method will be made available to the {@link ConnectionService}
2147 * associated with this {@link Call} and notified via
2148 * {@link Connection#onExtrasChanged(Bundle)}.
2149 * <p>
2150 * Extras added using this method will also be available to other running {@link InCallService}s
2151 * and notified via {@link Call.Callback#onDetailsChanged(Call, Details)}. The extras can be
2152 * accessed via {@link Details#getExtras()}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002153 *
2154 * @param extras The extras to add.
2155 */
2156 public final void putExtras(Bundle extras) {
2157 if (extras == null) {
2158 return;
2159 }
2160
2161 if (mExtras == null) {
2162 mExtras = new Bundle();
2163 }
2164 mExtras.putAll(extras);
2165 mInCallAdapter.putExtras(mTelecomCallId, extras);
2166 }
2167
2168 /**
2169 * Adds a boolean extra to this {@link Call}.
2170 *
2171 * @param key The extra key.
2172 * @param value The value.
2173 * @hide
2174 */
2175 public final void putExtra(String key, boolean value) {
2176 if (mExtras == null) {
2177 mExtras = new Bundle();
2178 }
2179 mExtras.putBoolean(key, value);
2180 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2181 }
2182
2183 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002184 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002185 *
2186 * @param key The extra key.
2187 * @param value The value.
2188 * @hide
2189 */
2190 public final void putExtra(String key, int value) {
2191 if (mExtras == null) {
2192 mExtras = new Bundle();
2193 }
2194 mExtras.putInt(key, value);
2195 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2196 }
2197
2198 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002199 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002200 *
2201 * @param key The extra key.
2202 * @param value The value.
2203 * @hide
2204 */
2205 public final void putExtra(String key, String value) {
2206 if (mExtras == null) {
2207 mExtras = new Bundle();
2208 }
2209 mExtras.putString(key, value);
2210 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2211 }
2212
2213 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002214 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002215 *
2216 * @param keys The keys of the extras to remove.
2217 */
2218 public final void removeExtras(List<String> keys) {
2219 if (mExtras != null) {
2220 for (String key : keys) {
2221 mExtras.remove(key);
2222 }
2223 if (mExtras.size() == 0) {
2224 mExtras = null;
2225 }
2226 }
2227 mInCallAdapter.removeExtras(mTelecomCallId, keys);
2228 }
2229
2230 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002231 * Removes extras from this {@link Call}.
2232 *
2233 * @param keys The keys of the extras to remove.
2234 */
2235 public final void removeExtras(String ... keys) {
2236 removeExtras(Arrays.asList(keys));
2237 }
2238
2239 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002240 * Obtains the parent of this {@code Call} in a conference, if any.
2241 *
2242 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
2243 * child of any conference {@code Call}s.
2244 */
2245 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002246 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002247 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002248 }
2249 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07002250 }
2251
2252 /**
2253 * Obtains the children of this conference {@code Call}, if any.
2254 *
2255 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
2256 * {@code List} otherwise.
2257 */
2258 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002259 if (!mChildrenCached) {
2260 mChildrenCached = true;
2261 mChildren.clear();
2262
2263 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002264 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002265 if (call == null) {
2266 // At least one child was still not found, so do not save true for "cached"
2267 mChildrenCached = false;
2268 } else {
2269 mChildren.add(call);
2270 }
2271 }
2272 }
2273
Ihab Awade63fadb2014-07-09 21:52:04 -07002274 return mUnmodifiableChildren;
2275 }
2276
2277 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002278 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
2279 *
2280 * @return The list of conferenceable {@code Call}s.
2281 */
2282 public List<Call> getConferenceableCalls() {
2283 return mUnmodifiableConferenceableCalls;
2284 }
2285
2286 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002287 * Obtains the state of this {@code Call}.
2288 *
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002289 * @return The call state.
2290 * @deprecated The call state is available via {@link Call.Details#getState()}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002291 */
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002292 @Deprecated
2293 public @CallState int getState() {
Ihab Awade63fadb2014-07-09 21:52:04 -07002294 return mState;
2295 }
2296
2297 /**
Hall Liuef98bf82020-01-09 15:22:44 -08002298 * Returns the child {@link Call} in a generic conference that is currently active.
Hall Liu135e53aa2020-02-27 18:34:11 -08002299 *
2300 * A "generic conference" is the mechanism used to support two simultaneous calls on a device
2301 * in CDMA networks. It is effectively equivalent to having one call active and one call on hold
2302 * in GSM or IMS calls. This method returns the currently active call.
2303 *
2304 * In a generic conference, the network exposes the conference to us as a single call, and we
2305 * switch between talking to the two participants using a CDMA flash command. Since the network
2306 * exposes no additional information about the call, the only way we know which caller we're
2307 * currently talking to is by keeping track of the flash commands that we've sent to the
2308 * network.
2309 *
Hall Liuef98bf82020-01-09 15:22:44 -08002310 * For calls that are not generic conferences, or when the generic conference has more than
2311 * 2 children, returns {@code null}.
2312 * @see Details#PROPERTY_GENERIC_CONFERENCE
2313 * @return The active child call.
2314 */
2315 public @Nullable Call getGenericConferenceActiveChildCall() {
2316 if (mActiveGenericConferenceChild != null) {
2317 return mPhone.internalGetCallByTelecomId(mActiveGenericConferenceChild);
2318 }
2319 return null;
2320 }
2321
2322 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002323 * Obtains a list of canned, pre-configured message responses to present to the user as
Tyler Gunn434fc2c2020-10-06 14:23:54 -07002324 * ways of rejecting an incoming {@code Call} using via a text message.
2325 * <p>
2326 * <em>Note:</em> Since canned responses may be loaded from the file system, they are not
2327 * guaranteed to be present when this {@link Call} is first added to the {@link InCallService}
2328 * via {@link InCallService#onCallAdded(Call)}. The callback
2329 * {@link Call.Callback#onCannedTextResponsesLoaded(Call, List)} will be called when/if canned
2330 * responses for the call become available.
Ihab Awade63fadb2014-07-09 21:52:04 -07002331 *
2332 * @see #reject(boolean, String)
2333 *
2334 * @return A list of canned text message responses.
2335 */
2336 public List<String> getCannedTextResponses() {
2337 return mCannedTextResponses;
2338 }
2339
2340 /**
2341 * Obtains an object that can be used to display video from this {@code Call}.
2342 *
Andrew Lee50aca232014-07-22 16:41:54 -07002343 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002344 */
Andrew Lee50aca232014-07-22 16:41:54 -07002345 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002346 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07002347 }
2348
2349 /**
2350 * Obtains an object containing call details.
2351 *
2352 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
2353 * result may be {@code null}.
2354 */
2355 public Details getDetails() {
2356 return mDetails;
2357 }
2358
2359 /**
Hall Liu95d55872017-01-25 17:12:49 -08002360 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
2361 * receive RTT text data, as well as to change the RTT mode.
2362 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
2363 */
2364 public @Nullable RttCall getRttCall() {
2365 return mRttCall;
2366 }
2367
2368 /**
2369 * Returns whether this call has an active RTT connection.
2370 * @return true if there is a connection, false otherwise.
2371 */
2372 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08002373 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08002374 }
2375
2376 /**
Andrew Leeda80c872015-04-15 14:09:50 -07002377 * Registers a callback to this {@code Call}.
2378 *
2379 * @param callback A {@code Callback}.
2380 */
2381 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07002382 registerCallback(callback, new Handler());
2383 }
2384
2385 /**
2386 * Registers a callback to this {@code Call}.
2387 *
2388 * @param callback A {@code Callback}.
2389 * @param handler A handler which command and status changes will be delivered to.
2390 */
2391 public void registerCallback(Callback callback, Handler handler) {
2392 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07002393 // Don't allow new callback registration if the call is already being destroyed.
2394 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002395 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
2396 }
Andrew Leeda80c872015-04-15 14:09:50 -07002397 }
2398
2399 /**
2400 * Unregisters a callback from this {@code Call}.
2401 *
2402 * @param callback A {@code Callback}.
2403 */
2404 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002405 // Don't allow callback deregistration if the call is already being destroyed.
2406 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002407 for (CallbackRecord<Callback> record : mCallbackRecords) {
2408 if (record.getCallback() == callback) {
2409 mCallbackRecords.remove(record);
2410 break;
2411 }
2412 }
Andrew Leeda80c872015-04-15 14:09:50 -07002413 }
2414 }
2415
Santos Cordon3c20d632016-02-25 16:12:35 -08002416 @Override
2417 public String toString() {
2418 return new StringBuilder().
2419 append("Call [id: ").
2420 append(mTelecomCallId).
2421 append(", state: ").
2422 append(stateToString(mState)).
2423 append(", details: ").
2424 append(mDetails).
2425 append("]").toString();
2426 }
2427
2428 /**
2429 * @param state An integer value of a {@code STATE_*} constant.
2430 * @return A string representation of the value.
2431 */
2432 private static String stateToString(int state) {
2433 switch (state) {
2434 case STATE_NEW:
2435 return "NEW";
2436 case STATE_RINGING:
2437 return "RINGING";
2438 case STATE_DIALING:
2439 return "DIALING";
2440 case STATE_ACTIVE:
2441 return "ACTIVE";
2442 case STATE_HOLDING:
2443 return "HOLDING";
2444 case STATE_DISCONNECTED:
2445 return "DISCONNECTED";
2446 case STATE_CONNECTING:
2447 return "CONNECTING";
2448 case STATE_DISCONNECTING:
2449 return "DISCONNECTING";
2450 case STATE_SELECT_PHONE_ACCOUNT:
2451 return "SELECT_PHONE_ACCOUNT";
Hall Liu4e35b642019-10-14 17:50:45 -07002452 case STATE_SIMULATED_RINGING:
2453 return "SIMULATED_RINGING";
2454 case STATE_AUDIO_PROCESSING:
2455 return "AUDIO_PROCESSING";
Santos Cordon3c20d632016-02-25 16:12:35 -08002456 default:
2457 Log.w(Call.class, "Unknown state %d", state);
2458 return "UNKNOWN";
2459 }
2460 }
2461
Andrew Leeda80c872015-04-15 14:09:50 -07002462 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002463 * Adds a listener to this {@code Call}.
2464 *
2465 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002466 * @deprecated Use {@link #registerCallback} instead.
2467 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002468 */
Andrew Leeda80c872015-04-15 14:09:50 -07002469 @Deprecated
2470 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002471 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002472 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002473 }
2474
2475 /**
2476 * Removes a listener from this {@code Call}.
2477 *
2478 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002479 * @deprecated Use {@link #unregisterCallback} instead.
2480 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002481 */
Andrew Leeda80c872015-04-15 14:09:50 -07002482 @Deprecated
2483 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002484 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002485 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002486 }
2487
2488 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002489 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2490 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002491 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002492 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002493 mInCallAdapter = inCallAdapter;
2494 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002495 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002496 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002497 }
2498
2499 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002500 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002501 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002502 mPhone = phone;
2503 mTelecomCallId = telecomCallId;
2504 mInCallAdapter = inCallAdapter;
2505 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002506 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002507 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002508 }
2509
2510 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002511 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002512 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002513 }
2514
2515 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002516 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002517
Ihab Awade63fadb2014-07-09 21:52:04 -07002518 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002519 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002520 boolean detailsChanged = !Objects.equals(mDetails, details);
2521 if (detailsChanged) {
2522 mDetails = details;
2523 }
2524
2525 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002526 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2527 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2528 mCannedTextResponses =
2529 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002530 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002531 }
2532
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002533 IVideoProvider previousVideoProvider = mVideoCallImpl == null ? null :
2534 mVideoCallImpl.getVideoProvider();
2535 IVideoProvider newVideoProvider = parcelableCall.getVideoProvider();
2536
2537 // parcelableCall.isVideoCallProviderChanged is only true when we have a video provider
2538 // specified; so we should check if the actual IVideoProvider changes as well.
2539 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged()
2540 && !Objects.equals(previousVideoProvider, newVideoProvider);
Andrew Lee50aca232014-07-22 16:41:54 -07002541 if (videoCallChanged) {
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002542 if (mVideoCallImpl != null) {
2543 mVideoCallImpl.destroy();
2544 }
2545 mVideoCallImpl = parcelableCall.isVideoCallProviderChanged() ?
2546 parcelableCall.getVideoCallImpl(mCallingPackage, mTargetSdkVersion) : null;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002547 }
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002548
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002549 if (mVideoCallImpl != null) {
2550 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002551 }
2552
Santos Cordone3c507b2015-04-23 14:44:19 -07002553 int state = parcelableCall.getState();
Hall Liu31de23d2019-10-11 15:38:29 -07002554 if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2555 state = Call.STATE_RINGING;
2556 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002557 boolean stateChanged = mState != state;
2558 if (stateChanged) {
2559 mState = state;
2560 }
2561
Santos Cordon823fd3c2014-08-07 18:35:18 -07002562 String parentId = parcelableCall.getParentCallId();
2563 boolean parentChanged = !Objects.equals(mParentId, parentId);
2564 if (parentChanged) {
2565 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002566 }
2567
Santos Cordon823fd3c2014-08-07 18:35:18 -07002568 List<String> childCallIds = parcelableCall.getChildCallIds();
2569 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2570 if (childrenChanged) {
2571 mChildrenIds.clear();
2572 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2573 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002574 }
2575
Hall Liuef98bf82020-01-09 15:22:44 -08002576 String activeChildCallId = parcelableCall.getActiveChildCallId();
2577 boolean activeChildChanged = !Objects.equals(activeChildCallId,
2578 mActiveGenericConferenceChild);
2579 if (activeChildChanged) {
2580 mActiveGenericConferenceChild = activeChildCallId;
2581 }
2582
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002583 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2584 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2585 for (String otherId : conferenceableCallIds) {
2586 if (callIdMap.containsKey(otherId)) {
2587 conferenceableCalls.add(callIdMap.get(otherId));
2588 }
2589 }
2590
2591 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2592 mConferenceableCalls.clear();
2593 mConferenceableCalls.addAll(conferenceableCalls);
2594 fireConferenceableCallsChanged();
2595 }
2596
Hall Liu95d55872017-01-25 17:12:49 -08002597 boolean isRttChanged = false;
2598 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002599 if (parcelableCall.getIsRttCallChanged()
2600 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002601 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2602 InputStreamReader receiveStream = new InputStreamReader(
2603 new ParcelFileDescriptor.AutoCloseInputStream(
2604 parcelableRttCall.getReceiveStream()),
2605 StandardCharsets.UTF_8);
2606 OutputStreamWriter transmitStream = new OutputStreamWriter(
2607 new ParcelFileDescriptor.AutoCloseOutputStream(
2608 parcelableRttCall.getTransmitStream()),
2609 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002610 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002611 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2612 if (mRttCall == null) {
2613 isRttChanged = true;
2614 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2615 rttModeChanged = true;
2616 }
2617 mRttCall = newRttCall;
2618 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2619 && parcelableCall.getIsRttCallChanged()) {
2620 isRttChanged = true;
Tyler Gunn4cd42482021-04-30 16:23:15 -07002621 mRttCall.close();
Hall Liu95d55872017-01-25 17:12:49 -08002622 mRttCall = null;
2623 }
2624
Ihab Awade63fadb2014-07-09 21:52:04 -07002625 // Now we fire updates, ensuring that any client who listens to any of these notifications
2626 // gets the most up-to-date state.
2627
2628 if (stateChanged) {
2629 fireStateChanged(mState);
2630 }
2631 if (detailsChanged) {
2632 fireDetailsChanged(mDetails);
2633 }
2634 if (cannedTextResponsesChanged) {
2635 fireCannedTextResponsesLoaded(mCannedTextResponses);
2636 }
Andrew Lee50aca232014-07-22 16:41:54 -07002637 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002638 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002639 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002640 if (parentChanged) {
2641 fireParentChanged(getParent());
2642 }
Hall Liuef98bf82020-01-09 15:22:44 -08002643 if (childrenChanged || activeChildChanged) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002644 fireChildrenChanged(getChildren());
2645 }
Hall Liu95d55872017-01-25 17:12:49 -08002646 if (isRttChanged) {
2647 fireOnIsRttChanged(mRttCall != null, mRttCall);
2648 }
2649 if (rttModeChanged) {
2650 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2651 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002652
2653 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2654 // remove ourselves from the Phone. Note that we do this after completing all state updates
2655 // so a client can cleanly transition all their UI to the state appropriate for a
2656 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2657 if (mState == STATE_DISCONNECTED) {
2658 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002659 }
2660 }
2661
2662 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002663 final void internalSetPostDialWait(String remaining) {
2664 mRemainingPostDialSequence = remaining;
2665 firePostDialWait(mRemainingPostDialSequence);
2666 }
2667
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002668 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002669 final void internalSetDisconnected() {
2670 if (mState != Call.STATE_DISCONNECTED) {
2671 mState = Call.STATE_DISCONNECTED;
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002672 if (mDetails != null) {
2673 mDetails = new Details(mState,
2674 mDetails.getTelecomCallId(),
2675 mDetails.getHandle(),
2676 mDetails.getHandlePresentation(),
2677 mDetails.getCallerDisplayName(),
2678 mDetails.getCallerDisplayNamePresentation(),
2679 mDetails.getAccountHandle(),
2680 mDetails.getCallCapabilities(),
2681 mDetails.getCallProperties(),
2682 mDetails.getDisconnectCause(),
2683 mDetails.getConnectTimeMillis(),
2684 mDetails.getGatewayInfo(),
2685 mDetails.getVideoState(),
2686 mDetails.getStatusHints(),
2687 mDetails.getExtras(),
2688 mDetails.getIntentExtras(),
2689 mDetails.getCreationTimeMillis(),
2690 mDetails.getContactDisplayName(),
2691 mDetails.getCallDirection(),
Edgar Arriagae5bec822022-10-14 14:25:43 -07002692 mDetails.getCallerNumberVerificationStatus(),
2693 mDetails.getContactPhotoUri()
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002694 );
2695 fireDetailsChanged(mDetails);
2696 }
Santos Cordonf30d7e92014-08-26 09:54:33 -07002697 fireStateChanged(mState);
2698 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002699 }
2700 }
2701
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002702 /** {@hide} */
2703 final void internalOnConnectionEvent(String event, Bundle extras) {
2704 fireOnConnectionEvent(event, extras);
2705 }
2706
Hall Liu95d55872017-01-25 17:12:49 -08002707 /** {@hide} */
2708 final void internalOnRttUpgradeRequest(final int requestId) {
2709 for (CallbackRecord<Callback> record : mCallbackRecords) {
2710 final Call call = this;
2711 final Callback callback = record.getCallback();
2712 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2713 }
2714 }
2715
Hall Liu57006aa2017-02-06 10:49:48 -08002716 /** @hide */
2717 final void internalOnRttInitiationFailure(int reason) {
2718 for (CallbackRecord<Callback> record : mCallbackRecords) {
2719 final Call call = this;
2720 final Callback callback = record.getCallback();
2721 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2722 }
2723 }
2724
Sanket Padawe85291f62017-12-01 13:59:27 -08002725 /** {@hide} */
2726 final void internalOnHandoverFailed(int error) {
2727 for (CallbackRecord<Callback> record : mCallbackRecords) {
2728 final Call call = this;
2729 final Callback callback = record.getCallback();
2730 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2731 }
2732 }
2733
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002734 /** {@hide} */
2735 final void internalOnHandoverComplete() {
2736 for (CallbackRecord<Callback> record : mCallbackRecords) {
2737 final Call call = this;
2738 final Callback callback = record.getCallback();
2739 record.getHandler().post(() -> callback.onHandoverComplete(call));
2740 }
2741 }
2742
Andrew Lee011728f2015-04-23 15:47:06 -07002743 private void fireStateChanged(final int newState) {
2744 for (CallbackRecord<Callback> record : mCallbackRecords) {
2745 final Call call = this;
2746 final Callback callback = record.getCallback();
2747 record.getHandler().post(new Runnable() {
2748 @Override
2749 public void run() {
2750 callback.onStateChanged(call, newState);
2751 }
2752 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002753 }
2754 }
2755
Andrew Lee011728f2015-04-23 15:47:06 -07002756 private void fireParentChanged(final Call newParent) {
2757 for (CallbackRecord<Callback> record : mCallbackRecords) {
2758 final Call call = this;
2759 final Callback callback = record.getCallback();
2760 record.getHandler().post(new Runnable() {
2761 @Override
2762 public void run() {
2763 callback.onParentChanged(call, newParent);
2764 }
2765 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002766 }
2767 }
2768
Andrew Lee011728f2015-04-23 15:47:06 -07002769 private void fireChildrenChanged(final List<Call> children) {
2770 for (CallbackRecord<Callback> record : mCallbackRecords) {
2771 final Call call = this;
2772 final Callback callback = record.getCallback();
2773 record.getHandler().post(new Runnable() {
2774 @Override
2775 public void run() {
2776 callback.onChildrenChanged(call, children);
2777 }
2778 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002779 }
2780 }
2781
Andrew Lee011728f2015-04-23 15:47:06 -07002782 private void fireDetailsChanged(final Details details) {
2783 for (CallbackRecord<Callback> record : mCallbackRecords) {
2784 final Call call = this;
2785 final Callback callback = record.getCallback();
2786 record.getHandler().post(new Runnable() {
2787 @Override
2788 public void run() {
2789 callback.onDetailsChanged(call, details);
2790 }
2791 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002792 }
2793 }
2794
Andrew Lee011728f2015-04-23 15:47:06 -07002795 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2796 for (CallbackRecord<Callback> record : mCallbackRecords) {
2797 final Call call = this;
2798 final Callback callback = record.getCallback();
2799 record.getHandler().post(new Runnable() {
2800 @Override
2801 public void run() {
2802 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2803 }
2804 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002805 }
2806 }
2807
Andrew Lee011728f2015-04-23 15:47:06 -07002808 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2809 for (CallbackRecord<Callback> record : mCallbackRecords) {
2810 final Call call = this;
2811 final Callback callback = record.getCallback();
2812 record.getHandler().post(new Runnable() {
2813 @Override
2814 public void run() {
2815 callback.onVideoCallChanged(call, videoCall);
2816 }
2817 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002818 }
2819 }
2820
Andrew Lee011728f2015-04-23 15:47:06 -07002821 private void firePostDialWait(final String remainingPostDialSequence) {
2822 for (CallbackRecord<Callback> record : mCallbackRecords) {
2823 final Call call = this;
2824 final Callback callback = record.getCallback();
2825 record.getHandler().post(new Runnable() {
2826 @Override
2827 public void run() {
2828 callback.onPostDialWait(call, remainingPostDialSequence);
2829 }
2830 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002831 }
2832 }
2833
2834 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002835 /**
2836 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2837 * onCallRemoved callback, we remove this call from the Phone's record
2838 * only once all of the registered onCallDestroyed callbacks are executed.
2839 * All the callbacks get removed from our records as a part of this operation
2840 * since onCallDestroyed is the final callback.
2841 */
2842 final Call call = this;
2843 if (mCallbackRecords.isEmpty()) {
2844 // No callbacks registered, remove the call from Phone's record.
2845 mPhone.internalRemoveCall(call);
2846 }
2847 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002848 final Callback callback = record.getCallback();
2849 record.getHandler().post(new Runnable() {
2850 @Override
2851 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002852 boolean isFinalRemoval = false;
2853 RuntimeException toThrow = null;
2854 try {
2855 callback.onCallDestroyed(call);
2856 } catch (RuntimeException e) {
2857 toThrow = e;
2858 }
2859 synchronized(Call.this) {
2860 mCallbackRecords.remove(record);
2861 if (mCallbackRecords.isEmpty()) {
2862 isFinalRemoval = true;
2863 }
2864 }
2865 if (isFinalRemoval) {
2866 mPhone.internalRemoveCall(call);
2867 }
2868 if (toThrow != null) {
2869 throw toThrow;
2870 }
Andrew Lee011728f2015-04-23 15:47:06 -07002871 }
2872 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002873 }
2874 }
2875
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002876 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002877 for (CallbackRecord<Callback> record : mCallbackRecords) {
2878 final Call call = this;
2879 final Callback callback = record.getCallback();
2880 record.getHandler().post(new Runnable() {
2881 @Override
2882 public void run() {
2883 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2884 }
2885 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002886 }
2887 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002888
2889 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002890 * Notifies listeners of an incoming connection event.
2891 * <p>
2892 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2893 *
2894 * @param event
2895 * @param extras
2896 */
2897 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2898 for (CallbackRecord<Callback> record : mCallbackRecords) {
2899 final Call call = this;
2900 final Callback callback = record.getCallback();
2901 record.getHandler().post(new Runnable() {
2902 @Override
2903 public void run() {
2904 callback.onConnectionEvent(call, event, extras);
2905 }
2906 });
2907 }
2908 }
2909
2910 /**
Hall Liu95d55872017-01-25 17:12:49 -08002911 * Notifies listeners of an RTT on/off change
2912 *
2913 * @param enabled True if RTT is now enabled, false otherwise
2914 */
2915 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2916 for (CallbackRecord<Callback> record : mCallbackRecords) {
2917 final Call call = this;
2918 final Callback callback = record.getCallback();
2919 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2920 }
2921 }
2922
2923 /**
2924 * Notifies listeners of a RTT mode change
2925 *
2926 * @param mode The new RTT mode
2927 */
2928 private void fireOnRttModeChanged(final int mode) {
2929 for (CallbackRecord<Callback> record : mCallbackRecords) {
2930 final Call call = this;
2931 final Callback callback = record.getCallback();
2932 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2933 }
2934 }
2935
2936 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002937 * Determines if two bundles are equal.
2938 *
2939 * @param bundle The original bundle.
2940 * @param newBundle The bundle to compare with.
2941 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2942 */
2943 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2944 if (bundle == null || newBundle == null) {
2945 return bundle == newBundle;
2946 }
2947
2948 if (bundle.size() != newBundle.size()) {
2949 return false;
2950 }
2951
2952 for(String key : bundle.keySet()) {
2953 if (key != null) {
2954 final Object value = bundle.get(key);
2955 final Object newValue = newBundle.get(key);
Grace Jia17005bd2022-05-12 12:49:02 -07002956 if (!newBundle.containsKey(key)) {
2957 return false;
2958 }
2959 if (value instanceof Bundle && newValue instanceof Bundle) {
2960 if (!areBundlesEqual((Bundle) value, (Bundle) newValue)) {
2961 return false;
2962 }
2963 }
2964 if (value instanceof byte[] && newValue instanceof byte[]) {
2965 if (!Arrays.equals((byte[]) value, (byte[]) newValue)) {
2966 return false;
2967 }
2968 } else if (!Objects.equals(value, newValue)) {
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002969 return false;
2970 }
2971 }
2972 }
2973 return true;
2974 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002975}