blob: 5cef2cb0a16130c9796fee821fe28d4565656893 [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 /**
363 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
364 * call because they have declined to answer it. This typically means that they are unable
365 * to answer the call at this time and would prefer it be sent to voicemail.
366 */
367 public static final int REJECT_REASON_DECLINED = 1;
368
369 /**
370 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
371 * call because it is an unwanted call. This allows the user to indicate that they are
372 * rejecting a call because it is likely a nuisance call.
373 */
374 public static final int REJECT_REASON_UNWANTED = 2;
375
376 /**
377 * @hide
378 */
379 @IntDef(prefix = { "REJECT_REASON_" },
380 value = {REJECT_REASON_DECLINED, REJECT_REASON_UNWANTED})
381 @Retention(RetentionPolicy.SOURCE)
382 public @interface RejectReason {};
383
Ihab Awade63fadb2014-07-09 21:52:04 -0700384 public static class Details {
Tyler Gunn94f8f112018-12-17 09:56:11 -0800385 /** @hide */
386 @Retention(RetentionPolicy.SOURCE)
387 @IntDef(
388 prefix = { "DIRECTION_" },
389 value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
390 public @interface CallDirection {}
391
392 /**
393 * Indicates that the call is neither and incoming nor an outgoing call. This can be the
394 * case for calls reported directly by a {@link ConnectionService} in special cases such as
395 * call handovers.
396 */
397 public static final int DIRECTION_UNKNOWN = -1;
398
399 /**
400 * Indicates that the call is an incoming call.
401 */
402 public static final int DIRECTION_INCOMING = 0;
403
404 /**
405 * Indicates that the call is an outgoing call.
406 */
407 public static final int DIRECTION_OUTGOING = 1;
408
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800409 /** Call can currently be put on hold or unheld. */
410 public static final int CAPABILITY_HOLD = 0x00000001;
411
412 /** Call supports the hold feature. */
413 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
414
415 /**
416 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
417 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
418 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
419 * capability allows a merge button to be shown while the conference call is in the foreground
420 * of the in-call UI.
421 * <p>
422 * This is only intended for use by a {@link Conference}.
423 */
424 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
425
426 /**
427 * Calls within a conference can be swapped between foreground and background.
428 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
429 * <p>
430 * This is only intended for use by a {@link Conference}.
431 */
432 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
433
434 /**
435 * @hide
436 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700437 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800438
439 /** Call supports responding via text option. */
440 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
441
442 /** Call can be muted. */
443 public static final int CAPABILITY_MUTE = 0x00000040;
444
445 /**
446 * Call supports conference call management. This capability only applies to {@link Conference}
447 * calls which can have {@link Connection}s as children.
448 */
449 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
450
451 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700452 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800453 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700454 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800455
456 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700457 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800458 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700459 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800460
461 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700462 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800463 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700464 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700465 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800466
467 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700468 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800469 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700470 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
471
472 /**
473 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700474 */
475 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
476
477 /**
478 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700479 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700480 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700481 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800482
483 /**
484 * Call is able to be separated from its parent {@code Conference}, if any.
485 */
486 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
487
488 /**
489 * Call is able to be individually disconnected when in a {@code Conference}.
490 */
491 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
492
493 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500494 * Speed up audio setup for MT call.
495 * @hide
496 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700497 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
498
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700499 /**
500 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700501 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800502 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
503 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
504 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700505 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800506 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700507 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
508
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700509 /**
510 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700511 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700512 */
513 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
514
Bryce Lee81901682015-08-28 16:38:02 -0700515 /**
516 * Call sends responses through connection.
517 * @hide
518 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800519 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
520
521 /**
522 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
523 * <p>
524 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
525 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
526 * downgraded from a video call back to a VideoState of
527 * {@link VideoProfile#STATE_AUDIO_ONLY}.
528 * <p>
529 * Intuitively, a call which can be downgraded to audio should also have local and remote
530 * video
531 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
532 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
533 */
534 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700535
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700536 /**
537 * When set for an external call, indicates that this {@code Call} can be pulled from a
538 * remote device to the current device.
539 * <p>
540 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
541 * <p>
542 * An {@link InCallService} will only see calls with this capability if it has the
543 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
544 * in its manifest.
545 * <p>
546 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700547 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700548 */
549 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
550
Pooja Jaind34698d2017-12-28 14:15:31 +0530551 /** Call supports the deflect feature. */
552 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
553
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800554 /**
555 * Call supports adding participants to the call via
Grace Jia8587ee52020-07-10 15:42:32 -0700556 * {@link #addConferenceParticipants(List)}. Once participants are added, the call becomes
557 * an adhoc conference call ({@link #PROPERTY_IS_ADHOC_CONFERENCE}).
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800558 */
Ravi Paluri404babb2020-01-23 19:02:44 +0530559 public static final int CAPABILITY_ADD_PARTICIPANT = 0x02000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530560
561 /**
562 * When set for a call, indicates that this {@code Call} can be transferred to another
563 * number.
Tyler Gunn460360d2020-07-29 10:21:45 -0700564 * Call supports the confirmed and unconfirmed call transfer feature.
Ravi Palurif4b38e72020-02-05 12:35:41 +0530565 *
566 * @hide
567 */
568 public static final int CAPABILITY_TRANSFER = 0x04000000;
569
570 /**
571 * When set for a call, indicates that this {@code Call} can be transferred to another
572 * ongoing call.
573 * Call supports the consultative call transfer feature.
574 *
575 * @hide
576 */
577 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x08000000;
578
Alvin Dey2f37d772018-05-18 23:16:10 +0530579 /**
580 * Indicates whether the remote party supports RTT or not to the UI.
581 */
582
583 public static final int CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT = 0x10000000;
584
Tyler Gunnd11a3152015-03-18 13:09:14 -0700585 //******************************************************************************************
Alvin Dey2f37d772018-05-18 23:16:10 +0530586 // Next CAPABILITY value: 0x20000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700587 //******************************************************************************************
588
589 /**
590 * Whether the call is currently a conference.
591 */
592 public static final int PROPERTY_CONFERENCE = 0x00000001;
593
594 /**
595 * Whether the call is a generic conference, where we do not know the precise state of
596 * participants in the conference (eg. on CDMA).
597 */
598 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
599
600 /**
601 * Whether the call is made while the device is in emergency callback mode.
602 */
603 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
604
605 /**
606 * Connection is using WIFI.
607 */
608 public static final int PROPERTY_WIFI = 0x00000008;
609
610 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700611 * When set, the UI should indicate to the user that a call is using high definition
612 * audio.
613 * <p>
614 * The underlying {@link ConnectionService} is responsible for reporting this
615 * property. It is important to note that this property is not intended to report the
616 * actual audio codec being used for a Call, but whether the call should be indicated
617 * to the user as high definition.
618 * <p>
619 * The Android Telephony stack reports this property for calls based on a number
620 * of factors, including which audio codec is used and whether a call is using an HD
621 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
622 * and in these cases this property will not be set for a call even if the underlying audio
623 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700624 */
625 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
626
Tony Maka68dcce2015-12-17 09:31:18 +0000627 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100628 * Whether the call is associated with the work profile.
629 */
630 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
631
632 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700633 * When set, indicates that this {@code Call} does not actually exist locally for the
634 * {@link ConnectionService}.
635 * <p>
636 * Consider, for example, a scenario where a user has two phones with the same phone number.
637 * When a user places a call on one device, the telephony stack can represent that call on
638 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700639 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700640 * <p>
641 * An {@link InCallService} will only see calls with this property if it has the
642 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
643 * in its manifest.
644 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700645 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700646 */
647 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
648
Brad Ebinger15847072016-05-18 11:08:36 -0700649 /**
650 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
651 */
652 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
653
Tyler Gunn24e18332017-02-10 09:42:49 -0800654 /**
655 * Indicates that the call is from a self-managed {@link ConnectionService}.
656 * <p>
657 * See also {@link Connection#PROPERTY_SELF_MANAGED}
658 */
659 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
660
Eric Erfanianec881872017-12-06 16:27:53 -0800661 /**
662 * Indicates the call used Assisted Dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700663 *
664 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanianec881872017-12-06 16:27:53 -0800665 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800666 public static final int PROPERTY_ASSISTED_DIALING = 0x00000200;
Eric Erfanianec881872017-12-06 16:27:53 -0800667
Hall Liue9041242018-02-09 16:40:03 -0800668 /**
669 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
670 * {@link RttCall} object that is used to send and receive text.
671 */
672 public static final int PROPERTY_RTT = 0x00000400;
673
Tyler Gunn5bd90852018-09-21 09:37:07 -0700674 /**
675 * Indicates that the call has been identified as the network as an emergency call. This
676 * property may be set for both incoming and outgoing calls which the network identifies as
677 * emergency calls.
678 */
679 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
680
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700681 /**
682 * Indicates that the call is using VoIP audio mode.
683 * <p>
684 * When this property is set, the {@link android.media.AudioManager} audio mode for this
685 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
686 * property is not set, the audio mode for this call will be
687 * {@link android.media.AudioManager#MODE_IN_CALL}.
688 * <p>
689 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
690 * <p>
691 * You can use this property to determine whether an un-answered incoming call or a held
692 * call will use VoIP audio mode (if the call does not currently have focus, the system
693 * audio mode may not reflect the mode the call will use).
694 */
695 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
696
Ravi Paluri80aa2142019-12-02 11:57:37 +0530697 /**
698 * Indicates that the call is an adhoc conference call. This property can be set for both
Grace Jia8587ee52020-07-10 15:42:32 -0700699 * incoming and outgoing calls. An adhoc conference call is formed using
700 * {@link #addConferenceParticipants(List)},
701 * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}, or
702 * {@link TelecomManager#startConference(List, Bundle)}, rather than by merging existing
703 * call using {@link #conference(Call)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530704 */
705 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 0x00002000;
706
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800707 /**
Sooraj Sasindranfa1e57a2021-03-22 13:44:14 -0700708 * Connection is using cross sim technology.
709 * <p>
710 * Indicates that the {@link Connection} is using a cross sim technology which would
711 * register IMS over internet APN of default data subscription.
712 * <p>
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800713 */
714 public static final int PROPERTY_CROSS_SIM = 0x00004000;
715
Andrew Lee2378ea72015-04-29 14:38:11 -0700716 //******************************************************************************************
Ravi Paluri80aa2142019-12-02 11:57:37 +0530717 // Next PROPERTY value: 0x00004000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700718 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800719
Tyler Gunn1e406ca2021-03-18 16:47:14 -0700720 private final @CallState int mState;
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800721 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700722 private final Uri mHandle;
723 private final int mHandlePresentation;
724 private final String mCallerDisplayName;
725 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700726 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700727 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700728 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800729 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700730 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700731 private final long mConnectTimeMillis;
732 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700733 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700734 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700735 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700736 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700737 private final long mCreationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -0800738 private final String mContactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800739 private final @CallDirection int mCallDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700740 private final @Connection.VerificationStatus int mCallerNumberVerificationStatus;
Ihab Awade63fadb2014-07-09 21:52:04 -0700741
742 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800743 * Whether the supplied capabilities supports the specified capability.
744 *
745 * @param capabilities A bit field of capabilities.
746 * @param capability The capability to check capabilities for.
747 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800748 */
749 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800750 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800751 }
752
753 /**
754 * Whether the capabilities of this {@code Details} supports the specified capability.
755 *
756 * @param capability The capability to check capabilities for.
757 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800758 */
759 public boolean can(int capability) {
760 return can(mCallCapabilities, capability);
761 }
762
763 /**
764 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
765 *
766 * @param capabilities A capability bit field.
767 * @return A human readable string representation.
768 */
769 public static String capabilitiesToString(int capabilities) {
770 StringBuilder builder = new StringBuilder();
771 builder.append("[Capabilities:");
772 if (can(capabilities, CAPABILITY_HOLD)) {
773 builder.append(" CAPABILITY_HOLD");
774 }
775 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
776 builder.append(" CAPABILITY_SUPPORT_HOLD");
777 }
778 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
779 builder.append(" CAPABILITY_MERGE_CONFERENCE");
780 }
781 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
782 builder.append(" CAPABILITY_SWAP_CONFERENCE");
783 }
784 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
785 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
786 }
787 if (can(capabilities, CAPABILITY_MUTE)) {
788 builder.append(" CAPABILITY_MUTE");
789 }
790 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
791 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
792 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700793 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
794 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
795 }
796 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
797 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
798 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700799 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
800 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800801 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700802 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
803 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
804 }
805 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
806 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
807 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800808 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
809 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
810 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700811 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
812 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800813 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500814 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700815 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500816 }
Rekha Kumar07366812015-03-24 16:42:31 -0700817 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
818 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
819 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700820 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
821 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
822 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700823 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
824 builder.append(" CAPABILITY_CAN_PULL_CALL");
825 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530826 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
827 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
828 }
Ravi Paluri404babb2020-01-23 19:02:44 +0530829 if (can(capabilities, CAPABILITY_ADD_PARTICIPANT)) {
830 builder.append(" CAPABILITY_ADD_PARTICIPANT");
831 }
Ravi Palurif4b38e72020-02-05 12:35:41 +0530832 if (can(capabilities, CAPABILITY_TRANSFER)) {
833 builder.append(" CAPABILITY_TRANSFER");
834 }
835 if (can(capabilities, CAPABILITY_TRANSFER_CONSULTATIVE)) {
836 builder.append(" CAPABILITY_TRANSFER_CONSULTATIVE");
837 }
Alvin Dey2f37d772018-05-18 23:16:10 +0530838 if (can(capabilities, CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT)) {
839 builder.append(" CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT");
840 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800841 builder.append("]");
842 return builder.toString();
843 }
844
845 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700846 * Whether the supplied properties includes the specified property.
847 *
848 * @param properties A bit field of properties.
849 * @param property The property to check properties for.
850 * @return Whether the specified property is supported.
851 */
852 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800853 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700854 }
855
856 /**
857 * Whether the properties of this {@code Details} includes the specified property.
858 *
859 * @param property The property to check properties for.
860 * @return Whether the specified property is supported.
861 */
862 public boolean hasProperty(int property) {
863 return hasProperty(mCallProperties, property);
864 }
865
866 /**
867 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
868 *
869 * @param properties A property bit field.
870 * @return A human readable string representation.
871 */
872 public static String propertiesToString(int properties) {
873 StringBuilder builder = new StringBuilder();
874 builder.append("[Properties:");
875 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
876 builder.append(" PROPERTY_CONFERENCE");
877 }
878 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
879 builder.append(" PROPERTY_GENERIC_CONFERENCE");
880 }
881 if (hasProperty(properties, PROPERTY_WIFI)) {
882 builder.append(" PROPERTY_WIFI");
883 }
884 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
885 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
886 }
887 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700888 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700889 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700890 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
891 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
892 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700893 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700894 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
895 }
Tyler Gunnc9503d62020-01-27 10:30:51 -0800896 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800897 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
898 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700899 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
900 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
901 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700902 if (hasProperty(properties, PROPERTY_RTT)) {
903 builder.append(" PROPERTY_RTT");
904 }
905 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
906 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
907 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530908 if (hasProperty(properties, PROPERTY_IS_ADHOC_CONFERENCE)) {
909 builder.append(" PROPERTY_IS_ADHOC_CONFERENCE");
910 }
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800911 if (hasProperty(properties, PROPERTY_CROSS_SIM)) {
912 builder.append(" PROPERTY_CROSS_SIM");
913 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700914 builder.append("]");
915 return builder.toString();
916 }
917
Tyler Gunn1e406ca2021-03-18 16:47:14 -0700918 /**
919 * @return the state of the {@link Call} represented by this {@link Call.Details}.
920 */
921 public final @CallState int getState() {
922 return mState;
923 }
924
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800925 /** {@hide} */
Hall Liu31de23d2019-10-11 15:38:29 -0700926 @TestApi
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800927 public String getTelecomCallId() {
928 return mTelecomCallId;
929 }
930
Andrew Lee2378ea72015-04-29 14:38:11 -0700931 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700932 * @return The handle (e.g., phone number) to which the {@code Call} is currently
933 * connected.
934 */
935 public Uri getHandle() {
936 return mHandle;
937 }
938
939 /**
940 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700941 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700942 */
943 public int getHandlePresentation() {
944 return mHandlePresentation;
945 }
946
947 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800948 * The display name for the caller.
949 * <p>
950 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800951 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700952 * @return The display name for the caller.
953 */
954 public String getCallerDisplayName() {
955 return mCallerDisplayName;
956 }
957
958 /**
959 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700960 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700961 */
962 public int getCallerDisplayNamePresentation() {
963 return mCallerDisplayNamePresentation;
964 }
965
966 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700967 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
968 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700969 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700970 public PhoneAccountHandle getAccountHandle() {
971 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700972 }
973
974 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800975 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
976 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700977 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700978 public int getCallCapabilities() {
979 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700980 }
981
982 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700983 * @return A bitmask of the properties of the {@code Call}, as defined by the various
984 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700985 */
986 public int getCallProperties() {
987 return mCallProperties;
988 }
989
990 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800991 * @return a bitmask of the audio routes available for the call.
992 *
993 * @hide
994 */
995 public int getSupportedAudioRoutes() {
996 return mSupportedAudioRoutes;
997 }
998
999 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001000 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -07001001 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001002 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001003 public DisconnectCause getDisconnectCause() {
1004 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -07001005 }
1006
1007 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001008 * Returns the time the {@link Call} connected (i.e. became active). This information is
1009 * updated periodically, but user interfaces should not rely on this to display the "call
1010 * time clock". For the time when the call was first added to Telecom, see
1011 * {@link #getCreationTimeMillis()}.
1012 *
1013 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -07001014 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -07001015 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -07001016 return mConnectTimeMillis;
1017 }
1018
1019 /**
1020 * @return Information about any calling gateway the {@code Call} may be using.
1021 */
1022 public GatewayInfo getGatewayInfo() {
1023 return mGatewayInfo;
1024 }
1025
Andrew Lee7a341382014-07-15 17:05:08 -07001026 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -07001027 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -07001028 */
1029 public int getVideoState() {
1030 return mVideoState;
1031 }
1032
Ihab Awad5d0410f2014-07-30 10:07:40 -07001033 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001034 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -07001035 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -07001036 */
1037 public StatusHints getStatusHints() {
1038 return mStatusHints;
1039 }
1040
Nancy Chen10798dc2014-08-08 14:00:25 -07001041 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001042 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -07001043 */
1044 public Bundle getExtras() {
1045 return mExtras;
1046 }
1047
Santos Cordon6b7f9552015-05-27 17:21:45 -07001048 /**
1049 * @return The extras used with the original intent to place this call.
1050 */
1051 public Bundle getIntentExtras() {
1052 return mIntentExtras;
1053 }
1054
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001055 /**
1056 * Returns the time when the call was first created and added to Telecom. This is the same
1057 * time that is logged as the start time in the Call Log (see
1058 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
1059 * (became active), see {@link #getConnectTimeMillis()}.
1060 *
1061 * @return The creation time of the call, in millis since the epoch.
1062 */
1063 public long getCreationTimeMillis() {
1064 return mCreationTimeMillis;
1065 }
1066
Tyler Gunnd081f042018-12-04 12:56:45 -08001067 /**
Hall Liuef98bf82020-01-09 15:22:44 -08001068 * Returns the name of the caller on the remote end, as derived from a
1069 * {@link android.provider.ContactsContract} lookup of the call's handle.
1070 * @return The name of the caller, or {@code null} if the lookup is not yet complete, if
1071 * there's no contacts entry for the caller, or if the {@link InCallService} does
1072 * not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
1073 */
1074 public @Nullable String getContactDisplayName() {
1075 return mContactDisplayName;
1076 }
1077
1078 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -08001079 * Indicates whether the call is an incoming or outgoing call.
1080 * @return The call's direction.
1081 */
1082 public @CallDirection int getCallDirection() {
1083 return mCallDirection;
1084 }
1085
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001086 /**
1087 * Gets the verification status for the phone number of an incoming call as identified in
1088 * ATIS-1000082.
Tyler Gunn9c642492020-10-08 13:37:03 -07001089 * <p>
1090 * For incoming calls, the number verification status indicates whether the device was
1091 * able to verify the authenticity of the calling number using the STIR process outlined
1092 * in ATIS-1000082. {@link Connection#VERIFICATION_STATUS_NOT_VERIFIED} indicates that
1093 * the network was not able to use STIR to verify the caller's number (i.e. nothing is
1094 * known regarding the authenticity of the number.
1095 * {@link Connection#VERIFICATION_STATUS_PASSED} indicates that the network was able to
1096 * use STIR to verify the caller's number. This indicates that the network has a high
1097 * degree of confidence that the incoming call actually originated from the indicated
1098 * number. {@link Connection#VERIFICATION_STATUS_FAILED} indicates that the network's
1099 * STIR verification did not pass. This indicates that the incoming call may not
1100 * actually be from the indicated number. This could occur if, for example, the caller
1101 * is using an impersonated phone number.
1102 * <p>
1103 * A {@link CallScreeningService} can use this information to help determine if an
1104 * incoming call is potentially an unwanted call. A verification status of
1105 * {@link Connection#VERIFICATION_STATUS_FAILED} indicates that an incoming call may not
1106 * actually be from the number indicated on the call (i.e. impersonated number) and that it
1107 * should potentially be blocked. Likewise,
1108 * {@link Connection#VERIFICATION_STATUS_PASSED} can be used as a positive signal to
1109 * help clarify that the incoming call is originating from the indicated number and it
1110 * is less likely to be an undesirable call.
1111 * <p>
1112 * An {@link InCallService} can use this information to provide a visual indicator to the
1113 * user regarding the verification status of a call and to help identify calls from
1114 * potentially impersonated numbers.
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001115 * @return the verification status.
1116 */
1117 public @Connection.VerificationStatus int getCallerNumberVerificationStatus() {
1118 return mCallerNumberVerificationStatus;
1119 }
1120
Ihab Awade63fadb2014-07-09 21:52:04 -07001121 @Override
1122 public boolean equals(Object o) {
1123 if (o instanceof Details) {
1124 Details d = (Details) o;
1125 return
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001126 Objects.equals(mState, d.mState) &&
Ihab Awade63fadb2014-07-09 21:52:04 -07001127 Objects.equals(mHandle, d.mHandle) &&
1128 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
1129 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
1130 Objects.equals(mCallerDisplayNamePresentation,
1131 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -07001132 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -07001133 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -07001134 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001135 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -07001136 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -07001137 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -07001138 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -07001139 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001140 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001141 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -08001142 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Hall Liuef98bf82020-01-09 15:22:44 -08001143 Objects.equals(mContactDisplayName, d.mContactDisplayName) &&
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001144 Objects.equals(mCallDirection, d.mCallDirection) &&
1145 Objects.equals(mCallerNumberVerificationStatus,
1146 d.mCallerNumberVerificationStatus);
Ihab Awade63fadb2014-07-09 21:52:04 -07001147 }
1148 return false;
1149 }
1150
1151 @Override
1152 public int hashCode() {
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001153 return Objects.hash(mState,
1154 mHandle,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001155 mHandlePresentation,
1156 mCallerDisplayName,
1157 mCallerDisplayNamePresentation,
1158 mAccountHandle,
1159 mCallCapabilities,
1160 mCallProperties,
1161 mDisconnectCause,
1162 mConnectTimeMillis,
1163 mGatewayInfo,
1164 mVideoState,
1165 mStatusHints,
1166 mExtras,
1167 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001168 mCreationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001169 mContactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001170 mCallDirection,
1171 mCallerNumberVerificationStatus);
Ihab Awade63fadb2014-07-09 21:52:04 -07001172 }
1173
1174 /** {@hide} */
1175 public Details(
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001176 @CallState int state,
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001177 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -07001178 Uri handle,
1179 int handlePresentation,
1180 String callerDisplayName,
1181 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -07001182 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -07001183 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -07001184 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001185 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -07001186 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -07001187 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -07001188 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -07001189 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -07001190 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001191 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001192 long creationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001193 String contactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001194 int callDirection,
1195 int callerNumberVerificationStatus) {
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001196 mState = state;
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001197 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001198 mHandle = handle;
1199 mHandlePresentation = handlePresentation;
1200 mCallerDisplayName = callerDisplayName;
1201 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -07001202 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -07001203 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -07001204 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001205 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -07001206 mConnectTimeMillis = connectTimeMillis;
1207 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -07001208 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -07001209 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -07001210 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001211 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001212 mCreationTimeMillis = creationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -08001213 mContactDisplayName = contactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -08001214 mCallDirection = callDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001215 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
Ihab Awade63fadb2014-07-09 21:52:04 -07001216 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001217
1218 /** {@hide} */
1219 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
1220 return new Details(
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001221 parcelableCall.getState(),
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001222 parcelableCall.getId(),
1223 parcelableCall.getHandle(),
1224 parcelableCall.getHandlePresentation(),
1225 parcelableCall.getCallerDisplayName(),
1226 parcelableCall.getCallerDisplayNamePresentation(),
1227 parcelableCall.getAccountHandle(),
1228 parcelableCall.getCapabilities(),
1229 parcelableCall.getProperties(),
1230 parcelableCall.getDisconnectCause(),
1231 parcelableCall.getConnectTimeMillis(),
1232 parcelableCall.getGatewayInfo(),
1233 parcelableCall.getVideoState(),
1234 parcelableCall.getStatusHints(),
1235 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001236 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -08001237 parcelableCall.getCreationTimeMillis(),
Hall Liuef98bf82020-01-09 15:22:44 -08001238 parcelableCall.getContactDisplayName(),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001239 parcelableCall.getCallDirection(),
1240 parcelableCall.getCallerNumberVerificationStatus());
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001241 }
Santos Cordon3c20d632016-02-25 16:12:35 -08001242
1243 @Override
1244 public String toString() {
1245 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001246 sb.append("[id: ");
1247 sb.append(mTelecomCallId);
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001248 sb.append(", state: ");
1249 sb.append(Call.stateToString(mState));
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001250 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -08001251 sb.append(mAccountHandle);
1252 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001253 sb.append(Log.piiHandle(mHandle));
1254 sb.append(", hdlPres: ");
1255 sb.append(mHandlePresentation);
1256 sb.append(", videoState: ");
1257 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -08001258 sb.append(", caps: ");
1259 sb.append(capabilitiesToString(mCallCapabilities));
1260 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001261 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001262 sb.append("]");
1263 return sb.toString();
1264 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001265 }
1266
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001267 /**
1268 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1269 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1270 * implementation.
1271 * <p>
1272 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1273 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1274 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1275 * {@link Callback} implementation, if desired.
1276 * <p>
1277 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1278 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1279 * (typically in {@link InCallService#onCallRemoved(Call)}).
1280 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1281 * reach your implementation of {@link Callback}, so it is important to register your callback
1282 * as soon as your {@link InCallService} is notified of a new call via
1283 * {@link InCallService#onCallAdded(Call)}.
1284 */
Andrew Leeda80c872015-04-15 14:09:50 -07001285 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001286 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001287 * @hide
1288 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001289 @IntDef(prefix = { "HANDOVER_" },
1290 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001291 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001292 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001293 @Retention(RetentionPolicy.SOURCE)
1294 public @interface HandoverFailureErrors {}
1295
1296 /**
1297 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001298 * to handover the call to rejects the handover request.
1299 * <p>
1300 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1301 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1302 * {@code null} {@link Connection} from
1303 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1304 * ConnectionRequest)}.
1305 * <p>
1306 * For more information on call handovers, see
1307 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001308 */
1309 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1310
1311 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001312 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1313 * is initiated but the source or destination app does not support handover.
1314 * <p>
1315 * Will be returned when a handover is requested via
1316 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1317 * {@link PhoneAccountHandle} does not declare
1318 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1319 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1320 * {@link Details#getAccountHandle()}) does not declare
1321 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1322 * <p>
1323 * For more information on call handovers, see
1324 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001325 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001326 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001327
1328 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001329 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1330 * user rejects the handover request.
1331 * <p>
1332 * For more information on call handovers, see
1333 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001334 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001335 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001336
Sanket Padawe85291f62017-12-01 13:59:27 -08001337 /**
1338 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1339 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001340 * <p>
1341 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1342 * called on an emergency call, or if any other call is an emergency call.
1343 * <p>
1344 * Handovers are not permitted while there are ongoing emergency calls.
1345 * <p>
1346 * For more information on call handovers, see
1347 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001348 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001349 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001350
Tyler Gunn9d127732018-03-02 15:45:51 -08001351 /**
1352 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1353 * fails for an unknown reason.
1354 * <p>
1355 * For more information on call handovers, see
1356 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1357 */
1358 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001359
1360 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001361 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1362 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001363 * @param call The {@code Call} invoking this method.
1364 * @param state The new state of the {@code Call}.
1365 */
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001366 public void onStateChanged(Call call, @CallState int state) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001367
1368 /**
1369 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1370 *
1371 * @param call The {@code Call} invoking this method.
1372 * @param parent The new parent of the {@code Call}.
1373 */
1374 public void onParentChanged(Call call, Call parent) {}
1375
1376 /**
1377 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1378 *
1379 * @param call The {@code Call} invoking this method.
1380 * @param children The new children of the {@code Call}.
1381 */
1382 public void onChildrenChanged(Call call, List<Call> children) {}
1383
1384 /**
1385 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1386 *
1387 * @param call The {@code Call} invoking this method.
1388 * @param details A {@code Details} object describing the {@code Call}.
1389 */
1390 public void onDetailsChanged(Call call, Details details) {}
1391
1392 /**
1393 * Invoked when the text messages that can be used as responses to the incoming
1394 * {@code Call} are loaded from the relevant database.
1395 * See {@link #getCannedTextResponses()}.
1396 *
1397 * @param call The {@code Call} invoking this method.
1398 * @param cannedTextResponses The text messages useable as responses.
1399 */
1400 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1401
1402 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001403 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1404 * character. This causes the post-dial signals to stop pending user confirmation. An
1405 * implementation should present this choice to the user and invoke
1406 * {@link #postDialContinue(boolean)} when the user makes the choice.
1407 *
1408 * @param call The {@code Call} invoking this method.
1409 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1410 */
1411 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1412
1413 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001414 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001415 *
1416 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001417 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001418 */
Andrew Lee50aca232014-07-22 16:41:54 -07001419 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001420
1421 /**
1422 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1423 * up their UI for the {@code Call} in response to state transitions. Specifically,
1424 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1425 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1426 * clients should wait for this method to be invoked.
1427 *
1428 * @param call The {@code Call} being destroyed.
1429 */
1430 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001431
1432 /**
1433 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1434 * conferenced.
1435 *
1436 * @param call The {@code Call} being updated.
1437 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1438 * conferenced.
1439 */
1440 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001441
1442 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001443 * Invoked when a {@link Call} receives an event from its associated {@link Connection} or
1444 * {@link Conference}.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001445 * <p>
1446 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1447 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1448 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1449 * possible that a {@link ConnectionService} has defined its own Connection events which a
1450 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001451 * <p>
Tyler Gunn5567d742019-10-31 13:04:37 -07001452 * See {@link Connection#sendConnectionEvent(String, Bundle)},
1453 * {@link Conference#sendConferenceEvent(String, Bundle)}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001454 *
1455 * @param call The {@code Call} receiving the event.
1456 * @param event The event.
1457 * @param extras Extras associated with the connection event.
1458 */
1459 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001460
1461 /**
1462 * Invoked when the RTT mode changes for this call.
1463 * @param call The call whose RTT mode has changed.
1464 * @param mode the new RTT mode, one of
1465 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1466 * or {@link RttCall#RTT_MODE_VCO}
1467 */
1468 public void onRttModeChanged(Call call, int mode) {}
1469
1470 /**
1471 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1472 * @param call The call whose RTT status has changed.
1473 * @param enabled whether RTT is now enabled or disabled
1474 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1475 * on, null otherwise.
1476 */
1477 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1478
1479 /**
1480 * Invoked when the remote end of the connection has requested that an RTT communication
1481 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1482 * with the same ID that this method is invoked with.
1483 * @param call The call which the RTT request was placed on
1484 * @param id The ID of the request.
1485 */
1486 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001487
1488 /**
1489 * Invoked when the RTT session failed to initiate for some reason, including rejection
1490 * by the remote party.
Tyler Gunnb9a04962022-02-17 08:23:54 -08001491 * <p>
1492 * This callback will ONLY be invoked to report a failure related to a user initiated
1493 * session modification request (i.e. {@link Call#sendRttRequest()}).
1494 * <p>
1495 * If a call is initiated with {@link TelecomManager#EXTRA_START_CALL_WITH_RTT} specified,
1496 * the availability of RTT can be determined by checking {@link Details#PROPERTY_RTT}
1497 * once the call enters state {@link Details#STATE_ACTIVE}.
1498 *
Hall Liu57006aa2017-02-06 10:49:48 -08001499 * @param call The call which the RTT initiation failure occurred on.
1500 * @param reason One of the status codes defined in
Tyler Gunnb9a04962022-02-17 08:23:54 -08001501 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1502 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liu57006aa2017-02-06 10:49:48 -08001503 */
Tyler Gunnb9a04962022-02-17 08:23:54 -08001504 public void onRttInitiationFailure(Call call,
1505 @android.telecom.Connection.RttModifyStatus.RttSessionModifyStatus int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001506
1507 /**
1508 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1509 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001510 * <p>
1511 * For a full discussion of the handover process and the APIs involved, see
1512 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1513 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001514 * @param call The call which had initiated handover.
1515 */
1516 public void onHandoverComplete(Call call) {}
1517
1518 /**
1519 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1520 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001521 * <p>
1522 * For a full discussion of the handover process and the APIs involved, see
1523 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1524 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001525 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001526 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001527 */
1528 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001529 }
1530
1531 /**
1532 * A class that holds the state that describes the state of the RTT channel to the remote
1533 * party, if it is active.
1534 */
1535 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001536 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001537 @Retention(RetentionPolicy.SOURCE)
1538 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1539 public @interface RttAudioMode {}
1540
1541 /**
1542 * For metrics use. Default value in the proto.
1543 * @hide
1544 */
1545 public static final int RTT_MODE_INVALID = 0;
1546
1547 /**
1548 * Indicates that there should be a bidirectional audio stream between the two parties
1549 * on the call.
1550 */
1551 public static final int RTT_MODE_FULL = 1;
1552
1553 /**
1554 * Indicates that the local user should be able to hear the audio stream from the remote
1555 * user, but not vice versa. Equivalent to muting the microphone.
1556 */
1557 public static final int RTT_MODE_HCO = 2;
1558
1559 /**
1560 * Indicates that the remote user should be able to hear the audio stream from the local
1561 * user, but not vice versa. Equivalent to setting the volume to zero.
1562 */
1563 public static final int RTT_MODE_VCO = 3;
1564
1565 private static final int READ_BUFFER_SIZE = 1000;
1566
1567 private InputStreamReader mReceiveStream;
1568 private OutputStreamWriter mTransmitStream;
1569 private int mRttMode;
1570 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001571 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001572 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1573
1574 /**
1575 * @hide
1576 */
Hall Liu57006aa2017-02-06 10:49:48 -08001577 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1578 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1579 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001580 mReceiveStream = receiveStream;
1581 mTransmitStream = transmitStream;
1582 mRttMode = mode;
1583 mInCallAdapter = inCallAdapter;
1584 }
1585
1586 /**
1587 * Returns the current RTT audio mode.
1588 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1589 * {@link #RTT_MODE_HCO}.
1590 */
1591 public int getRttAudioMode() {
1592 return mRttMode;
1593 }
1594
1595 /**
1596 * Sets the RTT audio mode. The requested mode change will be communicated through
1597 * {@link Callback#onRttModeChanged(Call, int)}.
1598 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1599 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1600 */
1601 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001602 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001603 }
1604
1605 /**
1606 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
Hall Liudc46c852020-10-29 16:15:33 -07001607 * RTT transmits text in real-time, this method should be called once for each user action.
1608 * For example, when the user enters text as discrete characters using the keyboard, this
1609 * method should be called once for each character. However, if the user enters text by
1610 * pasting or autocomplete, the entire contents of the pasted or autocompleted text should
1611 * be sent in one call to this method.
Hall Liu95d55872017-01-25 17:12:49 -08001612 *
1613 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1614 * lead to interleaved text.
1615 * @param input The message to send to the remote user.
1616 */
1617 public void write(String input) throws IOException {
1618 mTransmitStream.write(input);
1619 mTransmitStream.flush();
1620 }
1621
1622 /**
1623 * Reads a string from the remote user, blocking if there is no data available. Returns
1624 * {@code null} if the RTT conversation has been terminated and there is no further data
1625 * to read.
1626 *
1627 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1628 * lead to interleaved text.
1629 * @return A string containing text sent by the remote user, or {@code null} if the
1630 * conversation has been terminated or if there was an error while reading.
1631 */
Hall Liub1c8a772017-07-17 17:04:41 -07001632 public String read() {
1633 try {
1634 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1635 if (numRead < 0) {
1636 return null;
1637 }
1638 return new String(mReadBuffer, 0, numRead);
1639 } catch (IOException e) {
1640 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001641 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001642 }
Hall Liuffa4a812017-03-02 16:11:00 -08001643 }
1644
1645 /**
1646 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1647 * be read.
1648 * @return A string containing text entered by the user, or {@code null} if the user has
1649 * not entered any new text yet.
1650 */
1651 public String readImmediately() throws IOException {
1652 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001653 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1654 if (numRead < 0) {
1655 return null;
1656 }
1657 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001658 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001659 return null;
1660 }
1661 }
Hall Liue9041242018-02-09 16:40:03 -08001662
1663 /**
1664 * Closes the underlying file descriptors
1665 * @hide
1666 */
1667 public void close() {
1668 try {
1669 mReceiveStream.close();
1670 } catch (IOException e) {
1671 // ignore
1672 }
1673 try {
1674 mTransmitStream.close();
1675 } catch (IOException e) {
1676 // ignore
1677 }
1678 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001679 }
1680
Andrew Leeda80c872015-04-15 14:09:50 -07001681 /**
1682 * @deprecated Use {@code Call.Callback} instead.
1683 * @hide
1684 */
1685 @Deprecated
1686 @SystemApi
1687 public static abstract class Listener extends Callback { }
1688
Ihab Awade63fadb2014-07-09 21:52:04 -07001689 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001690 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001691 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001692 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001693 private final List<Call> mChildren = new ArrayList<>();
1694 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001695 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001696 private final List<Call> mConferenceableCalls = new ArrayList<>();
1697 private final List<Call> mUnmodifiableConferenceableCalls =
1698 Collections.unmodifiableList(mConferenceableCalls);
1699
Santos Cordon823fd3c2014-08-07 18:35:18 -07001700 private boolean mChildrenCached;
1701 private String mParentId = null;
Hall Liuef98bf82020-01-09 15:22:44 -08001702 private String mActiveGenericConferenceChild = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001703 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001704 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001705 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001706 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001707 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001708 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001709 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001710 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001711 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001712
1713 /**
1714 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1715 *
1716 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1717 * remaining or this {@code Call} is not in a post-dial state.
1718 */
1719 public String getRemainingPostDialSequence() {
1720 return mRemainingPostDialSequence;
1721 }
1722
1723 /**
1724 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001725 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001726 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001727 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001728 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001729 }
1730
1731 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301732 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1733 *
1734 * @param address The address to which the call will be deflected.
1735 */
1736 public void deflect(Uri address) {
1737 mInCallAdapter.deflectCall(mTelecomCallId, address);
1738 }
1739
1740 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001741 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1742 *
1743 * @param rejectWithMessage Whether to reject with a text message.
1744 * @param textMessage An optional text message with which to respond.
1745 */
1746 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001747 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001748 }
1749
1750 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001751 * Instructs the {@link ConnectionService} providing this {@link #STATE_RINGING} call that the
1752 * user has chosen to reject the call and has indicated a reason why the call is being rejected.
1753 *
1754 * @param rejectReason the reason the call is being rejected.
1755 */
1756 public void reject(@RejectReason int rejectReason) {
1757 mInCallAdapter.rejectCall(mTelecomCallId, rejectReason);
1758 }
1759
1760 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05301761 * Instructs this {@code Call} to be transferred to another number.
1762 *
1763 * @param targetNumber The address to which the call will be transferred.
Tyler Gunn460360d2020-07-29 10:21:45 -07001764 * @param isConfirmationRequired if {@code true} it will initiate a confirmed transfer,
1765 * if {@code false}, it will initiate an unconfirmed transfer.
Ravi Palurif4b38e72020-02-05 12:35:41 +05301766 *
1767 * @hide
1768 */
1769 public void transfer(@NonNull Uri targetNumber, boolean isConfirmationRequired) {
1770 mInCallAdapter.transferCall(mTelecomCallId, targetNumber, isConfirmationRequired);
1771 }
1772
1773 /**
1774 * Instructs this {@code Call} to be transferred to another ongoing call.
1775 * This will initiate CONSULTATIVE transfer.
1776 * @param toCall The other ongoing {@code Call} to which this call will be transferred.
1777 *
1778 * @hide
1779 */
1780 public void transfer(@NonNull android.telecom.Call toCall) {
1781 mInCallAdapter.transferCall(mTelecomCallId, toCall.mTelecomCallId);
1782 }
1783
1784 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001785 * Instructs this {@code Call} to disconnect.
1786 */
1787 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001788 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001789 }
1790
1791 /**
1792 * Instructs this {@code Call} to go on hold.
1793 */
1794 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001795 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001796 }
1797
1798 /**
1799 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1800 */
1801 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001802 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001803 }
1804
1805 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001806 * Instructs Telecom to put the call into the background audio processing state.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001807 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001808 * This method can be called either when the call is in {@link #STATE_RINGING} or
1809 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1810 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1811 * order to capture and play audio on the call stream.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001812 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001813 * This method can only be called by the default dialer app.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001814 * <p>
1815 * Apps built with SDK version {@link android.os.Build.VERSION_CODES#R} or later which are using
1816 * the microphone as part of audio processing should specify the foreground service type using
1817 * the attribute {@link android.R.attr#foregroundServiceType} in the {@link InCallService}
1818 * service element of the app's manifest file.
1819 * The {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_MICROPHONE} attribute should be specified.
1820 * @see <a href="https://developer.android.com/preview/privacy/foreground-service-types">
1821 * the Android Developer Site</a> for more information.
Hall Liu6dfa2492019-10-01 17:20:39 -07001822 * @hide
1823 */
1824 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001825 public void enterBackgroundAudioProcessing() {
1826 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1827 throw new IllegalStateException("Call must be active or ringing");
1828 }
1829 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1830 }
1831
1832 /**
1833 * Instructs Telecom to come out of the background audio processing state requested by
1834 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1835 *
1836 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1837 *
1838 * @param shouldRing If true, Telecom will put the call into the
1839 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1840 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1841 * immediately.
1842 * @hide
1843 */
1844 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001845 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1846 if (mState != STATE_AUDIO_PROCESSING) {
1847 throw new IllegalStateException("Call must in the audio processing state");
1848 }
1849 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1850 }
1851
1852 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001853 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1854 *
1855 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1856 *
1857 * @param digit A character representing the DTMF digit for which to play the tone. This
1858 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1859 */
1860 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001861 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001862 }
1863
1864 /**
1865 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1866 * currently playing.
1867 *
1868 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1869 * currently playing, this method will do nothing.
1870 */
1871 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001872 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001873 }
1874
1875 /**
1876 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1877 *
1878 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1879 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001880 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001881 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001882 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1883 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001884 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001885 * {@code Call} will pause playing the tones and notify callbacks via
1886 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001887 * should display to the user an indication of this state and an affordance to continue
1888 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1889 * app should invoke the {@link #postDialContinue(boolean)} method.
1890 *
1891 * @param proceed Whether or not to continue with the post-dial sequence.
1892 */
1893 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001894 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001895 }
1896
1897 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001898 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001899 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001900 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001901 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1902 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001903
1904 }
1905
1906 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001907 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001908 *
1909 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001910 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001911 public void conference(Call callToConferenceWith) {
1912 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001913 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001914 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001915 }
1916
1917 /**
1918 * Instructs this {@code Call} to split from any conference call with which it may be
1919 * connected.
1920 */
1921 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001922 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001923 }
1924
1925 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001926 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001927 */
1928 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001929 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001930 }
1931
1932 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001933 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001934 */
1935 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001936 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001937 }
1938
1939 /**
Ravi Paluri404babb2020-01-23 19:02:44 +05301940 * Pulls participants to existing call by forming a conference call.
1941 * See {@link Details#CAPABILITY_ADD_PARTICIPANT}.
1942 *
1943 * @param participants participants to be pulled to existing call.
1944 */
1945 public void addConferenceParticipants(@NonNull List<Uri> participants) {
1946 mInCallAdapter.addConferenceParticipants(mTelecomCallId, participants);
1947 }
1948
1949 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001950 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1951 * device.
1952 * <p>
1953 * Calls to this method are ignored if the call does not have the
1954 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1955 * <p>
1956 * An {@link InCallService} will only see calls which support this method if it has the
1957 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1958 * in its manifest.
1959 */
1960 public void pullExternalCall() {
1961 // If this isn't an external call, ignore the request.
1962 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1963 return;
1964 }
1965
1966 mInCallAdapter.pullExternalCall(mTelecomCallId);
1967 }
1968
1969 /**
1970 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1971 * the {@link ConnectionService}.
1972 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001973 * Call events are used to communicate point in time information from an {@link InCallService}
1974 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1975 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1976 * {@link ConnectionService}.
1977 * <p>
1978 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1979 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1980 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001981 * Events are exposed to {@link ConnectionService} implementations via
1982 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1983 * <p>
1984 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001985 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1986 * ignore some events altogether.
1987 * <p>
1988 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1989 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1990 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1991 * they define their own event types in this namespace. When defining a custom event type,
1992 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1993 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1994 * <p>
1995 * When defining events and the associated extras, it is important to keep their behavior
1996 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1997 * events/extras should me maintained to ensure backwards compatibility with older
1998 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001999 *
2000 * @param event The connection event.
2001 * @param extras Bundle containing extra information associated with the event.
2002 */
2003 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08002004 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002005 }
2006
2007 /**
Hall Liu95d55872017-01-25 17:12:49 -08002008 * Sends an RTT upgrade request to the remote end of the connection. Success is not
2009 * guaranteed, and notification of success will be via the
2010 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
2011 */
2012 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08002013 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08002014 }
2015
2016 /**
2017 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
2018 * callback.
2019 * The ID used here should be the same as the ID that was received via the callback.
2020 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
2021 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
2022 */
2023 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08002024 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08002025 }
2026
2027 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07002028 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
2029 * by {@code toHandle}. The videoState specified indicates the desired video state after the
2030 * handover.
2031 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08002032 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2033 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2034 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2035 * is referred to as the source of the handover, and the video calling app is referred to as the
2036 * destination.
2037 * <p>
2038 * When considering a handover scenario the device this method is called on is considered the
2039 * <em>initiating</em> device (since the user initiates the handover from this device), and the
2040 * other device is considered the <em>receiving</em> device.
2041 * <p>
2042 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
2043 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
2044 * and invoke
2045 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
2046 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
2047 * call to it. The app returns an instance of {@link Connection} to represent the handover call
2048 * At this point the app should display UI to indicate to the user that a call
2049 * handover is in process.
2050 * <p>
2051 * The destination app is responsible for communicating the handover request from the
2052 * <em>initiating</em> device to the <em>receiving</em> device.
2053 * <p>
2054 * When the app on the <em>receiving</em> device receives the handover request, it calls
2055 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
2056 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
2057 * the destination app on the <em>receiving</em> device should show UI to allow the user to
2058 * choose whether they want to continue their call in the destination app.
2059 * <p>
2060 * When the destination app on the <em>receiving</em> device calls
2061 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
2062 * {@link ConnectionService} and call
2063 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
2064 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
2065 * {@link Connection} to represent the handover call.
2066 * <p>
2067 * If the user of the <em>receiving</em> device accepts the handover, the app calls
2068 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
2069 * original call. If the user rejects the handover, the app calls
2070 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
2071 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
2072 * <p>
2073 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
2074 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
2075 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
2076 * <p>
2077 * Errors in the handover process are reported to the {@link InCallService} via
2078 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
2079 * the involved {@link ConnectionService}s via
2080 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002081 *
2082 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
2083 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08002084 * @param videoState Indicates the video state desired after the handover (see the
2085 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07002086 * @param extras Bundle containing extra information to be passed to the
2087 * {@link ConnectionService}
2088 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002089 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
2090 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002091 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
2092 }
2093
2094 /**
Hall Liu95d55872017-01-25 17:12:49 -08002095 * Terminate the RTT session on this call. The resulting state change will be notified via
2096 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
2097 */
2098 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08002099 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08002100 }
2101
2102 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002103 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
2104 * added.
2105 * <p>
2106 * No assumptions should be made as to how an In-Call UI or service will handle these
2107 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2108 *
2109 * @param extras The extras to add.
2110 */
2111 public final void putExtras(Bundle extras) {
2112 if (extras == null) {
2113 return;
2114 }
2115
2116 if (mExtras == null) {
2117 mExtras = new Bundle();
2118 }
2119 mExtras.putAll(extras);
2120 mInCallAdapter.putExtras(mTelecomCallId, extras);
2121 }
2122
2123 /**
2124 * Adds a boolean extra to this {@link Call}.
2125 *
2126 * @param key The extra key.
2127 * @param value The value.
2128 * @hide
2129 */
2130 public final void putExtra(String key, boolean value) {
2131 if (mExtras == null) {
2132 mExtras = new Bundle();
2133 }
2134 mExtras.putBoolean(key, value);
2135 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2136 }
2137
2138 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002139 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002140 *
2141 * @param key The extra key.
2142 * @param value The value.
2143 * @hide
2144 */
2145 public final void putExtra(String key, int value) {
2146 if (mExtras == null) {
2147 mExtras = new Bundle();
2148 }
2149 mExtras.putInt(key, value);
2150 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2151 }
2152
2153 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002154 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002155 *
2156 * @param key The extra key.
2157 * @param value The value.
2158 * @hide
2159 */
2160 public final void putExtra(String key, String value) {
2161 if (mExtras == null) {
2162 mExtras = new Bundle();
2163 }
2164 mExtras.putString(key, value);
2165 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2166 }
2167
2168 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002169 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002170 *
2171 * @param keys The keys of the extras to remove.
2172 */
2173 public final void removeExtras(List<String> keys) {
2174 if (mExtras != null) {
2175 for (String key : keys) {
2176 mExtras.remove(key);
2177 }
2178 if (mExtras.size() == 0) {
2179 mExtras = null;
2180 }
2181 }
2182 mInCallAdapter.removeExtras(mTelecomCallId, keys);
2183 }
2184
2185 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002186 * Removes extras from this {@link Call}.
2187 *
2188 * @param keys The keys of the extras to remove.
2189 */
2190 public final void removeExtras(String ... keys) {
2191 removeExtras(Arrays.asList(keys));
2192 }
2193
2194 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002195 * Obtains the parent of this {@code Call} in a conference, if any.
2196 *
2197 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
2198 * child of any conference {@code Call}s.
2199 */
2200 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002201 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002202 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002203 }
2204 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07002205 }
2206
2207 /**
2208 * Obtains the children of this conference {@code Call}, if any.
2209 *
2210 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
2211 * {@code List} otherwise.
2212 */
2213 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002214 if (!mChildrenCached) {
2215 mChildrenCached = true;
2216 mChildren.clear();
2217
2218 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002219 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002220 if (call == null) {
2221 // At least one child was still not found, so do not save true for "cached"
2222 mChildrenCached = false;
2223 } else {
2224 mChildren.add(call);
2225 }
2226 }
2227 }
2228
Ihab Awade63fadb2014-07-09 21:52:04 -07002229 return mUnmodifiableChildren;
2230 }
2231
2232 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002233 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
2234 *
2235 * @return The list of conferenceable {@code Call}s.
2236 */
2237 public List<Call> getConferenceableCalls() {
2238 return mUnmodifiableConferenceableCalls;
2239 }
2240
2241 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002242 * Obtains the state of this {@code Call}.
2243 *
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002244 * @return The call state.
2245 * @deprecated The call state is available via {@link Call.Details#getState()}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002246 */
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002247 @Deprecated
2248 public @CallState int getState() {
Ihab Awade63fadb2014-07-09 21:52:04 -07002249 return mState;
2250 }
2251
2252 /**
Hall Liuef98bf82020-01-09 15:22:44 -08002253 * Returns the child {@link Call} in a generic conference that is currently active.
Hall Liu135e53aa2020-02-27 18:34:11 -08002254 *
2255 * A "generic conference" is the mechanism used to support two simultaneous calls on a device
2256 * in CDMA networks. It is effectively equivalent to having one call active and one call on hold
2257 * in GSM or IMS calls. This method returns the currently active call.
2258 *
2259 * In a generic conference, the network exposes the conference to us as a single call, and we
2260 * switch between talking to the two participants using a CDMA flash command. Since the network
2261 * exposes no additional information about the call, the only way we know which caller we're
2262 * currently talking to is by keeping track of the flash commands that we've sent to the
2263 * network.
2264 *
Hall Liuef98bf82020-01-09 15:22:44 -08002265 * For calls that are not generic conferences, or when the generic conference has more than
2266 * 2 children, returns {@code null}.
2267 * @see Details#PROPERTY_GENERIC_CONFERENCE
2268 * @return The active child call.
2269 */
2270 public @Nullable Call getGenericConferenceActiveChildCall() {
2271 if (mActiveGenericConferenceChild != null) {
2272 return mPhone.internalGetCallByTelecomId(mActiveGenericConferenceChild);
2273 }
2274 return null;
2275 }
2276
2277 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002278 * Obtains a list of canned, pre-configured message responses to present to the user as
Tyler Gunn434fc2c2020-10-06 14:23:54 -07002279 * ways of rejecting an incoming {@code Call} using via a text message.
2280 * <p>
2281 * <em>Note:</em> Since canned responses may be loaded from the file system, they are not
2282 * guaranteed to be present when this {@link Call} is first added to the {@link InCallService}
2283 * via {@link InCallService#onCallAdded(Call)}. The callback
2284 * {@link Call.Callback#onCannedTextResponsesLoaded(Call, List)} will be called when/if canned
2285 * responses for the call become available.
Ihab Awade63fadb2014-07-09 21:52:04 -07002286 *
2287 * @see #reject(boolean, String)
2288 *
2289 * @return A list of canned text message responses.
2290 */
2291 public List<String> getCannedTextResponses() {
2292 return mCannedTextResponses;
2293 }
2294
2295 /**
2296 * Obtains an object that can be used to display video from this {@code Call}.
2297 *
Andrew Lee50aca232014-07-22 16:41:54 -07002298 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002299 */
Andrew Lee50aca232014-07-22 16:41:54 -07002300 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002301 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07002302 }
2303
2304 /**
2305 * Obtains an object containing call details.
2306 *
2307 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
2308 * result may be {@code null}.
2309 */
2310 public Details getDetails() {
2311 return mDetails;
2312 }
2313
2314 /**
Hall Liu95d55872017-01-25 17:12:49 -08002315 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
2316 * receive RTT text data, as well as to change the RTT mode.
2317 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
2318 */
2319 public @Nullable RttCall getRttCall() {
2320 return mRttCall;
2321 }
2322
2323 /**
2324 * Returns whether this call has an active RTT connection.
2325 * @return true if there is a connection, false otherwise.
2326 */
2327 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08002328 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08002329 }
2330
2331 /**
Andrew Leeda80c872015-04-15 14:09:50 -07002332 * Registers a callback to this {@code Call}.
2333 *
2334 * @param callback A {@code Callback}.
2335 */
2336 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07002337 registerCallback(callback, new Handler());
2338 }
2339
2340 /**
2341 * Registers a callback to this {@code Call}.
2342 *
2343 * @param callback A {@code Callback}.
2344 * @param handler A handler which command and status changes will be delivered to.
2345 */
2346 public void registerCallback(Callback callback, Handler handler) {
2347 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07002348 // Don't allow new callback registration if the call is already being destroyed.
2349 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002350 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
2351 }
Andrew Leeda80c872015-04-15 14:09:50 -07002352 }
2353
2354 /**
2355 * Unregisters a callback from this {@code Call}.
2356 *
2357 * @param callback A {@code Callback}.
2358 */
2359 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002360 // Don't allow callback deregistration if the call is already being destroyed.
2361 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002362 for (CallbackRecord<Callback> record : mCallbackRecords) {
2363 if (record.getCallback() == callback) {
2364 mCallbackRecords.remove(record);
2365 break;
2366 }
2367 }
Andrew Leeda80c872015-04-15 14:09:50 -07002368 }
2369 }
2370
Santos Cordon3c20d632016-02-25 16:12:35 -08002371 @Override
2372 public String toString() {
2373 return new StringBuilder().
2374 append("Call [id: ").
2375 append(mTelecomCallId).
2376 append(", state: ").
2377 append(stateToString(mState)).
2378 append(", details: ").
2379 append(mDetails).
2380 append("]").toString();
2381 }
2382
2383 /**
2384 * @param state An integer value of a {@code STATE_*} constant.
2385 * @return A string representation of the value.
2386 */
2387 private static String stateToString(int state) {
2388 switch (state) {
2389 case STATE_NEW:
2390 return "NEW";
2391 case STATE_RINGING:
2392 return "RINGING";
2393 case STATE_DIALING:
2394 return "DIALING";
2395 case STATE_ACTIVE:
2396 return "ACTIVE";
2397 case STATE_HOLDING:
2398 return "HOLDING";
2399 case STATE_DISCONNECTED:
2400 return "DISCONNECTED";
2401 case STATE_CONNECTING:
2402 return "CONNECTING";
2403 case STATE_DISCONNECTING:
2404 return "DISCONNECTING";
2405 case STATE_SELECT_PHONE_ACCOUNT:
2406 return "SELECT_PHONE_ACCOUNT";
Hall Liu4e35b642019-10-14 17:50:45 -07002407 case STATE_SIMULATED_RINGING:
2408 return "SIMULATED_RINGING";
2409 case STATE_AUDIO_PROCESSING:
2410 return "AUDIO_PROCESSING";
Santos Cordon3c20d632016-02-25 16:12:35 -08002411 default:
2412 Log.w(Call.class, "Unknown state %d", state);
2413 return "UNKNOWN";
2414 }
2415 }
2416
Andrew Leeda80c872015-04-15 14:09:50 -07002417 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002418 * Adds a listener to this {@code Call}.
2419 *
2420 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002421 * @deprecated Use {@link #registerCallback} instead.
2422 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002423 */
Andrew Leeda80c872015-04-15 14:09:50 -07002424 @Deprecated
2425 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002426 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002427 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002428 }
2429
2430 /**
2431 * Removes a listener from this {@code Call}.
2432 *
2433 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002434 * @deprecated Use {@link #unregisterCallback} instead.
2435 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002436 */
Andrew Leeda80c872015-04-15 14:09:50 -07002437 @Deprecated
2438 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002439 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002440 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002441 }
2442
2443 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002444 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2445 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002446 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002447 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002448 mInCallAdapter = inCallAdapter;
2449 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002450 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002451 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002452 }
2453
2454 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002455 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002456 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002457 mPhone = phone;
2458 mTelecomCallId = telecomCallId;
2459 mInCallAdapter = inCallAdapter;
2460 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002461 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002462 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002463 }
2464
2465 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002466 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002467 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002468 }
2469
2470 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002471 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002472
Ihab Awade63fadb2014-07-09 21:52:04 -07002473 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002474 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002475 boolean detailsChanged = !Objects.equals(mDetails, details);
2476 if (detailsChanged) {
2477 mDetails = details;
2478 }
2479
2480 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002481 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2482 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2483 mCannedTextResponses =
2484 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002485 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002486 }
2487
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002488 IVideoProvider previousVideoProvider = mVideoCallImpl == null ? null :
2489 mVideoCallImpl.getVideoProvider();
2490 IVideoProvider newVideoProvider = parcelableCall.getVideoProvider();
2491
2492 // parcelableCall.isVideoCallProviderChanged is only true when we have a video provider
2493 // specified; so we should check if the actual IVideoProvider changes as well.
2494 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged()
2495 && !Objects.equals(previousVideoProvider, newVideoProvider);
Andrew Lee50aca232014-07-22 16:41:54 -07002496 if (videoCallChanged) {
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002497 if (mVideoCallImpl != null) {
2498 mVideoCallImpl.destroy();
2499 }
2500 mVideoCallImpl = parcelableCall.isVideoCallProviderChanged() ?
2501 parcelableCall.getVideoCallImpl(mCallingPackage, mTargetSdkVersion) : null;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002502 }
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002503
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002504 if (mVideoCallImpl != null) {
2505 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002506 }
2507
Santos Cordone3c507b2015-04-23 14:44:19 -07002508 int state = parcelableCall.getState();
Hall Liu31de23d2019-10-11 15:38:29 -07002509 if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2510 state = Call.STATE_RINGING;
2511 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002512 boolean stateChanged = mState != state;
2513 if (stateChanged) {
2514 mState = state;
2515 }
2516
Santos Cordon823fd3c2014-08-07 18:35:18 -07002517 String parentId = parcelableCall.getParentCallId();
2518 boolean parentChanged = !Objects.equals(mParentId, parentId);
2519 if (parentChanged) {
2520 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002521 }
2522
Santos Cordon823fd3c2014-08-07 18:35:18 -07002523 List<String> childCallIds = parcelableCall.getChildCallIds();
2524 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2525 if (childrenChanged) {
2526 mChildrenIds.clear();
2527 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2528 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002529 }
2530
Hall Liuef98bf82020-01-09 15:22:44 -08002531 String activeChildCallId = parcelableCall.getActiveChildCallId();
2532 boolean activeChildChanged = !Objects.equals(activeChildCallId,
2533 mActiveGenericConferenceChild);
2534 if (activeChildChanged) {
2535 mActiveGenericConferenceChild = activeChildCallId;
2536 }
2537
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002538 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2539 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2540 for (String otherId : conferenceableCallIds) {
2541 if (callIdMap.containsKey(otherId)) {
2542 conferenceableCalls.add(callIdMap.get(otherId));
2543 }
2544 }
2545
2546 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2547 mConferenceableCalls.clear();
2548 mConferenceableCalls.addAll(conferenceableCalls);
2549 fireConferenceableCallsChanged();
2550 }
2551
Hall Liu95d55872017-01-25 17:12:49 -08002552 boolean isRttChanged = false;
2553 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002554 if (parcelableCall.getIsRttCallChanged()
2555 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002556 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2557 InputStreamReader receiveStream = new InputStreamReader(
2558 new ParcelFileDescriptor.AutoCloseInputStream(
2559 parcelableRttCall.getReceiveStream()),
2560 StandardCharsets.UTF_8);
2561 OutputStreamWriter transmitStream = new OutputStreamWriter(
2562 new ParcelFileDescriptor.AutoCloseOutputStream(
2563 parcelableRttCall.getTransmitStream()),
2564 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002565 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002566 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2567 if (mRttCall == null) {
2568 isRttChanged = true;
2569 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2570 rttModeChanged = true;
2571 }
2572 mRttCall = newRttCall;
2573 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2574 && parcelableCall.getIsRttCallChanged()) {
2575 isRttChanged = true;
Tyler Gunn4cd42482021-04-30 16:23:15 -07002576 mRttCall.close();
Hall Liu95d55872017-01-25 17:12:49 -08002577 mRttCall = null;
2578 }
2579
Ihab Awade63fadb2014-07-09 21:52:04 -07002580 // Now we fire updates, ensuring that any client who listens to any of these notifications
2581 // gets the most up-to-date state.
2582
2583 if (stateChanged) {
2584 fireStateChanged(mState);
2585 }
2586 if (detailsChanged) {
2587 fireDetailsChanged(mDetails);
2588 }
2589 if (cannedTextResponsesChanged) {
2590 fireCannedTextResponsesLoaded(mCannedTextResponses);
2591 }
Andrew Lee50aca232014-07-22 16:41:54 -07002592 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002593 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002594 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002595 if (parentChanged) {
2596 fireParentChanged(getParent());
2597 }
Hall Liuef98bf82020-01-09 15:22:44 -08002598 if (childrenChanged || activeChildChanged) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002599 fireChildrenChanged(getChildren());
2600 }
Hall Liu95d55872017-01-25 17:12:49 -08002601 if (isRttChanged) {
2602 fireOnIsRttChanged(mRttCall != null, mRttCall);
2603 }
2604 if (rttModeChanged) {
2605 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2606 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002607
2608 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2609 // remove ourselves from the Phone. Note that we do this after completing all state updates
2610 // so a client can cleanly transition all their UI to the state appropriate for a
2611 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2612 if (mState == STATE_DISCONNECTED) {
2613 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002614 }
2615 }
2616
2617 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002618 final void internalSetPostDialWait(String remaining) {
2619 mRemainingPostDialSequence = remaining;
2620 firePostDialWait(mRemainingPostDialSequence);
2621 }
2622
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002623 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002624 final void internalSetDisconnected() {
2625 if (mState != Call.STATE_DISCONNECTED) {
2626 mState = Call.STATE_DISCONNECTED;
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002627 if (mDetails != null) {
2628 mDetails = new Details(mState,
2629 mDetails.getTelecomCallId(),
2630 mDetails.getHandle(),
2631 mDetails.getHandlePresentation(),
2632 mDetails.getCallerDisplayName(),
2633 mDetails.getCallerDisplayNamePresentation(),
2634 mDetails.getAccountHandle(),
2635 mDetails.getCallCapabilities(),
2636 mDetails.getCallProperties(),
2637 mDetails.getDisconnectCause(),
2638 mDetails.getConnectTimeMillis(),
2639 mDetails.getGatewayInfo(),
2640 mDetails.getVideoState(),
2641 mDetails.getStatusHints(),
2642 mDetails.getExtras(),
2643 mDetails.getIntentExtras(),
2644 mDetails.getCreationTimeMillis(),
2645 mDetails.getContactDisplayName(),
2646 mDetails.getCallDirection(),
2647 mDetails.getCallerNumberVerificationStatus()
2648 );
2649 fireDetailsChanged(mDetails);
2650 }
Santos Cordonf30d7e92014-08-26 09:54:33 -07002651 fireStateChanged(mState);
2652 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002653 }
2654 }
2655
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002656 /** {@hide} */
2657 final void internalOnConnectionEvent(String event, Bundle extras) {
2658 fireOnConnectionEvent(event, extras);
2659 }
2660
Hall Liu95d55872017-01-25 17:12:49 -08002661 /** {@hide} */
2662 final void internalOnRttUpgradeRequest(final int requestId) {
2663 for (CallbackRecord<Callback> record : mCallbackRecords) {
2664 final Call call = this;
2665 final Callback callback = record.getCallback();
2666 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2667 }
2668 }
2669
Hall Liu57006aa2017-02-06 10:49:48 -08002670 /** @hide */
2671 final void internalOnRttInitiationFailure(int reason) {
2672 for (CallbackRecord<Callback> record : mCallbackRecords) {
2673 final Call call = this;
2674 final Callback callback = record.getCallback();
2675 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2676 }
2677 }
2678
Sanket Padawe85291f62017-12-01 13:59:27 -08002679 /** {@hide} */
2680 final void internalOnHandoverFailed(int error) {
2681 for (CallbackRecord<Callback> record : mCallbackRecords) {
2682 final Call call = this;
2683 final Callback callback = record.getCallback();
2684 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2685 }
2686 }
2687
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002688 /** {@hide} */
2689 final void internalOnHandoverComplete() {
2690 for (CallbackRecord<Callback> record : mCallbackRecords) {
2691 final Call call = this;
2692 final Callback callback = record.getCallback();
2693 record.getHandler().post(() -> callback.onHandoverComplete(call));
2694 }
2695 }
2696
Andrew Lee011728f2015-04-23 15:47:06 -07002697 private void fireStateChanged(final int newState) {
2698 for (CallbackRecord<Callback> record : mCallbackRecords) {
2699 final Call call = this;
2700 final Callback callback = record.getCallback();
2701 record.getHandler().post(new Runnable() {
2702 @Override
2703 public void run() {
2704 callback.onStateChanged(call, newState);
2705 }
2706 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002707 }
2708 }
2709
Andrew Lee011728f2015-04-23 15:47:06 -07002710 private void fireParentChanged(final Call newParent) {
2711 for (CallbackRecord<Callback> record : mCallbackRecords) {
2712 final Call call = this;
2713 final Callback callback = record.getCallback();
2714 record.getHandler().post(new Runnable() {
2715 @Override
2716 public void run() {
2717 callback.onParentChanged(call, newParent);
2718 }
2719 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002720 }
2721 }
2722
Andrew Lee011728f2015-04-23 15:47:06 -07002723 private void fireChildrenChanged(final List<Call> children) {
2724 for (CallbackRecord<Callback> record : mCallbackRecords) {
2725 final Call call = this;
2726 final Callback callback = record.getCallback();
2727 record.getHandler().post(new Runnable() {
2728 @Override
2729 public void run() {
2730 callback.onChildrenChanged(call, children);
2731 }
2732 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002733 }
2734 }
2735
Andrew Lee011728f2015-04-23 15:47:06 -07002736 private void fireDetailsChanged(final Details details) {
2737 for (CallbackRecord<Callback> record : mCallbackRecords) {
2738 final Call call = this;
2739 final Callback callback = record.getCallback();
2740 record.getHandler().post(new Runnable() {
2741 @Override
2742 public void run() {
2743 callback.onDetailsChanged(call, details);
2744 }
2745 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002746 }
2747 }
2748
Andrew Lee011728f2015-04-23 15:47:06 -07002749 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2750 for (CallbackRecord<Callback> record : mCallbackRecords) {
2751 final Call call = this;
2752 final Callback callback = record.getCallback();
2753 record.getHandler().post(new Runnable() {
2754 @Override
2755 public void run() {
2756 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2757 }
2758 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002759 }
2760 }
2761
Andrew Lee011728f2015-04-23 15:47:06 -07002762 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2763 for (CallbackRecord<Callback> record : mCallbackRecords) {
2764 final Call call = this;
2765 final Callback callback = record.getCallback();
2766 record.getHandler().post(new Runnable() {
2767 @Override
2768 public void run() {
2769 callback.onVideoCallChanged(call, videoCall);
2770 }
2771 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002772 }
2773 }
2774
Andrew Lee011728f2015-04-23 15:47:06 -07002775 private void firePostDialWait(final String remainingPostDialSequence) {
2776 for (CallbackRecord<Callback> record : mCallbackRecords) {
2777 final Call call = this;
2778 final Callback callback = record.getCallback();
2779 record.getHandler().post(new Runnable() {
2780 @Override
2781 public void run() {
2782 callback.onPostDialWait(call, remainingPostDialSequence);
2783 }
2784 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002785 }
2786 }
2787
2788 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002789 /**
2790 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2791 * onCallRemoved callback, we remove this call from the Phone's record
2792 * only once all of the registered onCallDestroyed callbacks are executed.
2793 * All the callbacks get removed from our records as a part of this operation
2794 * since onCallDestroyed is the final callback.
2795 */
2796 final Call call = this;
2797 if (mCallbackRecords.isEmpty()) {
2798 // No callbacks registered, remove the call from Phone's record.
2799 mPhone.internalRemoveCall(call);
2800 }
2801 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002802 final Callback callback = record.getCallback();
2803 record.getHandler().post(new Runnable() {
2804 @Override
2805 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002806 boolean isFinalRemoval = false;
2807 RuntimeException toThrow = null;
2808 try {
2809 callback.onCallDestroyed(call);
2810 } catch (RuntimeException e) {
2811 toThrow = e;
2812 }
2813 synchronized(Call.this) {
2814 mCallbackRecords.remove(record);
2815 if (mCallbackRecords.isEmpty()) {
2816 isFinalRemoval = true;
2817 }
2818 }
2819 if (isFinalRemoval) {
2820 mPhone.internalRemoveCall(call);
2821 }
2822 if (toThrow != null) {
2823 throw toThrow;
2824 }
Andrew Lee011728f2015-04-23 15:47:06 -07002825 }
2826 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002827 }
2828 }
2829
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002830 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002831 for (CallbackRecord<Callback> record : mCallbackRecords) {
2832 final Call call = this;
2833 final Callback callback = record.getCallback();
2834 record.getHandler().post(new Runnable() {
2835 @Override
2836 public void run() {
2837 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2838 }
2839 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002840 }
2841 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002842
2843 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002844 * Notifies listeners of an incoming connection event.
2845 * <p>
2846 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2847 *
2848 * @param event
2849 * @param extras
2850 */
2851 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2852 for (CallbackRecord<Callback> record : mCallbackRecords) {
2853 final Call call = this;
2854 final Callback callback = record.getCallback();
2855 record.getHandler().post(new Runnable() {
2856 @Override
2857 public void run() {
2858 callback.onConnectionEvent(call, event, extras);
2859 }
2860 });
2861 }
2862 }
2863
2864 /**
Hall Liu95d55872017-01-25 17:12:49 -08002865 * Notifies listeners of an RTT on/off change
2866 *
2867 * @param enabled True if RTT is now enabled, false otherwise
2868 */
2869 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2870 for (CallbackRecord<Callback> record : mCallbackRecords) {
2871 final Call call = this;
2872 final Callback callback = record.getCallback();
2873 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2874 }
2875 }
2876
2877 /**
2878 * Notifies listeners of a RTT mode change
2879 *
2880 * @param mode The new RTT mode
2881 */
2882 private void fireOnRttModeChanged(final int mode) {
2883 for (CallbackRecord<Callback> record : mCallbackRecords) {
2884 final Call call = this;
2885 final Callback callback = record.getCallback();
2886 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2887 }
2888 }
2889
2890 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002891 * Determines if two bundles are equal.
2892 *
2893 * @param bundle The original bundle.
2894 * @param newBundle The bundle to compare with.
2895 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2896 */
2897 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2898 if (bundle == null || newBundle == null) {
2899 return bundle == newBundle;
2900 }
2901
2902 if (bundle.size() != newBundle.size()) {
2903 return false;
2904 }
2905
2906 for(String key : bundle.keySet()) {
2907 if (key != null) {
2908 final Object value = bundle.get(key);
2909 final Object newValue = newBundle.get(key);
Grace Jia17005bd2022-05-12 12:49:02 -07002910 if (!newBundle.containsKey(key)) {
2911 return false;
2912 }
2913 if (value instanceof Bundle && newValue instanceof Bundle) {
2914 if (!areBundlesEqual((Bundle) value, (Bundle) newValue)) {
2915 return false;
2916 }
2917 }
2918 if (value instanceof byte[] && newValue instanceof byte[]) {
2919 if (!Arrays.equals((byte[]) value, (byte[]) newValue)) {
2920 return false;
2921 }
2922 } else if (!Objects.equals(value, newValue)) {
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002923 return false;
2924 }
2925 }
2926 }
2927 return true;
2928 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002929}