blob: 874c10c8ea83a3e2daabab6da9bfdae4e383f163 [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 /**
272 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
273 * call because they have declined to answer it. This typically means that they are unable
274 * to answer the call at this time and would prefer it be sent to voicemail.
275 */
276 public static final int REJECT_REASON_DECLINED = 1;
277
278 /**
279 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
280 * call because it is an unwanted call. This allows the user to indicate that they are
281 * rejecting a call because it is likely a nuisance call.
282 */
283 public static final int REJECT_REASON_UNWANTED = 2;
284
285 /**
286 * @hide
287 */
288 @IntDef(prefix = { "REJECT_REASON_" },
289 value = {REJECT_REASON_DECLINED, REJECT_REASON_UNWANTED})
290 @Retention(RetentionPolicy.SOURCE)
291 public @interface RejectReason {};
292
Ihab Awade63fadb2014-07-09 21:52:04 -0700293 public static class Details {
Tyler Gunn94f8f112018-12-17 09:56:11 -0800294 /** @hide */
295 @Retention(RetentionPolicy.SOURCE)
296 @IntDef(
297 prefix = { "DIRECTION_" },
298 value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
299 public @interface CallDirection {}
300
301 /**
302 * Indicates that the call is neither and incoming nor an outgoing call. This can be the
303 * case for calls reported directly by a {@link ConnectionService} in special cases such as
304 * call handovers.
305 */
306 public static final int DIRECTION_UNKNOWN = -1;
307
308 /**
309 * Indicates that the call is an incoming call.
310 */
311 public static final int DIRECTION_INCOMING = 0;
312
313 /**
314 * Indicates that the call is an outgoing call.
315 */
316 public static final int DIRECTION_OUTGOING = 1;
317
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800318 /** Call can currently be put on hold or unheld. */
319 public static final int CAPABILITY_HOLD = 0x00000001;
320
321 /** Call supports the hold feature. */
322 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
323
324 /**
325 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
326 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
327 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
328 * capability allows a merge button to be shown while the conference call is in the foreground
329 * of the in-call UI.
330 * <p>
331 * This is only intended for use by a {@link Conference}.
332 */
333 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
334
335 /**
336 * Calls within a conference can be swapped between foreground and background.
337 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
338 * <p>
339 * This is only intended for use by a {@link Conference}.
340 */
341 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
342
343 /**
344 * @hide
345 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700346 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800347
348 /** Call supports responding via text option. */
349 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
350
351 /** Call can be muted. */
352 public static final int CAPABILITY_MUTE = 0x00000040;
353
354 /**
355 * Call supports conference call management. This capability only applies to {@link Conference}
356 * calls which can have {@link Connection}s as children.
357 */
358 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
359
360 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700361 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800362 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700363 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800364
365 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700366 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800367 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700368 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800369
370 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700371 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800372 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700373 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700374 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800375
376 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700377 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800378 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700379 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
380
381 /**
382 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700383 */
384 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
385
386 /**
387 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700388 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700389 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700390 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800391
392 /**
393 * Call is able to be separated from its parent {@code Conference}, if any.
394 */
395 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
396
397 /**
398 * Call is able to be individually disconnected when in a {@code Conference}.
399 */
400 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
401
402 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500403 * Speed up audio setup for MT call.
404 * @hide
405 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700406 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
407
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700408 /**
409 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700410 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800411 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
412 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
413 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700414 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800415 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700416 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
417
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700418 /**
419 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700420 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700421 */
422 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
423
Bryce Lee81901682015-08-28 16:38:02 -0700424 /**
425 * Call sends responses through connection.
426 * @hide
427 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800428 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
429
430 /**
431 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
432 * <p>
433 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
434 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
435 * downgraded from a video call back to a VideoState of
436 * {@link VideoProfile#STATE_AUDIO_ONLY}.
437 * <p>
438 * Intuitively, a call which can be downgraded to audio should also have local and remote
439 * video
440 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
441 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
442 */
443 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700444
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700445 /**
446 * When set for an external call, indicates that this {@code Call} can be pulled from a
447 * remote device to the current device.
448 * <p>
449 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
450 * <p>
451 * An {@link InCallService} will only see calls with this capability if it has the
452 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
453 * in its manifest.
454 * <p>
455 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700456 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700457 */
458 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
459
Pooja Jaind34698d2017-12-28 14:15:31 +0530460 /** Call supports the deflect feature. */
461 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
462
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800463 /**
464 * Call supports adding participants to the call via
Grace Jia8587ee52020-07-10 15:42:32 -0700465 * {@link #addConferenceParticipants(List)}. Once participants are added, the call becomes
466 * an adhoc conference call ({@link #PROPERTY_IS_ADHOC_CONFERENCE}).
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800467 */
Ravi Paluri404babb2020-01-23 19:02:44 +0530468 public static final int CAPABILITY_ADD_PARTICIPANT = 0x02000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530469
470 /**
471 * When set for a call, indicates that this {@code Call} can be transferred to another
472 * number.
Tyler Gunn460360d2020-07-29 10:21:45 -0700473 * Call supports the confirmed and unconfirmed call transfer feature.
Ravi Palurif4b38e72020-02-05 12:35:41 +0530474 *
475 * @hide
476 */
477 public static final int CAPABILITY_TRANSFER = 0x04000000;
478
479 /**
480 * When set for a call, indicates that this {@code Call} can be transferred to another
481 * ongoing call.
482 * Call supports the consultative call transfer feature.
483 *
484 * @hide
485 */
486 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x08000000;
487
Alvin Dey2f37d772018-05-18 23:16:10 +0530488 /**
489 * Indicates whether the remote party supports RTT or not to the UI.
490 */
491
492 public static final int CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT = 0x10000000;
493
Tyler Gunnd11a3152015-03-18 13:09:14 -0700494 //******************************************************************************************
Alvin Dey2f37d772018-05-18 23:16:10 +0530495 // Next CAPABILITY value: 0x20000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700496 //******************************************************************************************
497
498 /**
499 * Whether the call is currently a conference.
500 */
501 public static final int PROPERTY_CONFERENCE = 0x00000001;
502
503 /**
504 * Whether the call is a generic conference, where we do not know the precise state of
505 * participants in the conference (eg. on CDMA).
506 */
507 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
508
509 /**
510 * Whether the call is made while the device is in emergency callback mode.
511 */
512 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
513
514 /**
515 * Connection is using WIFI.
516 */
517 public static final int PROPERTY_WIFI = 0x00000008;
518
519 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700520 * When set, the UI should indicate to the user that a call is using high definition
521 * audio.
522 * <p>
523 * The underlying {@link ConnectionService} is responsible for reporting this
524 * property. It is important to note that this property is not intended to report the
525 * actual audio codec being used for a Call, but whether the call should be indicated
526 * to the user as high definition.
527 * <p>
528 * The Android Telephony stack reports this property for calls based on a number
529 * of factors, including which audio codec is used and whether a call is using an HD
530 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
531 * and in these cases this property will not be set for a call even if the underlying audio
532 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700533 */
534 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
535
Tony Maka68dcce2015-12-17 09:31:18 +0000536 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100537 * Whether the call is associated with the work profile.
538 */
539 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
540
541 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700542 * When set, indicates that this {@code Call} does not actually exist locally for the
543 * {@link ConnectionService}.
544 * <p>
545 * Consider, for example, a scenario where a user has two phones with the same phone number.
546 * When a user places a call on one device, the telephony stack can represent that call on
547 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700548 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700549 * <p>
550 * An {@link InCallService} will only see calls with this property if it has the
551 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
552 * in its manifest.
553 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700554 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700555 */
556 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
557
Brad Ebinger15847072016-05-18 11:08:36 -0700558 /**
559 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
560 */
561 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
562
Tyler Gunn24e18332017-02-10 09:42:49 -0800563 /**
564 * Indicates that the call is from a self-managed {@link ConnectionService}.
565 * <p>
566 * See also {@link Connection#PROPERTY_SELF_MANAGED}
567 */
568 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
569
Eric Erfanianec881872017-12-06 16:27:53 -0800570 /**
571 * Indicates the call used Assisted Dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700572 *
573 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanianec881872017-12-06 16:27:53 -0800574 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800575 public static final int PROPERTY_ASSISTED_DIALING = 0x00000200;
Eric Erfanianec881872017-12-06 16:27:53 -0800576
Hall Liue9041242018-02-09 16:40:03 -0800577 /**
578 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
579 * {@link RttCall} object that is used to send and receive text.
580 */
581 public static final int PROPERTY_RTT = 0x00000400;
582
Tyler Gunn5bd90852018-09-21 09:37:07 -0700583 /**
584 * Indicates that the call has been identified as the network as an emergency call. This
585 * property may be set for both incoming and outgoing calls which the network identifies as
586 * emergency calls.
587 */
588 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
589
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700590 /**
591 * Indicates that the call is using VoIP audio mode.
592 * <p>
593 * When this property is set, the {@link android.media.AudioManager} audio mode for this
594 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
595 * property is not set, the audio mode for this call will be
596 * {@link android.media.AudioManager#MODE_IN_CALL}.
597 * <p>
598 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
599 * <p>
600 * You can use this property to determine whether an un-answered incoming call or a held
601 * call will use VoIP audio mode (if the call does not currently have focus, the system
602 * audio mode may not reflect the mode the call will use).
603 */
604 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
605
Ravi Paluri80aa2142019-12-02 11:57:37 +0530606 /**
607 * Indicates that the call is an adhoc conference call. This property can be set for both
Grace Jia8587ee52020-07-10 15:42:32 -0700608 * incoming and outgoing calls. An adhoc conference call is formed using
609 * {@link #addConferenceParticipants(List)},
610 * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}, or
611 * {@link TelecomManager#startConference(List, Bundle)}, rather than by merging existing
612 * call using {@link #conference(Call)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530613 */
614 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 0x00002000;
615
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800616 /**
Sooraj Sasindranfa1e57a2021-03-22 13:44:14 -0700617 * Connection is using cross sim technology.
618 * <p>
619 * Indicates that the {@link Connection} is using a cross sim technology which would
620 * register IMS over internet APN of default data subscription.
621 * <p>
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800622 */
623 public static final int PROPERTY_CROSS_SIM = 0x00004000;
624
Grant Menke6ca706b2023-08-23 07:46:09 -0700625 /**
626 * The connection is using transactional call APIs.
627 * <p>
628 * The underlying connection was added as a transactional call via the
629 * {@link TelecomManager#addCall} API.
630 */
Grant Menke417190a2023-08-30 14:39:29 -0700631 @FlaggedApi(Flags.FLAG_VOIP_APP_ACTIONS_SUPPORT)
Grant Menke6ca706b2023-08-23 07:46:09 -0700632 public static final int PROPERTY_IS_TRANSACTIONAL = 0x00008000;
633
Andrew Lee2378ea72015-04-29 14:38:11 -0700634 //******************************************************************************************
Grant Menke6ca706b2023-08-23 07:46:09 -0700635 // Next PROPERTY value: 0x00010000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700636 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800637
Tyler Gunn1e406ca2021-03-18 16:47:14 -0700638 private final @CallState int mState;
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800639 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700640 private final Uri mHandle;
641 private final int mHandlePresentation;
642 private final String mCallerDisplayName;
643 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700644 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700645 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700646 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800647 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700648 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700649 private final long mConnectTimeMillis;
650 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700651 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700652 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700653 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700654 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700655 private final long mCreationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -0800656 private final String mContactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800657 private final @CallDirection int mCallDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700658 private final @Connection.VerificationStatus int mCallerNumberVerificationStatus;
Edgar Arriagae5bec822022-10-14 14:25:43 -0700659 private final Uri mContactPhotoUri;
Ihab Awade63fadb2014-07-09 21:52:04 -0700660
661 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800662 * Whether the supplied capabilities supports the specified capability.
663 *
664 * @param capabilities A bit field of capabilities.
665 * @param capability The capability to check capabilities for.
666 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800667 */
668 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800669 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800670 }
671
672 /**
673 * Whether the capabilities of this {@code Details} supports the specified capability.
674 *
675 * @param capability The capability to check capabilities for.
676 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800677 */
678 public boolean can(int capability) {
679 return can(mCallCapabilities, capability);
680 }
681
682 /**
683 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
684 *
685 * @param capabilities A capability bit field.
686 * @return A human readable string representation.
687 */
688 public static String capabilitiesToString(int capabilities) {
689 StringBuilder builder = new StringBuilder();
690 builder.append("[Capabilities:");
691 if (can(capabilities, CAPABILITY_HOLD)) {
692 builder.append(" CAPABILITY_HOLD");
693 }
694 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
695 builder.append(" CAPABILITY_SUPPORT_HOLD");
696 }
697 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
698 builder.append(" CAPABILITY_MERGE_CONFERENCE");
699 }
700 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
701 builder.append(" CAPABILITY_SWAP_CONFERENCE");
702 }
703 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
704 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
705 }
706 if (can(capabilities, CAPABILITY_MUTE)) {
707 builder.append(" CAPABILITY_MUTE");
708 }
709 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
710 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
711 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700712 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
713 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
714 }
715 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
716 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
717 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700718 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
719 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800720 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700721 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
722 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
723 }
724 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
725 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
726 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800727 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
728 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
729 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700730 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
731 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800732 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500733 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700734 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500735 }
Rekha Kumar07366812015-03-24 16:42:31 -0700736 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
737 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
738 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700739 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
740 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
741 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700742 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
743 builder.append(" CAPABILITY_CAN_PULL_CALL");
744 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530745 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
746 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
747 }
Ravi Paluri404babb2020-01-23 19:02:44 +0530748 if (can(capabilities, CAPABILITY_ADD_PARTICIPANT)) {
749 builder.append(" CAPABILITY_ADD_PARTICIPANT");
750 }
Ravi Palurif4b38e72020-02-05 12:35:41 +0530751 if (can(capabilities, CAPABILITY_TRANSFER)) {
752 builder.append(" CAPABILITY_TRANSFER");
753 }
754 if (can(capabilities, CAPABILITY_TRANSFER_CONSULTATIVE)) {
755 builder.append(" CAPABILITY_TRANSFER_CONSULTATIVE");
756 }
Alvin Dey2f37d772018-05-18 23:16:10 +0530757 if (can(capabilities, CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT)) {
758 builder.append(" CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT");
759 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800760 builder.append("]");
761 return builder.toString();
762 }
763
764 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700765 * Whether the supplied properties includes the specified property.
766 *
767 * @param properties A bit field of properties.
768 * @param property The property to check properties for.
769 * @return Whether the specified property is supported.
770 */
771 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800772 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700773 }
774
775 /**
776 * Whether the properties of this {@code Details} includes the specified property.
777 *
778 * @param property The property to check properties for.
779 * @return Whether the specified property is supported.
780 */
781 public boolean hasProperty(int property) {
782 return hasProperty(mCallProperties, property);
783 }
784
785 /**
786 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
787 *
788 * @param properties A property bit field.
789 * @return A human readable string representation.
790 */
791 public static String propertiesToString(int properties) {
792 StringBuilder builder = new StringBuilder();
793 builder.append("[Properties:");
794 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
795 builder.append(" PROPERTY_CONFERENCE");
796 }
797 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
798 builder.append(" PROPERTY_GENERIC_CONFERENCE");
799 }
800 if (hasProperty(properties, PROPERTY_WIFI)) {
801 builder.append(" PROPERTY_WIFI");
802 }
803 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
804 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
805 }
806 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700807 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700808 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700809 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
810 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
811 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700812 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700813 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
814 }
Tyler Gunnc9503d62020-01-27 10:30:51 -0800815 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800816 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
817 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700818 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
819 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
820 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700821 if (hasProperty(properties, PROPERTY_RTT)) {
822 builder.append(" PROPERTY_RTT");
823 }
824 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
825 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
826 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530827 if (hasProperty(properties, PROPERTY_IS_ADHOC_CONFERENCE)) {
828 builder.append(" PROPERTY_IS_ADHOC_CONFERENCE");
829 }
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800830 if (hasProperty(properties, PROPERTY_CROSS_SIM)) {
831 builder.append(" PROPERTY_CROSS_SIM");
832 }
Grant Menke6ca706b2023-08-23 07:46:09 -0700833 if (hasProperty(properties, PROPERTY_IS_TRANSACTIONAL)) {
834 builder.append(" PROPERTY_IS_TRANSACTIONAL");
835 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700836 builder.append("]");
837 return builder.toString();
838 }
839
Tyler Gunn1e406ca2021-03-18 16:47:14 -0700840 /**
841 * @return the state of the {@link Call} represented by this {@link Call.Details}.
842 */
843 public final @CallState int getState() {
844 return mState;
845 }
846
Grant Menke626dd262023-07-24 15:19:36 -0700847 /**
848 * @return the Telecom identifier associated with this {@link Call} . This is not a stable
849 * identifier and is not guaranteed to be unique across device reboots.
850 */
Grant Menke37155c82023-10-10 14:17:26 -0700851 @FlaggedApi(Flags.FLAG_CALL_DETAILS_ID_CHANGES)
Grant Menke626dd262023-07-24 15:19:36 -0700852 public @NonNull String getId() { return mTelecomCallId; }
853
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800854 /** {@hide} */
Hall Liu31de23d2019-10-11 15:38:29 -0700855 @TestApi
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800856 public String getTelecomCallId() {
857 return mTelecomCallId;
858 }
859
Andrew Lee2378ea72015-04-29 14:38:11 -0700860 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700861 * @return The handle (e.g., phone number) to which the {@code Call} is currently
862 * connected.
863 */
864 public Uri getHandle() {
865 return mHandle;
866 }
867
868 /**
869 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700870 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700871 */
872 public int getHandlePresentation() {
873 return mHandlePresentation;
874 }
875
876 /**
Edgar Arriagae5bec822022-10-14 14:25:43 -0700877 * @return The contact photo URI which corresponds to
878 * {@link android.provider.ContactsContract.PhoneLookup#PHOTO_URI}, or {@code null} if the
879 * lookup is not yet complete, if there's no contacts entry for the caller,
880 * or if the {@link InCallService} does not hold the
881 * {@link android.Manifest.permission#READ_CONTACTS} permission.
882 */
883 public @Nullable Uri getContactPhotoUri() {
884 return mContactPhotoUri;
885 }
886
887 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800888 * The display name for the caller.
889 * <p>
890 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800891 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700892 * @return The display name for the caller.
893 */
894 public String getCallerDisplayName() {
895 return mCallerDisplayName;
896 }
897
898 /**
899 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700900 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700901 */
902 public int getCallerDisplayNamePresentation() {
903 return mCallerDisplayNamePresentation;
904 }
905
906 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700907 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
908 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700909 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700910 public PhoneAccountHandle getAccountHandle() {
911 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700912 }
913
914 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800915 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
916 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700917 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700918 public int getCallCapabilities() {
919 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700920 }
921
922 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700923 * @return A bitmask of the properties of the {@code Call}, as defined by the various
924 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700925 */
926 public int getCallProperties() {
927 return mCallProperties;
928 }
929
930 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800931 * @return a bitmask of the audio routes available for the call.
932 *
933 * @hide
934 */
935 public int getSupportedAudioRoutes() {
936 return mSupportedAudioRoutes;
937 }
938
939 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700940 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700941 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700942 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700943 public DisconnectCause getDisconnectCause() {
944 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700945 }
946
947 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700948 * Returns the time the {@link Call} connected (i.e. became active). This information is
949 * updated periodically, but user interfaces should not rely on this to display the "call
950 * time clock". For the time when the call was first added to Telecom, see
951 * {@link #getCreationTimeMillis()}.
952 *
953 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700954 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700955 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700956 return mConnectTimeMillis;
957 }
958
959 /**
960 * @return Information about any calling gateway the {@code Call} may be using.
961 */
962 public GatewayInfo getGatewayInfo() {
963 return mGatewayInfo;
964 }
965
Andrew Lee7a341382014-07-15 17:05:08 -0700966 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700967 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700968 */
969 public int getVideoState() {
970 return mVideoState;
971 }
972
Ihab Awad5d0410f2014-07-30 10:07:40 -0700973 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700974 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700975 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700976 */
977 public StatusHints getStatusHints() {
978 return mStatusHints;
979 }
980
Nancy Chen10798dc2014-08-08 14:00:25 -0700981 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700982 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700983 */
984 public Bundle getExtras() {
985 return mExtras;
986 }
987
Santos Cordon6b7f9552015-05-27 17:21:45 -0700988 /**
989 * @return The extras used with the original intent to place this call.
990 */
991 public Bundle getIntentExtras() {
992 return mIntentExtras;
993 }
994
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700995 /**
996 * Returns the time when the call was first created and added to Telecom. This is the same
997 * time that is logged as the start time in the Call Log (see
998 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
999 * (became active), see {@link #getConnectTimeMillis()}.
1000 *
1001 * @return The creation time of the call, in millis since the epoch.
1002 */
1003 public long getCreationTimeMillis() {
1004 return mCreationTimeMillis;
1005 }
1006
Tyler Gunnd081f042018-12-04 12:56:45 -08001007 /**
Hall Liuef98bf82020-01-09 15:22:44 -08001008 * Returns the name of the caller on the remote end, as derived from a
1009 * {@link android.provider.ContactsContract} lookup of the call's handle.
1010 * @return The name of the caller, or {@code null} if the lookup is not yet complete, if
1011 * there's no contacts entry for the caller, or if the {@link InCallService} does
1012 * not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
1013 */
1014 public @Nullable String getContactDisplayName() {
1015 return mContactDisplayName;
1016 }
1017
1018 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -08001019 * Indicates whether the call is an incoming or outgoing call.
1020 * @return The call's direction.
1021 */
1022 public @CallDirection int getCallDirection() {
1023 return mCallDirection;
1024 }
1025
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001026 /**
1027 * Gets the verification status for the phone number of an incoming call as identified in
1028 * ATIS-1000082.
Tyler Gunn9c642492020-10-08 13:37:03 -07001029 * <p>
1030 * For incoming calls, the number verification status indicates whether the device was
1031 * able to verify the authenticity of the calling number using the STIR process outlined
1032 * in ATIS-1000082. {@link Connection#VERIFICATION_STATUS_NOT_VERIFIED} indicates that
1033 * the network was not able to use STIR to verify the caller's number (i.e. nothing is
1034 * known regarding the authenticity of the number.
1035 * {@link Connection#VERIFICATION_STATUS_PASSED} indicates that the network was able to
1036 * use STIR to verify the caller's number. This indicates that the network has a high
1037 * degree of confidence that the incoming call actually originated from the indicated
1038 * number. {@link Connection#VERIFICATION_STATUS_FAILED} indicates that the network's
1039 * STIR verification did not pass. This indicates that the incoming call may not
1040 * actually be from the indicated number. This could occur if, for example, the caller
1041 * is using an impersonated phone number.
1042 * <p>
1043 * A {@link CallScreeningService} can use this information to help determine if an
1044 * incoming call is potentially an unwanted call. A verification status of
1045 * {@link Connection#VERIFICATION_STATUS_FAILED} indicates that an incoming call may not
1046 * actually be from the number indicated on the call (i.e. impersonated number) and that it
1047 * should potentially be blocked. Likewise,
1048 * {@link Connection#VERIFICATION_STATUS_PASSED} can be used as a positive signal to
1049 * help clarify that the incoming call is originating from the indicated number and it
1050 * is less likely to be an undesirable call.
1051 * <p>
1052 * An {@link InCallService} can use this information to provide a visual indicator to the
1053 * user regarding the verification status of a call and to help identify calls from
1054 * potentially impersonated numbers.
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001055 * @return the verification status.
1056 */
1057 public @Connection.VerificationStatus int getCallerNumberVerificationStatus() {
1058 return mCallerNumberVerificationStatus;
1059 }
1060
Ihab Awade63fadb2014-07-09 21:52:04 -07001061 @Override
1062 public boolean equals(Object o) {
1063 if (o instanceof Details) {
1064 Details d = (Details) o;
1065 return
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001066 Objects.equals(mState, d.mState) &&
Ihab Awade63fadb2014-07-09 21:52:04 -07001067 Objects.equals(mHandle, d.mHandle) &&
1068 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
1069 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
1070 Objects.equals(mCallerDisplayNamePresentation,
1071 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -07001072 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -07001073 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -07001074 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001075 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -07001076 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -07001077 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -07001078 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -07001079 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001080 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001081 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -08001082 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Hall Liuef98bf82020-01-09 15:22:44 -08001083 Objects.equals(mContactDisplayName, d.mContactDisplayName) &&
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001084 Objects.equals(mCallDirection, d.mCallDirection) &&
1085 Objects.equals(mCallerNumberVerificationStatus,
Edgar Arriagae5bec822022-10-14 14:25:43 -07001086 d.mCallerNumberVerificationStatus) &&
1087 Objects.equals(mContactPhotoUri, d.mContactPhotoUri);
Ihab Awade63fadb2014-07-09 21:52:04 -07001088 }
1089 return false;
1090 }
1091
1092 @Override
1093 public int hashCode() {
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001094 return Objects.hash(mState,
1095 mHandle,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001096 mHandlePresentation,
1097 mCallerDisplayName,
1098 mCallerDisplayNamePresentation,
1099 mAccountHandle,
1100 mCallCapabilities,
1101 mCallProperties,
1102 mDisconnectCause,
1103 mConnectTimeMillis,
1104 mGatewayInfo,
1105 mVideoState,
1106 mStatusHints,
1107 mExtras,
1108 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001109 mCreationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001110 mContactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001111 mCallDirection,
Edgar Arriagae5bec822022-10-14 14:25:43 -07001112 mCallerNumberVerificationStatus,
1113 mContactPhotoUri);
Ihab Awade63fadb2014-07-09 21:52:04 -07001114 }
1115
1116 /** {@hide} */
1117 public Details(
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001118 @CallState int state,
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001119 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -07001120 Uri handle,
1121 int handlePresentation,
1122 String callerDisplayName,
1123 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -07001124 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -07001125 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -07001126 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001127 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -07001128 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -07001129 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -07001130 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -07001131 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -07001132 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001133 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001134 long creationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001135 String contactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001136 int callDirection,
Edgar Arriagae5bec822022-10-14 14:25:43 -07001137 int callerNumberVerificationStatus,
1138 Uri contactPhotoUri) {
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001139 mState = state;
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001140 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001141 mHandle = handle;
1142 mHandlePresentation = handlePresentation;
1143 mCallerDisplayName = callerDisplayName;
1144 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -07001145 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -07001146 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -07001147 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001148 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -07001149 mConnectTimeMillis = connectTimeMillis;
1150 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -07001151 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -07001152 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -07001153 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001154 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001155 mCreationTimeMillis = creationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -08001156 mContactDisplayName = contactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -08001157 mCallDirection = callDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001158 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
Edgar Arriagae5bec822022-10-14 14:25:43 -07001159 mContactPhotoUri = contactPhotoUri;
Ihab Awade63fadb2014-07-09 21:52:04 -07001160 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001161
1162 /** {@hide} */
1163 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
1164 return new Details(
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001165 parcelableCall.getState(),
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001166 parcelableCall.getId(),
1167 parcelableCall.getHandle(),
1168 parcelableCall.getHandlePresentation(),
1169 parcelableCall.getCallerDisplayName(),
1170 parcelableCall.getCallerDisplayNamePresentation(),
1171 parcelableCall.getAccountHandle(),
1172 parcelableCall.getCapabilities(),
1173 parcelableCall.getProperties(),
1174 parcelableCall.getDisconnectCause(),
1175 parcelableCall.getConnectTimeMillis(),
1176 parcelableCall.getGatewayInfo(),
1177 parcelableCall.getVideoState(),
1178 parcelableCall.getStatusHints(),
1179 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001180 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -08001181 parcelableCall.getCreationTimeMillis(),
Hall Liuef98bf82020-01-09 15:22:44 -08001182 parcelableCall.getContactDisplayName(),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001183 parcelableCall.getCallDirection(),
Edgar Arriagae5bec822022-10-14 14:25:43 -07001184 parcelableCall.getCallerNumberVerificationStatus(),
1185 parcelableCall.getContactPhotoUri()
1186 );
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001187 }
Santos Cordon3c20d632016-02-25 16:12:35 -08001188
1189 @Override
1190 public String toString() {
1191 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001192 sb.append("[id: ");
1193 sb.append(mTelecomCallId);
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001194 sb.append(", state: ");
1195 sb.append(Call.stateToString(mState));
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001196 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -08001197 sb.append(mAccountHandle);
1198 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001199 sb.append(Log.piiHandle(mHandle));
1200 sb.append(", hdlPres: ");
1201 sb.append(mHandlePresentation);
1202 sb.append(", videoState: ");
1203 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -08001204 sb.append(", caps: ");
1205 sb.append(capabilitiesToString(mCallCapabilities));
1206 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001207 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001208 sb.append("]");
1209 return sb.toString();
1210 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001211 }
1212
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001213 /**
1214 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1215 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1216 * implementation.
1217 * <p>
1218 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1219 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1220 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1221 * {@link Callback} implementation, if desired.
1222 * <p>
1223 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1224 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1225 * (typically in {@link InCallService#onCallRemoved(Call)}).
1226 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1227 * reach your implementation of {@link Callback}, so it is important to register your callback
1228 * as soon as your {@link InCallService} is notified of a new call via
1229 * {@link InCallService#onCallAdded(Call)}.
1230 */
Andrew Leeda80c872015-04-15 14:09:50 -07001231 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001232 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001233 * @hide
1234 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001235 @IntDef(prefix = { "HANDOVER_" },
1236 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001237 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001238 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001239 @Retention(RetentionPolicy.SOURCE)
1240 public @interface HandoverFailureErrors {}
1241
1242 /**
1243 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001244 * to handover the call to rejects the handover request.
1245 * <p>
1246 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1247 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1248 * {@code null} {@link Connection} from
1249 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1250 * ConnectionRequest)}.
1251 * <p>
1252 * For more information on call handovers, see
1253 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001254 */
1255 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1256
1257 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001258 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1259 * is initiated but the source or destination app does not support handover.
1260 * <p>
1261 * Will be returned when a handover is requested via
1262 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1263 * {@link PhoneAccountHandle} does not declare
1264 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1265 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1266 * {@link Details#getAccountHandle()}) does not declare
1267 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1268 * <p>
1269 * For more information on call handovers, see
1270 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001271 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001272 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001273
1274 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001275 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1276 * user rejects the handover request.
1277 * <p>
1278 * For more information on call handovers, see
1279 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001280 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001281 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001282
Sanket Padawe85291f62017-12-01 13:59:27 -08001283 /**
1284 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1285 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001286 * <p>
1287 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1288 * called on an emergency call, or if any other call is an emergency call.
1289 * <p>
1290 * Handovers are not permitted while there are ongoing emergency calls.
1291 * <p>
1292 * For more information on call handovers, see
1293 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001294 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001295 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001296
Tyler Gunn9d127732018-03-02 15:45:51 -08001297 /**
1298 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1299 * fails for an unknown reason.
1300 * <p>
1301 * For more information on call handovers, see
1302 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1303 */
1304 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001305
1306 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001307 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1308 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001309 * @param call The {@code Call} invoking this method.
1310 * @param state The new state of the {@code Call}.
1311 */
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001312 public void onStateChanged(Call call, @CallState int state) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001313
1314 /**
1315 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1316 *
1317 * @param call The {@code Call} invoking this method.
1318 * @param parent The new parent of the {@code Call}.
1319 */
1320 public void onParentChanged(Call call, Call parent) {}
1321
1322 /**
1323 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1324 *
1325 * @param call The {@code Call} invoking this method.
1326 * @param children The new children of the {@code Call}.
1327 */
1328 public void onChildrenChanged(Call call, List<Call> children) {}
1329
1330 /**
1331 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1332 *
1333 * @param call The {@code Call} invoking this method.
1334 * @param details A {@code Details} object describing the {@code Call}.
1335 */
1336 public void onDetailsChanged(Call call, Details details) {}
1337
1338 /**
1339 * Invoked when the text messages that can be used as responses to the incoming
1340 * {@code Call} are loaded from the relevant database.
1341 * See {@link #getCannedTextResponses()}.
1342 *
1343 * @param call The {@code Call} invoking this method.
1344 * @param cannedTextResponses The text messages useable as responses.
1345 */
1346 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1347
1348 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001349 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1350 * character. This causes the post-dial signals to stop pending user confirmation. An
1351 * implementation should present this choice to the user and invoke
1352 * {@link #postDialContinue(boolean)} when the user makes the choice.
1353 *
1354 * @param call The {@code Call} invoking this method.
1355 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1356 */
1357 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1358
1359 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001360 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001361 *
1362 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001363 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001364 */
Andrew Lee50aca232014-07-22 16:41:54 -07001365 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001366
1367 /**
1368 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1369 * up their UI for the {@code Call} in response to state transitions. Specifically,
1370 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1371 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1372 * clients should wait for this method to be invoked.
1373 *
1374 * @param call The {@code Call} being destroyed.
1375 */
1376 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001377
1378 /**
1379 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1380 * conferenced.
1381 *
1382 * @param call The {@code Call} being updated.
1383 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1384 * conferenced.
1385 */
1386 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001387
1388 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001389 * Invoked when a {@link Call} receives an event from its associated {@link Connection} or
1390 * {@link Conference}.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001391 * <p>
1392 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1393 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1394 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1395 * possible that a {@link ConnectionService} has defined its own Connection events which a
1396 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001397 * <p>
Tyler Gunn5567d742019-10-31 13:04:37 -07001398 * See {@link Connection#sendConnectionEvent(String, Bundle)},
1399 * {@link Conference#sendConferenceEvent(String, Bundle)}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001400 *
1401 * @param call The {@code Call} receiving the event.
1402 * @param event The event.
1403 * @param extras Extras associated with the connection event.
1404 */
1405 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001406
1407 /**
1408 * Invoked when the RTT mode changes for this call.
1409 * @param call The call whose RTT mode has changed.
1410 * @param mode the new RTT mode, one of
1411 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1412 * or {@link RttCall#RTT_MODE_VCO}
1413 */
1414 public void onRttModeChanged(Call call, int mode) {}
1415
1416 /**
1417 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1418 * @param call The call whose RTT status has changed.
1419 * @param enabled whether RTT is now enabled or disabled
1420 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1421 * on, null otherwise.
1422 */
1423 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1424
1425 /**
1426 * Invoked when the remote end of the connection has requested that an RTT communication
1427 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1428 * with the same ID that this method is invoked with.
1429 * @param call The call which the RTT request was placed on
1430 * @param id The ID of the request.
1431 */
1432 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001433
1434 /**
1435 * Invoked when the RTT session failed to initiate for some reason, including rejection
1436 * by the remote party.
Tyler Gunnb9a04962022-02-17 08:23:54 -08001437 * <p>
1438 * This callback will ONLY be invoked to report a failure related to a user initiated
1439 * session modification request (i.e. {@link Call#sendRttRequest()}).
1440 * <p>
1441 * If a call is initiated with {@link TelecomManager#EXTRA_START_CALL_WITH_RTT} specified,
1442 * the availability of RTT can be determined by checking {@link Details#PROPERTY_RTT}
1443 * once the call enters state {@link Details#STATE_ACTIVE}.
1444 *
Hall Liu57006aa2017-02-06 10:49:48 -08001445 * @param call The call which the RTT initiation failure occurred on.
1446 * @param reason One of the status codes defined in
Tyler Gunnb9a04962022-02-17 08:23:54 -08001447 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1448 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liu57006aa2017-02-06 10:49:48 -08001449 */
Tyler Gunnb9a04962022-02-17 08:23:54 -08001450 public void onRttInitiationFailure(Call call,
1451 @android.telecom.Connection.RttModifyStatus.RttSessionModifyStatus int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001452
1453 /**
1454 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1455 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001456 * <p>
1457 * For a full discussion of the handover process and the APIs involved, see
1458 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1459 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001460 * @param call The call which had initiated handover.
1461 */
1462 public void onHandoverComplete(Call call) {}
1463
1464 /**
1465 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1466 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001467 * <p>
1468 * For a full discussion of the handover process and the APIs involved, see
1469 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1470 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001471 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001472 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001473 */
1474 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001475 }
1476
1477 /**
1478 * A class that holds the state that describes the state of the RTT channel to the remote
1479 * party, if it is active.
1480 */
1481 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001482 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001483 @Retention(RetentionPolicy.SOURCE)
1484 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1485 public @interface RttAudioMode {}
1486
1487 /**
1488 * For metrics use. Default value in the proto.
1489 * @hide
1490 */
1491 public static final int RTT_MODE_INVALID = 0;
1492
1493 /**
1494 * Indicates that there should be a bidirectional audio stream between the two parties
1495 * on the call.
1496 */
1497 public static final int RTT_MODE_FULL = 1;
1498
1499 /**
1500 * Indicates that the local user should be able to hear the audio stream from the remote
1501 * user, but not vice versa. Equivalent to muting the microphone.
1502 */
1503 public static final int RTT_MODE_HCO = 2;
1504
1505 /**
1506 * Indicates that the remote user should be able to hear the audio stream from the local
1507 * user, but not vice versa. Equivalent to setting the volume to zero.
1508 */
1509 public static final int RTT_MODE_VCO = 3;
1510
1511 private static final int READ_BUFFER_SIZE = 1000;
1512
1513 private InputStreamReader mReceiveStream;
1514 private OutputStreamWriter mTransmitStream;
1515 private int mRttMode;
1516 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001517 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001518 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1519
1520 /**
1521 * @hide
1522 */
Hall Liu57006aa2017-02-06 10:49:48 -08001523 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1524 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1525 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001526 mReceiveStream = receiveStream;
1527 mTransmitStream = transmitStream;
1528 mRttMode = mode;
1529 mInCallAdapter = inCallAdapter;
1530 }
1531
1532 /**
1533 * Returns the current RTT audio mode.
1534 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1535 * {@link #RTT_MODE_HCO}.
1536 */
1537 public int getRttAudioMode() {
1538 return mRttMode;
1539 }
1540
1541 /**
1542 * Sets the RTT audio mode. The requested mode change will be communicated through
1543 * {@link Callback#onRttModeChanged(Call, int)}.
1544 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1545 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1546 */
1547 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001548 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001549 }
1550
1551 /**
1552 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
Hall Liudc46c852020-10-29 16:15:33 -07001553 * RTT transmits text in real-time, this method should be called once for each user action.
1554 * For example, when the user enters text as discrete characters using the keyboard, this
1555 * method should be called once for each character. However, if the user enters text by
1556 * pasting or autocomplete, the entire contents of the pasted or autocompleted text should
1557 * be sent in one call to this method.
Hall Liu95d55872017-01-25 17:12:49 -08001558 *
1559 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1560 * lead to interleaved text.
1561 * @param input The message to send to the remote user.
1562 */
1563 public void write(String input) throws IOException {
1564 mTransmitStream.write(input);
1565 mTransmitStream.flush();
1566 }
1567
1568 /**
1569 * Reads a string from the remote user, blocking if there is no data available. Returns
1570 * {@code null} if the RTT conversation has been terminated and there is no further data
1571 * to read.
1572 *
1573 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1574 * lead to interleaved text.
1575 * @return A string containing text sent by the remote user, or {@code null} if the
1576 * conversation has been terminated or if there was an error while reading.
1577 */
Hall Liub1c8a772017-07-17 17:04:41 -07001578 public String read() {
1579 try {
1580 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1581 if (numRead < 0) {
1582 return null;
1583 }
1584 return new String(mReadBuffer, 0, numRead);
1585 } catch (IOException e) {
1586 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001587 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001588 }
Hall Liuffa4a812017-03-02 16:11:00 -08001589 }
1590
1591 /**
1592 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1593 * be read.
1594 * @return A string containing text entered by the user, or {@code null} if the user has
1595 * not entered any new text yet.
1596 */
1597 public String readImmediately() throws IOException {
1598 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001599 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1600 if (numRead < 0) {
1601 return null;
1602 }
1603 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001604 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001605 return null;
1606 }
1607 }
Hall Liue9041242018-02-09 16:40:03 -08001608
1609 /**
1610 * Closes the underlying file descriptors
1611 * @hide
1612 */
1613 public void close() {
1614 try {
1615 mReceiveStream.close();
1616 } catch (IOException e) {
1617 // ignore
1618 }
1619 try {
1620 mTransmitStream.close();
1621 } catch (IOException e) {
1622 // ignore
1623 }
1624 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001625 }
1626
Andrew Leeda80c872015-04-15 14:09:50 -07001627 /**
1628 * @deprecated Use {@code Call.Callback} instead.
1629 * @hide
1630 */
1631 @Deprecated
1632 @SystemApi
1633 public static abstract class Listener extends Callback { }
1634
Ihab Awade63fadb2014-07-09 21:52:04 -07001635 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001636 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001637 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001638 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001639 private final List<Call> mChildren = new ArrayList<>();
1640 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001641 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001642 private final List<Call> mConferenceableCalls = new ArrayList<>();
1643 private final List<Call> mUnmodifiableConferenceableCalls =
1644 Collections.unmodifiableList(mConferenceableCalls);
1645
Santos Cordon823fd3c2014-08-07 18:35:18 -07001646 private boolean mChildrenCached;
1647 private String mParentId = null;
Hall Liuef98bf82020-01-09 15:22:44 -08001648 private String mActiveGenericConferenceChild = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001649 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001650 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001651 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001652 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001653 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001654 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001655 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001656 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001657 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001658
1659 /**
1660 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1661 *
1662 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1663 * remaining or this {@code Call} is not in a post-dial state.
1664 */
1665 public String getRemainingPostDialSequence() {
1666 return mRemainingPostDialSequence;
1667 }
1668
1669 /**
1670 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001671 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001672 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001673 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001674 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001675 }
1676
1677 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301678 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1679 *
1680 * @param address The address to which the call will be deflected.
1681 */
1682 public void deflect(Uri address) {
1683 mInCallAdapter.deflectCall(mTelecomCallId, address);
1684 }
1685
1686 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001687 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1688 *
1689 * @param rejectWithMessage Whether to reject with a text message.
1690 * @param textMessage An optional text message with which to respond.
1691 */
1692 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001693 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001694 }
1695
1696 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001697 * Instructs the {@link ConnectionService} providing this {@link #STATE_RINGING} call that the
1698 * user has chosen to reject the call and has indicated a reason why the call is being rejected.
1699 *
1700 * @param rejectReason the reason the call is being rejected.
1701 */
1702 public void reject(@RejectReason int rejectReason) {
1703 mInCallAdapter.rejectCall(mTelecomCallId, rejectReason);
1704 }
1705
1706 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05301707 * Instructs this {@code Call} to be transferred to another number.
1708 *
1709 * @param targetNumber The address to which the call will be transferred.
Tyler Gunn460360d2020-07-29 10:21:45 -07001710 * @param isConfirmationRequired if {@code true} it will initiate a confirmed transfer,
1711 * if {@code false}, it will initiate an unconfirmed transfer.
Ravi Palurif4b38e72020-02-05 12:35:41 +05301712 *
1713 * @hide
1714 */
1715 public void transfer(@NonNull Uri targetNumber, boolean isConfirmationRequired) {
1716 mInCallAdapter.transferCall(mTelecomCallId, targetNumber, isConfirmationRequired);
1717 }
1718
1719 /**
1720 * Instructs this {@code Call} to be transferred to another ongoing call.
1721 * This will initiate CONSULTATIVE transfer.
1722 * @param toCall The other ongoing {@code Call} to which this call will be transferred.
1723 *
1724 * @hide
1725 */
1726 public void transfer(@NonNull android.telecom.Call toCall) {
1727 mInCallAdapter.transferCall(mTelecomCallId, toCall.mTelecomCallId);
1728 }
1729
1730 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001731 * Instructs this {@code Call} to disconnect.
1732 */
1733 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001734 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001735 }
1736
1737 /**
1738 * Instructs this {@code Call} to go on hold.
1739 */
1740 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001741 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001742 }
1743
1744 /**
1745 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1746 */
1747 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001748 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001749 }
1750
1751 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001752 * Instructs Telecom to put the call into the background audio processing state.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001753 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001754 * This method can be called either when the call is in {@link #STATE_RINGING} or
1755 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1756 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1757 * order to capture and play audio on the call stream.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001758 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001759 * This method can only be called by the default dialer app.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001760 * <p>
1761 * Apps built with SDK version {@link android.os.Build.VERSION_CODES#R} or later which are using
1762 * the microphone as part of audio processing should specify the foreground service type using
1763 * the attribute {@link android.R.attr#foregroundServiceType} in the {@link InCallService}
1764 * service element of the app's manifest file.
1765 * The {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_MICROPHONE} attribute should be specified.
1766 * @see <a href="https://developer.android.com/preview/privacy/foreground-service-types">
1767 * the Android Developer Site</a> for more information.
Hall Liu6dfa2492019-10-01 17:20:39 -07001768 * @hide
1769 */
1770 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001771 public void enterBackgroundAudioProcessing() {
1772 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1773 throw new IllegalStateException("Call must be active or ringing");
1774 }
1775 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1776 }
1777
1778 /**
1779 * Instructs Telecom to come out of the background audio processing state requested by
1780 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1781 *
1782 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1783 *
1784 * @param shouldRing If true, Telecom will put the call into the
1785 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1786 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1787 * immediately.
1788 * @hide
1789 */
1790 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001791 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1792 if (mState != STATE_AUDIO_PROCESSING) {
1793 throw new IllegalStateException("Call must in the audio processing state");
1794 }
1795 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1796 }
1797
1798 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001799 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
Tyler Gunn2517d032023-02-06 16:34:54 +00001800 * <p>
1801 * Tones are both played locally for the user to hear and sent to the network to be relayed
1802 * to the remote device.
1803 * <p>
Anton Hansson84d6d752023-10-05 09:46:37 +00001804 * You must ensure that any call to {@link #playDtmfTone(char)} is followed by a matching
Tyler Gunn2517d032023-02-06 16:34:54 +00001805 * call to {@link #stopDtmfTone()} and that each tone is stopped before a new one is started.
1806 * The play and stop commands are relayed to the underlying
1807 * {@link android.telecom.ConnectionService} as executed; implementations may not correctly
1808 * handle out of order commands.
Ihab Awade63fadb2014-07-09 21:52:04 -07001809 *
1810 * @param digit A character representing the DTMF digit for which to play the tone. This
1811 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1812 */
1813 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001814 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001815 }
1816
1817 /**
1818 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1819 * currently playing.
1820 *
1821 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1822 * currently playing, this method will do nothing.
1823 */
1824 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001825 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001826 }
1827
1828 /**
1829 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1830 *
1831 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1832 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001833 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001834 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001835 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1836 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001837 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001838 * {@code Call} will pause playing the tones and notify callbacks via
1839 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001840 * should display to the user an indication of this state and an affordance to continue
1841 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1842 * app should invoke the {@link #postDialContinue(boolean)} method.
1843 *
1844 * @param proceed Whether or not to continue with the post-dial sequence.
1845 */
1846 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001847 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001848 }
1849
1850 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001851 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001852 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001853 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001854 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1855 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001856
1857 }
1858
1859 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001860 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001861 *
1862 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001863 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001864 public void conference(Call callToConferenceWith) {
1865 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001866 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001867 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001868 }
1869
1870 /**
1871 * Instructs this {@code Call} to split from any conference call with which it may be
1872 * connected.
1873 */
1874 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001875 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001876 }
1877
1878 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001879 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001880 */
1881 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001882 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001883 }
1884
1885 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001886 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001887 */
1888 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001889 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001890 }
1891
1892 /**
Ravi Paluri404babb2020-01-23 19:02:44 +05301893 * Pulls participants to existing call by forming a conference call.
1894 * See {@link Details#CAPABILITY_ADD_PARTICIPANT}.
1895 *
1896 * @param participants participants to be pulled to existing call.
1897 */
1898 public void addConferenceParticipants(@NonNull List<Uri> participants) {
1899 mInCallAdapter.addConferenceParticipants(mTelecomCallId, participants);
1900 }
1901
1902 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001903 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1904 * device.
1905 * <p>
1906 * Calls to this method are ignored if the call does not have the
1907 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1908 * <p>
1909 * An {@link InCallService} will only see calls which support this method if it has the
1910 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1911 * in its manifest.
1912 */
1913 public void pullExternalCall() {
1914 // If this isn't an external call, ignore the request.
1915 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1916 return;
1917 }
1918
1919 mInCallAdapter.pullExternalCall(mTelecomCallId);
1920 }
1921
1922 /**
1923 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1924 * the {@link ConnectionService}.
1925 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001926 * Call events are used to communicate point in time information from an {@link InCallService}
1927 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1928 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1929 * {@link ConnectionService}.
1930 * <p>
1931 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1932 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1933 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001934 * Events are exposed to {@link ConnectionService} implementations via
1935 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1936 * <p>
1937 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001938 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1939 * ignore some events altogether.
1940 * <p>
1941 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1942 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1943 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1944 * they define their own event types in this namespace. When defining a custom event type,
1945 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1946 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1947 * <p>
1948 * When defining events and the associated extras, it is important to keep their behavior
1949 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1950 * events/extras should me maintained to ensure backwards compatibility with older
1951 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001952 *
1953 * @param event The connection event.
1954 * @param extras Bundle containing extra information associated with the event.
1955 */
1956 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001957 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001958 }
1959
1960 /**
Hall Liu95d55872017-01-25 17:12:49 -08001961 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1962 * guaranteed, and notification of success will be via the
1963 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1964 */
1965 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001966 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001967 }
1968
1969 /**
1970 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1971 * callback.
1972 * The ID used here should be the same as the ID that was received via the callback.
1973 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1974 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1975 */
1976 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001977 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001978 }
1979
1980 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001981 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1982 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1983 * handover.
1984 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001985 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1986 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1987 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1988 * is referred to as the source of the handover, and the video calling app is referred to as the
1989 * destination.
1990 * <p>
1991 * When considering a handover scenario the device this method is called on is considered the
1992 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1993 * other device is considered the <em>receiving</em> device.
1994 * <p>
1995 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1996 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1997 * and invoke
1998 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1999 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
2000 * call to it. The app returns an instance of {@link Connection} to represent the handover call
2001 * At this point the app should display UI to indicate to the user that a call
2002 * handover is in process.
2003 * <p>
2004 * The destination app is responsible for communicating the handover request from the
2005 * <em>initiating</em> device to the <em>receiving</em> device.
2006 * <p>
2007 * When the app on the <em>receiving</em> device receives the handover request, it calls
2008 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
2009 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
2010 * the destination app on the <em>receiving</em> device should show UI to allow the user to
2011 * choose whether they want to continue their call in the destination app.
2012 * <p>
2013 * When the destination app on the <em>receiving</em> device calls
2014 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
2015 * {@link ConnectionService} and call
2016 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
2017 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
2018 * {@link Connection} to represent the handover call.
2019 * <p>
2020 * If the user of the <em>receiving</em> device accepts the handover, the app calls
2021 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
2022 * original call. If the user rejects the handover, the app calls
2023 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
2024 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
2025 * <p>
2026 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
2027 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
2028 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
2029 * <p>
2030 * Errors in the handover process are reported to the {@link InCallService} via
2031 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
2032 * the involved {@link ConnectionService}s via
2033 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002034 *
2035 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
2036 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08002037 * @param videoState Indicates the video state desired after the handover (see the
2038 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07002039 * @param extras Bundle containing extra information to be passed to the
2040 * {@link ConnectionService}
2041 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002042 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
2043 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002044 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
2045 }
2046
2047 /**
Hall Liu95d55872017-01-25 17:12:49 -08002048 * Terminate the RTT session on this call. The resulting state change will be notified via
2049 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
2050 */
2051 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08002052 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08002053 }
2054
2055 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002056 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
2057 * added.
2058 * <p>
2059 * No assumptions should be made as to how an In-Call UI or service will handle these
2060 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
Tyler Gunn6c100242023-01-09 11:23:18 -08002061 * <p>
2062 * Extras added using this method will be made available to the {@link ConnectionService}
2063 * associated with this {@link Call} and notified via
2064 * {@link Connection#onExtrasChanged(Bundle)}.
2065 * <p>
2066 * Extras added using this method will also be available to other running {@link InCallService}s
2067 * and notified via {@link Call.Callback#onDetailsChanged(Call, Details)}. The extras can be
2068 * accessed via {@link Details#getExtras()}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002069 *
2070 * @param extras The extras to add.
2071 */
2072 public final void putExtras(Bundle extras) {
2073 if (extras == null) {
2074 return;
2075 }
2076
2077 if (mExtras == null) {
2078 mExtras = new Bundle();
2079 }
2080 mExtras.putAll(extras);
2081 mInCallAdapter.putExtras(mTelecomCallId, extras);
2082 }
2083
2084 /**
2085 * Adds a boolean extra to this {@link Call}.
2086 *
2087 * @param key The extra key.
2088 * @param value The value.
2089 * @hide
2090 */
2091 public final void putExtra(String key, boolean value) {
2092 if (mExtras == null) {
2093 mExtras = new Bundle();
2094 }
2095 mExtras.putBoolean(key, value);
2096 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2097 }
2098
2099 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002100 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002101 *
2102 * @param key The extra key.
2103 * @param value The value.
2104 * @hide
2105 */
2106 public final void putExtra(String key, int value) {
2107 if (mExtras == null) {
2108 mExtras = new Bundle();
2109 }
2110 mExtras.putInt(key, value);
2111 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2112 }
2113
2114 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002115 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002116 *
2117 * @param key The extra key.
2118 * @param value The value.
2119 * @hide
2120 */
2121 public final void putExtra(String key, String value) {
2122 if (mExtras == null) {
2123 mExtras = new Bundle();
2124 }
2125 mExtras.putString(key, value);
2126 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2127 }
2128
2129 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002130 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002131 *
2132 * @param keys The keys of the extras to remove.
2133 */
2134 public final void removeExtras(List<String> keys) {
2135 if (mExtras != null) {
2136 for (String key : keys) {
2137 mExtras.remove(key);
2138 }
2139 if (mExtras.size() == 0) {
2140 mExtras = null;
2141 }
2142 }
2143 mInCallAdapter.removeExtras(mTelecomCallId, keys);
2144 }
2145
2146 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002147 * Removes extras from this {@link Call}.
2148 *
2149 * @param keys The keys of the extras to remove.
2150 */
2151 public final void removeExtras(String ... keys) {
2152 removeExtras(Arrays.asList(keys));
2153 }
2154
2155 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002156 * Obtains the parent of this {@code Call} in a conference, if any.
2157 *
2158 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
2159 * child of any conference {@code Call}s.
2160 */
2161 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002162 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002163 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002164 }
2165 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07002166 }
2167
2168 /**
2169 * Obtains the children of this conference {@code Call}, if any.
2170 *
2171 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
2172 * {@code List} otherwise.
2173 */
2174 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002175 if (!mChildrenCached) {
2176 mChildrenCached = true;
2177 mChildren.clear();
2178
2179 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002180 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002181 if (call == null) {
2182 // At least one child was still not found, so do not save true for "cached"
2183 mChildrenCached = false;
2184 } else {
2185 mChildren.add(call);
2186 }
2187 }
2188 }
2189
Ihab Awade63fadb2014-07-09 21:52:04 -07002190 return mUnmodifiableChildren;
2191 }
2192
2193 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002194 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
2195 *
2196 * @return The list of conferenceable {@code Call}s.
2197 */
2198 public List<Call> getConferenceableCalls() {
2199 return mUnmodifiableConferenceableCalls;
2200 }
2201
2202 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002203 * Obtains the state of this {@code Call}.
2204 *
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002205 * @return The call state.
2206 * @deprecated The call state is available via {@link Call.Details#getState()}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002207 */
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002208 @Deprecated
2209 public @CallState int getState() {
Ihab Awade63fadb2014-07-09 21:52:04 -07002210 return mState;
2211 }
2212
2213 /**
Hall Liuef98bf82020-01-09 15:22:44 -08002214 * Returns the child {@link Call} in a generic conference that is currently active.
Hall Liu135e53aa2020-02-27 18:34:11 -08002215 *
2216 * A "generic conference" is the mechanism used to support two simultaneous calls on a device
2217 * in CDMA networks. It is effectively equivalent to having one call active and one call on hold
2218 * in GSM or IMS calls. This method returns the currently active call.
2219 *
2220 * In a generic conference, the network exposes the conference to us as a single call, and we
2221 * switch between talking to the two participants using a CDMA flash command. Since the network
2222 * exposes no additional information about the call, the only way we know which caller we're
2223 * currently talking to is by keeping track of the flash commands that we've sent to the
2224 * network.
2225 *
Hall Liuef98bf82020-01-09 15:22:44 -08002226 * For calls that are not generic conferences, or when the generic conference has more than
2227 * 2 children, returns {@code null}.
2228 * @see Details#PROPERTY_GENERIC_CONFERENCE
2229 * @return The active child call.
2230 */
2231 public @Nullable Call getGenericConferenceActiveChildCall() {
2232 if (mActiveGenericConferenceChild != null) {
2233 return mPhone.internalGetCallByTelecomId(mActiveGenericConferenceChild);
2234 }
2235 return null;
2236 }
2237
2238 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002239 * Obtains a list of canned, pre-configured message responses to present to the user as
Tyler Gunn434fc2c2020-10-06 14:23:54 -07002240 * ways of rejecting an incoming {@code Call} using via a text message.
2241 * <p>
2242 * <em>Note:</em> Since canned responses may be loaded from the file system, they are not
2243 * guaranteed to be present when this {@link Call} is first added to the {@link InCallService}
2244 * via {@link InCallService#onCallAdded(Call)}. The callback
2245 * {@link Call.Callback#onCannedTextResponsesLoaded(Call, List)} will be called when/if canned
2246 * responses for the call become available.
Ihab Awade63fadb2014-07-09 21:52:04 -07002247 *
2248 * @see #reject(boolean, String)
2249 *
2250 * @return A list of canned text message responses.
2251 */
2252 public List<String> getCannedTextResponses() {
2253 return mCannedTextResponses;
2254 }
2255
2256 /**
2257 * Obtains an object that can be used to display video from this {@code Call}.
2258 *
Andrew Lee50aca232014-07-22 16:41:54 -07002259 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002260 */
Andrew Lee50aca232014-07-22 16:41:54 -07002261 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002262 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07002263 }
2264
2265 /**
2266 * Obtains an object containing call details.
2267 *
2268 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
2269 * result may be {@code null}.
2270 */
2271 public Details getDetails() {
2272 return mDetails;
2273 }
2274
2275 /**
Hall Liu95d55872017-01-25 17:12:49 -08002276 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
2277 * receive RTT text data, as well as to change the RTT mode.
2278 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
2279 */
2280 public @Nullable RttCall getRttCall() {
2281 return mRttCall;
2282 }
2283
2284 /**
2285 * Returns whether this call has an active RTT connection.
2286 * @return true if there is a connection, false otherwise.
2287 */
2288 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08002289 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08002290 }
2291
2292 /**
Andrew Leeda80c872015-04-15 14:09:50 -07002293 * Registers a callback to this {@code Call}.
2294 *
2295 * @param callback A {@code Callback}.
2296 */
2297 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07002298 registerCallback(callback, new Handler());
2299 }
2300
2301 /**
2302 * Registers a callback to this {@code Call}.
2303 *
2304 * @param callback A {@code Callback}.
2305 * @param handler A handler which command and status changes will be delivered to.
2306 */
2307 public void registerCallback(Callback callback, Handler handler) {
2308 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07002309 // Don't allow new callback registration if the call is already being destroyed.
2310 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002311 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
2312 }
Andrew Leeda80c872015-04-15 14:09:50 -07002313 }
2314
2315 /**
2316 * Unregisters a callback from this {@code Call}.
2317 *
2318 * @param callback A {@code Callback}.
2319 */
2320 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002321 // Don't allow callback deregistration if the call is already being destroyed.
2322 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002323 for (CallbackRecord<Callback> record : mCallbackRecords) {
2324 if (record.getCallback() == callback) {
2325 mCallbackRecords.remove(record);
2326 break;
2327 }
2328 }
Andrew Leeda80c872015-04-15 14:09:50 -07002329 }
2330 }
2331
Santos Cordon3c20d632016-02-25 16:12:35 -08002332 @Override
2333 public String toString() {
2334 return new StringBuilder().
2335 append("Call [id: ").
2336 append(mTelecomCallId).
2337 append(", state: ").
2338 append(stateToString(mState)).
2339 append(", details: ").
2340 append(mDetails).
2341 append("]").toString();
2342 }
2343
2344 /**
2345 * @param state An integer value of a {@code STATE_*} constant.
2346 * @return A string representation of the value.
2347 */
2348 private static String stateToString(int state) {
2349 switch (state) {
2350 case STATE_NEW:
2351 return "NEW";
2352 case STATE_RINGING:
2353 return "RINGING";
2354 case STATE_DIALING:
2355 return "DIALING";
2356 case STATE_ACTIVE:
2357 return "ACTIVE";
2358 case STATE_HOLDING:
2359 return "HOLDING";
2360 case STATE_DISCONNECTED:
2361 return "DISCONNECTED";
2362 case STATE_CONNECTING:
2363 return "CONNECTING";
2364 case STATE_DISCONNECTING:
2365 return "DISCONNECTING";
2366 case STATE_SELECT_PHONE_ACCOUNT:
2367 return "SELECT_PHONE_ACCOUNT";
Hall Liu4e35b642019-10-14 17:50:45 -07002368 case STATE_SIMULATED_RINGING:
2369 return "SIMULATED_RINGING";
2370 case STATE_AUDIO_PROCESSING:
2371 return "AUDIO_PROCESSING";
Santos Cordon3c20d632016-02-25 16:12:35 -08002372 default:
2373 Log.w(Call.class, "Unknown state %d", state);
2374 return "UNKNOWN";
2375 }
2376 }
2377
Andrew Leeda80c872015-04-15 14:09:50 -07002378 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002379 * Adds a listener to this {@code Call}.
2380 *
2381 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002382 * @deprecated Use {@link #registerCallback} instead.
2383 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002384 */
Andrew Leeda80c872015-04-15 14:09:50 -07002385 @Deprecated
2386 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002387 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002388 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002389 }
2390
2391 /**
2392 * Removes a listener from this {@code Call}.
2393 *
2394 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002395 * @deprecated Use {@link #unregisterCallback} instead.
2396 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002397 */
Andrew Leeda80c872015-04-15 14:09:50 -07002398 @Deprecated
2399 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002400 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002401 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002402 }
2403
2404 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002405 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2406 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002407 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002408 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002409 mInCallAdapter = inCallAdapter;
2410 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002411 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002412 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002413 }
2414
2415 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002416 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002417 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002418 mPhone = phone;
2419 mTelecomCallId = telecomCallId;
2420 mInCallAdapter = inCallAdapter;
2421 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002422 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002423 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002424 }
2425
2426 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002427 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002428 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002429 }
2430
2431 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002432 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002433
Ihab Awade63fadb2014-07-09 21:52:04 -07002434 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002435 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002436 boolean detailsChanged = !Objects.equals(mDetails, details);
2437 if (detailsChanged) {
2438 mDetails = details;
2439 }
2440
2441 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002442 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2443 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2444 mCannedTextResponses =
2445 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002446 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002447 }
2448
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002449 IVideoProvider previousVideoProvider = mVideoCallImpl == null ? null :
2450 mVideoCallImpl.getVideoProvider();
2451 IVideoProvider newVideoProvider = parcelableCall.getVideoProvider();
2452
2453 // parcelableCall.isVideoCallProviderChanged is only true when we have a video provider
2454 // specified; so we should check if the actual IVideoProvider changes as well.
2455 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged()
2456 && !Objects.equals(previousVideoProvider, newVideoProvider);
Andrew Lee50aca232014-07-22 16:41:54 -07002457 if (videoCallChanged) {
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002458 if (mVideoCallImpl != null) {
2459 mVideoCallImpl.destroy();
2460 }
2461 mVideoCallImpl = parcelableCall.isVideoCallProviderChanged() ?
2462 parcelableCall.getVideoCallImpl(mCallingPackage, mTargetSdkVersion) : null;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002463 }
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002464
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002465 if (mVideoCallImpl != null) {
2466 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002467 }
2468
Santos Cordone3c507b2015-04-23 14:44:19 -07002469 int state = parcelableCall.getState();
Hall Liu31de23d2019-10-11 15:38:29 -07002470 if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2471 state = Call.STATE_RINGING;
2472 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002473 boolean stateChanged = mState != state;
2474 if (stateChanged) {
2475 mState = state;
2476 }
2477
Santos Cordon823fd3c2014-08-07 18:35:18 -07002478 String parentId = parcelableCall.getParentCallId();
2479 boolean parentChanged = !Objects.equals(mParentId, parentId);
2480 if (parentChanged) {
2481 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002482 }
2483
Santos Cordon823fd3c2014-08-07 18:35:18 -07002484 List<String> childCallIds = parcelableCall.getChildCallIds();
2485 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2486 if (childrenChanged) {
2487 mChildrenIds.clear();
2488 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2489 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002490 }
2491
Hall Liuef98bf82020-01-09 15:22:44 -08002492 String activeChildCallId = parcelableCall.getActiveChildCallId();
2493 boolean activeChildChanged = !Objects.equals(activeChildCallId,
2494 mActiveGenericConferenceChild);
2495 if (activeChildChanged) {
2496 mActiveGenericConferenceChild = activeChildCallId;
2497 }
2498
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002499 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2500 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2501 for (String otherId : conferenceableCallIds) {
2502 if (callIdMap.containsKey(otherId)) {
2503 conferenceableCalls.add(callIdMap.get(otherId));
2504 }
2505 }
2506
2507 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2508 mConferenceableCalls.clear();
2509 mConferenceableCalls.addAll(conferenceableCalls);
2510 fireConferenceableCallsChanged();
2511 }
2512
Hall Liu95d55872017-01-25 17:12:49 -08002513 boolean isRttChanged = false;
2514 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002515 if (parcelableCall.getIsRttCallChanged()
2516 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002517 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2518 InputStreamReader receiveStream = new InputStreamReader(
2519 new ParcelFileDescriptor.AutoCloseInputStream(
2520 parcelableRttCall.getReceiveStream()),
2521 StandardCharsets.UTF_8);
2522 OutputStreamWriter transmitStream = new OutputStreamWriter(
2523 new ParcelFileDescriptor.AutoCloseOutputStream(
2524 parcelableRttCall.getTransmitStream()),
2525 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002526 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002527 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2528 if (mRttCall == null) {
2529 isRttChanged = true;
2530 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2531 rttModeChanged = true;
2532 }
2533 mRttCall = newRttCall;
2534 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2535 && parcelableCall.getIsRttCallChanged()) {
2536 isRttChanged = true;
Tyler Gunn4cd42482021-04-30 16:23:15 -07002537 mRttCall.close();
Hall Liu95d55872017-01-25 17:12:49 -08002538 mRttCall = null;
2539 }
2540
Ihab Awade63fadb2014-07-09 21:52:04 -07002541 // Now we fire updates, ensuring that any client who listens to any of these notifications
2542 // gets the most up-to-date state.
2543
2544 if (stateChanged) {
2545 fireStateChanged(mState);
2546 }
2547 if (detailsChanged) {
2548 fireDetailsChanged(mDetails);
2549 }
2550 if (cannedTextResponsesChanged) {
2551 fireCannedTextResponsesLoaded(mCannedTextResponses);
2552 }
Andrew Lee50aca232014-07-22 16:41:54 -07002553 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002554 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002555 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002556 if (parentChanged) {
2557 fireParentChanged(getParent());
2558 }
Hall Liuef98bf82020-01-09 15:22:44 -08002559 if (childrenChanged || activeChildChanged) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002560 fireChildrenChanged(getChildren());
2561 }
Hall Liu95d55872017-01-25 17:12:49 -08002562 if (isRttChanged) {
2563 fireOnIsRttChanged(mRttCall != null, mRttCall);
2564 }
2565 if (rttModeChanged) {
2566 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2567 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002568
2569 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2570 // remove ourselves from the Phone. Note that we do this after completing all state updates
2571 // so a client can cleanly transition all their UI to the state appropriate for a
2572 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
qing278fdb12021-10-26 19:05:51 +00002573 // Check if the original state is already disconnected, otherwise onCallRemoved will be
2574 // triggered before onCallAdded.
2575 if (mState == STATE_DISCONNECTED && stateChanged) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002576 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002577 }
2578 }
2579
2580 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002581 final void internalSetPostDialWait(String remaining) {
2582 mRemainingPostDialSequence = remaining;
2583 firePostDialWait(mRemainingPostDialSequence);
2584 }
2585
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002586 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002587 final void internalSetDisconnected() {
2588 if (mState != Call.STATE_DISCONNECTED) {
2589 mState = Call.STATE_DISCONNECTED;
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002590 if (mDetails != null) {
2591 mDetails = new Details(mState,
2592 mDetails.getTelecomCallId(),
2593 mDetails.getHandle(),
2594 mDetails.getHandlePresentation(),
2595 mDetails.getCallerDisplayName(),
2596 mDetails.getCallerDisplayNamePresentation(),
2597 mDetails.getAccountHandle(),
2598 mDetails.getCallCapabilities(),
2599 mDetails.getCallProperties(),
2600 mDetails.getDisconnectCause(),
2601 mDetails.getConnectTimeMillis(),
2602 mDetails.getGatewayInfo(),
2603 mDetails.getVideoState(),
2604 mDetails.getStatusHints(),
2605 mDetails.getExtras(),
2606 mDetails.getIntentExtras(),
2607 mDetails.getCreationTimeMillis(),
2608 mDetails.getContactDisplayName(),
2609 mDetails.getCallDirection(),
Edgar Arriagae5bec822022-10-14 14:25:43 -07002610 mDetails.getCallerNumberVerificationStatus(),
2611 mDetails.getContactPhotoUri()
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002612 );
2613 fireDetailsChanged(mDetails);
2614 }
Santos Cordonf30d7e92014-08-26 09:54:33 -07002615 fireStateChanged(mState);
2616 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002617 }
2618 }
2619
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002620 /** {@hide} */
2621 final void internalOnConnectionEvent(String event, Bundle extras) {
2622 fireOnConnectionEvent(event, extras);
2623 }
2624
Hall Liu95d55872017-01-25 17:12:49 -08002625 /** {@hide} */
2626 final void internalOnRttUpgradeRequest(final int requestId) {
2627 for (CallbackRecord<Callback> record : mCallbackRecords) {
2628 final Call call = this;
2629 final Callback callback = record.getCallback();
2630 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2631 }
2632 }
2633
Hall Liu57006aa2017-02-06 10:49:48 -08002634 /** @hide */
2635 final void internalOnRttInitiationFailure(int reason) {
2636 for (CallbackRecord<Callback> record : mCallbackRecords) {
2637 final Call call = this;
2638 final Callback callback = record.getCallback();
2639 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2640 }
2641 }
2642
Sanket Padawe85291f62017-12-01 13:59:27 -08002643 /** {@hide} */
2644 final void internalOnHandoverFailed(int error) {
2645 for (CallbackRecord<Callback> record : mCallbackRecords) {
2646 final Call call = this;
2647 final Callback callback = record.getCallback();
2648 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2649 }
2650 }
2651
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002652 /** {@hide} */
2653 final void internalOnHandoverComplete() {
2654 for (CallbackRecord<Callback> record : mCallbackRecords) {
2655 final Call call = this;
2656 final Callback callback = record.getCallback();
2657 record.getHandler().post(() -> callback.onHandoverComplete(call));
2658 }
2659 }
2660
Andrew Lee011728f2015-04-23 15:47:06 -07002661 private void fireStateChanged(final int newState) {
2662 for (CallbackRecord<Callback> record : mCallbackRecords) {
2663 final Call call = this;
2664 final Callback callback = record.getCallback();
2665 record.getHandler().post(new Runnable() {
2666 @Override
2667 public void run() {
2668 callback.onStateChanged(call, newState);
2669 }
2670 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002671 }
2672 }
2673
Andrew Lee011728f2015-04-23 15:47:06 -07002674 private void fireParentChanged(final Call newParent) {
2675 for (CallbackRecord<Callback> record : mCallbackRecords) {
2676 final Call call = this;
2677 final Callback callback = record.getCallback();
2678 record.getHandler().post(new Runnable() {
2679 @Override
2680 public void run() {
2681 callback.onParentChanged(call, newParent);
2682 }
2683 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002684 }
2685 }
2686
Andrew Lee011728f2015-04-23 15:47:06 -07002687 private void fireChildrenChanged(final List<Call> children) {
2688 for (CallbackRecord<Callback> record : mCallbackRecords) {
2689 final Call call = this;
2690 final Callback callback = record.getCallback();
2691 record.getHandler().post(new Runnable() {
2692 @Override
2693 public void run() {
2694 callback.onChildrenChanged(call, children);
2695 }
2696 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002697 }
2698 }
2699
Andrew Lee011728f2015-04-23 15:47:06 -07002700 private void fireDetailsChanged(final Details details) {
2701 for (CallbackRecord<Callback> record : mCallbackRecords) {
2702 final Call call = this;
2703 final Callback callback = record.getCallback();
2704 record.getHandler().post(new Runnable() {
2705 @Override
2706 public void run() {
2707 callback.onDetailsChanged(call, details);
2708 }
2709 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002710 }
2711 }
2712
Andrew Lee011728f2015-04-23 15:47:06 -07002713 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2714 for (CallbackRecord<Callback> record : mCallbackRecords) {
2715 final Call call = this;
2716 final Callback callback = record.getCallback();
2717 record.getHandler().post(new Runnable() {
2718 @Override
2719 public void run() {
2720 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2721 }
2722 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002723 }
2724 }
2725
Andrew Lee011728f2015-04-23 15:47:06 -07002726 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2727 for (CallbackRecord<Callback> record : mCallbackRecords) {
2728 final Call call = this;
2729 final Callback callback = record.getCallback();
2730 record.getHandler().post(new Runnable() {
2731 @Override
2732 public void run() {
2733 callback.onVideoCallChanged(call, videoCall);
2734 }
2735 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002736 }
2737 }
2738
Andrew Lee011728f2015-04-23 15:47:06 -07002739 private void firePostDialWait(final String remainingPostDialSequence) {
2740 for (CallbackRecord<Callback> record : mCallbackRecords) {
2741 final Call call = this;
2742 final Callback callback = record.getCallback();
2743 record.getHandler().post(new Runnable() {
2744 @Override
2745 public void run() {
2746 callback.onPostDialWait(call, remainingPostDialSequence);
2747 }
2748 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002749 }
2750 }
2751
2752 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002753 /**
2754 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2755 * onCallRemoved callback, we remove this call from the Phone's record
2756 * only once all of the registered onCallDestroyed callbacks are executed.
2757 * All the callbacks get removed from our records as a part of this operation
2758 * since onCallDestroyed is the final callback.
2759 */
2760 final Call call = this;
2761 if (mCallbackRecords.isEmpty()) {
2762 // No callbacks registered, remove the call from Phone's record.
2763 mPhone.internalRemoveCall(call);
2764 }
2765 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002766 final Callback callback = record.getCallback();
2767 record.getHandler().post(new Runnable() {
2768 @Override
2769 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002770 boolean isFinalRemoval = false;
2771 RuntimeException toThrow = null;
2772 try {
2773 callback.onCallDestroyed(call);
2774 } catch (RuntimeException e) {
2775 toThrow = e;
2776 }
2777 synchronized(Call.this) {
2778 mCallbackRecords.remove(record);
2779 if (mCallbackRecords.isEmpty()) {
2780 isFinalRemoval = true;
2781 }
2782 }
2783 if (isFinalRemoval) {
2784 mPhone.internalRemoveCall(call);
2785 }
2786 if (toThrow != null) {
2787 throw toThrow;
2788 }
Andrew Lee011728f2015-04-23 15:47:06 -07002789 }
2790 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002791 }
2792 }
2793
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002794 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002795 for (CallbackRecord<Callback> record : mCallbackRecords) {
2796 final Call call = this;
2797 final Callback callback = record.getCallback();
2798 record.getHandler().post(new Runnable() {
2799 @Override
2800 public void run() {
2801 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2802 }
2803 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002804 }
2805 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002806
2807 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002808 * Notifies listeners of an incoming connection event.
2809 * <p>
2810 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2811 *
2812 * @param event
2813 * @param extras
2814 */
2815 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2816 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.onConnectionEvent(call, event, extras);
2823 }
2824 });
2825 }
2826 }
2827
2828 /**
Hall Liu95d55872017-01-25 17:12:49 -08002829 * Notifies listeners of an RTT on/off change
2830 *
2831 * @param enabled True if RTT is now enabled, false otherwise
2832 */
2833 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2834 for (CallbackRecord<Callback> record : mCallbackRecords) {
2835 final Call call = this;
2836 final Callback callback = record.getCallback();
2837 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2838 }
2839 }
2840
2841 /**
2842 * Notifies listeners of a RTT mode change
2843 *
2844 * @param mode The new RTT mode
2845 */
2846 private void fireOnRttModeChanged(final int mode) {
2847 for (CallbackRecord<Callback> record : mCallbackRecords) {
2848 final Call call = this;
2849 final Callback callback = record.getCallback();
2850 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2851 }
2852 }
2853
2854 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002855 * Determines if two bundles are equal.
2856 *
2857 * @param bundle The original bundle.
2858 * @param newBundle The bundle to compare with.
2859 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2860 */
2861 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2862 if (bundle == null || newBundle == null) {
2863 return bundle == newBundle;
2864 }
2865
2866 if (bundle.size() != newBundle.size()) {
2867 return false;
2868 }
2869
2870 for(String key : bundle.keySet()) {
2871 if (key != null) {
Grace Jia17005bd2022-05-12 12:49:02 -07002872 if (!newBundle.containsKey(key)) {
2873 return false;
2874 }
qing723dac62022-10-28 03:40:43 +00002875 // In case new call extra contains non-framework class objects, return false to
2876 // force update the call extra
2877 try {
2878 final Object value = bundle.get(key);
2879 final Object newValue = newBundle.get(key);
2880 if (value instanceof Bundle && newValue instanceof Bundle) {
2881 if (!areBundlesEqual((Bundle) value, (Bundle) newValue)) {
2882 return false;
2883 }
2884 }
2885 if (value instanceof byte[] && newValue instanceof byte[]) {
2886 if (!Arrays.equals((byte[]) value, (byte[]) newValue)) {
2887 return false;
2888 }
2889 } else if (!Objects.equals(value, newValue)) {
Grace Jia17005bd2022-05-12 12:49:02 -07002890 return false;
2891 }
qing723dac62022-10-28 03:40:43 +00002892 } catch (BadParcelableException e) {
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002893 return false;
2894 }
2895 }
2896 }
2897 return true;
2898 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002899}