blob: a52614d5cda18f6d88fac79b0407a8e7c13bd291 [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
Grant Menke417190a2023-08-30 14:39:29 -070019import android.annotation.FlaggedApi;
Hall Liu95d55872017-01-25 17:12:49 -080020import android.annotation.IntDef;
Ravi Paluri404babb2020-01-23 19:02:44 +053021import android.annotation.NonNull;
Hall Liu95d55872017-01-25 17:12:49 -080022import android.annotation.Nullable;
Andrew Leeda80c872015-04-15 14:09:50 -070023import android.annotation.SystemApi;
Hall Liu6dfa2492019-10-01 17:20:39 -070024import android.annotation.TestApi;
Artur Satayev53ada2a2019-12-10 17:47:56 +000025import android.compat.annotation.UnsupportedAppUsage;
Tyler Gunn460b7d42020-05-15 10:19:32 -070026import android.content.pm.ServiceInfo;
Ihab Awade63fadb2014-07-09 21:52:04 -070027import android.net.Uri;
qing723dac62022-10-28 03:40:43 +000028import android.os.BadParcelableException;
Tyler Gunn6e3ecc42018-11-12 11:30:56 -080029import android.os.Build;
Nancy Chen10798dc2014-08-08 14:00:25 -070030import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070031import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080032import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070033
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -080034import com.android.internal.telecom.IVideoProvider;
Grant Menke417190a2023-08-30 14:39:29 -070035import com.android.server.telecom.flags.Flags;
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -080036
Hall Liu95d55872017-01-25 17:12:49 -080037import java.io.IOException;
38import java.io.InputStreamReader;
39import java.io.OutputStreamWriter;
Hall Liu95d55872017-01-25 17:12:49 -080040import java.lang.annotation.Retention;
41import java.lang.annotation.RetentionPolicy;
42import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070043import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070044import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070045import java.util.Collections;
46import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070047import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070048import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070049import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070050
51/**
52 * Represents an ongoing phone call that the in-call app should present to the user.
53 */
54public final class Call {
55 /**
56 * The state of a {@code Call} when newly created.
57 */
58 public static final int STATE_NEW = 0;
59
60 /**
61 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
62 */
63 public static final int STATE_DIALING = 1;
64
65 /**
66 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
67 */
68 public static final int STATE_RINGING = 2;
69
70 /**
71 * The state of a {@code Call} when in a holding state.
72 */
73 public static final int STATE_HOLDING = 3;
74
75 /**
76 * The state of a {@code Call} when actively supporting conversation.
77 */
78 public static final int STATE_ACTIVE = 4;
79
80 /**
81 * The state of a {@code Call} when no further voice or other communication is being
82 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
83 * is no longer active, and the local data transport has or inevitably will release resources
84 * associated with this {@code Call}.
85 */
86 public static final int STATE_DISCONNECTED = 7;
87
Nancy Chen5da0fd52014-07-08 14:16:17 -070088 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070089 * The state of an outgoing {@code Call} when waiting on user to select a
90 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070091 */
Santos Cordone3c507b2015-04-23 14:44:19 -070092 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
93
94 /**
95 * @hide
96 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
97 */
98 @Deprecated
99 @SystemApi
100 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -0700101
Nancy Chene20930f2014-08-07 16:17:21 -0700102 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -0700103 * The initial state of an outgoing {@code Call}.
104 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
105 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -0700106 */
107 public static final int STATE_CONNECTING = 9;
108
Nancy Chen513c8922014-09-17 14:47:20 -0700109 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700110 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
111 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
112 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
113 */
114 public static final int STATE_DISCONNECTING = 10;
115
116 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700117 * The state of an external call which is in the process of being pulled from a remote device to
118 * the local device.
119 * <p>
120 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
121 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
122 * <p>
123 * An {@link InCallService} will only see this state if it has the
124 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
125 * manifest.
126 */
127 public static final int STATE_PULLING_CALL = 11;
128
129 /**
Hall Liu6dfa2492019-10-01 17:20:39 -0700130 * The state of a call that is active with the network, but the audio from the call is
131 * being intercepted by an app on the local device. Telecom does not hold audio focus in this
132 * state, and the call will be invisible to the user except for a persistent notification.
133 */
134 public static final int STATE_AUDIO_PROCESSING = 12;
135
136 /**
137 * The state of a call that is being presented to the user after being in
138 * {@link #STATE_AUDIO_PROCESSING}. The call is still active with the network in this case, and
139 * Telecom will hold audio focus and play a ringtone if appropriate.
140 */
141 public static final int STATE_SIMULATED_RINGING = 13;
142
143 /**
Tyler Gunn1e406ca2021-03-18 16:47:14 -0700144 * @hide
145 */
146 @IntDef(prefix = { "STATE_" },
147 value = {
148 STATE_NEW,
149 STATE_DIALING,
150 STATE_RINGING,
151 STATE_HOLDING,
152 STATE_ACTIVE,
153 STATE_DISCONNECTED,
154 STATE_SELECT_PHONE_ACCOUNT,
155 STATE_CONNECTING,
156 STATE_DISCONNECTING,
157 STATE_PULLING_CALL,
158 STATE_AUDIO_PROCESSING,
159 STATE_SIMULATED_RINGING
160 })
161 @Retention(RetentionPolicy.SOURCE)
162 public @interface CallState {};
163
164 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700165 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
166 * extras. Used to pass the phone accounts to display on the front end to the user in order to
167 * select phone accounts to (for example) place a call.
Hall Liu34d9e242018-11-21 17:05:58 -0800168 * @deprecated Use the list from {@link #EXTRA_SUGGESTED_PHONE_ACCOUNTS} instead.
Nancy Chen513c8922014-09-17 14:47:20 -0700169 */
Hall Liu34d9e242018-11-21 17:05:58 -0800170 @Deprecated
Nancy Chen513c8922014-09-17 14:47:20 -0700171 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
172
mike dooley4af561f2016-12-20 08:55:17 -0800173 /**
Thomas Stuart5ca875eb2022-08-03 18:39:57 -0700174 * Extra key intended for {@link InCallService}s that notify the user of an incoming call. When
175 * EXTRA_IS_SUPPRESSED_BY_DO_NOT_DISTURB returns true, the {@link InCallService} should not
176 * interrupt the user of the incoming call because the call is being suppressed by Do Not
177 * Disturb settings.
178 *
179 * This extra will be removed from the {@link Call} object for {@link InCallService}s that do
180 * not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
181 */
182 public static final String EXTRA_IS_SUPPRESSED_BY_DO_NOT_DISTURB =
183 "android.telecom.extra.IS_SUPPRESSED_BY_DO_NOT_DISTURB";
184
185 /**
Hall Liu34d9e242018-11-21 17:05:58 -0800186 * Key for extra used to pass along a list of {@link PhoneAccountSuggestion}s to the in-call
187 * UI when a call enters the {@link #STATE_SELECT_PHONE_ACCOUNT} state. The list included here
188 * will have the same length and be in the same order as the list passed with
189 * {@link #AVAILABLE_PHONE_ACCOUNTS}.
190 */
191 public static final String EXTRA_SUGGESTED_PHONE_ACCOUNTS =
192 "android.telecom.extra.SUGGESTED_PHONE_ACCOUNTS";
193
194 /**
mike dooley91217422017-03-09 12:58:42 -0800195 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
196 * when the last outgoing emergency call was made. This is used to identify potential emergency
197 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800198 */
199 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
200 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
201
Usman Abdullahb0dc29a2019-03-06 15:54:56 -0800202
203 /**
204 * Extra key used to indicate whether a {@link CallScreeningService} has requested to silence
205 * the ringtone for a call. If the {@link InCallService} declares
206 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} in its manifest, it should not
207 * play a ringtone for an incoming call with this extra key set.
208 */
209 public static final String EXTRA_SILENT_RINGING_REQUESTED =
210 "android.telecom.extra.SILENT_RINGING_REQUESTED";
211
Tyler Gunn8bf76572017-04-06 15:30:08 -0700212 /**
Tyler Gunnd5821842021-02-05 11:12:57 -0800213 * Event reported from the Telecom stack to report an in-call diagnostic message which the
214 * dialer app may opt to display to the user. A diagnostic message is used to communicate
215 * scenarios the device has detected which may impact the quality of the ongoing call.
216 * <p>
217 * For example a problem with a bluetooth headset may generate a recommendation for the user to
218 * try using the speakerphone instead, or if the device detects it has entered a poor service
219 * area, the user might be warned so that they can finish their call prior to it dropping.
220 * <p>
221 * A diagnostic message is considered persistent in nature. When the user enters a poor service
222 * area, for example, the accompanying diagnostic message persists until they leave the area
223 * of poor service. Each message is accompanied with a {@link #EXTRA_DIAGNOSTIC_MESSAGE_ID}
224 * which uniquely identifies the diagnostic condition being reported. The framework raises a
225 * call event of type {@link #EVENT_CLEAR_DIAGNOSTIC_MESSAGE} when the condition reported has
226 * been cleared. The dialer app should display the diagnostic message until it is cleared.
227 * If multiple diagnostic messages are sent with different IDs (which have not yet been cleared)
228 * the dialer app should prioritize the most recently received message, but still provide the
229 * user with a means to review past messages.
230 * <p>
231 * The text of the message is found in {@link #EXTRA_DIAGNOSTIC_MESSAGE} in the form of a human
232 * readable {@link CharSequence} which is intended for display in the call UX.
233 * <p>
234 * The telecom framework audibly notifies the user of the presence of a diagnostic message, so
235 * the dialer app needs only to concern itself with visually displaying the message.
236 * <p>
237 * The dialer app receives this event via
238 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
239 */
240 public static final String EVENT_DISPLAY_DIAGNOSTIC_MESSAGE =
241 "android.telecom.event.DISPLAY_DIAGNOSTIC_MESSAGE";
242
243 /**
244 * Event reported from the telecom framework when a diagnostic message previously raised with
245 * {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE} has cleared and is no longer pertinent.
246 * <p>
247 * The {@link #EXTRA_DIAGNOSTIC_MESSAGE_ID} indicates the diagnostic message which has been
248 * cleared.
249 * <p>
250 * The dialer app receives this event via
251 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
252 */
253 public static final String EVENT_CLEAR_DIAGNOSTIC_MESSAGE =
254 "android.telecom.event.CLEAR_DIAGNOSTIC_MESSAGE";
255
256 /**
257 * Integer extra representing a message ID for a message posted via
258 * {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE}. Used to ensure that the dialer app knows when
259 * the message in question has cleared via {@link #EVENT_CLEAR_DIAGNOSTIC_MESSAGE}.
260 */
261 public static final String EXTRA_DIAGNOSTIC_MESSAGE_ID =
262 "android.telecom.extra.DIAGNOSTIC_MESSAGE_ID";
263
264 /**
265 * {@link CharSequence} extra used with {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE}. This is the
266 * diagnostic message the dialer app should display.
267 */
268 public static final String EXTRA_DIAGNOSTIC_MESSAGE =
269 "android.telecom.extra.DIAGNOSTIC_MESSAGE";
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800270
271 /**
Thomas Stuart4fab0832023-12-28 16:35:42 -0800272 * Boolean indicating that the call is a verified business call.
273 *
274 * {@link Connection#setExtras(Bundle)} or {@link Connection#putExtras(Bundle)}
275 * should be used to notify Telecom this extra has been set.
276 */
277 @FlaggedApi(Flags.FLAG_BUSINESS_CALL_COMPOSER)
278 public static final String EXTRA_IS_BUSINESS_CALL =
279 "android.telecom.extra.IS_BUSINESS_CALL";
280
281 /**
282 * String value indicating the asserted display name reported via
283 * ImsCallProfile#EXTRA_ASSERTED_DISPLAY_NAME.
284 *
285 * {@link Connection#setExtras(Bundle)} or {@link Connection#putExtras(Bundle)}
286 * should be used to notify Telecom this extra has been set.
287 */
288 @FlaggedApi(Flags.FLAG_BUSINESS_CALL_COMPOSER)
289 public static final String EXTRA_ASSERTED_DISPLAY_NAME =
290 "android.telecom.extra.ASSERTED_DISPLAY_NAME";
291
292 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800293 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
294 * call because they have declined to answer it. This typically means that they are unable
295 * to answer the call at this time and would prefer it be sent to voicemail.
296 */
297 public static final int REJECT_REASON_DECLINED = 1;
298
299 /**
300 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
301 * call because it is an unwanted call. This allows the user to indicate that they are
302 * rejecting a call because it is likely a nuisance call.
303 */
304 public static final int REJECT_REASON_UNWANTED = 2;
305
306 /**
307 * @hide
308 */
309 @IntDef(prefix = { "REJECT_REASON_" },
310 value = {REJECT_REASON_DECLINED, REJECT_REASON_UNWANTED})
311 @Retention(RetentionPolicy.SOURCE)
312 public @interface RejectReason {};
313
Ihab Awade63fadb2014-07-09 21:52:04 -0700314 public static class Details {
Tyler Gunn94f8f112018-12-17 09:56:11 -0800315 /** @hide */
316 @Retention(RetentionPolicy.SOURCE)
317 @IntDef(
318 prefix = { "DIRECTION_" },
319 value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
320 public @interface CallDirection {}
321
322 /**
323 * Indicates that the call is neither and incoming nor an outgoing call. This can be the
324 * case for calls reported directly by a {@link ConnectionService} in special cases such as
325 * call handovers.
326 */
327 public static final int DIRECTION_UNKNOWN = -1;
328
329 /**
330 * Indicates that the call is an incoming call.
331 */
332 public static final int DIRECTION_INCOMING = 0;
333
334 /**
335 * Indicates that the call is an outgoing call.
336 */
337 public static final int DIRECTION_OUTGOING = 1;
338
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800339 /** Call can currently be put on hold or unheld. */
340 public static final int CAPABILITY_HOLD = 0x00000001;
341
342 /** Call supports the hold feature. */
343 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
344
345 /**
346 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
347 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
348 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
349 * capability allows a merge button to be shown while the conference call is in the foreground
350 * of the in-call UI.
351 * <p>
352 * This is only intended for use by a {@link Conference}.
353 */
354 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
355
356 /**
357 * Calls within a conference can be swapped between foreground and background.
358 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
359 * <p>
360 * This is only intended for use by a {@link Conference}.
361 */
362 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
363
364 /**
365 * @hide
366 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700367 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800368
369 /** Call supports responding via text option. */
370 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
371
372 /** Call can be muted. */
373 public static final int CAPABILITY_MUTE = 0x00000040;
374
375 /**
376 * Call supports conference call management. This capability only applies to {@link Conference}
377 * calls which can have {@link Connection}s as children.
378 */
379 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
380
381 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700382 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800383 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700384 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800385
386 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700387 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800388 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700389 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800390
391 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700392 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800393 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700394 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700395 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800396
397 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700398 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800399 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700400 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
401
402 /**
403 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700404 */
405 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
406
407 /**
408 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700409 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700410 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700411 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800412
413 /**
414 * Call is able to be separated from its parent {@code Conference}, if any.
415 */
416 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
417
418 /**
419 * Call is able to be individually disconnected when in a {@code Conference}.
420 */
421 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
422
423 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500424 * Speed up audio setup for MT call.
425 * @hide
426 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700427 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
428
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700429 /**
430 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700431 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800432 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
433 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
434 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700435 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800436 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700437 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
438
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700439 /**
440 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700441 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700442 */
443 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
444
Bryce Lee81901682015-08-28 16:38:02 -0700445 /**
446 * Call sends responses through connection.
447 * @hide
448 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800449 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
450
451 /**
452 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
453 * <p>
454 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
455 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
456 * downgraded from a video call back to a VideoState of
457 * {@link VideoProfile#STATE_AUDIO_ONLY}.
458 * <p>
459 * Intuitively, a call which can be downgraded to audio should also have local and remote
460 * video
461 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
462 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
463 */
464 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700465
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700466 /**
467 * When set for an external call, indicates that this {@code Call} can be pulled from a
468 * remote device to the current device.
469 * <p>
470 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
471 * <p>
472 * An {@link InCallService} will only see calls with this capability if it has the
473 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
474 * in its manifest.
475 * <p>
476 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700477 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700478 */
479 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
480
Pooja Jaind34698d2017-12-28 14:15:31 +0530481 /** Call supports the deflect feature. */
482 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
483
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800484 /**
485 * Call supports adding participants to the call via
Grace Jia8587ee52020-07-10 15:42:32 -0700486 * {@link #addConferenceParticipants(List)}. Once participants are added, the call becomes
487 * an adhoc conference call ({@link #PROPERTY_IS_ADHOC_CONFERENCE}).
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800488 */
Ravi Paluri404babb2020-01-23 19:02:44 +0530489 public static final int CAPABILITY_ADD_PARTICIPANT = 0x02000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530490
491 /**
492 * When set for a call, indicates that this {@code Call} can be transferred to another
493 * number.
Tyler Gunn460360d2020-07-29 10:21:45 -0700494 * Call supports the confirmed and unconfirmed call transfer feature.
Ravi Palurif4b38e72020-02-05 12:35:41 +0530495 *
496 * @hide
497 */
498 public static final int CAPABILITY_TRANSFER = 0x04000000;
499
500 /**
501 * When set for a call, indicates that this {@code Call} can be transferred to another
502 * ongoing call.
503 * Call supports the consultative call transfer feature.
504 *
505 * @hide
506 */
507 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x08000000;
508
Alvin Dey2f37d772018-05-18 23:16:10 +0530509 /**
510 * Indicates whether the remote party supports RTT or not to the UI.
511 */
512
513 public static final int CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT = 0x10000000;
514
Tyler Gunnd11a3152015-03-18 13:09:14 -0700515 //******************************************************************************************
Alvin Dey2f37d772018-05-18 23:16:10 +0530516 // Next CAPABILITY value: 0x20000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700517 //******************************************************************************************
518
519 /**
520 * Whether the call is currently a conference.
521 */
522 public static final int PROPERTY_CONFERENCE = 0x00000001;
523
524 /**
525 * Whether the call is a generic conference, where we do not know the precise state of
526 * participants in the conference (eg. on CDMA).
527 */
528 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
529
530 /**
531 * Whether the call is made while the device is in emergency callback mode.
532 */
533 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
534
535 /**
536 * Connection is using WIFI.
537 */
538 public static final int PROPERTY_WIFI = 0x00000008;
539
540 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700541 * When set, the UI should indicate to the user that a call is using high definition
542 * audio.
543 * <p>
544 * The underlying {@link ConnectionService} is responsible for reporting this
545 * property. It is important to note that this property is not intended to report the
546 * actual audio codec being used for a Call, but whether the call should be indicated
547 * to the user as high definition.
548 * <p>
549 * The Android Telephony stack reports this property for calls based on a number
550 * of factors, including which audio codec is used and whether a call is using an HD
551 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
552 * and in these cases this property will not be set for a call even if the underlying audio
553 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700554 */
555 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
556
Tony Maka68dcce2015-12-17 09:31:18 +0000557 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100558 * Whether the call is associated with the work profile.
559 */
560 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
561
562 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700563 * When set, indicates that this {@code Call} does not actually exist locally for the
564 * {@link ConnectionService}.
565 * <p>
566 * Consider, for example, a scenario where a user has two phones with the same phone number.
567 * When a user places a call on one device, the telephony stack can represent that call on
568 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700569 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700570 * <p>
571 * An {@link InCallService} will only see calls with this property if it has the
572 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
573 * in its manifest.
574 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700575 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700576 */
577 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
578
Brad Ebinger15847072016-05-18 11:08:36 -0700579 /**
580 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
581 */
582 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
583
Tyler Gunn24e18332017-02-10 09:42:49 -0800584 /**
585 * Indicates that the call is from a self-managed {@link ConnectionService}.
586 * <p>
587 * See also {@link Connection#PROPERTY_SELF_MANAGED}
588 */
589 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
590
Eric Erfanianec881872017-12-06 16:27:53 -0800591 /**
592 * Indicates the call used Assisted Dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700593 *
594 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanianec881872017-12-06 16:27:53 -0800595 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800596 public static final int PROPERTY_ASSISTED_DIALING = 0x00000200;
Eric Erfanianec881872017-12-06 16:27:53 -0800597
Hall Liue9041242018-02-09 16:40:03 -0800598 /**
599 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
600 * {@link RttCall} object that is used to send and receive text.
601 */
602 public static final int PROPERTY_RTT = 0x00000400;
603
Tyler Gunn5bd90852018-09-21 09:37:07 -0700604 /**
605 * Indicates that the call has been identified as the network as an emergency call. This
606 * property may be set for both incoming and outgoing calls which the network identifies as
607 * emergency calls.
608 */
609 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
610
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700611 /**
612 * Indicates that the call is using VoIP audio mode.
613 * <p>
614 * When this property is set, the {@link android.media.AudioManager} audio mode for this
615 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
616 * property is not set, the audio mode for this call will be
617 * {@link android.media.AudioManager#MODE_IN_CALL}.
618 * <p>
619 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
620 * <p>
621 * You can use this property to determine whether an un-answered incoming call or a held
622 * call will use VoIP audio mode (if the call does not currently have focus, the system
623 * audio mode may not reflect the mode the call will use).
624 */
625 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
626
Ravi Paluri80aa2142019-12-02 11:57:37 +0530627 /**
628 * Indicates that the call is an adhoc conference call. This property can be set for both
Grace Jia8587ee52020-07-10 15:42:32 -0700629 * incoming and outgoing calls. An adhoc conference call is formed using
630 * {@link #addConferenceParticipants(List)},
631 * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}, or
632 * {@link TelecomManager#startConference(List, Bundle)}, rather than by merging existing
633 * call using {@link #conference(Call)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530634 */
635 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 0x00002000;
636
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800637 /**
Sooraj Sasindranfa1e57a2021-03-22 13:44:14 -0700638 * Connection is using cross sim technology.
639 * <p>
640 * Indicates that the {@link Connection} is using a cross sim technology which would
641 * register IMS over internet APN of default data subscription.
642 * <p>
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800643 */
644 public static final int PROPERTY_CROSS_SIM = 0x00004000;
645
Grant Menke6ca706b2023-08-23 07:46:09 -0700646 /**
647 * The connection is using transactional call APIs.
648 * <p>
649 * The underlying connection was added as a transactional call via the
650 * {@link TelecomManager#addCall} API.
651 */
Grant Menke417190a2023-08-30 14:39:29 -0700652 @FlaggedApi(Flags.FLAG_VOIP_APP_ACTIONS_SUPPORT)
Grant Menke6ca706b2023-08-23 07:46:09 -0700653 public static final int PROPERTY_IS_TRANSACTIONAL = 0x00008000;
654
Andrew Lee2378ea72015-04-29 14:38:11 -0700655 //******************************************************************************************
Grant Menke6ca706b2023-08-23 07:46:09 -0700656 // Next PROPERTY value: 0x00010000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700657 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800658
Tyler Gunn1e406ca2021-03-18 16:47:14 -0700659 private final @CallState int mState;
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800660 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700661 private final Uri mHandle;
662 private final int mHandlePresentation;
663 private final String mCallerDisplayName;
664 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700665 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700666 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700667 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800668 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700669 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700670 private final long mConnectTimeMillis;
671 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700672 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700673 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700674 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700675 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700676 private final long mCreationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -0800677 private final String mContactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800678 private final @CallDirection int mCallDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700679 private final @Connection.VerificationStatus int mCallerNumberVerificationStatus;
Edgar Arriagae5bec822022-10-14 14:25:43 -0700680 private final Uri mContactPhotoUri;
Ihab Awade63fadb2014-07-09 21:52:04 -0700681
682 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800683 * Whether the supplied capabilities supports the specified capability.
684 *
685 * @param capabilities A bit field of capabilities.
686 * @param capability The capability to check capabilities for.
687 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800688 */
689 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800690 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800691 }
692
693 /**
694 * Whether the capabilities of this {@code Details} supports the specified capability.
695 *
696 * @param capability The capability to check capabilities for.
697 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800698 */
699 public boolean can(int capability) {
700 return can(mCallCapabilities, capability);
701 }
702
703 /**
704 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
705 *
706 * @param capabilities A capability bit field.
707 * @return A human readable string representation.
708 */
709 public static String capabilitiesToString(int capabilities) {
710 StringBuilder builder = new StringBuilder();
711 builder.append("[Capabilities:");
712 if (can(capabilities, CAPABILITY_HOLD)) {
713 builder.append(" CAPABILITY_HOLD");
714 }
715 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
716 builder.append(" CAPABILITY_SUPPORT_HOLD");
717 }
718 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
719 builder.append(" CAPABILITY_MERGE_CONFERENCE");
720 }
721 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
722 builder.append(" CAPABILITY_SWAP_CONFERENCE");
723 }
724 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
725 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
726 }
727 if (can(capabilities, CAPABILITY_MUTE)) {
728 builder.append(" CAPABILITY_MUTE");
729 }
730 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
731 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
732 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700733 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
734 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
735 }
736 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
737 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
738 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700739 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
740 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800741 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700742 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
743 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
744 }
745 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
746 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
747 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800748 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
749 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
750 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700751 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
752 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800753 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500754 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700755 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500756 }
Rekha Kumar07366812015-03-24 16:42:31 -0700757 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
758 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
759 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700760 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
761 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
762 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700763 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
764 builder.append(" CAPABILITY_CAN_PULL_CALL");
765 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530766 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
767 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
768 }
Ravi Paluri404babb2020-01-23 19:02:44 +0530769 if (can(capabilities, CAPABILITY_ADD_PARTICIPANT)) {
770 builder.append(" CAPABILITY_ADD_PARTICIPANT");
771 }
Ravi Palurif4b38e72020-02-05 12:35:41 +0530772 if (can(capabilities, CAPABILITY_TRANSFER)) {
773 builder.append(" CAPABILITY_TRANSFER");
774 }
775 if (can(capabilities, CAPABILITY_TRANSFER_CONSULTATIVE)) {
776 builder.append(" CAPABILITY_TRANSFER_CONSULTATIVE");
777 }
Alvin Dey2f37d772018-05-18 23:16:10 +0530778 if (can(capabilities, CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT)) {
779 builder.append(" CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT");
780 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800781 builder.append("]");
782 return builder.toString();
783 }
784
785 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700786 * Whether the supplied properties includes the specified property.
787 *
788 * @param properties A bit field of properties.
789 * @param property The property to check properties for.
790 * @return Whether the specified property is supported.
791 */
792 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800793 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700794 }
795
796 /**
797 * Whether the properties of this {@code Details} includes the specified property.
798 *
799 * @param property The property to check properties for.
800 * @return Whether the specified property is supported.
801 */
802 public boolean hasProperty(int property) {
803 return hasProperty(mCallProperties, property);
804 }
805
806 /**
807 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
808 *
809 * @param properties A property bit field.
810 * @return A human readable string representation.
811 */
812 public static String propertiesToString(int properties) {
813 StringBuilder builder = new StringBuilder();
814 builder.append("[Properties:");
815 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
816 builder.append(" PROPERTY_CONFERENCE");
817 }
818 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
819 builder.append(" PROPERTY_GENERIC_CONFERENCE");
820 }
821 if (hasProperty(properties, PROPERTY_WIFI)) {
822 builder.append(" PROPERTY_WIFI");
823 }
824 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
825 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
826 }
827 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700828 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700829 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700830 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
831 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
832 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700833 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700834 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
835 }
Tyler Gunnc9503d62020-01-27 10:30:51 -0800836 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800837 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
838 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700839 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
840 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
841 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700842 if (hasProperty(properties, PROPERTY_RTT)) {
843 builder.append(" PROPERTY_RTT");
844 }
845 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
846 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
847 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530848 if (hasProperty(properties, PROPERTY_IS_ADHOC_CONFERENCE)) {
849 builder.append(" PROPERTY_IS_ADHOC_CONFERENCE");
850 }
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800851 if (hasProperty(properties, PROPERTY_CROSS_SIM)) {
852 builder.append(" PROPERTY_CROSS_SIM");
853 }
Grant Menke6ca706b2023-08-23 07:46:09 -0700854 if (hasProperty(properties, PROPERTY_IS_TRANSACTIONAL)) {
855 builder.append(" PROPERTY_IS_TRANSACTIONAL");
856 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700857 builder.append("]");
858 return builder.toString();
859 }
860
Tyler Gunn1e406ca2021-03-18 16:47:14 -0700861 /**
862 * @return the state of the {@link Call} represented by this {@link Call.Details}.
863 */
864 public final @CallState int getState() {
865 return mState;
866 }
867
Grant Menke626dd262023-07-24 15:19:36 -0700868 /**
869 * @return the Telecom identifier associated with this {@link Call} . This is not a stable
870 * identifier and is not guaranteed to be unique across device reboots.
871 */
Grant Menke37155c82023-10-10 14:17:26 -0700872 @FlaggedApi(Flags.FLAG_CALL_DETAILS_ID_CHANGES)
Grant Menke626dd262023-07-24 15:19:36 -0700873 public @NonNull String getId() { return mTelecomCallId; }
874
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800875 /** {@hide} */
Hall Liu31de23d2019-10-11 15:38:29 -0700876 @TestApi
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800877 public String getTelecomCallId() {
878 return mTelecomCallId;
879 }
880
Andrew Lee2378ea72015-04-29 14:38:11 -0700881 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700882 * @return The handle (e.g., phone number) to which the {@code Call} is currently
883 * connected.
884 */
885 public Uri getHandle() {
886 return mHandle;
887 }
888
889 /**
890 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700891 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700892 */
893 public int getHandlePresentation() {
894 return mHandlePresentation;
895 }
896
897 /**
Edgar Arriagae5bec822022-10-14 14:25:43 -0700898 * @return The contact photo URI which corresponds to
899 * {@link android.provider.ContactsContract.PhoneLookup#PHOTO_URI}, or {@code null} if the
900 * lookup is not yet complete, if there's no contacts entry for the caller,
901 * or if the {@link InCallService} does not hold the
902 * {@link android.Manifest.permission#READ_CONTACTS} permission.
903 */
904 public @Nullable Uri getContactPhotoUri() {
905 return mContactPhotoUri;
906 }
907
908 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800909 * The display name for the caller.
910 * <p>
911 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800912 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700913 * @return The display name for the caller.
914 */
915 public String getCallerDisplayName() {
916 return mCallerDisplayName;
917 }
918
919 /**
920 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700921 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700922 */
923 public int getCallerDisplayNamePresentation() {
924 return mCallerDisplayNamePresentation;
925 }
926
927 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700928 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
929 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700930 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700931 public PhoneAccountHandle getAccountHandle() {
932 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700933 }
934
935 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800936 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
937 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700938 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700939 public int getCallCapabilities() {
940 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700941 }
942
943 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700944 * @return A bitmask of the properties of the {@code Call}, as defined by the various
945 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700946 */
947 public int getCallProperties() {
948 return mCallProperties;
949 }
950
951 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800952 * @return a bitmask of the audio routes available for the call.
953 *
954 * @hide
955 */
956 public int getSupportedAudioRoutes() {
957 return mSupportedAudioRoutes;
958 }
959
960 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700961 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700962 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700963 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700964 public DisconnectCause getDisconnectCause() {
965 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700966 }
967
968 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700969 * Returns the time the {@link Call} connected (i.e. became active). This information is
970 * updated periodically, but user interfaces should not rely on this to display the "call
971 * time clock". For the time when the call was first added to Telecom, see
972 * {@link #getCreationTimeMillis()}.
973 *
974 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700975 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700976 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700977 return mConnectTimeMillis;
978 }
979
980 /**
981 * @return Information about any calling gateway the {@code Call} may be using.
982 */
983 public GatewayInfo getGatewayInfo() {
984 return mGatewayInfo;
985 }
986
Andrew Lee7a341382014-07-15 17:05:08 -0700987 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700988 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700989 */
990 public int getVideoState() {
991 return mVideoState;
992 }
993
Ihab Awad5d0410f2014-07-30 10:07:40 -0700994 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700995 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700996 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700997 */
998 public StatusHints getStatusHints() {
999 return mStatusHints;
1000 }
1001
Nancy Chen10798dc2014-08-08 14:00:25 -07001002 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001003 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -07001004 */
1005 public Bundle getExtras() {
1006 return mExtras;
1007 }
1008
Santos Cordon6b7f9552015-05-27 17:21:45 -07001009 /**
1010 * @return The extras used with the original intent to place this call.
1011 */
1012 public Bundle getIntentExtras() {
1013 return mIntentExtras;
1014 }
1015
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001016 /**
1017 * Returns the time when the call was first created and added to Telecom. This is the same
1018 * time that is logged as the start time in the Call Log (see
1019 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
1020 * (became active), see {@link #getConnectTimeMillis()}.
1021 *
1022 * @return The creation time of the call, in millis since the epoch.
1023 */
1024 public long getCreationTimeMillis() {
1025 return mCreationTimeMillis;
1026 }
1027
Tyler Gunnd081f042018-12-04 12:56:45 -08001028 /**
Hall Liuef98bf82020-01-09 15:22:44 -08001029 * Returns the name of the caller on the remote end, as derived from a
1030 * {@link android.provider.ContactsContract} lookup of the call's handle.
1031 * @return The name of the caller, or {@code null} if the lookup is not yet complete, if
1032 * there's no contacts entry for the caller, or if the {@link InCallService} does
1033 * not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
1034 */
1035 public @Nullable String getContactDisplayName() {
1036 return mContactDisplayName;
1037 }
1038
1039 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -08001040 * Indicates whether the call is an incoming or outgoing call.
1041 * @return The call's direction.
1042 */
1043 public @CallDirection int getCallDirection() {
1044 return mCallDirection;
1045 }
1046
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001047 /**
1048 * Gets the verification status for the phone number of an incoming call as identified in
1049 * ATIS-1000082.
Tyler Gunn9c642492020-10-08 13:37:03 -07001050 * <p>
1051 * For incoming calls, the number verification status indicates whether the device was
1052 * able to verify the authenticity of the calling number using the STIR process outlined
1053 * in ATIS-1000082. {@link Connection#VERIFICATION_STATUS_NOT_VERIFIED} indicates that
1054 * the network was not able to use STIR to verify the caller's number (i.e. nothing is
1055 * known regarding the authenticity of the number.
1056 * {@link Connection#VERIFICATION_STATUS_PASSED} indicates that the network was able to
1057 * use STIR to verify the caller's number. This indicates that the network has a high
1058 * degree of confidence that the incoming call actually originated from the indicated
1059 * number. {@link Connection#VERIFICATION_STATUS_FAILED} indicates that the network's
1060 * STIR verification did not pass. This indicates that the incoming call may not
1061 * actually be from the indicated number. This could occur if, for example, the caller
1062 * is using an impersonated phone number.
1063 * <p>
1064 * A {@link CallScreeningService} can use this information to help determine if an
1065 * incoming call is potentially an unwanted call. A verification status of
1066 * {@link Connection#VERIFICATION_STATUS_FAILED} indicates that an incoming call may not
1067 * actually be from the number indicated on the call (i.e. impersonated number) and that it
1068 * should potentially be blocked. Likewise,
1069 * {@link Connection#VERIFICATION_STATUS_PASSED} can be used as a positive signal to
1070 * help clarify that the incoming call is originating from the indicated number and it
1071 * is less likely to be an undesirable call.
1072 * <p>
1073 * An {@link InCallService} can use this information to provide a visual indicator to the
1074 * user regarding the verification status of a call and to help identify calls from
1075 * potentially impersonated numbers.
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001076 * @return the verification status.
1077 */
1078 public @Connection.VerificationStatus int getCallerNumberVerificationStatus() {
1079 return mCallerNumberVerificationStatus;
1080 }
1081
Ihab Awade63fadb2014-07-09 21:52:04 -07001082 @Override
1083 public boolean equals(Object o) {
1084 if (o instanceof Details) {
1085 Details d = (Details) o;
1086 return
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001087 Objects.equals(mState, d.mState) &&
Ihab Awade63fadb2014-07-09 21:52:04 -07001088 Objects.equals(mHandle, d.mHandle) &&
1089 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
1090 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
1091 Objects.equals(mCallerDisplayNamePresentation,
1092 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -07001093 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -07001094 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -07001095 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001096 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -07001097 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -07001098 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -07001099 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -07001100 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001101 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001102 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -08001103 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Hall Liuef98bf82020-01-09 15:22:44 -08001104 Objects.equals(mContactDisplayName, d.mContactDisplayName) &&
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001105 Objects.equals(mCallDirection, d.mCallDirection) &&
1106 Objects.equals(mCallerNumberVerificationStatus,
Edgar Arriagae5bec822022-10-14 14:25:43 -07001107 d.mCallerNumberVerificationStatus) &&
1108 Objects.equals(mContactPhotoUri, d.mContactPhotoUri);
Ihab Awade63fadb2014-07-09 21:52:04 -07001109 }
1110 return false;
1111 }
1112
1113 @Override
1114 public int hashCode() {
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001115 return Objects.hash(mState,
1116 mHandle,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001117 mHandlePresentation,
1118 mCallerDisplayName,
1119 mCallerDisplayNamePresentation,
1120 mAccountHandle,
1121 mCallCapabilities,
1122 mCallProperties,
1123 mDisconnectCause,
1124 mConnectTimeMillis,
1125 mGatewayInfo,
1126 mVideoState,
1127 mStatusHints,
1128 mExtras,
1129 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001130 mCreationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001131 mContactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001132 mCallDirection,
Edgar Arriagae5bec822022-10-14 14:25:43 -07001133 mCallerNumberVerificationStatus,
1134 mContactPhotoUri);
Ihab Awade63fadb2014-07-09 21:52:04 -07001135 }
1136
1137 /** {@hide} */
1138 public Details(
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001139 @CallState int state,
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001140 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -07001141 Uri handle,
1142 int handlePresentation,
1143 String callerDisplayName,
1144 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -07001145 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -07001146 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -07001147 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001148 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -07001149 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -07001150 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -07001151 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -07001152 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -07001153 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001154 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001155 long creationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001156 String contactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001157 int callDirection,
Edgar Arriagae5bec822022-10-14 14:25:43 -07001158 int callerNumberVerificationStatus,
1159 Uri contactPhotoUri) {
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001160 mState = state;
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001161 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001162 mHandle = handle;
1163 mHandlePresentation = handlePresentation;
1164 mCallerDisplayName = callerDisplayName;
1165 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -07001166 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -07001167 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -07001168 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001169 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -07001170 mConnectTimeMillis = connectTimeMillis;
1171 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -07001172 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -07001173 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -07001174 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001175 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001176 mCreationTimeMillis = creationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -08001177 mContactDisplayName = contactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -08001178 mCallDirection = callDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001179 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
Edgar Arriagae5bec822022-10-14 14:25:43 -07001180 mContactPhotoUri = contactPhotoUri;
Ihab Awade63fadb2014-07-09 21:52:04 -07001181 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001182
1183 /** {@hide} */
1184 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
1185 return new Details(
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001186 parcelableCall.getState(),
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001187 parcelableCall.getId(),
1188 parcelableCall.getHandle(),
1189 parcelableCall.getHandlePresentation(),
1190 parcelableCall.getCallerDisplayName(),
1191 parcelableCall.getCallerDisplayNamePresentation(),
1192 parcelableCall.getAccountHandle(),
1193 parcelableCall.getCapabilities(),
1194 parcelableCall.getProperties(),
1195 parcelableCall.getDisconnectCause(),
1196 parcelableCall.getConnectTimeMillis(),
1197 parcelableCall.getGatewayInfo(),
1198 parcelableCall.getVideoState(),
1199 parcelableCall.getStatusHints(),
1200 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001201 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -08001202 parcelableCall.getCreationTimeMillis(),
Hall Liuef98bf82020-01-09 15:22:44 -08001203 parcelableCall.getContactDisplayName(),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001204 parcelableCall.getCallDirection(),
Edgar Arriagae5bec822022-10-14 14:25:43 -07001205 parcelableCall.getCallerNumberVerificationStatus(),
1206 parcelableCall.getContactPhotoUri()
1207 );
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001208 }
Santos Cordon3c20d632016-02-25 16:12:35 -08001209
1210 @Override
1211 public String toString() {
1212 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001213 sb.append("[id: ");
1214 sb.append(mTelecomCallId);
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001215 sb.append(", state: ");
1216 sb.append(Call.stateToString(mState));
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001217 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -08001218 sb.append(mAccountHandle);
1219 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001220 sb.append(Log.piiHandle(mHandle));
1221 sb.append(", hdlPres: ");
1222 sb.append(mHandlePresentation);
1223 sb.append(", videoState: ");
1224 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -08001225 sb.append(", caps: ");
1226 sb.append(capabilitiesToString(mCallCapabilities));
1227 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001228 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001229 sb.append("]");
1230 return sb.toString();
1231 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001232 }
1233
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001234 /**
1235 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1236 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1237 * implementation.
1238 * <p>
1239 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1240 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1241 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1242 * {@link Callback} implementation, if desired.
1243 * <p>
1244 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1245 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1246 * (typically in {@link InCallService#onCallRemoved(Call)}).
1247 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1248 * reach your implementation of {@link Callback}, so it is important to register your callback
1249 * as soon as your {@link InCallService} is notified of a new call via
1250 * {@link InCallService#onCallAdded(Call)}.
1251 */
Andrew Leeda80c872015-04-15 14:09:50 -07001252 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001253 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001254 * @hide
1255 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001256 @IntDef(prefix = { "HANDOVER_" },
1257 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001258 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001259 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001260 @Retention(RetentionPolicy.SOURCE)
1261 public @interface HandoverFailureErrors {}
1262
1263 /**
1264 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001265 * to handover the call to rejects the handover request.
1266 * <p>
1267 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1268 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1269 * {@code null} {@link Connection} from
1270 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1271 * ConnectionRequest)}.
1272 * <p>
1273 * For more information on call handovers, see
1274 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001275 */
1276 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1277
1278 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001279 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1280 * is initiated but the source or destination app does not support handover.
1281 * <p>
1282 * Will be returned when a handover is requested via
1283 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1284 * {@link PhoneAccountHandle} does not declare
1285 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1286 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1287 * {@link Details#getAccountHandle()}) does not declare
1288 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1289 * <p>
1290 * For more information on call handovers, see
1291 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001292 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001293 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001294
1295 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001296 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1297 * user rejects the handover request.
1298 * <p>
1299 * For more information on call handovers, see
1300 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001301 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001302 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001303
Sanket Padawe85291f62017-12-01 13:59:27 -08001304 /**
1305 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1306 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001307 * <p>
1308 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1309 * called on an emergency call, or if any other call is an emergency call.
1310 * <p>
1311 * Handovers are not permitted while there are ongoing emergency calls.
1312 * <p>
1313 * For more information on call handovers, see
1314 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001315 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001316 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001317
Tyler Gunn9d127732018-03-02 15:45:51 -08001318 /**
1319 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1320 * fails for an unknown reason.
1321 * <p>
1322 * For more information on call handovers, see
1323 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1324 */
1325 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001326
1327 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001328 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1329 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001330 * @param call The {@code Call} invoking this method.
1331 * @param state The new state of the {@code Call}.
1332 */
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001333 public void onStateChanged(Call call, @CallState int state) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001334
1335 /**
1336 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1337 *
1338 * @param call The {@code Call} invoking this method.
1339 * @param parent The new parent of the {@code Call}.
1340 */
1341 public void onParentChanged(Call call, Call parent) {}
1342
1343 /**
1344 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1345 *
1346 * @param call The {@code Call} invoking this method.
1347 * @param children The new children of the {@code Call}.
1348 */
1349 public void onChildrenChanged(Call call, List<Call> children) {}
1350
1351 /**
1352 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1353 *
1354 * @param call The {@code Call} invoking this method.
1355 * @param details A {@code Details} object describing the {@code Call}.
1356 */
1357 public void onDetailsChanged(Call call, Details details) {}
1358
1359 /**
1360 * Invoked when the text messages that can be used as responses to the incoming
1361 * {@code Call} are loaded from the relevant database.
1362 * See {@link #getCannedTextResponses()}.
1363 *
1364 * @param call The {@code Call} invoking this method.
1365 * @param cannedTextResponses The text messages useable as responses.
1366 */
1367 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1368
1369 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001370 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1371 * character. This causes the post-dial signals to stop pending user confirmation. An
1372 * implementation should present this choice to the user and invoke
1373 * {@link #postDialContinue(boolean)} when the user makes the choice.
1374 *
1375 * @param call The {@code Call} invoking this method.
1376 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1377 */
1378 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1379
1380 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001381 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001382 *
1383 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001384 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001385 */
Andrew Lee50aca232014-07-22 16:41:54 -07001386 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001387
1388 /**
1389 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1390 * up their UI for the {@code Call} in response to state transitions. Specifically,
1391 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1392 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1393 * clients should wait for this method to be invoked.
1394 *
1395 * @param call The {@code Call} being destroyed.
1396 */
1397 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001398
1399 /**
1400 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1401 * conferenced.
1402 *
1403 * @param call The {@code Call} being updated.
1404 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1405 * conferenced.
1406 */
1407 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001408
1409 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001410 * Invoked when a {@link Call} receives an event from its associated {@link Connection} or
1411 * {@link Conference}.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001412 * <p>
1413 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1414 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1415 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1416 * possible that a {@link ConnectionService} has defined its own Connection events which a
1417 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001418 * <p>
Tyler Gunn5567d742019-10-31 13:04:37 -07001419 * See {@link Connection#sendConnectionEvent(String, Bundle)},
1420 * {@link Conference#sendConferenceEvent(String, Bundle)}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001421 *
1422 * @param call The {@code Call} receiving the event.
1423 * @param event The event.
1424 * @param extras Extras associated with the connection event.
1425 */
1426 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001427
1428 /**
1429 * Invoked when the RTT mode changes for this call.
1430 * @param call The call whose RTT mode has changed.
1431 * @param mode the new RTT mode, one of
1432 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1433 * or {@link RttCall#RTT_MODE_VCO}
1434 */
1435 public void onRttModeChanged(Call call, int mode) {}
1436
1437 /**
1438 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1439 * @param call The call whose RTT status has changed.
1440 * @param enabled whether RTT is now enabled or disabled
1441 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1442 * on, null otherwise.
1443 */
1444 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1445
1446 /**
1447 * Invoked when the remote end of the connection has requested that an RTT communication
1448 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1449 * with the same ID that this method is invoked with.
1450 * @param call The call which the RTT request was placed on
1451 * @param id The ID of the request.
1452 */
1453 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001454
1455 /**
1456 * Invoked when the RTT session failed to initiate for some reason, including rejection
1457 * by the remote party.
Tyler Gunnb9a04962022-02-17 08:23:54 -08001458 * <p>
1459 * This callback will ONLY be invoked to report a failure related to a user initiated
1460 * session modification request (i.e. {@link Call#sendRttRequest()}).
1461 * <p>
1462 * If a call is initiated with {@link TelecomManager#EXTRA_START_CALL_WITH_RTT} specified,
1463 * the availability of RTT can be determined by checking {@link Details#PROPERTY_RTT}
1464 * once the call enters state {@link Details#STATE_ACTIVE}.
1465 *
Hall Liu57006aa2017-02-06 10:49:48 -08001466 * @param call The call which the RTT initiation failure occurred on.
1467 * @param reason One of the status codes defined in
Tyler Gunnb9a04962022-02-17 08:23:54 -08001468 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1469 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liu57006aa2017-02-06 10:49:48 -08001470 */
Tyler Gunnb9a04962022-02-17 08:23:54 -08001471 public void onRttInitiationFailure(Call call,
1472 @android.telecom.Connection.RttModifyStatus.RttSessionModifyStatus int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001473
1474 /**
1475 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1476 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001477 * <p>
1478 * For a full discussion of the handover process and the APIs involved, see
1479 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1480 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001481 * @param call The call which had initiated handover.
1482 */
1483 public void onHandoverComplete(Call call) {}
1484
1485 /**
1486 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1487 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001488 * <p>
1489 * For a full discussion of the handover process and the APIs involved, see
1490 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1491 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001492 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001493 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001494 */
1495 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001496 }
1497
1498 /**
1499 * A class that holds the state that describes the state of the RTT channel to the remote
1500 * party, if it is active.
1501 */
1502 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001503 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001504 @Retention(RetentionPolicy.SOURCE)
1505 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1506 public @interface RttAudioMode {}
1507
1508 /**
1509 * For metrics use. Default value in the proto.
1510 * @hide
1511 */
1512 public static final int RTT_MODE_INVALID = 0;
1513
1514 /**
1515 * Indicates that there should be a bidirectional audio stream between the two parties
1516 * on the call.
1517 */
1518 public static final int RTT_MODE_FULL = 1;
1519
1520 /**
1521 * Indicates that the local user should be able to hear the audio stream from the remote
1522 * user, but not vice versa. Equivalent to muting the microphone.
1523 */
1524 public static final int RTT_MODE_HCO = 2;
1525
1526 /**
1527 * Indicates that the remote user should be able to hear the audio stream from the local
1528 * user, but not vice versa. Equivalent to setting the volume to zero.
1529 */
1530 public static final int RTT_MODE_VCO = 3;
1531
1532 private static final int READ_BUFFER_SIZE = 1000;
1533
1534 private InputStreamReader mReceiveStream;
1535 private OutputStreamWriter mTransmitStream;
1536 private int mRttMode;
1537 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001538 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001539 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1540
1541 /**
1542 * @hide
1543 */
Hall Liu57006aa2017-02-06 10:49:48 -08001544 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1545 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1546 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001547 mReceiveStream = receiveStream;
1548 mTransmitStream = transmitStream;
1549 mRttMode = mode;
1550 mInCallAdapter = inCallAdapter;
1551 }
1552
1553 /**
1554 * Returns the current RTT audio mode.
1555 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1556 * {@link #RTT_MODE_HCO}.
1557 */
1558 public int getRttAudioMode() {
1559 return mRttMode;
1560 }
1561
1562 /**
1563 * Sets the RTT audio mode. The requested mode change will be communicated through
1564 * {@link Callback#onRttModeChanged(Call, int)}.
1565 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1566 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1567 */
1568 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001569 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001570 }
1571
1572 /**
1573 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
Hall Liudc46c852020-10-29 16:15:33 -07001574 * RTT transmits text in real-time, this method should be called once for each user action.
1575 * For example, when the user enters text as discrete characters using the keyboard, this
1576 * method should be called once for each character. However, if the user enters text by
1577 * pasting or autocomplete, the entire contents of the pasted or autocompleted text should
1578 * be sent in one call to this method.
Hall Liu95d55872017-01-25 17:12:49 -08001579 *
1580 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1581 * lead to interleaved text.
1582 * @param input The message to send to the remote user.
1583 */
1584 public void write(String input) throws IOException {
1585 mTransmitStream.write(input);
1586 mTransmitStream.flush();
1587 }
1588
1589 /**
1590 * Reads a string from the remote user, blocking if there is no data available. Returns
1591 * {@code null} if the RTT conversation has been terminated and there is no further data
1592 * to read.
1593 *
1594 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1595 * lead to interleaved text.
1596 * @return A string containing text sent by the remote user, or {@code null} if the
1597 * conversation has been terminated or if there was an error while reading.
1598 */
Hall Liub1c8a772017-07-17 17:04:41 -07001599 public String read() {
1600 try {
1601 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1602 if (numRead < 0) {
1603 return null;
1604 }
1605 return new String(mReadBuffer, 0, numRead);
1606 } catch (IOException e) {
1607 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001608 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001609 }
Hall Liuffa4a812017-03-02 16:11:00 -08001610 }
1611
1612 /**
1613 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1614 * be read.
1615 * @return A string containing text entered by the user, or {@code null} if the user has
1616 * not entered any new text yet.
1617 */
1618 public String readImmediately() throws IOException {
1619 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001620 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1621 if (numRead < 0) {
1622 return null;
1623 }
1624 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001625 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001626 return null;
1627 }
1628 }
Hall Liue9041242018-02-09 16:40:03 -08001629
1630 /**
1631 * Closes the underlying file descriptors
1632 * @hide
1633 */
1634 public void close() {
1635 try {
1636 mReceiveStream.close();
1637 } catch (IOException e) {
1638 // ignore
1639 }
1640 try {
1641 mTransmitStream.close();
1642 } catch (IOException e) {
1643 // ignore
1644 }
1645 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001646 }
1647
Andrew Leeda80c872015-04-15 14:09:50 -07001648 /**
1649 * @deprecated Use {@code Call.Callback} instead.
1650 * @hide
1651 */
1652 @Deprecated
1653 @SystemApi
1654 public static abstract class Listener extends Callback { }
1655
Ihab Awade63fadb2014-07-09 21:52:04 -07001656 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001657 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001658 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001659 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001660 private final List<Call> mChildren = new ArrayList<>();
1661 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001662 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001663 private final List<Call> mConferenceableCalls = new ArrayList<>();
1664 private final List<Call> mUnmodifiableConferenceableCalls =
1665 Collections.unmodifiableList(mConferenceableCalls);
1666
Santos Cordon823fd3c2014-08-07 18:35:18 -07001667 private boolean mChildrenCached;
1668 private String mParentId = null;
Hall Liuef98bf82020-01-09 15:22:44 -08001669 private String mActiveGenericConferenceChild = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001670 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001671 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001672 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001673 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001674 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001675 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001676 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001677 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001678 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001679
1680 /**
1681 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1682 *
1683 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1684 * remaining or this {@code Call} is not in a post-dial state.
1685 */
1686 public String getRemainingPostDialSequence() {
1687 return mRemainingPostDialSequence;
1688 }
1689
1690 /**
1691 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001692 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001693 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001694 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001695 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001696 }
1697
1698 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301699 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1700 *
1701 * @param address The address to which the call will be deflected.
1702 */
1703 public void deflect(Uri address) {
1704 mInCallAdapter.deflectCall(mTelecomCallId, address);
1705 }
1706
1707 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001708 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1709 *
1710 * @param rejectWithMessage Whether to reject with a text message.
1711 * @param textMessage An optional text message with which to respond.
1712 */
1713 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001714 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001715 }
1716
1717 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001718 * Instructs the {@link ConnectionService} providing this {@link #STATE_RINGING} call that the
1719 * user has chosen to reject the call and has indicated a reason why the call is being rejected.
1720 *
1721 * @param rejectReason the reason the call is being rejected.
1722 */
1723 public void reject(@RejectReason int rejectReason) {
1724 mInCallAdapter.rejectCall(mTelecomCallId, rejectReason);
1725 }
1726
1727 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05301728 * Instructs this {@code Call} to be transferred to another number.
1729 *
1730 * @param targetNumber The address to which the call will be transferred.
Tyler Gunn460360d2020-07-29 10:21:45 -07001731 * @param isConfirmationRequired if {@code true} it will initiate a confirmed transfer,
1732 * if {@code false}, it will initiate an unconfirmed transfer.
Ravi Palurif4b38e72020-02-05 12:35:41 +05301733 *
1734 * @hide
1735 */
1736 public void transfer(@NonNull Uri targetNumber, boolean isConfirmationRequired) {
1737 mInCallAdapter.transferCall(mTelecomCallId, targetNumber, isConfirmationRequired);
1738 }
1739
1740 /**
1741 * Instructs this {@code Call} to be transferred to another ongoing call.
1742 * This will initiate CONSULTATIVE transfer.
1743 * @param toCall The other ongoing {@code Call} to which this call will be transferred.
1744 *
1745 * @hide
1746 */
1747 public void transfer(@NonNull android.telecom.Call toCall) {
1748 mInCallAdapter.transferCall(mTelecomCallId, toCall.mTelecomCallId);
1749 }
1750
1751 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001752 * Instructs this {@code Call} to disconnect.
1753 */
1754 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001755 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001756 }
1757
1758 /**
1759 * Instructs this {@code Call} to go on hold.
1760 */
1761 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001762 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001763 }
1764
1765 /**
1766 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1767 */
1768 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001769 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001770 }
1771
1772 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001773 * Instructs Telecom to put the call into the background audio processing state.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001774 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001775 * This method can be called either when the call is in {@link #STATE_RINGING} or
1776 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1777 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1778 * order to capture and play audio on the call stream.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001779 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001780 * This method can only be called by the default dialer app.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001781 * <p>
1782 * Apps built with SDK version {@link android.os.Build.VERSION_CODES#R} or later which are using
1783 * the microphone as part of audio processing should specify the foreground service type using
1784 * the attribute {@link android.R.attr#foregroundServiceType} in the {@link InCallService}
1785 * service element of the app's manifest file.
1786 * The {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_MICROPHONE} attribute should be specified.
1787 * @see <a href="https://developer.android.com/preview/privacy/foreground-service-types">
1788 * the Android Developer Site</a> for more information.
Hall Liu6dfa2492019-10-01 17:20:39 -07001789 * @hide
1790 */
1791 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001792 public void enterBackgroundAudioProcessing() {
1793 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1794 throw new IllegalStateException("Call must be active or ringing");
1795 }
1796 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1797 }
1798
1799 /**
1800 * Instructs Telecom to come out of the background audio processing state requested by
1801 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1802 *
1803 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1804 *
1805 * @param shouldRing If true, Telecom will put the call into the
1806 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1807 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1808 * immediately.
1809 * @hide
1810 */
1811 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001812 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1813 if (mState != STATE_AUDIO_PROCESSING) {
1814 throw new IllegalStateException("Call must in the audio processing state");
1815 }
1816 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1817 }
1818
1819 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001820 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
Tyler Gunn2517d032023-02-06 16:34:54 +00001821 * <p>
1822 * Tones are both played locally for the user to hear and sent to the network to be relayed
1823 * to the remote device.
1824 * <p>
Anton Hansson84d6d752023-10-05 09:46:37 +00001825 * You must ensure that any call to {@link #playDtmfTone(char)} is followed by a matching
Tyler Gunn2517d032023-02-06 16:34:54 +00001826 * call to {@link #stopDtmfTone()} and that each tone is stopped before a new one is started.
1827 * The play and stop commands are relayed to the underlying
1828 * {@link android.telecom.ConnectionService} as executed; implementations may not correctly
1829 * handle out of order commands.
Ihab Awade63fadb2014-07-09 21:52:04 -07001830 *
1831 * @param digit A character representing the DTMF digit for which to play the tone. This
1832 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1833 */
1834 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001835 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001836 }
1837
1838 /**
1839 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1840 * currently playing.
1841 *
1842 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1843 * currently playing, this method will do nothing.
1844 */
1845 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001846 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001847 }
1848
1849 /**
1850 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1851 *
1852 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1853 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001854 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001855 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001856 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1857 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001858 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001859 * {@code Call} will pause playing the tones and notify callbacks via
1860 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001861 * should display to the user an indication of this state and an affordance to continue
1862 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1863 * app should invoke the {@link #postDialContinue(boolean)} method.
1864 *
1865 * @param proceed Whether or not to continue with the post-dial sequence.
1866 */
1867 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001868 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001869 }
1870
1871 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001872 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001873 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001874 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001875 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1876 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001877
1878 }
1879
1880 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001881 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001882 *
1883 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001884 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001885 public void conference(Call callToConferenceWith) {
1886 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001887 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001888 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001889 }
1890
1891 /**
1892 * Instructs this {@code Call} to split from any conference call with which it may be
1893 * connected.
1894 */
1895 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001896 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001897 }
1898
1899 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001900 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001901 */
1902 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001903 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001904 }
1905
1906 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001907 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001908 */
1909 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001910 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001911 }
1912
1913 /**
Ravi Paluri404babb2020-01-23 19:02:44 +05301914 * Pulls participants to existing call by forming a conference call.
1915 * See {@link Details#CAPABILITY_ADD_PARTICIPANT}.
1916 *
1917 * @param participants participants to be pulled to existing call.
1918 */
1919 public void addConferenceParticipants(@NonNull List<Uri> participants) {
1920 mInCallAdapter.addConferenceParticipants(mTelecomCallId, participants);
1921 }
1922
1923 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001924 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1925 * device.
1926 * <p>
1927 * Calls to this method are ignored if the call does not have the
1928 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1929 * <p>
1930 * An {@link InCallService} will only see calls which support this method if it has the
1931 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1932 * in its manifest.
1933 */
1934 public void pullExternalCall() {
1935 // If this isn't an external call, ignore the request.
1936 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1937 return;
1938 }
1939
1940 mInCallAdapter.pullExternalCall(mTelecomCallId);
1941 }
1942
1943 /**
1944 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1945 * the {@link ConnectionService}.
1946 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001947 * Call events are used to communicate point in time information from an {@link InCallService}
1948 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1949 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1950 * {@link ConnectionService}.
1951 * <p>
1952 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1953 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1954 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001955 * Events are exposed to {@link ConnectionService} implementations via
1956 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1957 * <p>
1958 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001959 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1960 * ignore some events altogether.
1961 * <p>
1962 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1963 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1964 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1965 * they define their own event types in this namespace. When defining a custom event type,
1966 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1967 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1968 * <p>
1969 * When defining events and the associated extras, it is important to keep their behavior
1970 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1971 * events/extras should me maintained to ensure backwards compatibility with older
1972 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001973 *
1974 * @param event The connection event.
1975 * @param extras Bundle containing extra information associated with the event.
1976 */
1977 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001978 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001979 }
1980
1981 /**
Hall Liu95d55872017-01-25 17:12:49 -08001982 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1983 * guaranteed, and notification of success will be via the
1984 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1985 */
1986 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001987 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001988 }
1989
1990 /**
1991 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1992 * callback.
1993 * The ID used here should be the same as the ID that was received via the callback.
1994 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1995 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1996 */
1997 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001998 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001999 }
2000
2001 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07002002 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
2003 * by {@code toHandle}. The videoState specified indicates the desired video state after the
2004 * handover.
2005 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08002006 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2007 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2008 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2009 * is referred to as the source of the handover, and the video calling app is referred to as the
2010 * destination.
2011 * <p>
2012 * When considering a handover scenario the device this method is called on is considered the
2013 * <em>initiating</em> device (since the user initiates the handover from this device), and the
2014 * other device is considered the <em>receiving</em> device.
2015 * <p>
2016 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
2017 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
2018 * and invoke
2019 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
2020 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
2021 * call to it. The app returns an instance of {@link Connection} to represent the handover call
2022 * At this point the app should display UI to indicate to the user that a call
2023 * handover is in process.
2024 * <p>
2025 * The destination app is responsible for communicating the handover request from the
2026 * <em>initiating</em> device to the <em>receiving</em> device.
2027 * <p>
2028 * When the app on the <em>receiving</em> device receives the handover request, it calls
2029 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
2030 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
2031 * the destination app on the <em>receiving</em> device should show UI to allow the user to
2032 * choose whether they want to continue their call in the destination app.
2033 * <p>
2034 * When the destination app on the <em>receiving</em> device calls
2035 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
2036 * {@link ConnectionService} and call
2037 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
2038 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
2039 * {@link Connection} to represent the handover call.
2040 * <p>
2041 * If the user of the <em>receiving</em> device accepts the handover, the app calls
2042 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
2043 * original call. If the user rejects the handover, the app calls
2044 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
2045 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
2046 * <p>
2047 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
2048 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
2049 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
2050 * <p>
2051 * Errors in the handover process are reported to the {@link InCallService} via
2052 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
2053 * the involved {@link ConnectionService}s via
2054 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002055 *
2056 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
2057 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08002058 * @param videoState Indicates the video state desired after the handover (see the
2059 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07002060 * @param extras Bundle containing extra information to be passed to the
2061 * {@link ConnectionService}
2062 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002063 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
2064 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002065 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
2066 }
2067
2068 /**
Hall Liu95d55872017-01-25 17:12:49 -08002069 * Terminate the RTT session on this call. The resulting state change will be notified via
2070 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
2071 */
2072 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08002073 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08002074 }
2075
2076 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002077 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
2078 * added.
2079 * <p>
2080 * No assumptions should be made as to how an In-Call UI or service will handle these
2081 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
Tyler Gunn6c100242023-01-09 11:23:18 -08002082 * <p>
2083 * Extras added using this method will be made available to the {@link ConnectionService}
2084 * associated with this {@link Call} and notified via
2085 * {@link Connection#onExtrasChanged(Bundle)}.
2086 * <p>
2087 * Extras added using this method will also be available to other running {@link InCallService}s
2088 * and notified via {@link Call.Callback#onDetailsChanged(Call, Details)}. The extras can be
2089 * accessed via {@link Details#getExtras()}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002090 *
2091 * @param extras The extras to add.
2092 */
2093 public final void putExtras(Bundle extras) {
2094 if (extras == null) {
2095 return;
2096 }
2097
2098 if (mExtras == null) {
2099 mExtras = new Bundle();
2100 }
2101 mExtras.putAll(extras);
2102 mInCallAdapter.putExtras(mTelecomCallId, extras);
2103 }
2104
2105 /**
2106 * Adds a boolean extra to this {@link Call}.
2107 *
2108 * @param key The extra key.
2109 * @param value The value.
2110 * @hide
2111 */
2112 public final void putExtra(String key, boolean value) {
2113 if (mExtras == null) {
2114 mExtras = new Bundle();
2115 }
2116 mExtras.putBoolean(key, value);
2117 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2118 }
2119
2120 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002121 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002122 *
2123 * @param key The extra key.
2124 * @param value The value.
2125 * @hide
2126 */
2127 public final void putExtra(String key, int value) {
2128 if (mExtras == null) {
2129 mExtras = new Bundle();
2130 }
2131 mExtras.putInt(key, value);
2132 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2133 }
2134
2135 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002136 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002137 *
2138 * @param key The extra key.
2139 * @param value The value.
2140 * @hide
2141 */
2142 public final void putExtra(String key, String value) {
2143 if (mExtras == null) {
2144 mExtras = new Bundle();
2145 }
2146 mExtras.putString(key, value);
2147 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2148 }
2149
2150 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002151 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002152 *
2153 * @param keys The keys of the extras to remove.
2154 */
2155 public final void removeExtras(List<String> keys) {
2156 if (mExtras != null) {
2157 for (String key : keys) {
2158 mExtras.remove(key);
2159 }
2160 if (mExtras.size() == 0) {
2161 mExtras = null;
2162 }
2163 }
2164 mInCallAdapter.removeExtras(mTelecomCallId, keys);
2165 }
2166
2167 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002168 * Removes extras from this {@link Call}.
2169 *
2170 * @param keys The keys of the extras to remove.
2171 */
2172 public final void removeExtras(String ... keys) {
2173 removeExtras(Arrays.asList(keys));
2174 }
2175
2176 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002177 * Obtains the parent of this {@code Call} in a conference, if any.
2178 *
2179 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
2180 * child of any conference {@code Call}s.
2181 */
2182 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002183 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002184 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002185 }
2186 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07002187 }
2188
2189 /**
2190 * Obtains the children of this conference {@code Call}, if any.
2191 *
2192 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
2193 * {@code List} otherwise.
2194 */
2195 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002196 if (!mChildrenCached) {
2197 mChildrenCached = true;
2198 mChildren.clear();
2199
2200 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002201 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002202 if (call == null) {
2203 // At least one child was still not found, so do not save true for "cached"
2204 mChildrenCached = false;
2205 } else {
2206 mChildren.add(call);
2207 }
2208 }
2209 }
2210
Ihab Awade63fadb2014-07-09 21:52:04 -07002211 return mUnmodifiableChildren;
2212 }
2213
2214 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002215 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
2216 *
2217 * @return The list of conferenceable {@code Call}s.
2218 */
2219 public List<Call> getConferenceableCalls() {
2220 return mUnmodifiableConferenceableCalls;
2221 }
2222
2223 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002224 * Obtains the state of this {@code Call}.
2225 *
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002226 * @return The call state.
2227 * @deprecated The call state is available via {@link Call.Details#getState()}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002228 */
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002229 @Deprecated
2230 public @CallState int getState() {
Ihab Awade63fadb2014-07-09 21:52:04 -07002231 return mState;
2232 }
2233
2234 /**
Hall Liuef98bf82020-01-09 15:22:44 -08002235 * Returns the child {@link Call} in a generic conference that is currently active.
Hall Liu135e53aa2020-02-27 18:34:11 -08002236 *
2237 * A "generic conference" is the mechanism used to support two simultaneous calls on a device
2238 * in CDMA networks. It is effectively equivalent to having one call active and one call on hold
2239 * in GSM or IMS calls. This method returns the currently active call.
2240 *
2241 * In a generic conference, the network exposes the conference to us as a single call, and we
2242 * switch between talking to the two participants using a CDMA flash command. Since the network
2243 * exposes no additional information about the call, the only way we know which caller we're
2244 * currently talking to is by keeping track of the flash commands that we've sent to the
2245 * network.
2246 *
Hall Liuef98bf82020-01-09 15:22:44 -08002247 * For calls that are not generic conferences, or when the generic conference has more than
2248 * 2 children, returns {@code null}.
2249 * @see Details#PROPERTY_GENERIC_CONFERENCE
2250 * @return The active child call.
2251 */
2252 public @Nullable Call getGenericConferenceActiveChildCall() {
2253 if (mActiveGenericConferenceChild != null) {
2254 return mPhone.internalGetCallByTelecomId(mActiveGenericConferenceChild);
2255 }
2256 return null;
2257 }
2258
2259 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002260 * Obtains a list of canned, pre-configured message responses to present to the user as
Tyler Gunn434fc2c2020-10-06 14:23:54 -07002261 * ways of rejecting an incoming {@code Call} using via a text message.
2262 * <p>
2263 * <em>Note:</em> Since canned responses may be loaded from the file system, they are not
2264 * guaranteed to be present when this {@link Call} is first added to the {@link InCallService}
2265 * via {@link InCallService#onCallAdded(Call)}. The callback
2266 * {@link Call.Callback#onCannedTextResponsesLoaded(Call, List)} will be called when/if canned
2267 * responses for the call become available.
Ihab Awade63fadb2014-07-09 21:52:04 -07002268 *
2269 * @see #reject(boolean, String)
2270 *
2271 * @return A list of canned text message responses.
2272 */
2273 public List<String> getCannedTextResponses() {
2274 return mCannedTextResponses;
2275 }
2276
2277 /**
2278 * Obtains an object that can be used to display video from this {@code Call}.
2279 *
Andrew Lee50aca232014-07-22 16:41:54 -07002280 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002281 */
Andrew Lee50aca232014-07-22 16:41:54 -07002282 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002283 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07002284 }
2285
2286 /**
2287 * Obtains an object containing call details.
2288 *
2289 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
2290 * result may be {@code null}.
2291 */
2292 public Details getDetails() {
2293 return mDetails;
2294 }
2295
2296 /**
Hall Liu95d55872017-01-25 17:12:49 -08002297 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
2298 * receive RTT text data, as well as to change the RTT mode.
2299 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
2300 */
2301 public @Nullable RttCall getRttCall() {
2302 return mRttCall;
2303 }
2304
2305 /**
2306 * Returns whether this call has an active RTT connection.
2307 * @return true if there is a connection, false otherwise.
2308 */
2309 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08002310 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08002311 }
2312
2313 /**
Andrew Leeda80c872015-04-15 14:09:50 -07002314 * Registers a callback to this {@code Call}.
2315 *
2316 * @param callback A {@code Callback}.
2317 */
2318 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07002319 registerCallback(callback, new Handler());
2320 }
2321
2322 /**
2323 * Registers a callback to this {@code Call}.
2324 *
2325 * @param callback A {@code Callback}.
2326 * @param handler A handler which command and status changes will be delivered to.
2327 */
2328 public void registerCallback(Callback callback, Handler handler) {
2329 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07002330 // Don't allow new callback registration if the call is already being destroyed.
2331 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002332 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
2333 }
Andrew Leeda80c872015-04-15 14:09:50 -07002334 }
2335
2336 /**
2337 * Unregisters a callback from this {@code Call}.
2338 *
2339 * @param callback A {@code Callback}.
2340 */
2341 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002342 // Don't allow callback deregistration if the call is already being destroyed.
2343 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002344 for (CallbackRecord<Callback> record : mCallbackRecords) {
2345 if (record.getCallback() == callback) {
2346 mCallbackRecords.remove(record);
2347 break;
2348 }
2349 }
Andrew Leeda80c872015-04-15 14:09:50 -07002350 }
2351 }
2352
Santos Cordon3c20d632016-02-25 16:12:35 -08002353 @Override
2354 public String toString() {
2355 return new StringBuilder().
2356 append("Call [id: ").
2357 append(mTelecomCallId).
2358 append(", state: ").
2359 append(stateToString(mState)).
2360 append(", details: ").
2361 append(mDetails).
2362 append("]").toString();
2363 }
2364
2365 /**
2366 * @param state An integer value of a {@code STATE_*} constant.
2367 * @return A string representation of the value.
2368 */
2369 private static String stateToString(int state) {
2370 switch (state) {
2371 case STATE_NEW:
2372 return "NEW";
2373 case STATE_RINGING:
2374 return "RINGING";
2375 case STATE_DIALING:
2376 return "DIALING";
2377 case STATE_ACTIVE:
2378 return "ACTIVE";
2379 case STATE_HOLDING:
2380 return "HOLDING";
2381 case STATE_DISCONNECTED:
2382 return "DISCONNECTED";
2383 case STATE_CONNECTING:
2384 return "CONNECTING";
2385 case STATE_DISCONNECTING:
2386 return "DISCONNECTING";
2387 case STATE_SELECT_PHONE_ACCOUNT:
2388 return "SELECT_PHONE_ACCOUNT";
Hall Liu4e35b642019-10-14 17:50:45 -07002389 case STATE_SIMULATED_RINGING:
2390 return "SIMULATED_RINGING";
2391 case STATE_AUDIO_PROCESSING:
2392 return "AUDIO_PROCESSING";
Santos Cordon3c20d632016-02-25 16:12:35 -08002393 default:
2394 Log.w(Call.class, "Unknown state %d", state);
2395 return "UNKNOWN";
2396 }
2397 }
2398
Andrew Leeda80c872015-04-15 14:09:50 -07002399 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002400 * Adds a listener to this {@code Call}.
2401 *
2402 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002403 * @deprecated Use {@link #registerCallback} instead.
2404 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002405 */
Andrew Leeda80c872015-04-15 14:09:50 -07002406 @Deprecated
2407 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002408 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002409 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002410 }
2411
2412 /**
2413 * Removes a listener from this {@code Call}.
2414 *
2415 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002416 * @deprecated Use {@link #unregisterCallback} instead.
2417 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002418 */
Andrew Leeda80c872015-04-15 14:09:50 -07002419 @Deprecated
2420 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002421 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002422 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002423 }
2424
2425 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002426 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2427 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002428 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002429 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002430 mInCallAdapter = inCallAdapter;
2431 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002432 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002433 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002434 }
2435
2436 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002437 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002438 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002439 mPhone = phone;
2440 mTelecomCallId = telecomCallId;
2441 mInCallAdapter = inCallAdapter;
2442 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002443 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002444 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002445 }
2446
2447 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002448 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002449 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002450 }
2451
2452 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002453 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002454
Ihab Awade63fadb2014-07-09 21:52:04 -07002455 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002456 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002457 boolean detailsChanged = !Objects.equals(mDetails, details);
2458 if (detailsChanged) {
2459 mDetails = details;
2460 }
2461
2462 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002463 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2464 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2465 mCannedTextResponses =
2466 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002467 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002468 }
2469
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002470 IVideoProvider previousVideoProvider = mVideoCallImpl == null ? null :
2471 mVideoCallImpl.getVideoProvider();
2472 IVideoProvider newVideoProvider = parcelableCall.getVideoProvider();
2473
2474 // parcelableCall.isVideoCallProviderChanged is only true when we have a video provider
2475 // specified; so we should check if the actual IVideoProvider changes as well.
2476 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged()
2477 && !Objects.equals(previousVideoProvider, newVideoProvider);
Andrew Lee50aca232014-07-22 16:41:54 -07002478 if (videoCallChanged) {
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002479 if (mVideoCallImpl != null) {
2480 mVideoCallImpl.destroy();
2481 }
2482 mVideoCallImpl = parcelableCall.isVideoCallProviderChanged() ?
2483 parcelableCall.getVideoCallImpl(mCallingPackage, mTargetSdkVersion) : null;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002484 }
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002485
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002486 if (mVideoCallImpl != null) {
2487 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002488 }
2489
Santos Cordone3c507b2015-04-23 14:44:19 -07002490 int state = parcelableCall.getState();
Hall Liu31de23d2019-10-11 15:38:29 -07002491 if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2492 state = Call.STATE_RINGING;
2493 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002494 boolean stateChanged = mState != state;
2495 if (stateChanged) {
2496 mState = state;
2497 }
2498
Santos Cordon823fd3c2014-08-07 18:35:18 -07002499 String parentId = parcelableCall.getParentCallId();
2500 boolean parentChanged = !Objects.equals(mParentId, parentId);
2501 if (parentChanged) {
2502 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002503 }
2504
Santos Cordon823fd3c2014-08-07 18:35:18 -07002505 List<String> childCallIds = parcelableCall.getChildCallIds();
2506 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2507 if (childrenChanged) {
2508 mChildrenIds.clear();
2509 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2510 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002511 }
2512
Hall Liuef98bf82020-01-09 15:22:44 -08002513 String activeChildCallId = parcelableCall.getActiveChildCallId();
2514 boolean activeChildChanged = !Objects.equals(activeChildCallId,
2515 mActiveGenericConferenceChild);
2516 if (activeChildChanged) {
2517 mActiveGenericConferenceChild = activeChildCallId;
2518 }
2519
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002520 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2521 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2522 for (String otherId : conferenceableCallIds) {
2523 if (callIdMap.containsKey(otherId)) {
2524 conferenceableCalls.add(callIdMap.get(otherId));
2525 }
2526 }
2527
2528 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2529 mConferenceableCalls.clear();
2530 mConferenceableCalls.addAll(conferenceableCalls);
2531 fireConferenceableCallsChanged();
2532 }
2533
Hall Liu95d55872017-01-25 17:12:49 -08002534 boolean isRttChanged = false;
2535 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002536 if (parcelableCall.getIsRttCallChanged()
2537 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002538 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2539 InputStreamReader receiveStream = new InputStreamReader(
2540 new ParcelFileDescriptor.AutoCloseInputStream(
2541 parcelableRttCall.getReceiveStream()),
2542 StandardCharsets.UTF_8);
2543 OutputStreamWriter transmitStream = new OutputStreamWriter(
2544 new ParcelFileDescriptor.AutoCloseOutputStream(
2545 parcelableRttCall.getTransmitStream()),
2546 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002547 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002548 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2549 if (mRttCall == null) {
2550 isRttChanged = true;
2551 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2552 rttModeChanged = true;
2553 }
2554 mRttCall = newRttCall;
2555 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2556 && parcelableCall.getIsRttCallChanged()) {
2557 isRttChanged = true;
Tyler Gunn4cd42482021-04-30 16:23:15 -07002558 mRttCall.close();
Hall Liu95d55872017-01-25 17:12:49 -08002559 mRttCall = null;
2560 }
2561
Ihab Awade63fadb2014-07-09 21:52:04 -07002562 // Now we fire updates, ensuring that any client who listens to any of these notifications
2563 // gets the most up-to-date state.
2564
2565 if (stateChanged) {
2566 fireStateChanged(mState);
2567 }
2568 if (detailsChanged) {
2569 fireDetailsChanged(mDetails);
2570 }
2571 if (cannedTextResponsesChanged) {
2572 fireCannedTextResponsesLoaded(mCannedTextResponses);
2573 }
Andrew Lee50aca232014-07-22 16:41:54 -07002574 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002575 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002576 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002577 if (parentChanged) {
2578 fireParentChanged(getParent());
2579 }
Hall Liuef98bf82020-01-09 15:22:44 -08002580 if (childrenChanged || activeChildChanged) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002581 fireChildrenChanged(getChildren());
2582 }
Hall Liu95d55872017-01-25 17:12:49 -08002583 if (isRttChanged) {
2584 fireOnIsRttChanged(mRttCall != null, mRttCall);
2585 }
2586 if (rttModeChanged) {
2587 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2588 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002589
2590 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2591 // remove ourselves from the Phone. Note that we do this after completing all state updates
2592 // so a client can cleanly transition all their UI to the state appropriate for a
2593 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
qing278fdb12021-10-26 19:05:51 +00002594 // Check if the original state is already disconnected, otherwise onCallRemoved will be
2595 // triggered before onCallAdded.
2596 if (mState == STATE_DISCONNECTED && stateChanged) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002597 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002598 }
2599 }
2600
2601 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002602 final void internalSetPostDialWait(String remaining) {
2603 mRemainingPostDialSequence = remaining;
2604 firePostDialWait(mRemainingPostDialSequence);
2605 }
2606
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002607 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002608 final void internalSetDisconnected() {
2609 if (mState != Call.STATE_DISCONNECTED) {
2610 mState = Call.STATE_DISCONNECTED;
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002611 if (mDetails != null) {
2612 mDetails = new Details(mState,
2613 mDetails.getTelecomCallId(),
2614 mDetails.getHandle(),
2615 mDetails.getHandlePresentation(),
2616 mDetails.getCallerDisplayName(),
2617 mDetails.getCallerDisplayNamePresentation(),
2618 mDetails.getAccountHandle(),
2619 mDetails.getCallCapabilities(),
2620 mDetails.getCallProperties(),
2621 mDetails.getDisconnectCause(),
2622 mDetails.getConnectTimeMillis(),
2623 mDetails.getGatewayInfo(),
2624 mDetails.getVideoState(),
2625 mDetails.getStatusHints(),
2626 mDetails.getExtras(),
2627 mDetails.getIntentExtras(),
2628 mDetails.getCreationTimeMillis(),
2629 mDetails.getContactDisplayName(),
2630 mDetails.getCallDirection(),
Edgar Arriagae5bec822022-10-14 14:25:43 -07002631 mDetails.getCallerNumberVerificationStatus(),
2632 mDetails.getContactPhotoUri()
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002633 );
2634 fireDetailsChanged(mDetails);
2635 }
Santos Cordonf30d7e92014-08-26 09:54:33 -07002636 fireStateChanged(mState);
2637 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002638 }
2639 }
2640
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002641 /** {@hide} */
2642 final void internalOnConnectionEvent(String event, Bundle extras) {
2643 fireOnConnectionEvent(event, extras);
2644 }
2645
Hall Liu95d55872017-01-25 17:12:49 -08002646 /** {@hide} */
2647 final void internalOnRttUpgradeRequest(final int requestId) {
2648 for (CallbackRecord<Callback> record : mCallbackRecords) {
2649 final Call call = this;
2650 final Callback callback = record.getCallback();
2651 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2652 }
2653 }
2654
Hall Liu57006aa2017-02-06 10:49:48 -08002655 /** @hide */
2656 final void internalOnRttInitiationFailure(int reason) {
2657 for (CallbackRecord<Callback> record : mCallbackRecords) {
2658 final Call call = this;
2659 final Callback callback = record.getCallback();
2660 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2661 }
2662 }
2663
Sanket Padawe85291f62017-12-01 13:59:27 -08002664 /** {@hide} */
2665 final void internalOnHandoverFailed(int error) {
2666 for (CallbackRecord<Callback> record : mCallbackRecords) {
2667 final Call call = this;
2668 final Callback callback = record.getCallback();
2669 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2670 }
2671 }
2672
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002673 /** {@hide} */
2674 final void internalOnHandoverComplete() {
2675 for (CallbackRecord<Callback> record : mCallbackRecords) {
2676 final Call call = this;
2677 final Callback callback = record.getCallback();
2678 record.getHandler().post(() -> callback.onHandoverComplete(call));
2679 }
2680 }
2681
Andrew Lee011728f2015-04-23 15:47:06 -07002682 private void fireStateChanged(final int newState) {
2683 for (CallbackRecord<Callback> record : mCallbackRecords) {
2684 final Call call = this;
2685 final Callback callback = record.getCallback();
2686 record.getHandler().post(new Runnable() {
2687 @Override
2688 public void run() {
2689 callback.onStateChanged(call, newState);
2690 }
2691 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002692 }
2693 }
2694
Andrew Lee011728f2015-04-23 15:47:06 -07002695 private void fireParentChanged(final Call newParent) {
2696 for (CallbackRecord<Callback> record : mCallbackRecords) {
2697 final Call call = this;
2698 final Callback callback = record.getCallback();
2699 record.getHandler().post(new Runnable() {
2700 @Override
2701 public void run() {
2702 callback.onParentChanged(call, newParent);
2703 }
2704 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002705 }
2706 }
2707
Andrew Lee011728f2015-04-23 15:47:06 -07002708 private void fireChildrenChanged(final List<Call> children) {
2709 for (CallbackRecord<Callback> record : mCallbackRecords) {
2710 final Call call = this;
2711 final Callback callback = record.getCallback();
2712 record.getHandler().post(new Runnable() {
2713 @Override
2714 public void run() {
2715 callback.onChildrenChanged(call, children);
2716 }
2717 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002718 }
2719 }
2720
Andrew Lee011728f2015-04-23 15:47:06 -07002721 private void fireDetailsChanged(final Details details) {
2722 for (CallbackRecord<Callback> record : mCallbackRecords) {
2723 final Call call = this;
2724 final Callback callback = record.getCallback();
2725 record.getHandler().post(new Runnable() {
2726 @Override
2727 public void run() {
2728 callback.onDetailsChanged(call, details);
2729 }
2730 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002731 }
2732 }
2733
Andrew Lee011728f2015-04-23 15:47:06 -07002734 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2735 for (CallbackRecord<Callback> record : mCallbackRecords) {
2736 final Call call = this;
2737 final Callback callback = record.getCallback();
2738 record.getHandler().post(new Runnable() {
2739 @Override
2740 public void run() {
2741 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2742 }
2743 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002744 }
2745 }
2746
Andrew Lee011728f2015-04-23 15:47:06 -07002747 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2748 for (CallbackRecord<Callback> record : mCallbackRecords) {
2749 final Call call = this;
2750 final Callback callback = record.getCallback();
2751 record.getHandler().post(new Runnable() {
2752 @Override
2753 public void run() {
2754 callback.onVideoCallChanged(call, videoCall);
2755 }
2756 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002757 }
2758 }
2759
Andrew Lee011728f2015-04-23 15:47:06 -07002760 private void firePostDialWait(final String remainingPostDialSequence) {
2761 for (CallbackRecord<Callback> record : mCallbackRecords) {
2762 final Call call = this;
2763 final Callback callback = record.getCallback();
2764 record.getHandler().post(new Runnable() {
2765 @Override
2766 public void run() {
2767 callback.onPostDialWait(call, remainingPostDialSequence);
2768 }
2769 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002770 }
2771 }
2772
2773 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002774 /**
2775 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2776 * onCallRemoved callback, we remove this call from the Phone's record
2777 * only once all of the registered onCallDestroyed callbacks are executed.
2778 * All the callbacks get removed from our records as a part of this operation
2779 * since onCallDestroyed is the final callback.
2780 */
2781 final Call call = this;
2782 if (mCallbackRecords.isEmpty()) {
2783 // No callbacks registered, remove the call from Phone's record.
2784 mPhone.internalRemoveCall(call);
2785 }
2786 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002787 final Callback callback = record.getCallback();
2788 record.getHandler().post(new Runnable() {
2789 @Override
2790 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002791 boolean isFinalRemoval = false;
2792 RuntimeException toThrow = null;
2793 try {
2794 callback.onCallDestroyed(call);
2795 } catch (RuntimeException e) {
2796 toThrow = e;
2797 }
2798 synchronized(Call.this) {
2799 mCallbackRecords.remove(record);
2800 if (mCallbackRecords.isEmpty()) {
2801 isFinalRemoval = true;
2802 }
2803 }
2804 if (isFinalRemoval) {
2805 mPhone.internalRemoveCall(call);
2806 }
2807 if (toThrow != null) {
2808 throw toThrow;
2809 }
Andrew Lee011728f2015-04-23 15:47:06 -07002810 }
2811 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002812 }
2813 }
2814
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002815 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002816 for (CallbackRecord<Callback> record : mCallbackRecords) {
2817 final Call call = this;
2818 final Callback callback = record.getCallback();
2819 record.getHandler().post(new Runnable() {
2820 @Override
2821 public void run() {
2822 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2823 }
2824 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002825 }
2826 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002827
2828 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002829 * Notifies listeners of an incoming connection event.
2830 * <p>
2831 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2832 *
2833 * @param event
2834 * @param extras
2835 */
2836 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2837 for (CallbackRecord<Callback> record : mCallbackRecords) {
2838 final Call call = this;
2839 final Callback callback = record.getCallback();
2840 record.getHandler().post(new Runnable() {
2841 @Override
2842 public void run() {
2843 callback.onConnectionEvent(call, event, extras);
2844 }
2845 });
2846 }
2847 }
2848
2849 /**
Hall Liu95d55872017-01-25 17:12:49 -08002850 * Notifies listeners of an RTT on/off change
2851 *
2852 * @param enabled True if RTT is now enabled, false otherwise
2853 */
2854 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2855 for (CallbackRecord<Callback> record : mCallbackRecords) {
2856 final Call call = this;
2857 final Callback callback = record.getCallback();
2858 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2859 }
2860 }
2861
2862 /**
2863 * Notifies listeners of a RTT mode change
2864 *
2865 * @param mode The new RTT mode
2866 */
2867 private void fireOnRttModeChanged(final int mode) {
2868 for (CallbackRecord<Callback> record : mCallbackRecords) {
2869 final Call call = this;
2870 final Callback callback = record.getCallback();
2871 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2872 }
2873 }
2874
2875 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002876 * Determines if two bundles are equal.
2877 *
2878 * @param bundle The original bundle.
2879 * @param newBundle The bundle to compare with.
2880 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2881 */
2882 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2883 if (bundle == null || newBundle == null) {
2884 return bundle == newBundle;
2885 }
2886
2887 if (bundle.size() != newBundle.size()) {
2888 return false;
2889 }
2890
2891 for(String key : bundle.keySet()) {
2892 if (key != null) {
Grace Jia17005bd2022-05-12 12:49:02 -07002893 if (!newBundle.containsKey(key)) {
2894 return false;
2895 }
qing723dac62022-10-28 03:40:43 +00002896 // In case new call extra contains non-framework class objects, return false to
2897 // force update the call extra
2898 try {
2899 final Object value = bundle.get(key);
2900 final Object newValue = newBundle.get(key);
2901 if (value instanceof Bundle && newValue instanceof Bundle) {
2902 if (!areBundlesEqual((Bundle) value, (Bundle) newValue)) {
2903 return false;
2904 }
2905 }
2906 if (value instanceof byte[] && newValue instanceof byte[]) {
2907 if (!Arrays.equals((byte[]) value, (byte[]) newValue)) {
2908 return false;
2909 }
2910 } else if (!Objects.equals(value, newValue)) {
Grace Jia17005bd2022-05-12 12:49:02 -07002911 return false;
2912 }
qing723dac62022-10-28 03:40:43 +00002913 } catch (BadParcelableException e) {
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002914 return false;
2915 }
2916 }
2917 }
2918 return true;
2919 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002920}