blob: def52a517913527c3040b4ba407a57dddeca423c [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 /**
213 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
214 * Telecom that the user has requested that the current {@link Call} should be handed over
215 * to another {@link ConnectionService}.
216 * <p>
217 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
218 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
219 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700220 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
221 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700222 */
223 public static final String EVENT_REQUEST_HANDOVER =
224 "android.telecom.event.REQUEST_HANDOVER";
225
226 /**
227 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
228 * {@link PhoneAccountHandle} to which a call should be handed over to.
229 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700230 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
231 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700232 */
233 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
234 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
235
236 /**
237 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
238 * video state of the call when it is handed over to the new {@link PhoneAccount}.
239 * <p>
240 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
241 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
242 * {@link VideoProfile#STATE_TX_ENABLED}.
243 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700244 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
245 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700246 */
247 public static final String EXTRA_HANDOVER_VIDEO_STATE =
248 "android.telecom.extra.HANDOVER_VIDEO_STATE";
249
250 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700251 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
252 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
253 * information to the handover {@link ConnectionService} specified by
254 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
255 * <p>
256 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
257 * {@link ConnectionService} via the request extras when
258 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
259 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700260 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700261 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
262 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700263 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700264 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700265
266 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700267 * Call event sent from Telecom to the handover {@link ConnectionService} via
268 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
269 * to the {@link ConnectionService} has completed successfully.
270 * <p>
271 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700272 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700273 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
274 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700275 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700276 public static final String EVENT_HANDOVER_COMPLETE =
277 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700278
279 /**
280 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
281 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
282 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
283 * {@code null}.
284 * <p>
285 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
286 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700287 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
288 * APIs instead.
Tyler Gunn34a2b312017-06-23 08:32:00 -0700289 */
290 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
291 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
292
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700293 /**
294 * Call event sent from Telecom to the handover {@link ConnectionService} via
295 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
296 * to the {@link ConnectionService} has failed.
297 * <p>
298 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
299 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700300 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
301 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700302 */
303 public static final String EVENT_HANDOVER_FAILED =
304 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700305
Tyler Gunnd5821842021-02-05 11:12:57 -0800306 /**
307 * Event reported from the Telecom stack to report an in-call diagnostic message which the
308 * dialer app may opt to display to the user. A diagnostic message is used to communicate
309 * scenarios the device has detected which may impact the quality of the ongoing call.
310 * <p>
311 * For example a problem with a bluetooth headset may generate a recommendation for the user to
312 * try using the speakerphone instead, or if the device detects it has entered a poor service
313 * area, the user might be warned so that they can finish their call prior to it dropping.
314 * <p>
315 * A diagnostic message is considered persistent in nature. When the user enters a poor service
316 * area, for example, the accompanying diagnostic message persists until they leave the area
317 * of poor service. Each message is accompanied with a {@link #EXTRA_DIAGNOSTIC_MESSAGE_ID}
318 * which uniquely identifies the diagnostic condition being reported. The framework raises a
319 * call event of type {@link #EVENT_CLEAR_DIAGNOSTIC_MESSAGE} when the condition reported has
320 * been cleared. The dialer app should display the diagnostic message until it is cleared.
321 * If multiple diagnostic messages are sent with different IDs (which have not yet been cleared)
322 * the dialer app should prioritize the most recently received message, but still provide the
323 * user with a means to review past messages.
324 * <p>
325 * The text of the message is found in {@link #EXTRA_DIAGNOSTIC_MESSAGE} in the form of a human
326 * readable {@link CharSequence} which is intended for display in the call UX.
327 * <p>
328 * The telecom framework audibly notifies the user of the presence of a diagnostic message, so
329 * the dialer app needs only to concern itself with visually displaying the message.
330 * <p>
331 * The dialer app receives this event via
332 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
333 */
334 public static final String EVENT_DISPLAY_DIAGNOSTIC_MESSAGE =
335 "android.telecom.event.DISPLAY_DIAGNOSTIC_MESSAGE";
336
337 /**
338 * Event reported from the telecom framework when a diagnostic message previously raised with
339 * {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE} has cleared and is no longer pertinent.
340 * <p>
341 * The {@link #EXTRA_DIAGNOSTIC_MESSAGE_ID} indicates the diagnostic message which has been
342 * cleared.
343 * <p>
344 * The dialer app receives this event via
345 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
346 */
347 public static final String EVENT_CLEAR_DIAGNOSTIC_MESSAGE =
348 "android.telecom.event.CLEAR_DIAGNOSTIC_MESSAGE";
349
350 /**
351 * Integer extra representing a message ID for a message posted via
352 * {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE}. Used to ensure that the dialer app knows when
353 * the message in question has cleared via {@link #EVENT_CLEAR_DIAGNOSTIC_MESSAGE}.
354 */
355 public static final String EXTRA_DIAGNOSTIC_MESSAGE_ID =
356 "android.telecom.extra.DIAGNOSTIC_MESSAGE_ID";
357
358 /**
359 * {@link CharSequence} extra used with {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE}. This is the
360 * diagnostic message the dialer app should display.
361 */
362 public static final String EXTRA_DIAGNOSTIC_MESSAGE =
363 "android.telecom.extra.DIAGNOSTIC_MESSAGE";
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800364
365 /**
366 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
367 * call because they have declined to answer it. This typically means that they are unable
368 * to answer the call at this time and would prefer it be sent to voicemail.
369 */
370 public static final int REJECT_REASON_DECLINED = 1;
371
372 /**
373 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
374 * call because it is an unwanted call. This allows the user to indicate that they are
375 * rejecting a call because it is likely a nuisance call.
376 */
377 public static final int REJECT_REASON_UNWANTED = 2;
378
379 /**
380 * @hide
381 */
382 @IntDef(prefix = { "REJECT_REASON_" },
383 value = {REJECT_REASON_DECLINED, REJECT_REASON_UNWANTED})
384 @Retention(RetentionPolicy.SOURCE)
385 public @interface RejectReason {};
386
Ihab Awade63fadb2014-07-09 21:52:04 -0700387 public static class Details {
Tyler Gunn94f8f112018-12-17 09:56:11 -0800388 /** @hide */
389 @Retention(RetentionPolicy.SOURCE)
390 @IntDef(
391 prefix = { "DIRECTION_" },
392 value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
393 public @interface CallDirection {}
394
395 /**
396 * Indicates that the call is neither and incoming nor an outgoing call. This can be the
397 * case for calls reported directly by a {@link ConnectionService} in special cases such as
398 * call handovers.
399 */
400 public static final int DIRECTION_UNKNOWN = -1;
401
402 /**
403 * Indicates that the call is an incoming call.
404 */
405 public static final int DIRECTION_INCOMING = 0;
406
407 /**
408 * Indicates that the call is an outgoing call.
409 */
410 public static final int DIRECTION_OUTGOING = 1;
411
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800412 /** Call can currently be put on hold or unheld. */
413 public static final int CAPABILITY_HOLD = 0x00000001;
414
415 /** Call supports the hold feature. */
416 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
417
418 /**
419 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
420 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
421 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
422 * capability allows a merge button to be shown while the conference call is in the foreground
423 * of the in-call UI.
424 * <p>
425 * This is only intended for use by a {@link Conference}.
426 */
427 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
428
429 /**
430 * Calls within a conference can be swapped between foreground and background.
431 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
432 * <p>
433 * This is only intended for use by a {@link Conference}.
434 */
435 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
436
437 /**
438 * @hide
439 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700440 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800441
442 /** Call supports responding via text option. */
443 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
444
445 /** Call can be muted. */
446 public static final int CAPABILITY_MUTE = 0x00000040;
447
448 /**
449 * Call supports conference call management. This capability only applies to {@link Conference}
450 * calls which can have {@link Connection}s as children.
451 */
452 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
453
454 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700455 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800456 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700457 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800458
459 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700460 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800461 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700462 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800463
464 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700465 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800466 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700467 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700468 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800469
470 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700471 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800472 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700473 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
474
475 /**
476 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700477 */
478 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
479
480 /**
481 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700482 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700483 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700484 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800485
486 /**
487 * Call is able to be separated from its parent {@code Conference}, if any.
488 */
489 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
490
491 /**
492 * Call is able to be individually disconnected when in a {@code Conference}.
493 */
494 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
495
496 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500497 * Speed up audio setup for MT call.
498 * @hide
499 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700500 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
501
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700502 /**
503 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700504 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800505 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
506 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
507 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700508 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800509 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700510 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
511
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700512 /**
513 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700514 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700515 */
516 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
517
Bryce Lee81901682015-08-28 16:38:02 -0700518 /**
519 * Call sends responses through connection.
520 * @hide
521 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800522 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
523
524 /**
525 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
526 * <p>
527 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
528 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
529 * downgraded from a video call back to a VideoState of
530 * {@link VideoProfile#STATE_AUDIO_ONLY}.
531 * <p>
532 * Intuitively, a call which can be downgraded to audio should also have local and remote
533 * video
534 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
535 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
536 */
537 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700538
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700539 /**
540 * When set for an external call, indicates that this {@code Call} can be pulled from a
541 * remote device to the current device.
542 * <p>
543 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
544 * <p>
545 * An {@link InCallService} will only see calls with this capability if it has the
546 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
547 * in its manifest.
548 * <p>
549 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700550 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700551 */
552 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
553
Pooja Jaind34698d2017-12-28 14:15:31 +0530554 /** Call supports the deflect feature. */
555 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
556
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800557 /**
558 * Call supports adding participants to the call via
Grace Jia8587ee52020-07-10 15:42:32 -0700559 * {@link #addConferenceParticipants(List)}. Once participants are added, the call becomes
560 * an adhoc conference call ({@link #PROPERTY_IS_ADHOC_CONFERENCE}).
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800561 */
Ravi Paluri404babb2020-01-23 19:02:44 +0530562 public static final int CAPABILITY_ADD_PARTICIPANT = 0x02000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530563
564 /**
565 * When set for a call, indicates that this {@code Call} can be transferred to another
566 * number.
Tyler Gunn460360d2020-07-29 10:21:45 -0700567 * Call supports the confirmed and unconfirmed call transfer feature.
Ravi Palurif4b38e72020-02-05 12:35:41 +0530568 *
569 * @hide
570 */
571 public static final int CAPABILITY_TRANSFER = 0x04000000;
572
573 /**
574 * When set for a call, indicates that this {@code Call} can be transferred to another
575 * ongoing call.
576 * Call supports the consultative call transfer feature.
577 *
578 * @hide
579 */
580 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x08000000;
581
Alvin Dey2f37d772018-05-18 23:16:10 +0530582 /**
583 * Indicates whether the remote party supports RTT or not to the UI.
584 */
585
586 public static final int CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT = 0x10000000;
587
Tyler Gunnd11a3152015-03-18 13:09:14 -0700588 //******************************************************************************************
Alvin Dey2f37d772018-05-18 23:16:10 +0530589 // Next CAPABILITY value: 0x20000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700590 //******************************************************************************************
591
592 /**
593 * Whether the call is currently a conference.
594 */
595 public static final int PROPERTY_CONFERENCE = 0x00000001;
596
597 /**
598 * Whether the call is a generic conference, where we do not know the precise state of
599 * participants in the conference (eg. on CDMA).
600 */
601 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
602
603 /**
604 * Whether the call is made while the device is in emergency callback mode.
605 */
606 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
607
608 /**
609 * Connection is using WIFI.
610 */
611 public static final int PROPERTY_WIFI = 0x00000008;
612
613 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700614 * When set, the UI should indicate to the user that a call is using high definition
615 * audio.
616 * <p>
617 * The underlying {@link ConnectionService} is responsible for reporting this
618 * property. It is important to note that this property is not intended to report the
619 * actual audio codec being used for a Call, but whether the call should be indicated
620 * to the user as high definition.
621 * <p>
622 * The Android Telephony stack reports this property for calls based on a number
623 * of factors, including which audio codec is used and whether a call is using an HD
624 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
625 * and in these cases this property will not be set for a call even if the underlying audio
626 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700627 */
628 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
629
Tony Maka68dcce2015-12-17 09:31:18 +0000630 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100631 * Whether the call is associated with the work profile.
632 */
633 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
634
635 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700636 * When set, indicates that this {@code Call} does not actually exist locally for the
637 * {@link ConnectionService}.
638 * <p>
639 * Consider, for example, a scenario where a user has two phones with the same phone number.
640 * When a user places a call on one device, the telephony stack can represent that call on
641 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700642 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700643 * <p>
644 * An {@link InCallService} will only see calls with this property if it has the
645 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
646 * in its manifest.
647 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700648 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700649 */
650 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
651
Brad Ebinger15847072016-05-18 11:08:36 -0700652 /**
653 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
654 */
655 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
656
Tyler Gunn24e18332017-02-10 09:42:49 -0800657 /**
658 * Indicates that the call is from a self-managed {@link ConnectionService}.
659 * <p>
660 * See also {@link Connection#PROPERTY_SELF_MANAGED}
661 */
662 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
663
Eric Erfanianec881872017-12-06 16:27:53 -0800664 /**
665 * Indicates the call used Assisted Dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700666 *
667 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanianec881872017-12-06 16:27:53 -0800668 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800669 public static final int PROPERTY_ASSISTED_DIALING = 0x00000200;
Eric Erfanianec881872017-12-06 16:27:53 -0800670
Hall Liue9041242018-02-09 16:40:03 -0800671 /**
672 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
673 * {@link RttCall} object that is used to send and receive text.
674 */
675 public static final int PROPERTY_RTT = 0x00000400;
676
Tyler Gunn5bd90852018-09-21 09:37:07 -0700677 /**
678 * Indicates that the call has been identified as the network as an emergency call. This
679 * property may be set for both incoming and outgoing calls which the network identifies as
680 * emergency calls.
681 */
682 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
683
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700684 /**
685 * Indicates that the call is using VoIP audio mode.
686 * <p>
687 * When this property is set, the {@link android.media.AudioManager} audio mode for this
688 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
689 * property is not set, the audio mode for this call will be
690 * {@link android.media.AudioManager#MODE_IN_CALL}.
691 * <p>
692 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
693 * <p>
694 * You can use this property to determine whether an un-answered incoming call or a held
695 * call will use VoIP audio mode (if the call does not currently have focus, the system
696 * audio mode may not reflect the mode the call will use).
697 */
698 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
699
Ravi Paluri80aa2142019-12-02 11:57:37 +0530700 /**
701 * Indicates that the call is an adhoc conference call. This property can be set for both
Grace Jia8587ee52020-07-10 15:42:32 -0700702 * incoming and outgoing calls. An adhoc conference call is formed using
703 * {@link #addConferenceParticipants(List)},
704 * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}, or
705 * {@link TelecomManager#startConference(List, Bundle)}, rather than by merging existing
706 * call using {@link #conference(Call)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530707 */
708 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 0x00002000;
709
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800710 /**
Sooraj Sasindranfa1e57a2021-03-22 13:44:14 -0700711 * Connection is using cross sim technology.
712 * <p>
713 * Indicates that the {@link Connection} is using a cross sim technology which would
714 * register IMS over internet APN of default data subscription.
715 * <p>
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800716 */
717 public static final int PROPERTY_CROSS_SIM = 0x00004000;
718
Grant Menke6ca706b2023-08-23 07:46:09 -0700719 /**
720 * The connection is using transactional call APIs.
721 * <p>
722 * The underlying connection was added as a transactional call via the
723 * {@link TelecomManager#addCall} API.
724 */
Grant Menke417190a2023-08-30 14:39:29 -0700725 @FlaggedApi(Flags.FLAG_VOIP_APP_ACTIONS_SUPPORT)
Grant Menke6ca706b2023-08-23 07:46:09 -0700726 public static final int PROPERTY_IS_TRANSACTIONAL = 0x00008000;
727
Andrew Lee2378ea72015-04-29 14:38:11 -0700728 //******************************************************************************************
Grant Menke6ca706b2023-08-23 07:46:09 -0700729 // Next PROPERTY value: 0x00010000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700730 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800731
Tyler Gunn1e406ca2021-03-18 16:47:14 -0700732 private final @CallState int mState;
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800733 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700734 private final Uri mHandle;
735 private final int mHandlePresentation;
736 private final String mCallerDisplayName;
737 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700738 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700739 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700740 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800741 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700742 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700743 private final long mConnectTimeMillis;
744 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700745 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700746 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700747 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700748 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700749 private final long mCreationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -0800750 private final String mContactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800751 private final @CallDirection int mCallDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700752 private final @Connection.VerificationStatus int mCallerNumberVerificationStatus;
Edgar Arriagae5bec822022-10-14 14:25:43 -0700753 private final Uri mContactPhotoUri;
Ihab Awade63fadb2014-07-09 21:52:04 -0700754
755 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800756 * Whether the supplied capabilities supports the specified capability.
757 *
758 * @param capabilities A bit field of capabilities.
759 * @param capability The capability to check capabilities for.
760 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800761 */
762 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800763 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800764 }
765
766 /**
767 * Whether the capabilities of this {@code Details} supports the specified capability.
768 *
769 * @param capability The capability to check capabilities for.
770 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800771 */
772 public boolean can(int capability) {
773 return can(mCallCapabilities, capability);
774 }
775
776 /**
777 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
778 *
779 * @param capabilities A capability bit field.
780 * @return A human readable string representation.
781 */
782 public static String capabilitiesToString(int capabilities) {
783 StringBuilder builder = new StringBuilder();
784 builder.append("[Capabilities:");
785 if (can(capabilities, CAPABILITY_HOLD)) {
786 builder.append(" CAPABILITY_HOLD");
787 }
788 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
789 builder.append(" CAPABILITY_SUPPORT_HOLD");
790 }
791 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
792 builder.append(" CAPABILITY_MERGE_CONFERENCE");
793 }
794 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
795 builder.append(" CAPABILITY_SWAP_CONFERENCE");
796 }
797 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
798 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
799 }
800 if (can(capabilities, CAPABILITY_MUTE)) {
801 builder.append(" CAPABILITY_MUTE");
802 }
803 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
804 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
805 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700806 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
807 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
808 }
809 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
810 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
811 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700812 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
813 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800814 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700815 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
816 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
817 }
818 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
819 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
820 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800821 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
822 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
823 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700824 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
825 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800826 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500827 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700828 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500829 }
Rekha Kumar07366812015-03-24 16:42:31 -0700830 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
831 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
832 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700833 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
834 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
835 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700836 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
837 builder.append(" CAPABILITY_CAN_PULL_CALL");
838 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530839 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
840 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
841 }
Ravi Paluri404babb2020-01-23 19:02:44 +0530842 if (can(capabilities, CAPABILITY_ADD_PARTICIPANT)) {
843 builder.append(" CAPABILITY_ADD_PARTICIPANT");
844 }
Ravi Palurif4b38e72020-02-05 12:35:41 +0530845 if (can(capabilities, CAPABILITY_TRANSFER)) {
846 builder.append(" CAPABILITY_TRANSFER");
847 }
848 if (can(capabilities, CAPABILITY_TRANSFER_CONSULTATIVE)) {
849 builder.append(" CAPABILITY_TRANSFER_CONSULTATIVE");
850 }
Alvin Dey2f37d772018-05-18 23:16:10 +0530851 if (can(capabilities, CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT)) {
852 builder.append(" CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT");
853 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800854 builder.append("]");
855 return builder.toString();
856 }
857
858 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700859 * Whether the supplied properties includes the specified property.
860 *
861 * @param properties A bit field of properties.
862 * @param property The property to check properties for.
863 * @return Whether the specified property is supported.
864 */
865 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800866 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700867 }
868
869 /**
870 * Whether the properties of this {@code Details} includes the specified property.
871 *
872 * @param property The property to check properties for.
873 * @return Whether the specified property is supported.
874 */
875 public boolean hasProperty(int property) {
876 return hasProperty(mCallProperties, property);
877 }
878
879 /**
880 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
881 *
882 * @param properties A property bit field.
883 * @return A human readable string representation.
884 */
885 public static String propertiesToString(int properties) {
886 StringBuilder builder = new StringBuilder();
887 builder.append("[Properties:");
888 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
889 builder.append(" PROPERTY_CONFERENCE");
890 }
891 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
892 builder.append(" PROPERTY_GENERIC_CONFERENCE");
893 }
894 if (hasProperty(properties, PROPERTY_WIFI)) {
895 builder.append(" PROPERTY_WIFI");
896 }
897 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
898 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
899 }
900 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700901 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700902 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700903 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
904 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
905 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700906 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700907 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
908 }
Tyler Gunnc9503d62020-01-27 10:30:51 -0800909 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800910 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
911 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700912 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
913 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
914 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700915 if (hasProperty(properties, PROPERTY_RTT)) {
916 builder.append(" PROPERTY_RTT");
917 }
918 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
919 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
920 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530921 if (hasProperty(properties, PROPERTY_IS_ADHOC_CONFERENCE)) {
922 builder.append(" PROPERTY_IS_ADHOC_CONFERENCE");
923 }
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800924 if (hasProperty(properties, PROPERTY_CROSS_SIM)) {
925 builder.append(" PROPERTY_CROSS_SIM");
926 }
Grant Menke6ca706b2023-08-23 07:46:09 -0700927 if (hasProperty(properties, PROPERTY_IS_TRANSACTIONAL)) {
928 builder.append(" PROPERTY_IS_TRANSACTIONAL");
929 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700930 builder.append("]");
931 return builder.toString();
932 }
933
Tyler Gunn1e406ca2021-03-18 16:47:14 -0700934 /**
935 * @return the state of the {@link Call} represented by this {@link Call.Details}.
936 */
937 public final @CallState int getState() {
938 return mState;
939 }
940
Grant Menke626dd262023-07-24 15:19:36 -0700941 /**
942 * @return the Telecom identifier associated with this {@link Call} . This is not a stable
943 * identifier and is not guaranteed to be unique across device reboots.
944 */
Grant Menke37155c82023-10-10 14:17:26 -0700945 @FlaggedApi(Flags.FLAG_CALL_DETAILS_ID_CHANGES)
Grant Menke626dd262023-07-24 15:19:36 -0700946 public @NonNull String getId() { return mTelecomCallId; }
947
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800948 /** {@hide} */
Hall Liu31de23d2019-10-11 15:38:29 -0700949 @TestApi
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800950 public String getTelecomCallId() {
951 return mTelecomCallId;
952 }
953
Andrew Lee2378ea72015-04-29 14:38:11 -0700954 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700955 * @return The handle (e.g., phone number) to which the {@code Call} is currently
956 * connected.
957 */
958 public Uri getHandle() {
959 return mHandle;
960 }
961
962 /**
963 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700964 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700965 */
966 public int getHandlePresentation() {
967 return mHandlePresentation;
968 }
969
970 /**
Edgar Arriagae5bec822022-10-14 14:25:43 -0700971 * @return The contact photo URI which corresponds to
972 * {@link android.provider.ContactsContract.PhoneLookup#PHOTO_URI}, or {@code null} if the
973 * lookup is not yet complete, if there's no contacts entry for the caller,
974 * or if the {@link InCallService} does not hold the
975 * {@link android.Manifest.permission#READ_CONTACTS} permission.
976 */
977 public @Nullable Uri getContactPhotoUri() {
978 return mContactPhotoUri;
979 }
980
981 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800982 * The display name for the caller.
983 * <p>
984 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800985 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700986 * @return The display name for the caller.
987 */
988 public String getCallerDisplayName() {
989 return mCallerDisplayName;
990 }
991
992 /**
993 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700994 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700995 */
996 public int getCallerDisplayNamePresentation() {
997 return mCallerDisplayNamePresentation;
998 }
999
1000 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -07001001 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
1002 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001003 */
Evan Charlton8c8a0622014-07-20 12:31:00 -07001004 public PhoneAccountHandle getAccountHandle() {
1005 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -07001006 }
1007
1008 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001009 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
1010 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -07001011 */
Ihab Awad5d0410f2014-07-30 10:07:40 -07001012 public int getCallCapabilities() {
1013 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -07001014 }
1015
1016 /**
Andrew Lee2378ea72015-04-29 14:38:11 -07001017 * @return A bitmask of the properties of the {@code Call}, as defined by the various
1018 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -07001019 */
1020 public int getCallProperties() {
1021 return mCallProperties;
1022 }
1023
1024 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -08001025 * @return a bitmask of the audio routes available for the call.
1026 *
1027 * @hide
1028 */
1029 public int getSupportedAudioRoutes() {
1030 return mSupportedAudioRoutes;
1031 }
1032
1033 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001034 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -07001035 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001036 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001037 public DisconnectCause getDisconnectCause() {
1038 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -07001039 }
1040
1041 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001042 * Returns the time the {@link Call} connected (i.e. became active). This information is
1043 * updated periodically, but user interfaces should not rely on this to display the "call
1044 * time clock". For the time when the call was first added to Telecom, see
1045 * {@link #getCreationTimeMillis()}.
1046 *
1047 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -07001048 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -07001049 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -07001050 return mConnectTimeMillis;
1051 }
1052
1053 /**
1054 * @return Information about any calling gateway the {@code Call} may be using.
1055 */
1056 public GatewayInfo getGatewayInfo() {
1057 return mGatewayInfo;
1058 }
1059
Andrew Lee7a341382014-07-15 17:05:08 -07001060 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -07001061 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -07001062 */
1063 public int getVideoState() {
1064 return mVideoState;
1065 }
1066
Ihab Awad5d0410f2014-07-30 10:07:40 -07001067 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001068 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -07001069 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -07001070 */
1071 public StatusHints getStatusHints() {
1072 return mStatusHints;
1073 }
1074
Nancy Chen10798dc2014-08-08 14:00:25 -07001075 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001076 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -07001077 */
1078 public Bundle getExtras() {
1079 return mExtras;
1080 }
1081
Santos Cordon6b7f9552015-05-27 17:21:45 -07001082 /**
1083 * @return The extras used with the original intent to place this call.
1084 */
1085 public Bundle getIntentExtras() {
1086 return mIntentExtras;
1087 }
1088
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001089 /**
1090 * Returns the time when the call was first created and added to Telecom. This is the same
1091 * time that is logged as the start time in the Call Log (see
1092 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
1093 * (became active), see {@link #getConnectTimeMillis()}.
1094 *
1095 * @return The creation time of the call, in millis since the epoch.
1096 */
1097 public long getCreationTimeMillis() {
1098 return mCreationTimeMillis;
1099 }
1100
Tyler Gunnd081f042018-12-04 12:56:45 -08001101 /**
Hall Liuef98bf82020-01-09 15:22:44 -08001102 * Returns the name of the caller on the remote end, as derived from a
1103 * {@link android.provider.ContactsContract} lookup of the call's handle.
1104 * @return The name of the caller, or {@code null} if the lookup is not yet complete, if
1105 * there's no contacts entry for the caller, or if the {@link InCallService} does
1106 * not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
1107 */
1108 public @Nullable String getContactDisplayName() {
1109 return mContactDisplayName;
1110 }
1111
1112 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -08001113 * Indicates whether the call is an incoming or outgoing call.
1114 * @return The call's direction.
1115 */
1116 public @CallDirection int getCallDirection() {
1117 return mCallDirection;
1118 }
1119
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001120 /**
1121 * Gets the verification status for the phone number of an incoming call as identified in
1122 * ATIS-1000082.
Tyler Gunn9c642492020-10-08 13:37:03 -07001123 * <p>
1124 * For incoming calls, the number verification status indicates whether the device was
1125 * able to verify the authenticity of the calling number using the STIR process outlined
1126 * in ATIS-1000082. {@link Connection#VERIFICATION_STATUS_NOT_VERIFIED} indicates that
1127 * the network was not able to use STIR to verify the caller's number (i.e. nothing is
1128 * known regarding the authenticity of the number.
1129 * {@link Connection#VERIFICATION_STATUS_PASSED} indicates that the network was able to
1130 * use STIR to verify the caller's number. This indicates that the network has a high
1131 * degree of confidence that the incoming call actually originated from the indicated
1132 * number. {@link Connection#VERIFICATION_STATUS_FAILED} indicates that the network's
1133 * STIR verification did not pass. This indicates that the incoming call may not
1134 * actually be from the indicated number. This could occur if, for example, the caller
1135 * is using an impersonated phone number.
1136 * <p>
1137 * A {@link CallScreeningService} can use this information to help determine if an
1138 * incoming call is potentially an unwanted call. A verification status of
1139 * {@link Connection#VERIFICATION_STATUS_FAILED} indicates that an incoming call may not
1140 * actually be from the number indicated on the call (i.e. impersonated number) and that it
1141 * should potentially be blocked. Likewise,
1142 * {@link Connection#VERIFICATION_STATUS_PASSED} can be used as a positive signal to
1143 * help clarify that the incoming call is originating from the indicated number and it
1144 * is less likely to be an undesirable call.
1145 * <p>
1146 * An {@link InCallService} can use this information to provide a visual indicator to the
1147 * user regarding the verification status of a call and to help identify calls from
1148 * potentially impersonated numbers.
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001149 * @return the verification status.
1150 */
1151 public @Connection.VerificationStatus int getCallerNumberVerificationStatus() {
1152 return mCallerNumberVerificationStatus;
1153 }
1154
Ihab Awade63fadb2014-07-09 21:52:04 -07001155 @Override
1156 public boolean equals(Object o) {
1157 if (o instanceof Details) {
1158 Details d = (Details) o;
1159 return
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001160 Objects.equals(mState, d.mState) &&
Ihab Awade63fadb2014-07-09 21:52:04 -07001161 Objects.equals(mHandle, d.mHandle) &&
1162 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
1163 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
1164 Objects.equals(mCallerDisplayNamePresentation,
1165 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -07001166 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -07001167 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -07001168 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001169 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -07001170 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -07001171 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -07001172 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -07001173 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001174 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001175 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -08001176 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Hall Liuef98bf82020-01-09 15:22:44 -08001177 Objects.equals(mContactDisplayName, d.mContactDisplayName) &&
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001178 Objects.equals(mCallDirection, d.mCallDirection) &&
1179 Objects.equals(mCallerNumberVerificationStatus,
Edgar Arriagae5bec822022-10-14 14:25:43 -07001180 d.mCallerNumberVerificationStatus) &&
1181 Objects.equals(mContactPhotoUri, d.mContactPhotoUri);
Ihab Awade63fadb2014-07-09 21:52:04 -07001182 }
1183 return false;
1184 }
1185
1186 @Override
1187 public int hashCode() {
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001188 return Objects.hash(mState,
1189 mHandle,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001190 mHandlePresentation,
1191 mCallerDisplayName,
1192 mCallerDisplayNamePresentation,
1193 mAccountHandle,
1194 mCallCapabilities,
1195 mCallProperties,
1196 mDisconnectCause,
1197 mConnectTimeMillis,
1198 mGatewayInfo,
1199 mVideoState,
1200 mStatusHints,
1201 mExtras,
1202 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001203 mCreationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001204 mContactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001205 mCallDirection,
Edgar Arriagae5bec822022-10-14 14:25:43 -07001206 mCallerNumberVerificationStatus,
1207 mContactPhotoUri);
Ihab Awade63fadb2014-07-09 21:52:04 -07001208 }
1209
1210 /** {@hide} */
1211 public Details(
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001212 @CallState int state,
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001213 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -07001214 Uri handle,
1215 int handlePresentation,
1216 String callerDisplayName,
1217 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -07001218 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -07001219 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -07001220 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001221 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -07001222 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -07001223 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -07001224 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -07001225 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -07001226 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001227 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001228 long creationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001229 String contactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001230 int callDirection,
Edgar Arriagae5bec822022-10-14 14:25:43 -07001231 int callerNumberVerificationStatus,
1232 Uri contactPhotoUri) {
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001233 mState = state;
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001234 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001235 mHandle = handle;
1236 mHandlePresentation = handlePresentation;
1237 mCallerDisplayName = callerDisplayName;
1238 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -07001239 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -07001240 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -07001241 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001242 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -07001243 mConnectTimeMillis = connectTimeMillis;
1244 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -07001245 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -07001246 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -07001247 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001248 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001249 mCreationTimeMillis = creationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -08001250 mContactDisplayName = contactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -08001251 mCallDirection = callDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001252 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
Edgar Arriagae5bec822022-10-14 14:25:43 -07001253 mContactPhotoUri = contactPhotoUri;
Ihab Awade63fadb2014-07-09 21:52:04 -07001254 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001255
1256 /** {@hide} */
1257 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
1258 return new Details(
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001259 parcelableCall.getState(),
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001260 parcelableCall.getId(),
1261 parcelableCall.getHandle(),
1262 parcelableCall.getHandlePresentation(),
1263 parcelableCall.getCallerDisplayName(),
1264 parcelableCall.getCallerDisplayNamePresentation(),
1265 parcelableCall.getAccountHandle(),
1266 parcelableCall.getCapabilities(),
1267 parcelableCall.getProperties(),
1268 parcelableCall.getDisconnectCause(),
1269 parcelableCall.getConnectTimeMillis(),
1270 parcelableCall.getGatewayInfo(),
1271 parcelableCall.getVideoState(),
1272 parcelableCall.getStatusHints(),
1273 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001274 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -08001275 parcelableCall.getCreationTimeMillis(),
Hall Liuef98bf82020-01-09 15:22:44 -08001276 parcelableCall.getContactDisplayName(),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001277 parcelableCall.getCallDirection(),
Edgar Arriagae5bec822022-10-14 14:25:43 -07001278 parcelableCall.getCallerNumberVerificationStatus(),
1279 parcelableCall.getContactPhotoUri()
1280 );
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001281 }
Santos Cordon3c20d632016-02-25 16:12:35 -08001282
1283 @Override
1284 public String toString() {
1285 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001286 sb.append("[id: ");
1287 sb.append(mTelecomCallId);
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001288 sb.append(", state: ");
1289 sb.append(Call.stateToString(mState));
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001290 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -08001291 sb.append(mAccountHandle);
1292 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001293 sb.append(Log.piiHandle(mHandle));
1294 sb.append(", hdlPres: ");
1295 sb.append(mHandlePresentation);
1296 sb.append(", videoState: ");
1297 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -08001298 sb.append(", caps: ");
1299 sb.append(capabilitiesToString(mCallCapabilities));
1300 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001301 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001302 sb.append("]");
1303 return sb.toString();
1304 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001305 }
1306
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001307 /**
1308 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1309 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1310 * implementation.
1311 * <p>
1312 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1313 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1314 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1315 * {@link Callback} implementation, if desired.
1316 * <p>
1317 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1318 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1319 * (typically in {@link InCallService#onCallRemoved(Call)}).
1320 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1321 * reach your implementation of {@link Callback}, so it is important to register your callback
1322 * as soon as your {@link InCallService} is notified of a new call via
1323 * {@link InCallService#onCallAdded(Call)}.
1324 */
Andrew Leeda80c872015-04-15 14:09:50 -07001325 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001326 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001327 * @hide
1328 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001329 @IntDef(prefix = { "HANDOVER_" },
1330 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001331 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001332 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001333 @Retention(RetentionPolicy.SOURCE)
1334 public @interface HandoverFailureErrors {}
1335
1336 /**
1337 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001338 * to handover the call to rejects the handover request.
1339 * <p>
1340 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1341 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1342 * {@code null} {@link Connection} from
1343 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1344 * ConnectionRequest)}.
1345 * <p>
1346 * For more information on call handovers, see
1347 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001348 */
1349 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1350
1351 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001352 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1353 * is initiated but the source or destination app does not support handover.
1354 * <p>
1355 * Will be returned when a handover is requested via
1356 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1357 * {@link PhoneAccountHandle} does not declare
1358 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1359 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1360 * {@link Details#getAccountHandle()}) does not declare
1361 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1362 * <p>
1363 * For more information on call handovers, see
1364 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001365 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001366 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001367
1368 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001369 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1370 * user rejects the handover request.
1371 * <p>
1372 * For more information on call handovers, see
1373 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001374 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001375 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001376
Sanket Padawe85291f62017-12-01 13:59:27 -08001377 /**
1378 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1379 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001380 * <p>
1381 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1382 * called on an emergency call, or if any other call is an emergency call.
1383 * <p>
1384 * Handovers are not permitted while there are ongoing emergency calls.
1385 * <p>
1386 * For more information on call handovers, see
1387 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001388 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001389 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001390
Tyler Gunn9d127732018-03-02 15:45:51 -08001391 /**
1392 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1393 * fails for an unknown reason.
1394 * <p>
1395 * For more information on call handovers, see
1396 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1397 */
1398 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001399
1400 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001401 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1402 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001403 * @param call The {@code Call} invoking this method.
1404 * @param state The new state of the {@code Call}.
1405 */
Tyler Gunn1e406ca2021-03-18 16:47:14 -07001406 public void onStateChanged(Call call, @CallState int state) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001407
1408 /**
1409 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1410 *
1411 * @param call The {@code Call} invoking this method.
1412 * @param parent The new parent of the {@code Call}.
1413 */
1414 public void onParentChanged(Call call, Call parent) {}
1415
1416 /**
1417 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1418 *
1419 * @param call The {@code Call} invoking this method.
1420 * @param children The new children of the {@code Call}.
1421 */
1422 public void onChildrenChanged(Call call, List<Call> children) {}
1423
1424 /**
1425 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1426 *
1427 * @param call The {@code Call} invoking this method.
1428 * @param details A {@code Details} object describing the {@code Call}.
1429 */
1430 public void onDetailsChanged(Call call, Details details) {}
1431
1432 /**
1433 * Invoked when the text messages that can be used as responses to the incoming
1434 * {@code Call} are loaded from the relevant database.
1435 * See {@link #getCannedTextResponses()}.
1436 *
1437 * @param call The {@code Call} invoking this method.
1438 * @param cannedTextResponses The text messages useable as responses.
1439 */
1440 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1441
1442 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001443 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1444 * character. This causes the post-dial signals to stop pending user confirmation. An
1445 * implementation should present this choice to the user and invoke
1446 * {@link #postDialContinue(boolean)} when the user makes the choice.
1447 *
1448 * @param call The {@code Call} invoking this method.
1449 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1450 */
1451 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1452
1453 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001454 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001455 *
1456 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001457 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001458 */
Andrew Lee50aca232014-07-22 16:41:54 -07001459 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001460
1461 /**
1462 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1463 * up their UI for the {@code Call} in response to state transitions. Specifically,
1464 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1465 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1466 * clients should wait for this method to be invoked.
1467 *
1468 * @param call The {@code Call} being destroyed.
1469 */
1470 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001471
1472 /**
1473 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1474 * conferenced.
1475 *
1476 * @param call The {@code Call} being updated.
1477 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1478 * conferenced.
1479 */
1480 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001481
1482 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001483 * Invoked when a {@link Call} receives an event from its associated {@link Connection} or
1484 * {@link Conference}.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001485 * <p>
1486 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1487 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1488 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1489 * possible that a {@link ConnectionService} has defined its own Connection events which a
1490 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001491 * <p>
Tyler Gunn5567d742019-10-31 13:04:37 -07001492 * See {@link Connection#sendConnectionEvent(String, Bundle)},
1493 * {@link Conference#sendConferenceEvent(String, Bundle)}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001494 *
1495 * @param call The {@code Call} receiving the event.
1496 * @param event The event.
1497 * @param extras Extras associated with the connection event.
1498 */
1499 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001500
1501 /**
1502 * Invoked when the RTT mode changes for this call.
1503 * @param call The call whose RTT mode has changed.
1504 * @param mode the new RTT mode, one of
1505 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1506 * or {@link RttCall#RTT_MODE_VCO}
1507 */
1508 public void onRttModeChanged(Call call, int mode) {}
1509
1510 /**
1511 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1512 * @param call The call whose RTT status has changed.
1513 * @param enabled whether RTT is now enabled or disabled
1514 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1515 * on, null otherwise.
1516 */
1517 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1518
1519 /**
1520 * Invoked when the remote end of the connection has requested that an RTT communication
1521 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1522 * with the same ID that this method is invoked with.
1523 * @param call The call which the RTT request was placed on
1524 * @param id The ID of the request.
1525 */
1526 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001527
1528 /**
1529 * Invoked when the RTT session failed to initiate for some reason, including rejection
1530 * by the remote party.
Tyler Gunnb9a04962022-02-17 08:23:54 -08001531 * <p>
1532 * This callback will ONLY be invoked to report a failure related to a user initiated
1533 * session modification request (i.e. {@link Call#sendRttRequest()}).
1534 * <p>
1535 * If a call is initiated with {@link TelecomManager#EXTRA_START_CALL_WITH_RTT} specified,
1536 * the availability of RTT can be determined by checking {@link Details#PROPERTY_RTT}
1537 * once the call enters state {@link Details#STATE_ACTIVE}.
1538 *
Hall Liu57006aa2017-02-06 10:49:48 -08001539 * @param call The call which the RTT initiation failure occurred on.
1540 * @param reason One of the status codes defined in
Tyler Gunnb9a04962022-02-17 08:23:54 -08001541 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1542 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liu57006aa2017-02-06 10:49:48 -08001543 */
Tyler Gunnb9a04962022-02-17 08:23:54 -08001544 public void onRttInitiationFailure(Call call,
1545 @android.telecom.Connection.RttModifyStatus.RttSessionModifyStatus int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001546
1547 /**
1548 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1549 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001550 * <p>
1551 * For a full discussion of the handover process and the APIs involved, see
1552 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1553 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001554 * @param call The call which had initiated handover.
1555 */
1556 public void onHandoverComplete(Call call) {}
1557
1558 /**
1559 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1560 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001561 * <p>
1562 * For a full discussion of the handover process and the APIs involved, see
1563 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1564 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001565 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001566 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001567 */
1568 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001569 }
1570
1571 /**
1572 * A class that holds the state that describes the state of the RTT channel to the remote
1573 * party, if it is active.
1574 */
1575 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001576 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001577 @Retention(RetentionPolicy.SOURCE)
1578 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1579 public @interface RttAudioMode {}
1580
1581 /**
1582 * For metrics use. Default value in the proto.
1583 * @hide
1584 */
1585 public static final int RTT_MODE_INVALID = 0;
1586
1587 /**
1588 * Indicates that there should be a bidirectional audio stream between the two parties
1589 * on the call.
1590 */
1591 public static final int RTT_MODE_FULL = 1;
1592
1593 /**
1594 * Indicates that the local user should be able to hear the audio stream from the remote
1595 * user, but not vice versa. Equivalent to muting the microphone.
1596 */
1597 public static final int RTT_MODE_HCO = 2;
1598
1599 /**
1600 * Indicates that the remote user should be able to hear the audio stream from the local
1601 * user, but not vice versa. Equivalent to setting the volume to zero.
1602 */
1603 public static final int RTT_MODE_VCO = 3;
1604
1605 private static final int READ_BUFFER_SIZE = 1000;
1606
1607 private InputStreamReader mReceiveStream;
1608 private OutputStreamWriter mTransmitStream;
1609 private int mRttMode;
1610 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001611 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001612 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1613
1614 /**
1615 * @hide
1616 */
Hall Liu57006aa2017-02-06 10:49:48 -08001617 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1618 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1619 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001620 mReceiveStream = receiveStream;
1621 mTransmitStream = transmitStream;
1622 mRttMode = mode;
1623 mInCallAdapter = inCallAdapter;
1624 }
1625
1626 /**
1627 * Returns the current RTT audio mode.
1628 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1629 * {@link #RTT_MODE_HCO}.
1630 */
1631 public int getRttAudioMode() {
1632 return mRttMode;
1633 }
1634
1635 /**
1636 * Sets the RTT audio mode. The requested mode change will be communicated through
1637 * {@link Callback#onRttModeChanged(Call, int)}.
1638 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1639 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1640 */
1641 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001642 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001643 }
1644
1645 /**
1646 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
Hall Liudc46c852020-10-29 16:15:33 -07001647 * RTT transmits text in real-time, this method should be called once for each user action.
1648 * For example, when the user enters text as discrete characters using the keyboard, this
1649 * method should be called once for each character. However, if the user enters text by
1650 * pasting or autocomplete, the entire contents of the pasted or autocompleted text should
1651 * be sent in one call to this method.
Hall Liu95d55872017-01-25 17:12:49 -08001652 *
1653 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1654 * lead to interleaved text.
1655 * @param input The message to send to the remote user.
1656 */
1657 public void write(String input) throws IOException {
1658 mTransmitStream.write(input);
1659 mTransmitStream.flush();
1660 }
1661
1662 /**
1663 * Reads a string from the remote user, blocking if there is no data available. Returns
1664 * {@code null} if the RTT conversation has been terminated and there is no further data
1665 * to read.
1666 *
1667 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1668 * lead to interleaved text.
1669 * @return A string containing text sent by the remote user, or {@code null} if the
1670 * conversation has been terminated or if there was an error while reading.
1671 */
Hall Liub1c8a772017-07-17 17:04:41 -07001672 public String read() {
1673 try {
1674 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1675 if (numRead < 0) {
1676 return null;
1677 }
1678 return new String(mReadBuffer, 0, numRead);
1679 } catch (IOException e) {
1680 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001681 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001682 }
Hall Liuffa4a812017-03-02 16:11:00 -08001683 }
1684
1685 /**
1686 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1687 * be read.
1688 * @return A string containing text entered by the user, or {@code null} if the user has
1689 * not entered any new text yet.
1690 */
1691 public String readImmediately() throws IOException {
1692 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001693 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1694 if (numRead < 0) {
1695 return null;
1696 }
1697 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001698 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001699 return null;
1700 }
1701 }
Hall Liue9041242018-02-09 16:40:03 -08001702
1703 /**
1704 * Closes the underlying file descriptors
1705 * @hide
1706 */
1707 public void close() {
1708 try {
1709 mReceiveStream.close();
1710 } catch (IOException e) {
1711 // ignore
1712 }
1713 try {
1714 mTransmitStream.close();
1715 } catch (IOException e) {
1716 // ignore
1717 }
1718 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001719 }
1720
Andrew Leeda80c872015-04-15 14:09:50 -07001721 /**
1722 * @deprecated Use {@code Call.Callback} instead.
1723 * @hide
1724 */
1725 @Deprecated
1726 @SystemApi
1727 public static abstract class Listener extends Callback { }
1728
Ihab Awade63fadb2014-07-09 21:52:04 -07001729 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001730 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001731 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001732 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001733 private final List<Call> mChildren = new ArrayList<>();
1734 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001735 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001736 private final List<Call> mConferenceableCalls = new ArrayList<>();
1737 private final List<Call> mUnmodifiableConferenceableCalls =
1738 Collections.unmodifiableList(mConferenceableCalls);
1739
Santos Cordon823fd3c2014-08-07 18:35:18 -07001740 private boolean mChildrenCached;
1741 private String mParentId = null;
Hall Liuef98bf82020-01-09 15:22:44 -08001742 private String mActiveGenericConferenceChild = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001743 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001744 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001745 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001746 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001747 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001748 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001749 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001750 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001751 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001752
1753 /**
1754 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1755 *
1756 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1757 * remaining or this {@code Call} is not in a post-dial state.
1758 */
1759 public String getRemainingPostDialSequence() {
1760 return mRemainingPostDialSequence;
1761 }
1762
1763 /**
1764 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001765 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001766 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001767 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001768 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001769 }
1770
1771 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301772 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1773 *
1774 * @param address The address to which the call will be deflected.
1775 */
1776 public void deflect(Uri address) {
1777 mInCallAdapter.deflectCall(mTelecomCallId, address);
1778 }
1779
1780 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001781 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1782 *
1783 * @param rejectWithMessage Whether to reject with a text message.
1784 * @param textMessage An optional text message with which to respond.
1785 */
1786 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001787 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001788 }
1789
1790 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001791 * Instructs the {@link ConnectionService} providing this {@link #STATE_RINGING} call that the
1792 * user has chosen to reject the call and has indicated a reason why the call is being rejected.
1793 *
1794 * @param rejectReason the reason the call is being rejected.
1795 */
1796 public void reject(@RejectReason int rejectReason) {
1797 mInCallAdapter.rejectCall(mTelecomCallId, rejectReason);
1798 }
1799
1800 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05301801 * Instructs this {@code Call} to be transferred to another number.
1802 *
1803 * @param targetNumber The address to which the call will be transferred.
Tyler Gunn460360d2020-07-29 10:21:45 -07001804 * @param isConfirmationRequired if {@code true} it will initiate a confirmed transfer,
1805 * if {@code false}, it will initiate an unconfirmed transfer.
Ravi Palurif4b38e72020-02-05 12:35:41 +05301806 *
1807 * @hide
1808 */
1809 public void transfer(@NonNull Uri targetNumber, boolean isConfirmationRequired) {
1810 mInCallAdapter.transferCall(mTelecomCallId, targetNumber, isConfirmationRequired);
1811 }
1812
1813 /**
1814 * Instructs this {@code Call} to be transferred to another ongoing call.
1815 * This will initiate CONSULTATIVE transfer.
1816 * @param toCall The other ongoing {@code Call} to which this call will be transferred.
1817 *
1818 * @hide
1819 */
1820 public void transfer(@NonNull android.telecom.Call toCall) {
1821 mInCallAdapter.transferCall(mTelecomCallId, toCall.mTelecomCallId);
1822 }
1823
1824 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001825 * Instructs this {@code Call} to disconnect.
1826 */
1827 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001828 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001829 }
1830
1831 /**
1832 * Instructs this {@code Call} to go on hold.
1833 */
1834 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001835 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001836 }
1837
1838 /**
1839 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1840 */
1841 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001842 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001843 }
1844
1845 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001846 * Instructs Telecom to put the call into the background audio processing state.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001847 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001848 * This method can be called either when the call is in {@link #STATE_RINGING} or
1849 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1850 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1851 * order to capture and play audio on the call stream.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001852 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001853 * This method can only be called by the default dialer app.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001854 * <p>
1855 * Apps built with SDK version {@link android.os.Build.VERSION_CODES#R} or later which are using
1856 * the microphone as part of audio processing should specify the foreground service type using
1857 * the attribute {@link android.R.attr#foregroundServiceType} in the {@link InCallService}
1858 * service element of the app's manifest file.
1859 * The {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_MICROPHONE} attribute should be specified.
1860 * @see <a href="https://developer.android.com/preview/privacy/foreground-service-types">
1861 * the Android Developer Site</a> for more information.
Hall Liu6dfa2492019-10-01 17:20:39 -07001862 * @hide
1863 */
1864 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001865 public void enterBackgroundAudioProcessing() {
1866 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1867 throw new IllegalStateException("Call must be active or ringing");
1868 }
1869 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1870 }
1871
1872 /**
1873 * Instructs Telecom to come out of the background audio processing state requested by
1874 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1875 *
1876 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1877 *
1878 * @param shouldRing If true, Telecom will put the call into the
1879 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1880 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1881 * immediately.
1882 * @hide
1883 */
1884 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001885 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1886 if (mState != STATE_AUDIO_PROCESSING) {
1887 throw new IllegalStateException("Call must in the audio processing state");
1888 }
1889 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1890 }
1891
1892 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001893 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
Tyler Gunn2517d032023-02-06 16:34:54 +00001894 * <p>
1895 * Tones are both played locally for the user to hear and sent to the network to be relayed
1896 * to the remote device.
1897 * <p>
Anton Hansson84d6d752023-10-05 09:46:37 +00001898 * You must ensure that any call to {@link #playDtmfTone(char)} is followed by a matching
Tyler Gunn2517d032023-02-06 16:34:54 +00001899 * call to {@link #stopDtmfTone()} and that each tone is stopped before a new one is started.
1900 * The play and stop commands are relayed to the underlying
1901 * {@link android.telecom.ConnectionService} as executed; implementations may not correctly
1902 * handle out of order commands.
Ihab Awade63fadb2014-07-09 21:52:04 -07001903 *
1904 * @param digit A character representing the DTMF digit for which to play the tone. This
1905 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1906 */
1907 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001908 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001909 }
1910
1911 /**
1912 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1913 * currently playing.
1914 *
1915 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1916 * currently playing, this method will do nothing.
1917 */
1918 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001919 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001920 }
1921
1922 /**
1923 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1924 *
1925 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1926 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001927 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001928 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001929 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1930 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001931 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001932 * {@code Call} will pause playing the tones and notify callbacks via
1933 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001934 * should display to the user an indication of this state and an affordance to continue
1935 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1936 * app should invoke the {@link #postDialContinue(boolean)} method.
1937 *
1938 * @param proceed Whether or not to continue with the post-dial sequence.
1939 */
1940 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001941 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001942 }
1943
1944 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001945 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001946 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001947 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001948 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1949 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001950
1951 }
1952
1953 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001954 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001955 *
1956 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001957 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001958 public void conference(Call callToConferenceWith) {
1959 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001960 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001961 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001962 }
1963
1964 /**
1965 * Instructs this {@code Call} to split from any conference call with which it may be
1966 * connected.
1967 */
1968 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001969 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001970 }
1971
1972 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001973 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001974 */
1975 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001976 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001977 }
1978
1979 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001980 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001981 */
1982 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001983 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001984 }
1985
1986 /**
Ravi Paluri404babb2020-01-23 19:02:44 +05301987 * Pulls participants to existing call by forming a conference call.
1988 * See {@link Details#CAPABILITY_ADD_PARTICIPANT}.
1989 *
1990 * @param participants participants to be pulled to existing call.
1991 */
1992 public void addConferenceParticipants(@NonNull List<Uri> participants) {
1993 mInCallAdapter.addConferenceParticipants(mTelecomCallId, participants);
1994 }
1995
1996 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001997 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1998 * device.
1999 * <p>
2000 * Calls to this method are ignored if the call does not have the
2001 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
2002 * <p>
2003 * An {@link InCallService} will only see calls which support this method if it has the
2004 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
2005 * in its manifest.
2006 */
2007 public void pullExternalCall() {
2008 // If this isn't an external call, ignore the request.
2009 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
2010 return;
2011 }
2012
2013 mInCallAdapter.pullExternalCall(mTelecomCallId);
2014 }
2015
2016 /**
2017 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
2018 * the {@link ConnectionService}.
2019 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002020 * Call events are used to communicate point in time information from an {@link InCallService}
2021 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
2022 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
2023 * {@link ConnectionService}.
2024 * <p>
2025 * A {@link ConnectionService} can communicate to the {@link InCallService} using
2026 * {@link Connection#sendConnectionEvent(String, Bundle)}.
2027 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002028 * Events are exposed to {@link ConnectionService} implementations via
2029 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
2030 * <p>
2031 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002032 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
2033 * ignore some events altogether.
2034 * <p>
2035 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
2036 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
2037 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
2038 * they define their own event types in this namespace. When defining a custom event type,
2039 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
2040 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
2041 * <p>
2042 * When defining events and the associated extras, it is important to keep their behavior
2043 * consistent when the associated {@link InCallService} is updated. Support for deprecated
2044 * events/extras should me maintained to ensure backwards compatibility with older
2045 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002046 *
2047 * @param event The connection event.
2048 * @param extras Bundle containing extra information associated with the event.
2049 */
2050 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08002051 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002052 }
2053
2054 /**
Hall Liu95d55872017-01-25 17:12:49 -08002055 * Sends an RTT upgrade request to the remote end of the connection. Success is not
2056 * guaranteed, and notification of success will be via the
2057 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
2058 */
2059 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08002060 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08002061 }
2062
2063 /**
2064 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
2065 * callback.
2066 * The ID used here should be the same as the ID that was received via the callback.
2067 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
2068 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
2069 */
2070 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08002071 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08002072 }
2073
2074 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07002075 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
2076 * by {@code toHandle}. The videoState specified indicates the desired video state after the
2077 * handover.
2078 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08002079 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2080 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2081 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2082 * is referred to as the source of the handover, and the video calling app is referred to as the
2083 * destination.
2084 * <p>
2085 * When considering a handover scenario the device this method is called on is considered the
2086 * <em>initiating</em> device (since the user initiates the handover from this device), and the
2087 * other device is considered the <em>receiving</em> device.
2088 * <p>
2089 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
2090 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
2091 * and invoke
2092 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
2093 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
2094 * call to it. The app returns an instance of {@link Connection} to represent the handover call
2095 * At this point the app should display UI to indicate to the user that a call
2096 * handover is in process.
2097 * <p>
2098 * The destination app is responsible for communicating the handover request from the
2099 * <em>initiating</em> device to the <em>receiving</em> device.
2100 * <p>
2101 * When the app on the <em>receiving</em> device receives the handover request, it calls
2102 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
2103 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
2104 * the destination app on the <em>receiving</em> device should show UI to allow the user to
2105 * choose whether they want to continue their call in the destination app.
2106 * <p>
2107 * When the destination app on the <em>receiving</em> device calls
2108 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
2109 * {@link ConnectionService} and call
2110 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
2111 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
2112 * {@link Connection} to represent the handover call.
2113 * <p>
2114 * If the user of the <em>receiving</em> device accepts the handover, the app calls
2115 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
2116 * original call. If the user rejects the handover, the app calls
2117 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
2118 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
2119 * <p>
2120 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
2121 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
2122 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
2123 * <p>
2124 * Errors in the handover process are reported to the {@link InCallService} via
2125 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
2126 * the involved {@link ConnectionService}s via
2127 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002128 *
2129 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
2130 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08002131 * @param videoState Indicates the video state desired after the handover (see the
2132 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07002133 * @param extras Bundle containing extra information to be passed to the
2134 * {@link ConnectionService}
2135 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002136 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
2137 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002138 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
2139 }
2140
2141 /**
Hall Liu95d55872017-01-25 17:12:49 -08002142 * Terminate the RTT session on this call. The resulting state change will be notified via
2143 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
2144 */
2145 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08002146 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08002147 }
2148
2149 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002150 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
2151 * added.
2152 * <p>
2153 * No assumptions should be made as to how an In-Call UI or service will handle these
2154 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
Tyler Gunn6c100242023-01-09 11:23:18 -08002155 * <p>
2156 * Extras added using this method will be made available to the {@link ConnectionService}
2157 * associated with this {@link Call} and notified via
2158 * {@link Connection#onExtrasChanged(Bundle)}.
2159 * <p>
2160 * Extras added using this method will also be available to other running {@link InCallService}s
2161 * and notified via {@link Call.Callback#onDetailsChanged(Call, Details)}. The extras can be
2162 * accessed via {@link Details#getExtras()}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002163 *
2164 * @param extras The extras to add.
2165 */
2166 public final void putExtras(Bundle extras) {
2167 if (extras == null) {
2168 return;
2169 }
2170
2171 if (mExtras == null) {
2172 mExtras = new Bundle();
2173 }
2174 mExtras.putAll(extras);
2175 mInCallAdapter.putExtras(mTelecomCallId, extras);
2176 }
2177
2178 /**
2179 * Adds a boolean extra to this {@link Call}.
2180 *
2181 * @param key The extra key.
2182 * @param value The value.
2183 * @hide
2184 */
2185 public final void putExtra(String key, boolean value) {
2186 if (mExtras == null) {
2187 mExtras = new Bundle();
2188 }
2189 mExtras.putBoolean(key, value);
2190 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2191 }
2192
2193 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002194 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002195 *
2196 * @param key The extra key.
2197 * @param value The value.
2198 * @hide
2199 */
2200 public final void putExtra(String key, int value) {
2201 if (mExtras == null) {
2202 mExtras = new Bundle();
2203 }
2204 mExtras.putInt(key, value);
2205 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2206 }
2207
2208 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002209 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002210 *
2211 * @param key The extra key.
2212 * @param value The value.
2213 * @hide
2214 */
2215 public final void putExtra(String key, String value) {
2216 if (mExtras == null) {
2217 mExtras = new Bundle();
2218 }
2219 mExtras.putString(key, value);
2220 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2221 }
2222
2223 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002224 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002225 *
2226 * @param keys The keys of the extras to remove.
2227 */
2228 public final void removeExtras(List<String> keys) {
2229 if (mExtras != null) {
2230 for (String key : keys) {
2231 mExtras.remove(key);
2232 }
2233 if (mExtras.size() == 0) {
2234 mExtras = null;
2235 }
2236 }
2237 mInCallAdapter.removeExtras(mTelecomCallId, keys);
2238 }
2239
2240 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002241 * Removes extras from this {@link Call}.
2242 *
2243 * @param keys The keys of the extras to remove.
2244 */
2245 public final void removeExtras(String ... keys) {
2246 removeExtras(Arrays.asList(keys));
2247 }
2248
2249 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002250 * Obtains the parent of this {@code Call} in a conference, if any.
2251 *
2252 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
2253 * child of any conference {@code Call}s.
2254 */
2255 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002256 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002257 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002258 }
2259 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07002260 }
2261
2262 /**
2263 * Obtains the children of this conference {@code Call}, if any.
2264 *
2265 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
2266 * {@code List} otherwise.
2267 */
2268 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002269 if (!mChildrenCached) {
2270 mChildrenCached = true;
2271 mChildren.clear();
2272
2273 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002274 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002275 if (call == null) {
2276 // At least one child was still not found, so do not save true for "cached"
2277 mChildrenCached = false;
2278 } else {
2279 mChildren.add(call);
2280 }
2281 }
2282 }
2283
Ihab Awade63fadb2014-07-09 21:52:04 -07002284 return mUnmodifiableChildren;
2285 }
2286
2287 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002288 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
2289 *
2290 * @return The list of conferenceable {@code Call}s.
2291 */
2292 public List<Call> getConferenceableCalls() {
2293 return mUnmodifiableConferenceableCalls;
2294 }
2295
2296 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002297 * Obtains the state of this {@code Call}.
2298 *
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002299 * @return The call state.
2300 * @deprecated The call state is available via {@link Call.Details#getState()}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002301 */
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002302 @Deprecated
2303 public @CallState int getState() {
Ihab Awade63fadb2014-07-09 21:52:04 -07002304 return mState;
2305 }
2306
2307 /**
Hall Liuef98bf82020-01-09 15:22:44 -08002308 * Returns the child {@link Call} in a generic conference that is currently active.
Hall Liu135e53aa2020-02-27 18:34:11 -08002309 *
2310 * A "generic conference" is the mechanism used to support two simultaneous calls on a device
2311 * in CDMA networks. It is effectively equivalent to having one call active and one call on hold
2312 * in GSM or IMS calls. This method returns the currently active call.
2313 *
2314 * In a generic conference, the network exposes the conference to us as a single call, and we
2315 * switch between talking to the two participants using a CDMA flash command. Since the network
2316 * exposes no additional information about the call, the only way we know which caller we're
2317 * currently talking to is by keeping track of the flash commands that we've sent to the
2318 * network.
2319 *
Hall Liuef98bf82020-01-09 15:22:44 -08002320 * For calls that are not generic conferences, or when the generic conference has more than
2321 * 2 children, returns {@code null}.
2322 * @see Details#PROPERTY_GENERIC_CONFERENCE
2323 * @return The active child call.
2324 */
2325 public @Nullable Call getGenericConferenceActiveChildCall() {
2326 if (mActiveGenericConferenceChild != null) {
2327 return mPhone.internalGetCallByTelecomId(mActiveGenericConferenceChild);
2328 }
2329 return null;
2330 }
2331
2332 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002333 * Obtains a list of canned, pre-configured message responses to present to the user as
Tyler Gunn434fc2c2020-10-06 14:23:54 -07002334 * ways of rejecting an incoming {@code Call} using via a text message.
2335 * <p>
2336 * <em>Note:</em> Since canned responses may be loaded from the file system, they are not
2337 * guaranteed to be present when this {@link Call} is first added to the {@link InCallService}
2338 * via {@link InCallService#onCallAdded(Call)}. The callback
2339 * {@link Call.Callback#onCannedTextResponsesLoaded(Call, List)} will be called when/if canned
2340 * responses for the call become available.
Ihab Awade63fadb2014-07-09 21:52:04 -07002341 *
2342 * @see #reject(boolean, String)
2343 *
2344 * @return A list of canned text message responses.
2345 */
2346 public List<String> getCannedTextResponses() {
2347 return mCannedTextResponses;
2348 }
2349
2350 /**
2351 * Obtains an object that can be used to display video from this {@code Call}.
2352 *
Andrew Lee50aca232014-07-22 16:41:54 -07002353 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002354 */
Andrew Lee50aca232014-07-22 16:41:54 -07002355 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002356 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07002357 }
2358
2359 /**
2360 * Obtains an object containing call details.
2361 *
2362 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
2363 * result may be {@code null}.
2364 */
2365 public Details getDetails() {
2366 return mDetails;
2367 }
2368
2369 /**
Hall Liu95d55872017-01-25 17:12:49 -08002370 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
2371 * receive RTT text data, as well as to change the RTT mode.
2372 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
2373 */
2374 public @Nullable RttCall getRttCall() {
2375 return mRttCall;
2376 }
2377
2378 /**
2379 * Returns whether this call has an active RTT connection.
2380 * @return true if there is a connection, false otherwise.
2381 */
2382 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08002383 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08002384 }
2385
2386 /**
Andrew Leeda80c872015-04-15 14:09:50 -07002387 * Registers a callback to this {@code Call}.
2388 *
2389 * @param callback A {@code Callback}.
2390 */
2391 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07002392 registerCallback(callback, new Handler());
2393 }
2394
2395 /**
2396 * Registers a callback to this {@code Call}.
2397 *
2398 * @param callback A {@code Callback}.
2399 * @param handler A handler which command and status changes will be delivered to.
2400 */
2401 public void registerCallback(Callback callback, Handler handler) {
2402 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07002403 // Don't allow new callback registration if the call is already being destroyed.
2404 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002405 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
2406 }
Andrew Leeda80c872015-04-15 14:09:50 -07002407 }
2408
2409 /**
2410 * Unregisters a callback from this {@code Call}.
2411 *
2412 * @param callback A {@code Callback}.
2413 */
2414 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002415 // Don't allow callback deregistration if the call is already being destroyed.
2416 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002417 for (CallbackRecord<Callback> record : mCallbackRecords) {
2418 if (record.getCallback() == callback) {
2419 mCallbackRecords.remove(record);
2420 break;
2421 }
2422 }
Andrew Leeda80c872015-04-15 14:09:50 -07002423 }
2424 }
2425
Santos Cordon3c20d632016-02-25 16:12:35 -08002426 @Override
2427 public String toString() {
2428 return new StringBuilder().
2429 append("Call [id: ").
2430 append(mTelecomCallId).
2431 append(", state: ").
2432 append(stateToString(mState)).
2433 append(", details: ").
2434 append(mDetails).
2435 append("]").toString();
2436 }
2437
2438 /**
2439 * @param state An integer value of a {@code STATE_*} constant.
2440 * @return A string representation of the value.
2441 */
2442 private static String stateToString(int state) {
2443 switch (state) {
2444 case STATE_NEW:
2445 return "NEW";
2446 case STATE_RINGING:
2447 return "RINGING";
2448 case STATE_DIALING:
2449 return "DIALING";
2450 case STATE_ACTIVE:
2451 return "ACTIVE";
2452 case STATE_HOLDING:
2453 return "HOLDING";
2454 case STATE_DISCONNECTED:
2455 return "DISCONNECTED";
2456 case STATE_CONNECTING:
2457 return "CONNECTING";
2458 case STATE_DISCONNECTING:
2459 return "DISCONNECTING";
2460 case STATE_SELECT_PHONE_ACCOUNT:
2461 return "SELECT_PHONE_ACCOUNT";
Hall Liu4e35b642019-10-14 17:50:45 -07002462 case STATE_SIMULATED_RINGING:
2463 return "SIMULATED_RINGING";
2464 case STATE_AUDIO_PROCESSING:
2465 return "AUDIO_PROCESSING";
Santos Cordon3c20d632016-02-25 16:12:35 -08002466 default:
2467 Log.w(Call.class, "Unknown state %d", state);
2468 return "UNKNOWN";
2469 }
2470 }
2471
Andrew Leeda80c872015-04-15 14:09:50 -07002472 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002473 * Adds a listener to this {@code Call}.
2474 *
2475 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002476 * @deprecated Use {@link #registerCallback} instead.
2477 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002478 */
Andrew Leeda80c872015-04-15 14:09:50 -07002479 @Deprecated
2480 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002481 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002482 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002483 }
2484
2485 /**
2486 * Removes a listener from this {@code Call}.
2487 *
2488 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002489 * @deprecated Use {@link #unregisterCallback} instead.
2490 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002491 */
Andrew Leeda80c872015-04-15 14:09:50 -07002492 @Deprecated
2493 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002494 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002495 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002496 }
2497
2498 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002499 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2500 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002501 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002502 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002503 mInCallAdapter = inCallAdapter;
2504 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002505 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002506 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002507 }
2508
2509 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002510 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002511 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002512 mPhone = phone;
2513 mTelecomCallId = telecomCallId;
2514 mInCallAdapter = inCallAdapter;
2515 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002516 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002517 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002518 }
2519
2520 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002521 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002522 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002523 }
2524
2525 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002526 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002527
Ihab Awade63fadb2014-07-09 21:52:04 -07002528 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002529 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002530 boolean detailsChanged = !Objects.equals(mDetails, details);
2531 if (detailsChanged) {
2532 mDetails = details;
2533 }
2534
2535 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002536 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2537 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2538 mCannedTextResponses =
2539 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002540 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002541 }
2542
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002543 IVideoProvider previousVideoProvider = mVideoCallImpl == null ? null :
2544 mVideoCallImpl.getVideoProvider();
2545 IVideoProvider newVideoProvider = parcelableCall.getVideoProvider();
2546
2547 // parcelableCall.isVideoCallProviderChanged is only true when we have a video provider
2548 // specified; so we should check if the actual IVideoProvider changes as well.
2549 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged()
2550 && !Objects.equals(previousVideoProvider, newVideoProvider);
Andrew Lee50aca232014-07-22 16:41:54 -07002551 if (videoCallChanged) {
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002552 if (mVideoCallImpl != null) {
2553 mVideoCallImpl.destroy();
2554 }
2555 mVideoCallImpl = parcelableCall.isVideoCallProviderChanged() ?
2556 parcelableCall.getVideoCallImpl(mCallingPackage, mTargetSdkVersion) : null;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002557 }
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002558
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002559 if (mVideoCallImpl != null) {
2560 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002561 }
2562
Santos Cordone3c507b2015-04-23 14:44:19 -07002563 int state = parcelableCall.getState();
Hall Liu31de23d2019-10-11 15:38:29 -07002564 if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2565 state = Call.STATE_RINGING;
2566 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002567 boolean stateChanged = mState != state;
2568 if (stateChanged) {
2569 mState = state;
2570 }
2571
Santos Cordon823fd3c2014-08-07 18:35:18 -07002572 String parentId = parcelableCall.getParentCallId();
2573 boolean parentChanged = !Objects.equals(mParentId, parentId);
2574 if (parentChanged) {
2575 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002576 }
2577
Santos Cordon823fd3c2014-08-07 18:35:18 -07002578 List<String> childCallIds = parcelableCall.getChildCallIds();
2579 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2580 if (childrenChanged) {
2581 mChildrenIds.clear();
2582 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2583 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002584 }
2585
Hall Liuef98bf82020-01-09 15:22:44 -08002586 String activeChildCallId = parcelableCall.getActiveChildCallId();
2587 boolean activeChildChanged = !Objects.equals(activeChildCallId,
2588 mActiveGenericConferenceChild);
2589 if (activeChildChanged) {
2590 mActiveGenericConferenceChild = activeChildCallId;
2591 }
2592
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002593 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2594 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2595 for (String otherId : conferenceableCallIds) {
2596 if (callIdMap.containsKey(otherId)) {
2597 conferenceableCalls.add(callIdMap.get(otherId));
2598 }
2599 }
2600
2601 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2602 mConferenceableCalls.clear();
2603 mConferenceableCalls.addAll(conferenceableCalls);
2604 fireConferenceableCallsChanged();
2605 }
2606
Hall Liu95d55872017-01-25 17:12:49 -08002607 boolean isRttChanged = false;
2608 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002609 if (parcelableCall.getIsRttCallChanged()
2610 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002611 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2612 InputStreamReader receiveStream = new InputStreamReader(
2613 new ParcelFileDescriptor.AutoCloseInputStream(
2614 parcelableRttCall.getReceiveStream()),
2615 StandardCharsets.UTF_8);
2616 OutputStreamWriter transmitStream = new OutputStreamWriter(
2617 new ParcelFileDescriptor.AutoCloseOutputStream(
2618 parcelableRttCall.getTransmitStream()),
2619 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002620 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002621 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2622 if (mRttCall == null) {
2623 isRttChanged = true;
2624 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2625 rttModeChanged = true;
2626 }
2627 mRttCall = newRttCall;
2628 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2629 && parcelableCall.getIsRttCallChanged()) {
2630 isRttChanged = true;
Tyler Gunn4cd42482021-04-30 16:23:15 -07002631 mRttCall.close();
Hall Liu95d55872017-01-25 17:12:49 -08002632 mRttCall = null;
2633 }
2634
Ihab Awade63fadb2014-07-09 21:52:04 -07002635 // Now we fire updates, ensuring that any client who listens to any of these notifications
2636 // gets the most up-to-date state.
2637
2638 if (stateChanged) {
2639 fireStateChanged(mState);
2640 }
2641 if (detailsChanged) {
2642 fireDetailsChanged(mDetails);
2643 }
2644 if (cannedTextResponsesChanged) {
2645 fireCannedTextResponsesLoaded(mCannedTextResponses);
2646 }
Andrew Lee50aca232014-07-22 16:41:54 -07002647 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002648 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002649 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002650 if (parentChanged) {
2651 fireParentChanged(getParent());
2652 }
Hall Liuef98bf82020-01-09 15:22:44 -08002653 if (childrenChanged || activeChildChanged) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002654 fireChildrenChanged(getChildren());
2655 }
Hall Liu95d55872017-01-25 17:12:49 -08002656 if (isRttChanged) {
2657 fireOnIsRttChanged(mRttCall != null, mRttCall);
2658 }
2659 if (rttModeChanged) {
2660 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2661 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002662
2663 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2664 // remove ourselves from the Phone. Note that we do this after completing all state updates
2665 // so a client can cleanly transition all their UI to the state appropriate for a
2666 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
qing278fdb12021-10-26 19:05:51 +00002667 // Check if the original state is already disconnected, otherwise onCallRemoved will be
2668 // triggered before onCallAdded.
2669 if (mState == STATE_DISCONNECTED && stateChanged) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002670 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002671 }
2672 }
2673
2674 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002675 final void internalSetPostDialWait(String remaining) {
2676 mRemainingPostDialSequence = remaining;
2677 firePostDialWait(mRemainingPostDialSequence);
2678 }
2679
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002680 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002681 final void internalSetDisconnected() {
2682 if (mState != Call.STATE_DISCONNECTED) {
2683 mState = Call.STATE_DISCONNECTED;
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002684 if (mDetails != null) {
2685 mDetails = new Details(mState,
2686 mDetails.getTelecomCallId(),
2687 mDetails.getHandle(),
2688 mDetails.getHandlePresentation(),
2689 mDetails.getCallerDisplayName(),
2690 mDetails.getCallerDisplayNamePresentation(),
2691 mDetails.getAccountHandle(),
2692 mDetails.getCallCapabilities(),
2693 mDetails.getCallProperties(),
2694 mDetails.getDisconnectCause(),
2695 mDetails.getConnectTimeMillis(),
2696 mDetails.getGatewayInfo(),
2697 mDetails.getVideoState(),
2698 mDetails.getStatusHints(),
2699 mDetails.getExtras(),
2700 mDetails.getIntentExtras(),
2701 mDetails.getCreationTimeMillis(),
2702 mDetails.getContactDisplayName(),
2703 mDetails.getCallDirection(),
Edgar Arriagae5bec822022-10-14 14:25:43 -07002704 mDetails.getCallerNumberVerificationStatus(),
2705 mDetails.getContactPhotoUri()
Tyler Gunn1e406ca2021-03-18 16:47:14 -07002706 );
2707 fireDetailsChanged(mDetails);
2708 }
Santos Cordonf30d7e92014-08-26 09:54:33 -07002709 fireStateChanged(mState);
2710 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002711 }
2712 }
2713
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002714 /** {@hide} */
2715 final void internalOnConnectionEvent(String event, Bundle extras) {
2716 fireOnConnectionEvent(event, extras);
2717 }
2718
Hall Liu95d55872017-01-25 17:12:49 -08002719 /** {@hide} */
2720 final void internalOnRttUpgradeRequest(final int requestId) {
2721 for (CallbackRecord<Callback> record : mCallbackRecords) {
2722 final Call call = this;
2723 final Callback callback = record.getCallback();
2724 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2725 }
2726 }
2727
Hall Liu57006aa2017-02-06 10:49:48 -08002728 /** @hide */
2729 final void internalOnRttInitiationFailure(int reason) {
2730 for (CallbackRecord<Callback> record : mCallbackRecords) {
2731 final Call call = this;
2732 final Callback callback = record.getCallback();
2733 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2734 }
2735 }
2736
Sanket Padawe85291f62017-12-01 13:59:27 -08002737 /** {@hide} */
2738 final void internalOnHandoverFailed(int error) {
2739 for (CallbackRecord<Callback> record : mCallbackRecords) {
2740 final Call call = this;
2741 final Callback callback = record.getCallback();
2742 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2743 }
2744 }
2745
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002746 /** {@hide} */
2747 final void internalOnHandoverComplete() {
2748 for (CallbackRecord<Callback> record : mCallbackRecords) {
2749 final Call call = this;
2750 final Callback callback = record.getCallback();
2751 record.getHandler().post(() -> callback.onHandoverComplete(call));
2752 }
2753 }
2754
Andrew Lee011728f2015-04-23 15:47:06 -07002755 private void fireStateChanged(final int newState) {
2756 for (CallbackRecord<Callback> record : mCallbackRecords) {
2757 final Call call = this;
2758 final Callback callback = record.getCallback();
2759 record.getHandler().post(new Runnable() {
2760 @Override
2761 public void run() {
2762 callback.onStateChanged(call, newState);
2763 }
2764 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002765 }
2766 }
2767
Andrew Lee011728f2015-04-23 15:47:06 -07002768 private void fireParentChanged(final Call newParent) {
2769 for (CallbackRecord<Callback> record : mCallbackRecords) {
2770 final Call call = this;
2771 final Callback callback = record.getCallback();
2772 record.getHandler().post(new Runnable() {
2773 @Override
2774 public void run() {
2775 callback.onParentChanged(call, newParent);
2776 }
2777 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002778 }
2779 }
2780
Andrew Lee011728f2015-04-23 15:47:06 -07002781 private void fireChildrenChanged(final List<Call> children) {
2782 for (CallbackRecord<Callback> record : mCallbackRecords) {
2783 final Call call = this;
2784 final Callback callback = record.getCallback();
2785 record.getHandler().post(new Runnable() {
2786 @Override
2787 public void run() {
2788 callback.onChildrenChanged(call, children);
2789 }
2790 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002791 }
2792 }
2793
Andrew Lee011728f2015-04-23 15:47:06 -07002794 private void fireDetailsChanged(final Details details) {
2795 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.onDetailsChanged(call, details);
2802 }
2803 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002804 }
2805 }
2806
Andrew Lee011728f2015-04-23 15:47:06 -07002807 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2808 for (CallbackRecord<Callback> record : mCallbackRecords) {
2809 final Call call = this;
2810 final Callback callback = record.getCallback();
2811 record.getHandler().post(new Runnable() {
2812 @Override
2813 public void run() {
2814 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2815 }
2816 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002817 }
2818 }
2819
Andrew Lee011728f2015-04-23 15:47:06 -07002820 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2821 for (CallbackRecord<Callback> record : mCallbackRecords) {
2822 final Call call = this;
2823 final Callback callback = record.getCallback();
2824 record.getHandler().post(new Runnable() {
2825 @Override
2826 public void run() {
2827 callback.onVideoCallChanged(call, videoCall);
2828 }
2829 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002830 }
2831 }
2832
Andrew Lee011728f2015-04-23 15:47:06 -07002833 private void firePostDialWait(final String remainingPostDialSequence) {
2834 for (CallbackRecord<Callback> record : mCallbackRecords) {
2835 final Call call = this;
2836 final Callback callback = record.getCallback();
2837 record.getHandler().post(new Runnable() {
2838 @Override
2839 public void run() {
2840 callback.onPostDialWait(call, remainingPostDialSequence);
2841 }
2842 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002843 }
2844 }
2845
2846 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002847 /**
2848 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2849 * onCallRemoved callback, we remove this call from the Phone's record
2850 * only once all of the registered onCallDestroyed callbacks are executed.
2851 * All the callbacks get removed from our records as a part of this operation
2852 * since onCallDestroyed is the final callback.
2853 */
2854 final Call call = this;
2855 if (mCallbackRecords.isEmpty()) {
2856 // No callbacks registered, remove the call from Phone's record.
2857 mPhone.internalRemoveCall(call);
2858 }
2859 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002860 final Callback callback = record.getCallback();
2861 record.getHandler().post(new Runnable() {
2862 @Override
2863 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002864 boolean isFinalRemoval = false;
2865 RuntimeException toThrow = null;
2866 try {
2867 callback.onCallDestroyed(call);
2868 } catch (RuntimeException e) {
2869 toThrow = e;
2870 }
2871 synchronized(Call.this) {
2872 mCallbackRecords.remove(record);
2873 if (mCallbackRecords.isEmpty()) {
2874 isFinalRemoval = true;
2875 }
2876 }
2877 if (isFinalRemoval) {
2878 mPhone.internalRemoveCall(call);
2879 }
2880 if (toThrow != null) {
2881 throw toThrow;
2882 }
Andrew Lee011728f2015-04-23 15:47:06 -07002883 }
2884 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002885 }
2886 }
2887
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002888 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002889 for (CallbackRecord<Callback> record : mCallbackRecords) {
2890 final Call call = this;
2891 final Callback callback = record.getCallback();
2892 record.getHandler().post(new Runnable() {
2893 @Override
2894 public void run() {
2895 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2896 }
2897 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002898 }
2899 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002900
2901 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002902 * Notifies listeners of an incoming connection event.
2903 * <p>
2904 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2905 *
2906 * @param event
2907 * @param extras
2908 */
2909 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2910 for (CallbackRecord<Callback> record : mCallbackRecords) {
2911 final Call call = this;
2912 final Callback callback = record.getCallback();
2913 record.getHandler().post(new Runnable() {
2914 @Override
2915 public void run() {
2916 callback.onConnectionEvent(call, event, extras);
2917 }
2918 });
2919 }
2920 }
2921
2922 /**
Hall Liu95d55872017-01-25 17:12:49 -08002923 * Notifies listeners of an RTT on/off change
2924 *
2925 * @param enabled True if RTT is now enabled, false otherwise
2926 */
2927 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2928 for (CallbackRecord<Callback> record : mCallbackRecords) {
2929 final Call call = this;
2930 final Callback callback = record.getCallback();
2931 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2932 }
2933 }
2934
2935 /**
2936 * Notifies listeners of a RTT mode change
2937 *
2938 * @param mode The new RTT mode
2939 */
2940 private void fireOnRttModeChanged(final int mode) {
2941 for (CallbackRecord<Callback> record : mCallbackRecords) {
2942 final Call call = this;
2943 final Callback callback = record.getCallback();
2944 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2945 }
2946 }
2947
2948 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002949 * Determines if two bundles are equal.
2950 *
2951 * @param bundle The original bundle.
2952 * @param newBundle The bundle to compare with.
2953 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2954 */
2955 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2956 if (bundle == null || newBundle == null) {
2957 return bundle == newBundle;
2958 }
2959
2960 if (bundle.size() != newBundle.size()) {
2961 return false;
2962 }
2963
2964 for(String key : bundle.keySet()) {
2965 if (key != null) {
Grace Jia17005bd2022-05-12 12:49:02 -07002966 if (!newBundle.containsKey(key)) {
2967 return false;
2968 }
qing723dac62022-10-28 03:40:43 +00002969 // In case new call extra contains non-framework class objects, return false to
2970 // force update the call extra
2971 try {
2972 final Object value = bundle.get(key);
2973 final Object newValue = newBundle.get(key);
2974 if (value instanceof Bundle && newValue instanceof Bundle) {
2975 if (!areBundlesEqual((Bundle) value, (Bundle) newValue)) {
2976 return false;
2977 }
2978 }
2979 if (value instanceof byte[] && newValue instanceof byte[]) {
2980 if (!Arrays.equals((byte[]) value, (byte[]) newValue)) {
2981 return false;
2982 }
2983 } else if (!Objects.equals(value, newValue)) {
Grace Jia17005bd2022-05-12 12:49:02 -07002984 return false;
2985 }
qing723dac62022-10-28 03:40:43 +00002986 } catch (BadParcelableException e) {
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002987 return false;
2988 }
2989 }
2990 }
2991 return true;
2992 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002993}