blob: 91f7cee75775c7579bf09c7ab96b4b03d32091d7 [file] [log] [blame]
Ihab Awade63fadb2014-07-09 21:52:04 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awade63fadb2014-07-09 21:52:04 -070018
Hall Liu95d55872017-01-25 17:12:49 -080019import android.annotation.IntDef;
Ravi Paluri404babb2020-01-23 19:02:44 +053020import android.annotation.NonNull;
Hall Liu95d55872017-01-25 17:12:49 -080021import android.annotation.Nullable;
Andrew Leeda80c872015-04-15 14:09:50 -070022import android.annotation.SystemApi;
Hall Liu6dfa2492019-10-01 17:20:39 -070023import android.annotation.TestApi;
Artur Satayev53ada2a2019-12-10 17:47:56 +000024import android.compat.annotation.UnsupportedAppUsage;
Tyler Gunn460b7d42020-05-15 10:19:32 -070025import android.content.pm.ServiceInfo;
Ihab Awade63fadb2014-07-09 21:52:04 -070026import android.net.Uri;
Tyler Gunn6e3ecc42018-11-12 11:30:56 -080027import android.os.Build;
Nancy Chen10798dc2014-08-08 14:00:25 -070028import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070029import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080030import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070031
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -080032import com.android.internal.telecom.IVideoProvider;
33
Hall Liu95d55872017-01-25 17:12:49 -080034import java.io.IOException;
35import java.io.InputStreamReader;
36import java.io.OutputStreamWriter;
Hall Liu95d55872017-01-25 17:12:49 -080037import java.lang.annotation.Retention;
38import java.lang.annotation.RetentionPolicy;
39import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070040import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070041import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070042import java.util.Collections;
43import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070044import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070045import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070046import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070047
48/**
49 * Represents an ongoing phone call that the in-call app should present to the user.
50 */
51public final class Call {
52 /**
53 * The state of a {@code Call} when newly created.
54 */
55 public static final int STATE_NEW = 0;
56
57 /**
58 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
59 */
60 public static final int STATE_DIALING = 1;
61
62 /**
63 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
64 */
65 public static final int STATE_RINGING = 2;
66
67 /**
68 * The state of a {@code Call} when in a holding state.
69 */
70 public static final int STATE_HOLDING = 3;
71
72 /**
73 * The state of a {@code Call} when actively supporting conversation.
74 */
75 public static final int STATE_ACTIVE = 4;
76
77 /**
78 * The state of a {@code Call} when no further voice or other communication is being
79 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
80 * is no longer active, and the local data transport has or inevitably will release resources
81 * associated with this {@code Call}.
82 */
83 public static final int STATE_DISCONNECTED = 7;
84
Nancy Chen5da0fd52014-07-08 14:16:17 -070085 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070086 * The state of an outgoing {@code Call} when waiting on user to select a
87 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070088 */
Santos Cordone3c507b2015-04-23 14:44:19 -070089 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
90
91 /**
92 * @hide
93 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
94 */
95 @Deprecated
96 @SystemApi
97 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070098
Nancy Chene20930f2014-08-07 16:17:21 -070099 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -0700100 * The initial state of an outgoing {@code Call}.
101 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
102 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -0700103 */
104 public static final int STATE_CONNECTING = 9;
105
Nancy Chen513c8922014-09-17 14:47:20 -0700106 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700107 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
108 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
109 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
110 */
111 public static final int STATE_DISCONNECTING = 10;
112
113 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700114 * The state of an external call which is in the process of being pulled from a remote device to
115 * the local device.
116 * <p>
117 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
118 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
119 * <p>
120 * An {@link InCallService} will only see this state if it has the
121 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
122 * manifest.
123 */
124 public static final int STATE_PULLING_CALL = 11;
125
126 /**
Hall Liu6dfa2492019-10-01 17:20:39 -0700127 * The state of a call that is active with the network, but the audio from the call is
128 * being intercepted by an app on the local device. Telecom does not hold audio focus in this
129 * state, and the call will be invisible to the user except for a persistent notification.
130 */
131 public static final int STATE_AUDIO_PROCESSING = 12;
132
133 /**
134 * The state of a call that is being presented to the user after being in
135 * {@link #STATE_AUDIO_PROCESSING}. The call is still active with the network in this case, and
136 * Telecom will hold audio focus and play a ringtone if appropriate.
137 */
138 public static final int STATE_SIMULATED_RINGING = 13;
139
140 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700141 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
142 * extras. Used to pass the phone accounts to display on the front end to the user in order to
143 * select phone accounts to (for example) place a call.
Hall Liu34d9e242018-11-21 17:05:58 -0800144 * @deprecated Use the list from {@link #EXTRA_SUGGESTED_PHONE_ACCOUNTS} instead.
Nancy Chen513c8922014-09-17 14:47:20 -0700145 */
Hall Liu34d9e242018-11-21 17:05:58 -0800146 @Deprecated
Nancy Chen513c8922014-09-17 14:47:20 -0700147 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
148
mike dooley4af561f2016-12-20 08:55:17 -0800149 /**
Hall Liu34d9e242018-11-21 17:05:58 -0800150 * Key for extra used to pass along a list of {@link PhoneAccountSuggestion}s to the in-call
151 * UI when a call enters the {@link #STATE_SELECT_PHONE_ACCOUNT} state. The list included here
152 * will have the same length and be in the same order as the list passed with
153 * {@link #AVAILABLE_PHONE_ACCOUNTS}.
154 */
155 public static final String EXTRA_SUGGESTED_PHONE_ACCOUNTS =
156 "android.telecom.extra.SUGGESTED_PHONE_ACCOUNTS";
157
158 /**
mike dooley91217422017-03-09 12:58:42 -0800159 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
160 * when the last outgoing emergency call was made. This is used to identify potential emergency
161 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800162 */
163 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
164 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
165
Usman Abdullahb0dc29a2019-03-06 15:54:56 -0800166
167 /**
168 * Extra key used to indicate whether a {@link CallScreeningService} has requested to silence
169 * the ringtone for a call. If the {@link InCallService} declares
170 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} in its manifest, it should not
171 * play a ringtone for an incoming call with this extra key set.
172 */
173 public static final String EXTRA_SILENT_RINGING_REQUESTED =
174 "android.telecom.extra.SILENT_RINGING_REQUESTED";
175
Tyler Gunn8bf76572017-04-06 15:30:08 -0700176 /**
177 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
178 * Telecom that the user has requested that the current {@link Call} should be handed over
179 * to another {@link ConnectionService}.
180 * <p>
181 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
182 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
183 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700184 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
185 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700186 */
187 public static final String EVENT_REQUEST_HANDOVER =
188 "android.telecom.event.REQUEST_HANDOVER";
189
190 /**
191 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
192 * {@link PhoneAccountHandle} to which a call should be handed over to.
193 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700194 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
195 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700196 */
197 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
198 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
199
200 /**
201 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
202 * video state of the call when it is handed over to the new {@link PhoneAccount}.
203 * <p>
204 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
205 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
206 * {@link VideoProfile#STATE_TX_ENABLED}.
207 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700208 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
209 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700210 */
211 public static final String EXTRA_HANDOVER_VIDEO_STATE =
212 "android.telecom.extra.HANDOVER_VIDEO_STATE";
213
214 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700215 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
216 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
217 * information to the handover {@link ConnectionService} specified by
218 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
219 * <p>
220 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
221 * {@link ConnectionService} via the request extras when
222 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
223 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700224 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700225 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
226 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700227 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700228 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700229
230 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700231 * Call event sent from Telecom to the handover {@link ConnectionService} via
232 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
233 * to the {@link ConnectionService} has completed successfully.
234 * <p>
235 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700236 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700237 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
238 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700239 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700240 public static final String EVENT_HANDOVER_COMPLETE =
241 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700242
243 /**
244 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
245 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
246 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
247 * {@code null}.
248 * <p>
249 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
250 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700251 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
252 * APIs instead.
Tyler Gunn34a2b312017-06-23 08:32:00 -0700253 */
254 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
255 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
256
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700257 /**
258 * Call event sent from Telecom to the handover {@link ConnectionService} via
259 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
260 * to the {@link ConnectionService} has failed.
261 * <p>
262 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
263 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700264 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
265 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700266 */
267 public static final String EVENT_HANDOVER_FAILED =
268 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700269
Tyler Gunnd5821842021-02-05 11:12:57 -0800270 /**
271 * Event reported from the Telecom stack to report an in-call diagnostic message which the
272 * dialer app may opt to display to the user. A diagnostic message is used to communicate
273 * scenarios the device has detected which may impact the quality of the ongoing call.
274 * <p>
275 * For example a problem with a bluetooth headset may generate a recommendation for the user to
276 * try using the speakerphone instead, or if the device detects it has entered a poor service
277 * area, the user might be warned so that they can finish their call prior to it dropping.
278 * <p>
279 * A diagnostic message is considered persistent in nature. When the user enters a poor service
280 * area, for example, the accompanying diagnostic message persists until they leave the area
281 * of poor service. Each message is accompanied with a {@link #EXTRA_DIAGNOSTIC_MESSAGE_ID}
282 * which uniquely identifies the diagnostic condition being reported. The framework raises a
283 * call event of type {@link #EVENT_CLEAR_DIAGNOSTIC_MESSAGE} when the condition reported has
284 * been cleared. The dialer app should display the diagnostic message until it is cleared.
285 * If multiple diagnostic messages are sent with different IDs (which have not yet been cleared)
286 * the dialer app should prioritize the most recently received message, but still provide the
287 * user with a means to review past messages.
288 * <p>
289 * The text of the message is found in {@link #EXTRA_DIAGNOSTIC_MESSAGE} in the form of a human
290 * readable {@link CharSequence} which is intended for display in the call UX.
291 * <p>
292 * The telecom framework audibly notifies the user of the presence of a diagnostic message, so
293 * the dialer app needs only to concern itself with visually displaying the message.
294 * <p>
295 * The dialer app receives this event via
296 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
297 */
298 public static final String EVENT_DISPLAY_DIAGNOSTIC_MESSAGE =
299 "android.telecom.event.DISPLAY_DIAGNOSTIC_MESSAGE";
300
301 /**
302 * Event reported from the telecom framework when a diagnostic message previously raised with
303 * {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE} has cleared and is no longer pertinent.
304 * <p>
305 * The {@link #EXTRA_DIAGNOSTIC_MESSAGE_ID} indicates the diagnostic message which has been
306 * cleared.
307 * <p>
308 * The dialer app receives this event via
309 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
310 */
311 public static final String EVENT_CLEAR_DIAGNOSTIC_MESSAGE =
312 "android.telecom.event.CLEAR_DIAGNOSTIC_MESSAGE";
313
314 /**
315 * Integer extra representing a message ID for a message posted via
316 * {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE}. Used to ensure that the dialer app knows when
317 * the message in question has cleared via {@link #EVENT_CLEAR_DIAGNOSTIC_MESSAGE}.
318 */
319 public static final String EXTRA_DIAGNOSTIC_MESSAGE_ID =
320 "android.telecom.extra.DIAGNOSTIC_MESSAGE_ID";
321
322 /**
323 * {@link CharSequence} extra used with {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE}. This is the
324 * diagnostic message the dialer app should display.
325 */
326 public static final String EXTRA_DIAGNOSTIC_MESSAGE =
327 "android.telecom.extra.DIAGNOSTIC_MESSAGE";
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800328
329 /**
330 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
331 * call because they have declined to answer it. This typically means that they are unable
332 * to answer the call at this time and would prefer it be sent to voicemail.
333 */
334 public static final int REJECT_REASON_DECLINED = 1;
335
336 /**
337 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
338 * call because it is an unwanted call. This allows the user to indicate that they are
339 * rejecting a call because it is likely a nuisance call.
340 */
341 public static final int REJECT_REASON_UNWANTED = 2;
342
343 /**
344 * @hide
345 */
346 @IntDef(prefix = { "REJECT_REASON_" },
347 value = {REJECT_REASON_DECLINED, REJECT_REASON_UNWANTED})
348 @Retention(RetentionPolicy.SOURCE)
349 public @interface RejectReason {};
350
Ihab Awade63fadb2014-07-09 21:52:04 -0700351 public static class Details {
Tyler Gunn94f8f112018-12-17 09:56:11 -0800352 /** @hide */
353 @Retention(RetentionPolicy.SOURCE)
354 @IntDef(
355 prefix = { "DIRECTION_" },
356 value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
357 public @interface CallDirection {}
358
359 /**
360 * Indicates that the call is neither and incoming nor an outgoing call. This can be the
361 * case for calls reported directly by a {@link ConnectionService} in special cases such as
362 * call handovers.
363 */
364 public static final int DIRECTION_UNKNOWN = -1;
365
366 /**
367 * Indicates that the call is an incoming call.
368 */
369 public static final int DIRECTION_INCOMING = 0;
370
371 /**
372 * Indicates that the call is an outgoing call.
373 */
374 public static final int DIRECTION_OUTGOING = 1;
375
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800376 /** Call can currently be put on hold or unheld. */
377 public static final int CAPABILITY_HOLD = 0x00000001;
378
379 /** Call supports the hold feature. */
380 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
381
382 /**
383 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
384 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
385 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
386 * capability allows a merge button to be shown while the conference call is in the foreground
387 * of the in-call UI.
388 * <p>
389 * This is only intended for use by a {@link Conference}.
390 */
391 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
392
393 /**
394 * Calls within a conference can be swapped between foreground and background.
395 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
396 * <p>
397 * This is only intended for use by a {@link Conference}.
398 */
399 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
400
401 /**
402 * @hide
403 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700404 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800405
406 /** Call supports responding via text option. */
407 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
408
409 /** Call can be muted. */
410 public static final int CAPABILITY_MUTE = 0x00000040;
411
412 /**
413 * Call supports conference call management. This capability only applies to {@link Conference}
414 * calls which can have {@link Connection}s as children.
415 */
416 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
417
418 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700419 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800420 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700421 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800422
423 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700424 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800425 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700426 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800427
428 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700429 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800430 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700431 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700432 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800433
434 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700435 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800436 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700437 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
438
439 /**
440 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700441 */
442 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
443
444 /**
445 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700446 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700447 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700448 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800449
450 /**
451 * Call is able to be separated from its parent {@code Conference}, if any.
452 */
453 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
454
455 /**
456 * Call is able to be individually disconnected when in a {@code Conference}.
457 */
458 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
459
460 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500461 * Speed up audio setup for MT call.
462 * @hide
463 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700464 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
465
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700466 /**
467 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700468 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800469 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
470 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
471 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700472 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800473 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700474 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
475
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700476 /**
477 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700478 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700479 */
480 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
481
Bryce Lee81901682015-08-28 16:38:02 -0700482 /**
483 * Call sends responses through connection.
484 * @hide
485 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800486 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
487
488 /**
489 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
490 * <p>
491 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
492 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
493 * downgraded from a video call back to a VideoState of
494 * {@link VideoProfile#STATE_AUDIO_ONLY}.
495 * <p>
496 * Intuitively, a call which can be downgraded to audio should also have local and remote
497 * video
498 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
499 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
500 */
501 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700502
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700503 /**
504 * When set for an external call, indicates that this {@code Call} can be pulled from a
505 * remote device to the current device.
506 * <p>
507 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
508 * <p>
509 * An {@link InCallService} will only see calls with this capability if it has the
510 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
511 * in its manifest.
512 * <p>
513 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700514 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700515 */
516 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
517
Pooja Jaind34698d2017-12-28 14:15:31 +0530518 /** Call supports the deflect feature. */
519 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
520
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800521 /**
522 * Call supports adding participants to the call via
Grace Jia8587ee52020-07-10 15:42:32 -0700523 * {@link #addConferenceParticipants(List)}. Once participants are added, the call becomes
524 * an adhoc conference call ({@link #PROPERTY_IS_ADHOC_CONFERENCE}).
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800525 */
Ravi Paluri404babb2020-01-23 19:02:44 +0530526 public static final int CAPABILITY_ADD_PARTICIPANT = 0x02000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530527
528 /**
529 * When set for a call, indicates that this {@code Call} can be transferred to another
530 * number.
Tyler Gunn460360d2020-07-29 10:21:45 -0700531 * Call supports the confirmed and unconfirmed call transfer feature.
Ravi Palurif4b38e72020-02-05 12:35:41 +0530532 *
533 * @hide
534 */
535 public static final int CAPABILITY_TRANSFER = 0x04000000;
536
537 /**
538 * When set for a call, indicates that this {@code Call} can be transferred to another
539 * ongoing call.
540 * Call supports the consultative call transfer feature.
541 *
542 * @hide
543 */
544 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x08000000;
545
Tyler Gunnd11a3152015-03-18 13:09:14 -0700546 //******************************************************************************************
Ravi Palurif4b38e72020-02-05 12:35:41 +0530547 // Next CAPABILITY value: 0x10000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700548 //******************************************************************************************
549
550 /**
551 * Whether the call is currently a conference.
552 */
553 public static final int PROPERTY_CONFERENCE = 0x00000001;
554
555 /**
556 * Whether the call is a generic conference, where we do not know the precise state of
557 * participants in the conference (eg. on CDMA).
558 */
559 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
560
561 /**
562 * Whether the call is made while the device is in emergency callback mode.
563 */
564 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
565
566 /**
567 * Connection is using WIFI.
568 */
569 public static final int PROPERTY_WIFI = 0x00000008;
570
571 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700572 * When set, the UI should indicate to the user that a call is using high definition
573 * audio.
574 * <p>
575 * The underlying {@link ConnectionService} is responsible for reporting this
576 * property. It is important to note that this property is not intended to report the
577 * actual audio codec being used for a Call, but whether the call should be indicated
578 * to the user as high definition.
579 * <p>
580 * The Android Telephony stack reports this property for calls based on a number
581 * of factors, including which audio codec is used and whether a call is using an HD
582 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
583 * and in these cases this property will not be set for a call even if the underlying audio
584 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700585 */
586 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
587
Tony Maka68dcce2015-12-17 09:31:18 +0000588 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100589 * Whether the call is associated with the work profile.
590 */
591 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
592
593 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700594 * When set, indicates that this {@code Call} does not actually exist locally for the
595 * {@link ConnectionService}.
596 * <p>
597 * Consider, for example, a scenario where a user has two phones with the same phone number.
598 * When a user places a call on one device, the telephony stack can represent that call on
599 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700600 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700601 * <p>
602 * An {@link InCallService} will only see calls with this property if it has the
603 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
604 * in its manifest.
605 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700606 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700607 */
608 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
609
Brad Ebinger15847072016-05-18 11:08:36 -0700610 /**
611 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
612 */
613 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
614
Tyler Gunn24e18332017-02-10 09:42:49 -0800615 /**
616 * Indicates that the call is from a self-managed {@link ConnectionService}.
617 * <p>
618 * See also {@link Connection#PROPERTY_SELF_MANAGED}
619 */
620 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
621
Eric Erfanianec881872017-12-06 16:27:53 -0800622 /**
623 * Indicates the call used Assisted Dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700624 *
625 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanianec881872017-12-06 16:27:53 -0800626 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800627 public static final int PROPERTY_ASSISTED_DIALING = 0x00000200;
Eric Erfanianec881872017-12-06 16:27:53 -0800628
Hall Liue9041242018-02-09 16:40:03 -0800629 /**
630 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
631 * {@link RttCall} object that is used to send and receive text.
632 */
633 public static final int PROPERTY_RTT = 0x00000400;
634
Tyler Gunn5bd90852018-09-21 09:37:07 -0700635 /**
636 * Indicates that the call has been identified as the network as an emergency call. This
637 * property may be set for both incoming and outgoing calls which the network identifies as
638 * emergency calls.
639 */
640 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
641
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700642 /**
643 * Indicates that the call is using VoIP audio mode.
644 * <p>
645 * When this property is set, the {@link android.media.AudioManager} audio mode for this
646 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
647 * property is not set, the audio mode for this call will be
648 * {@link android.media.AudioManager#MODE_IN_CALL}.
649 * <p>
650 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
651 * <p>
652 * You can use this property to determine whether an un-answered incoming call or a held
653 * call will use VoIP audio mode (if the call does not currently have focus, the system
654 * audio mode may not reflect the mode the call will use).
655 */
656 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
657
Ravi Paluri80aa2142019-12-02 11:57:37 +0530658 /**
659 * Indicates that the call is an adhoc conference call. This property can be set for both
Grace Jia8587ee52020-07-10 15:42:32 -0700660 * incoming and outgoing calls. An adhoc conference call is formed using
661 * {@link #addConferenceParticipants(List)},
662 * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}, or
663 * {@link TelecomManager#startConference(List, Bundle)}, rather than by merging existing
664 * call using {@link #conference(Call)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530665 */
666 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 0x00002000;
667
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800668 /**
Sooraj Sasindranfa1e57a2021-03-22 13:44:14 -0700669 * Connection is using cross sim technology.
670 * <p>
671 * Indicates that the {@link Connection} is using a cross sim technology which would
672 * register IMS over internet APN of default data subscription.
673 * <p>
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800674 */
675 public static final int PROPERTY_CROSS_SIM = 0x00004000;
676
Andrew Lee2378ea72015-04-29 14:38:11 -0700677 //******************************************************************************************
Ravi Paluri80aa2142019-12-02 11:57:37 +0530678 // Next PROPERTY value: 0x00004000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700679 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800680
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800681 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700682 private final Uri mHandle;
683 private final int mHandlePresentation;
684 private final String mCallerDisplayName;
685 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700686 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700687 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700688 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800689 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700690 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700691 private final long mConnectTimeMillis;
692 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700693 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700694 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700695 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700696 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700697 private final long mCreationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -0800698 private final String mContactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800699 private final @CallDirection int mCallDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700700 private final @Connection.VerificationStatus int mCallerNumberVerificationStatus;
Ihab Awade63fadb2014-07-09 21:52:04 -0700701
702 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800703 * Whether the supplied capabilities supports the specified capability.
704 *
705 * @param capabilities A bit field of capabilities.
706 * @param capability The capability to check capabilities for.
707 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800708 */
709 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800710 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800711 }
712
713 /**
714 * Whether the capabilities of this {@code Details} supports the specified capability.
715 *
716 * @param capability The capability to check capabilities for.
717 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800718 */
719 public boolean can(int capability) {
720 return can(mCallCapabilities, capability);
721 }
722
723 /**
724 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
725 *
726 * @param capabilities A capability bit field.
727 * @return A human readable string representation.
728 */
729 public static String capabilitiesToString(int capabilities) {
730 StringBuilder builder = new StringBuilder();
731 builder.append("[Capabilities:");
732 if (can(capabilities, CAPABILITY_HOLD)) {
733 builder.append(" CAPABILITY_HOLD");
734 }
735 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
736 builder.append(" CAPABILITY_SUPPORT_HOLD");
737 }
738 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
739 builder.append(" CAPABILITY_MERGE_CONFERENCE");
740 }
741 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
742 builder.append(" CAPABILITY_SWAP_CONFERENCE");
743 }
744 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
745 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
746 }
747 if (can(capabilities, CAPABILITY_MUTE)) {
748 builder.append(" CAPABILITY_MUTE");
749 }
750 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
751 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
752 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700753 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
754 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
755 }
756 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
757 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
758 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700759 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
760 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800761 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700762 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
763 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
764 }
765 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
766 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
767 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800768 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
769 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
770 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700771 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
772 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800773 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500774 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700775 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500776 }
Rekha Kumar07366812015-03-24 16:42:31 -0700777 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
778 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
779 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700780 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
781 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
782 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700783 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
784 builder.append(" CAPABILITY_CAN_PULL_CALL");
785 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530786 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
787 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
788 }
Ravi Paluri404babb2020-01-23 19:02:44 +0530789 if (can(capabilities, CAPABILITY_ADD_PARTICIPANT)) {
790 builder.append(" CAPABILITY_ADD_PARTICIPANT");
791 }
Ravi Palurif4b38e72020-02-05 12:35:41 +0530792 if (can(capabilities, CAPABILITY_TRANSFER)) {
793 builder.append(" CAPABILITY_TRANSFER");
794 }
795 if (can(capabilities, CAPABILITY_TRANSFER_CONSULTATIVE)) {
796 builder.append(" CAPABILITY_TRANSFER_CONSULTATIVE");
797 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800798 builder.append("]");
799 return builder.toString();
800 }
801
802 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700803 * Whether the supplied properties includes the specified property.
804 *
805 * @param properties A bit field of properties.
806 * @param property The property to check properties for.
807 * @return Whether the specified property is supported.
808 */
809 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800810 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700811 }
812
813 /**
814 * Whether the properties of this {@code Details} includes the specified property.
815 *
816 * @param property The property to check properties for.
817 * @return Whether the specified property is supported.
818 */
819 public boolean hasProperty(int property) {
820 return hasProperty(mCallProperties, property);
821 }
822
823 /**
824 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
825 *
826 * @param properties A property bit field.
827 * @return A human readable string representation.
828 */
829 public static String propertiesToString(int properties) {
830 StringBuilder builder = new StringBuilder();
831 builder.append("[Properties:");
832 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
833 builder.append(" PROPERTY_CONFERENCE");
834 }
835 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
836 builder.append(" PROPERTY_GENERIC_CONFERENCE");
837 }
838 if (hasProperty(properties, PROPERTY_WIFI)) {
839 builder.append(" PROPERTY_WIFI");
840 }
841 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
842 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
843 }
844 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700845 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700846 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700847 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
848 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
849 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700850 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700851 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
852 }
Tyler Gunnc9503d62020-01-27 10:30:51 -0800853 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800854 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
855 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700856 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
857 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
858 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700859 if (hasProperty(properties, PROPERTY_RTT)) {
860 builder.append(" PROPERTY_RTT");
861 }
862 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
863 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
864 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530865 if (hasProperty(properties, PROPERTY_IS_ADHOC_CONFERENCE)) {
866 builder.append(" PROPERTY_IS_ADHOC_CONFERENCE");
867 }
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800868 if (hasProperty(properties, PROPERTY_CROSS_SIM)) {
869 builder.append(" PROPERTY_CROSS_SIM");
870 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700871 builder.append("]");
872 return builder.toString();
873 }
874
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800875 /** {@hide} */
Hall Liu31de23d2019-10-11 15:38:29 -0700876 @TestApi
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800877 public String getTelecomCallId() {
878 return mTelecomCallId;
879 }
880
Andrew Lee2378ea72015-04-29 14:38:11 -0700881 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700882 * @return The handle (e.g., phone number) to which the {@code Call} is currently
883 * connected.
884 */
885 public Uri getHandle() {
886 return mHandle;
887 }
888
889 /**
890 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700891 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700892 */
893 public int getHandlePresentation() {
894 return mHandlePresentation;
895 }
896
897 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800898 * The display name for the caller.
899 * <p>
900 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800901 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700902 * @return The display name for the caller.
903 */
904 public String getCallerDisplayName() {
905 return mCallerDisplayName;
906 }
907
908 /**
909 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700910 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700911 */
912 public int getCallerDisplayNamePresentation() {
913 return mCallerDisplayNamePresentation;
914 }
915
916 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700917 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
918 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700919 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700920 public PhoneAccountHandle getAccountHandle() {
921 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700922 }
923
924 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800925 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
926 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700927 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700928 public int getCallCapabilities() {
929 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700930 }
931
932 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700933 * @return A bitmask of the properties of the {@code Call}, as defined by the various
934 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700935 */
936 public int getCallProperties() {
937 return mCallProperties;
938 }
939
940 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800941 * @return a bitmask of the audio routes available for the call.
942 *
943 * @hide
944 */
945 public int getSupportedAudioRoutes() {
946 return mSupportedAudioRoutes;
947 }
948
949 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700950 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700951 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700952 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700953 public DisconnectCause getDisconnectCause() {
954 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700955 }
956
957 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700958 * Returns the time the {@link Call} connected (i.e. became active). This information is
959 * updated periodically, but user interfaces should not rely on this to display the "call
960 * time clock". For the time when the call was first added to Telecom, see
961 * {@link #getCreationTimeMillis()}.
962 *
963 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700964 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700965 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700966 return mConnectTimeMillis;
967 }
968
969 /**
970 * @return Information about any calling gateway the {@code Call} may be using.
971 */
972 public GatewayInfo getGatewayInfo() {
973 return mGatewayInfo;
974 }
975
Andrew Lee7a341382014-07-15 17:05:08 -0700976 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700977 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700978 */
979 public int getVideoState() {
980 return mVideoState;
981 }
982
Ihab Awad5d0410f2014-07-30 10:07:40 -0700983 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700984 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700985 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700986 */
987 public StatusHints getStatusHints() {
988 return mStatusHints;
989 }
990
Nancy Chen10798dc2014-08-08 14:00:25 -0700991 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700992 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700993 */
994 public Bundle getExtras() {
995 return mExtras;
996 }
997
Santos Cordon6b7f9552015-05-27 17:21:45 -0700998 /**
999 * @return The extras used with the original intent to place this call.
1000 */
1001 public Bundle getIntentExtras() {
1002 return mIntentExtras;
1003 }
1004
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001005 /**
1006 * Returns the time when the call was first created and added to Telecom. This is the same
1007 * time that is logged as the start time in the Call Log (see
1008 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
1009 * (became active), see {@link #getConnectTimeMillis()}.
1010 *
1011 * @return The creation time of the call, in millis since the epoch.
1012 */
1013 public long getCreationTimeMillis() {
1014 return mCreationTimeMillis;
1015 }
1016
Tyler Gunnd081f042018-12-04 12:56:45 -08001017 /**
Hall Liuef98bf82020-01-09 15:22:44 -08001018 * Returns the name of the caller on the remote end, as derived from a
1019 * {@link android.provider.ContactsContract} lookup of the call's handle.
1020 * @return The name of the caller, or {@code null} if the lookup is not yet complete, if
1021 * there's no contacts entry for the caller, or if the {@link InCallService} does
1022 * not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
1023 */
1024 public @Nullable String getContactDisplayName() {
1025 return mContactDisplayName;
1026 }
1027
1028 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -08001029 * Indicates whether the call is an incoming or outgoing call.
1030 * @return The call's direction.
1031 */
1032 public @CallDirection int getCallDirection() {
1033 return mCallDirection;
1034 }
1035
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001036 /**
1037 * Gets the verification status for the phone number of an incoming call as identified in
1038 * ATIS-1000082.
Tyler Gunn9c642492020-10-08 13:37:03 -07001039 * <p>
1040 * For incoming calls, the number verification status indicates whether the device was
1041 * able to verify the authenticity of the calling number using the STIR process outlined
1042 * in ATIS-1000082. {@link Connection#VERIFICATION_STATUS_NOT_VERIFIED} indicates that
1043 * the network was not able to use STIR to verify the caller's number (i.e. nothing is
1044 * known regarding the authenticity of the number.
1045 * {@link Connection#VERIFICATION_STATUS_PASSED} indicates that the network was able to
1046 * use STIR to verify the caller's number. This indicates that the network has a high
1047 * degree of confidence that the incoming call actually originated from the indicated
1048 * number. {@link Connection#VERIFICATION_STATUS_FAILED} indicates that the network's
1049 * STIR verification did not pass. This indicates that the incoming call may not
1050 * actually be from the indicated number. This could occur if, for example, the caller
1051 * is using an impersonated phone number.
1052 * <p>
1053 * A {@link CallScreeningService} can use this information to help determine if an
1054 * incoming call is potentially an unwanted call. A verification status of
1055 * {@link Connection#VERIFICATION_STATUS_FAILED} indicates that an incoming call may not
1056 * actually be from the number indicated on the call (i.e. impersonated number) and that it
1057 * should potentially be blocked. Likewise,
1058 * {@link Connection#VERIFICATION_STATUS_PASSED} can be used as a positive signal to
1059 * help clarify that the incoming call is originating from the indicated number and it
1060 * is less likely to be an undesirable call.
1061 * <p>
1062 * An {@link InCallService} can use this information to provide a visual indicator to the
1063 * user regarding the verification status of a call and to help identify calls from
1064 * potentially impersonated numbers.
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001065 * @return the verification status.
1066 */
1067 public @Connection.VerificationStatus int getCallerNumberVerificationStatus() {
1068 return mCallerNumberVerificationStatus;
1069 }
1070
Ihab Awade63fadb2014-07-09 21:52:04 -07001071 @Override
1072 public boolean equals(Object o) {
1073 if (o instanceof Details) {
1074 Details d = (Details) o;
1075 return
1076 Objects.equals(mHandle, d.mHandle) &&
1077 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
1078 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
1079 Objects.equals(mCallerDisplayNamePresentation,
1080 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -07001081 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -07001082 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -07001083 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001084 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -07001085 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -07001086 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -07001087 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -07001088 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001089 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001090 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -08001091 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Hall Liuef98bf82020-01-09 15:22:44 -08001092 Objects.equals(mContactDisplayName, d.mContactDisplayName) &&
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001093 Objects.equals(mCallDirection, d.mCallDirection) &&
1094 Objects.equals(mCallerNumberVerificationStatus,
1095 d.mCallerNumberVerificationStatus);
Ihab Awade63fadb2014-07-09 21:52:04 -07001096 }
1097 return false;
1098 }
1099
1100 @Override
1101 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001102 return Objects.hash(mHandle,
1103 mHandlePresentation,
1104 mCallerDisplayName,
1105 mCallerDisplayNamePresentation,
1106 mAccountHandle,
1107 mCallCapabilities,
1108 mCallProperties,
1109 mDisconnectCause,
1110 mConnectTimeMillis,
1111 mGatewayInfo,
1112 mVideoState,
1113 mStatusHints,
1114 mExtras,
1115 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001116 mCreationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001117 mContactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001118 mCallDirection,
1119 mCallerNumberVerificationStatus);
Ihab Awade63fadb2014-07-09 21:52:04 -07001120 }
1121
1122 /** {@hide} */
1123 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001124 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -07001125 Uri handle,
1126 int handlePresentation,
1127 String callerDisplayName,
1128 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -07001129 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -07001130 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -07001131 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001132 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -07001133 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -07001134 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -07001135 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -07001136 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -07001137 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001138 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001139 long creationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001140 String contactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001141 int callDirection,
1142 int callerNumberVerificationStatus) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001143 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001144 mHandle = handle;
1145 mHandlePresentation = handlePresentation;
1146 mCallerDisplayName = callerDisplayName;
1147 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -07001148 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -07001149 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -07001150 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001151 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -07001152 mConnectTimeMillis = connectTimeMillis;
1153 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -07001154 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -07001155 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -07001156 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001157 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001158 mCreationTimeMillis = creationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -08001159 mContactDisplayName = contactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -08001160 mCallDirection = callDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001161 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
Ihab Awade63fadb2014-07-09 21:52:04 -07001162 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001163
1164 /** {@hide} */
1165 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
1166 return new Details(
1167 parcelableCall.getId(),
1168 parcelableCall.getHandle(),
1169 parcelableCall.getHandlePresentation(),
1170 parcelableCall.getCallerDisplayName(),
1171 parcelableCall.getCallerDisplayNamePresentation(),
1172 parcelableCall.getAccountHandle(),
1173 parcelableCall.getCapabilities(),
1174 parcelableCall.getProperties(),
1175 parcelableCall.getDisconnectCause(),
1176 parcelableCall.getConnectTimeMillis(),
1177 parcelableCall.getGatewayInfo(),
1178 parcelableCall.getVideoState(),
1179 parcelableCall.getStatusHints(),
1180 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001181 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -08001182 parcelableCall.getCreationTimeMillis(),
Hall Liuef98bf82020-01-09 15:22:44 -08001183 parcelableCall.getContactDisplayName(),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001184 parcelableCall.getCallDirection(),
1185 parcelableCall.getCallerNumberVerificationStatus());
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001186 }
Santos Cordon3c20d632016-02-25 16:12:35 -08001187
1188 @Override
1189 public String toString() {
1190 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001191 sb.append("[id: ");
1192 sb.append(mTelecomCallId);
1193 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -08001194 sb.append(mAccountHandle);
1195 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001196 sb.append(Log.piiHandle(mHandle));
1197 sb.append(", hdlPres: ");
1198 sb.append(mHandlePresentation);
1199 sb.append(", videoState: ");
1200 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -08001201 sb.append(", caps: ");
1202 sb.append(capabilitiesToString(mCallCapabilities));
1203 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001204 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001205 sb.append("]");
1206 return sb.toString();
1207 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001208 }
1209
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001210 /**
1211 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1212 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1213 * implementation.
1214 * <p>
1215 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1216 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1217 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1218 * {@link Callback} implementation, if desired.
1219 * <p>
1220 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1221 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1222 * (typically in {@link InCallService#onCallRemoved(Call)}).
1223 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1224 * reach your implementation of {@link Callback}, so it is important to register your callback
1225 * as soon as your {@link InCallService} is notified of a new call via
1226 * {@link InCallService#onCallAdded(Call)}.
1227 */
Andrew Leeda80c872015-04-15 14:09:50 -07001228 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001229 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001230 * @hide
1231 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001232 @IntDef(prefix = { "HANDOVER_" },
1233 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001234 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001235 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001236 @Retention(RetentionPolicy.SOURCE)
1237 public @interface HandoverFailureErrors {}
1238
1239 /**
1240 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001241 * to handover the call to rejects the handover request.
1242 * <p>
1243 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1244 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1245 * {@code null} {@link Connection} from
1246 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1247 * ConnectionRequest)}.
1248 * <p>
1249 * For more information on call handovers, see
1250 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001251 */
1252 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1253
1254 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001255 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1256 * is initiated but the source or destination app does not support handover.
1257 * <p>
1258 * Will be returned when a handover is requested via
1259 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1260 * {@link PhoneAccountHandle} does not declare
1261 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1262 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1263 * {@link Details#getAccountHandle()}) does not declare
1264 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1265 * <p>
1266 * For more information on call handovers, see
1267 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001268 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001269 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001270
1271 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001272 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1273 * user rejects the handover request.
1274 * <p>
1275 * For more information on call handovers, see
1276 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001277 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001278 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001279
Sanket Padawe85291f62017-12-01 13:59:27 -08001280 /**
1281 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1282 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001283 * <p>
1284 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1285 * called on an emergency call, or if any other call is an emergency call.
1286 * <p>
1287 * Handovers are not permitted while there are ongoing emergency calls.
1288 * <p>
1289 * For more information on call handovers, see
1290 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001291 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001292 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001293
Tyler Gunn9d127732018-03-02 15:45:51 -08001294 /**
1295 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1296 * fails for an unknown reason.
1297 * <p>
1298 * For more information on call handovers, see
1299 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1300 */
1301 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001302
1303 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001304 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1305 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001306 * @param call The {@code Call} invoking this method.
1307 * @param state The new state of the {@code Call}.
1308 */
1309 public void onStateChanged(Call call, int state) {}
1310
1311 /**
1312 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1313 *
1314 * @param call The {@code Call} invoking this method.
1315 * @param parent The new parent of the {@code Call}.
1316 */
1317 public void onParentChanged(Call call, Call parent) {}
1318
1319 /**
1320 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1321 *
1322 * @param call The {@code Call} invoking this method.
1323 * @param children The new children of the {@code Call}.
1324 */
1325 public void onChildrenChanged(Call call, List<Call> children) {}
1326
1327 /**
1328 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1329 *
1330 * @param call The {@code Call} invoking this method.
1331 * @param details A {@code Details} object describing the {@code Call}.
1332 */
1333 public void onDetailsChanged(Call call, Details details) {}
1334
1335 /**
1336 * Invoked when the text messages that can be used as responses to the incoming
1337 * {@code Call} are loaded from the relevant database.
1338 * See {@link #getCannedTextResponses()}.
1339 *
1340 * @param call The {@code Call} invoking this method.
1341 * @param cannedTextResponses The text messages useable as responses.
1342 */
1343 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1344
1345 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001346 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1347 * character. This causes the post-dial signals to stop pending user confirmation. An
1348 * implementation should present this choice to the user and invoke
1349 * {@link #postDialContinue(boolean)} when the user makes the choice.
1350 *
1351 * @param call The {@code Call} invoking this method.
1352 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1353 */
1354 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1355
1356 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001357 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001358 *
1359 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001360 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001361 */
Andrew Lee50aca232014-07-22 16:41:54 -07001362 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001363
1364 /**
1365 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1366 * up their UI for the {@code Call} in response to state transitions. Specifically,
1367 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1368 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1369 * clients should wait for this method to be invoked.
1370 *
1371 * @param call The {@code Call} being destroyed.
1372 */
1373 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001374
1375 /**
1376 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1377 * conferenced.
1378 *
1379 * @param call The {@code Call} being updated.
1380 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1381 * conferenced.
1382 */
1383 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001384
1385 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001386 * Invoked when a {@link Call} receives an event from its associated {@link Connection} or
1387 * {@link Conference}.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001388 * <p>
1389 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1390 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1391 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1392 * possible that a {@link ConnectionService} has defined its own Connection events which a
1393 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001394 * <p>
Tyler Gunn5567d742019-10-31 13:04:37 -07001395 * See {@link Connection#sendConnectionEvent(String, Bundle)},
1396 * {@link Conference#sendConferenceEvent(String, Bundle)}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001397 *
1398 * @param call The {@code Call} receiving the event.
1399 * @param event The event.
1400 * @param extras Extras associated with the connection event.
1401 */
1402 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001403
1404 /**
1405 * Invoked when the RTT mode changes for this call.
1406 * @param call The call whose RTT mode has changed.
1407 * @param mode the new RTT mode, one of
1408 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1409 * or {@link RttCall#RTT_MODE_VCO}
1410 */
1411 public void onRttModeChanged(Call call, int mode) {}
1412
1413 /**
1414 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1415 * @param call The call whose RTT status has changed.
1416 * @param enabled whether RTT is now enabled or disabled
1417 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1418 * on, null otherwise.
1419 */
1420 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1421
1422 /**
1423 * Invoked when the remote end of the connection has requested that an RTT communication
1424 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1425 * with the same ID that this method is invoked with.
1426 * @param call The call which the RTT request was placed on
1427 * @param id The ID of the request.
1428 */
1429 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001430
1431 /**
1432 * Invoked when the RTT session failed to initiate for some reason, including rejection
1433 * by the remote party.
1434 * @param call The call which the RTT initiation failure occurred on.
1435 * @param reason One of the status codes defined in
1436 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1437 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1438 */
1439 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001440
1441 /**
1442 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1443 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001444 * <p>
1445 * For a full discussion of the handover process and the APIs involved, see
1446 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1447 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001448 * @param call The call which had initiated handover.
1449 */
1450 public void onHandoverComplete(Call call) {}
1451
1452 /**
1453 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1454 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001455 * <p>
1456 * For a full discussion of the handover process and the APIs involved, see
1457 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1458 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001459 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001460 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001461 */
1462 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001463 }
1464
1465 /**
1466 * A class that holds the state that describes the state of the RTT channel to the remote
1467 * party, if it is active.
1468 */
1469 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001470 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001471 @Retention(RetentionPolicy.SOURCE)
1472 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1473 public @interface RttAudioMode {}
1474
1475 /**
1476 * For metrics use. Default value in the proto.
1477 * @hide
1478 */
1479 public static final int RTT_MODE_INVALID = 0;
1480
1481 /**
1482 * Indicates that there should be a bidirectional audio stream between the two parties
1483 * on the call.
1484 */
1485 public static final int RTT_MODE_FULL = 1;
1486
1487 /**
1488 * Indicates that the local user should be able to hear the audio stream from the remote
1489 * user, but not vice versa. Equivalent to muting the microphone.
1490 */
1491 public static final int RTT_MODE_HCO = 2;
1492
1493 /**
1494 * Indicates that the remote user should be able to hear the audio stream from the local
1495 * user, but not vice versa. Equivalent to setting the volume to zero.
1496 */
1497 public static final int RTT_MODE_VCO = 3;
1498
1499 private static final int READ_BUFFER_SIZE = 1000;
1500
1501 private InputStreamReader mReceiveStream;
1502 private OutputStreamWriter mTransmitStream;
1503 private int mRttMode;
1504 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001505 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001506 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1507
1508 /**
1509 * @hide
1510 */
Hall Liu57006aa2017-02-06 10:49:48 -08001511 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1512 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1513 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001514 mReceiveStream = receiveStream;
1515 mTransmitStream = transmitStream;
1516 mRttMode = mode;
1517 mInCallAdapter = inCallAdapter;
1518 }
1519
1520 /**
1521 * Returns the current RTT audio mode.
1522 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1523 * {@link #RTT_MODE_HCO}.
1524 */
1525 public int getRttAudioMode() {
1526 return mRttMode;
1527 }
1528
1529 /**
1530 * Sets the RTT audio mode. The requested mode change will be communicated through
1531 * {@link Callback#onRttModeChanged(Call, int)}.
1532 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1533 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1534 */
1535 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001536 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001537 }
1538
1539 /**
1540 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
Hall Liudc46c852020-10-29 16:15:33 -07001541 * RTT transmits text in real-time, this method should be called once for each user action.
1542 * For example, when the user enters text as discrete characters using the keyboard, this
1543 * method should be called once for each character. However, if the user enters text by
1544 * pasting or autocomplete, the entire contents of the pasted or autocompleted text should
1545 * be sent in one call to this method.
Hall Liu95d55872017-01-25 17:12:49 -08001546 *
1547 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1548 * lead to interleaved text.
1549 * @param input The message to send to the remote user.
1550 */
1551 public void write(String input) throws IOException {
1552 mTransmitStream.write(input);
1553 mTransmitStream.flush();
1554 }
1555
1556 /**
1557 * Reads a string from the remote user, blocking if there is no data available. Returns
1558 * {@code null} if the RTT conversation has been terminated and there is no further data
1559 * to read.
1560 *
1561 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1562 * lead to interleaved text.
1563 * @return A string containing text sent by the remote user, or {@code null} if the
1564 * conversation has been terminated or if there was an error while reading.
1565 */
Hall Liub1c8a772017-07-17 17:04:41 -07001566 public String read() {
1567 try {
1568 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1569 if (numRead < 0) {
1570 return null;
1571 }
1572 return new String(mReadBuffer, 0, numRead);
1573 } catch (IOException e) {
1574 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001575 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001576 }
Hall Liuffa4a812017-03-02 16:11:00 -08001577 }
1578
1579 /**
1580 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1581 * be read.
1582 * @return A string containing text entered by the user, or {@code null} if the user has
1583 * not entered any new text yet.
1584 */
1585 public String readImmediately() throws IOException {
1586 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001587 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1588 if (numRead < 0) {
1589 return null;
1590 }
1591 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001592 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001593 return null;
1594 }
1595 }
Hall Liue9041242018-02-09 16:40:03 -08001596
1597 /**
1598 * Closes the underlying file descriptors
1599 * @hide
1600 */
1601 public void close() {
1602 try {
1603 mReceiveStream.close();
1604 } catch (IOException e) {
1605 // ignore
1606 }
1607 try {
1608 mTransmitStream.close();
1609 } catch (IOException e) {
1610 // ignore
1611 }
1612 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001613 }
1614
Andrew Leeda80c872015-04-15 14:09:50 -07001615 /**
1616 * @deprecated Use {@code Call.Callback} instead.
1617 * @hide
1618 */
1619 @Deprecated
1620 @SystemApi
1621 public static abstract class Listener extends Callback { }
1622
Ihab Awade63fadb2014-07-09 21:52:04 -07001623 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001624 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001625 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001626 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001627 private final List<Call> mChildren = new ArrayList<>();
1628 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001629 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001630 private final List<Call> mConferenceableCalls = new ArrayList<>();
1631 private final List<Call> mUnmodifiableConferenceableCalls =
1632 Collections.unmodifiableList(mConferenceableCalls);
1633
Santos Cordon823fd3c2014-08-07 18:35:18 -07001634 private boolean mChildrenCached;
1635 private String mParentId = null;
Hall Liuef98bf82020-01-09 15:22:44 -08001636 private String mActiveGenericConferenceChild = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001637 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001638 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001639 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001640 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001641 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001642 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001643 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001644 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001645 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001646
1647 /**
1648 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1649 *
1650 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1651 * remaining or this {@code Call} is not in a post-dial state.
1652 */
1653 public String getRemainingPostDialSequence() {
1654 return mRemainingPostDialSequence;
1655 }
1656
1657 /**
1658 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001659 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001660 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001661 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001662 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001663 }
1664
1665 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301666 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1667 *
1668 * @param address The address to which the call will be deflected.
1669 */
1670 public void deflect(Uri address) {
1671 mInCallAdapter.deflectCall(mTelecomCallId, address);
1672 }
1673
1674 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001675 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1676 *
1677 * @param rejectWithMessage Whether to reject with a text message.
1678 * @param textMessage An optional text message with which to respond.
1679 */
1680 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001681 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001682 }
1683
1684 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001685 * Instructs the {@link ConnectionService} providing this {@link #STATE_RINGING} call that the
1686 * user has chosen to reject the call and has indicated a reason why the call is being rejected.
1687 *
1688 * @param rejectReason the reason the call is being rejected.
1689 */
1690 public void reject(@RejectReason int rejectReason) {
1691 mInCallAdapter.rejectCall(mTelecomCallId, rejectReason);
1692 }
1693
1694 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05301695 * Instructs this {@code Call} to be transferred to another number.
1696 *
1697 * @param targetNumber The address to which the call will be transferred.
Tyler Gunn460360d2020-07-29 10:21:45 -07001698 * @param isConfirmationRequired if {@code true} it will initiate a confirmed transfer,
1699 * if {@code false}, it will initiate an unconfirmed transfer.
Ravi Palurif4b38e72020-02-05 12:35:41 +05301700 *
1701 * @hide
1702 */
1703 public void transfer(@NonNull Uri targetNumber, boolean isConfirmationRequired) {
1704 mInCallAdapter.transferCall(mTelecomCallId, targetNumber, isConfirmationRequired);
1705 }
1706
1707 /**
1708 * Instructs this {@code Call} to be transferred to another ongoing call.
1709 * This will initiate CONSULTATIVE transfer.
1710 * @param toCall The other ongoing {@code Call} to which this call will be transferred.
1711 *
1712 * @hide
1713 */
1714 public void transfer(@NonNull android.telecom.Call toCall) {
1715 mInCallAdapter.transferCall(mTelecomCallId, toCall.mTelecomCallId);
1716 }
1717
1718 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001719 * Instructs this {@code Call} to disconnect.
1720 */
1721 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001722 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001723 }
1724
1725 /**
1726 * Instructs this {@code Call} to go on hold.
1727 */
1728 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001729 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001730 }
1731
1732 /**
1733 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1734 */
1735 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001736 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001737 }
1738
1739 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001740 * Instructs Telecom to put the call into the background audio processing state.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001741 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001742 * This method can be called either when the call is in {@link #STATE_RINGING} or
1743 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1744 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1745 * order to capture and play audio on the call stream.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001746 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001747 * This method can only be called by the default dialer app.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001748 * <p>
1749 * Apps built with SDK version {@link android.os.Build.VERSION_CODES#R} or later which are using
1750 * the microphone as part of audio processing should specify the foreground service type using
1751 * the attribute {@link android.R.attr#foregroundServiceType} in the {@link InCallService}
1752 * service element of the app's manifest file.
1753 * The {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_MICROPHONE} attribute should be specified.
1754 * @see <a href="https://developer.android.com/preview/privacy/foreground-service-types">
1755 * the Android Developer Site</a> for more information.
Hall Liu6dfa2492019-10-01 17:20:39 -07001756 * @hide
1757 */
1758 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001759 public void enterBackgroundAudioProcessing() {
1760 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1761 throw new IllegalStateException("Call must be active or ringing");
1762 }
1763 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1764 }
1765
1766 /**
1767 * Instructs Telecom to come out of the background audio processing state requested by
1768 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1769 *
1770 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1771 *
1772 * @param shouldRing If true, Telecom will put the call into the
1773 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1774 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1775 * immediately.
1776 * @hide
1777 */
1778 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001779 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1780 if (mState != STATE_AUDIO_PROCESSING) {
1781 throw new IllegalStateException("Call must in the audio processing state");
1782 }
1783 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1784 }
1785
1786 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001787 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1788 *
1789 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1790 *
1791 * @param digit A character representing the DTMF digit for which to play the tone. This
1792 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1793 */
1794 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001795 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001796 }
1797
1798 /**
1799 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1800 * currently playing.
1801 *
1802 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1803 * currently playing, this method will do nothing.
1804 */
1805 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001806 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001807 }
1808
1809 /**
1810 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1811 *
1812 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1813 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001814 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001815 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001816 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1817 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001818 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001819 * {@code Call} will pause playing the tones and notify callbacks via
1820 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001821 * should display to the user an indication of this state and an affordance to continue
1822 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1823 * app should invoke the {@link #postDialContinue(boolean)} method.
1824 *
1825 * @param proceed Whether or not to continue with the post-dial sequence.
1826 */
1827 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001828 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001829 }
1830
1831 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001832 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001833 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001834 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001835 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1836 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001837
1838 }
1839
1840 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001841 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001842 *
1843 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001844 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001845 public void conference(Call callToConferenceWith) {
1846 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001847 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001848 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001849 }
1850
1851 /**
1852 * Instructs this {@code Call} to split from any conference call with which it may be
1853 * connected.
1854 */
1855 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001856 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001857 }
1858
1859 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001860 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001861 */
1862 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001863 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001864 }
1865
1866 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001867 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001868 */
1869 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001870 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001871 }
1872
1873 /**
Ravi Paluri404babb2020-01-23 19:02:44 +05301874 * Pulls participants to existing call by forming a conference call.
1875 * See {@link Details#CAPABILITY_ADD_PARTICIPANT}.
1876 *
1877 * @param participants participants to be pulled to existing call.
1878 */
1879 public void addConferenceParticipants(@NonNull List<Uri> participants) {
1880 mInCallAdapter.addConferenceParticipants(mTelecomCallId, participants);
1881 }
1882
1883 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001884 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1885 * device.
1886 * <p>
1887 * Calls to this method are ignored if the call does not have the
1888 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1889 * <p>
1890 * An {@link InCallService} will only see calls which support this method if it has the
1891 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1892 * in its manifest.
1893 */
1894 public void pullExternalCall() {
1895 // If this isn't an external call, ignore the request.
1896 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1897 return;
1898 }
1899
1900 mInCallAdapter.pullExternalCall(mTelecomCallId);
1901 }
1902
1903 /**
1904 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1905 * the {@link ConnectionService}.
1906 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001907 * Call events are used to communicate point in time information from an {@link InCallService}
1908 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1909 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1910 * {@link ConnectionService}.
1911 * <p>
1912 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1913 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1914 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001915 * Events are exposed to {@link ConnectionService} implementations via
1916 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1917 * <p>
1918 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001919 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1920 * ignore some events altogether.
1921 * <p>
1922 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1923 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1924 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1925 * they define their own event types in this namespace. When defining a custom event type,
1926 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1927 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1928 * <p>
1929 * When defining events and the associated extras, it is important to keep their behavior
1930 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1931 * events/extras should me maintained to ensure backwards compatibility with older
1932 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001933 *
1934 * @param event The connection event.
1935 * @param extras Bundle containing extra information associated with the event.
1936 */
1937 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001938 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001939 }
1940
1941 /**
Hall Liu95d55872017-01-25 17:12:49 -08001942 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1943 * guaranteed, and notification of success will be via the
1944 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1945 */
1946 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001947 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001948 }
1949
1950 /**
1951 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1952 * callback.
1953 * The ID used here should be the same as the ID that was received via the callback.
1954 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1955 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1956 */
1957 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001958 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001959 }
1960
1961 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001962 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1963 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1964 * handover.
1965 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001966 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1967 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1968 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1969 * is referred to as the source of the handover, and the video calling app is referred to as the
1970 * destination.
1971 * <p>
1972 * When considering a handover scenario the device this method is called on is considered the
1973 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1974 * other device is considered the <em>receiving</em> device.
1975 * <p>
1976 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1977 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1978 * and invoke
1979 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1980 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1981 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1982 * At this point the app should display UI to indicate to the user that a call
1983 * handover is in process.
1984 * <p>
1985 * The destination app is responsible for communicating the handover request from the
1986 * <em>initiating</em> device to the <em>receiving</em> device.
1987 * <p>
1988 * When the app on the <em>receiving</em> device receives the handover request, it calls
1989 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1990 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1991 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1992 * choose whether they want to continue their call in the destination app.
1993 * <p>
1994 * When the destination app on the <em>receiving</em> device calls
1995 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1996 * {@link ConnectionService} and call
1997 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1998 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1999 * {@link Connection} to represent the handover call.
2000 * <p>
2001 * If the user of the <em>receiving</em> device accepts the handover, the app calls
2002 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
2003 * original call. If the user rejects the handover, the app calls
2004 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
2005 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
2006 * <p>
2007 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
2008 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
2009 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
2010 * <p>
2011 * Errors in the handover process are reported to the {@link InCallService} via
2012 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
2013 * the involved {@link ConnectionService}s via
2014 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002015 *
2016 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
2017 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08002018 * @param videoState Indicates the video state desired after the handover (see the
2019 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07002020 * @param extras Bundle containing extra information to be passed to the
2021 * {@link ConnectionService}
2022 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002023 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
2024 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002025 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
2026 }
2027
2028 /**
Hall Liu95d55872017-01-25 17:12:49 -08002029 * Terminate the RTT session on this call. The resulting state change will be notified via
2030 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
2031 */
2032 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08002033 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08002034 }
2035
2036 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002037 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
2038 * added.
2039 * <p>
2040 * No assumptions should be made as to how an In-Call UI or service will handle these
2041 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2042 *
2043 * @param extras The extras to add.
2044 */
2045 public final void putExtras(Bundle extras) {
2046 if (extras == null) {
2047 return;
2048 }
2049
2050 if (mExtras == null) {
2051 mExtras = new Bundle();
2052 }
2053 mExtras.putAll(extras);
2054 mInCallAdapter.putExtras(mTelecomCallId, extras);
2055 }
2056
2057 /**
2058 * Adds a boolean extra to this {@link Call}.
2059 *
2060 * @param key The extra key.
2061 * @param value The value.
2062 * @hide
2063 */
2064 public final void putExtra(String key, boolean value) {
2065 if (mExtras == null) {
2066 mExtras = new Bundle();
2067 }
2068 mExtras.putBoolean(key, value);
2069 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2070 }
2071
2072 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002073 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002074 *
2075 * @param key The extra key.
2076 * @param value The value.
2077 * @hide
2078 */
2079 public final void putExtra(String key, int value) {
2080 if (mExtras == null) {
2081 mExtras = new Bundle();
2082 }
2083 mExtras.putInt(key, value);
2084 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2085 }
2086
2087 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002088 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002089 *
2090 * @param key The extra key.
2091 * @param value The value.
2092 * @hide
2093 */
2094 public final void putExtra(String key, String value) {
2095 if (mExtras == null) {
2096 mExtras = new Bundle();
2097 }
2098 mExtras.putString(key, value);
2099 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2100 }
2101
2102 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002103 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002104 *
2105 * @param keys The keys of the extras to remove.
2106 */
2107 public final void removeExtras(List<String> keys) {
2108 if (mExtras != null) {
2109 for (String key : keys) {
2110 mExtras.remove(key);
2111 }
2112 if (mExtras.size() == 0) {
2113 mExtras = null;
2114 }
2115 }
2116 mInCallAdapter.removeExtras(mTelecomCallId, keys);
2117 }
2118
2119 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002120 * Removes extras from this {@link Call}.
2121 *
2122 * @param keys The keys of the extras to remove.
2123 */
2124 public final void removeExtras(String ... keys) {
2125 removeExtras(Arrays.asList(keys));
2126 }
2127
2128 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002129 * Obtains the parent of this {@code Call} in a conference, if any.
2130 *
2131 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
2132 * child of any conference {@code Call}s.
2133 */
2134 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002135 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002136 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002137 }
2138 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07002139 }
2140
2141 /**
2142 * Obtains the children of this conference {@code Call}, if any.
2143 *
2144 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
2145 * {@code List} otherwise.
2146 */
2147 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002148 if (!mChildrenCached) {
2149 mChildrenCached = true;
2150 mChildren.clear();
2151
2152 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002153 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002154 if (call == null) {
2155 // At least one child was still not found, so do not save true for "cached"
2156 mChildrenCached = false;
2157 } else {
2158 mChildren.add(call);
2159 }
2160 }
2161 }
2162
Ihab Awade63fadb2014-07-09 21:52:04 -07002163 return mUnmodifiableChildren;
2164 }
2165
2166 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002167 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
2168 *
2169 * @return The list of conferenceable {@code Call}s.
2170 */
2171 public List<Call> getConferenceableCalls() {
2172 return mUnmodifiableConferenceableCalls;
2173 }
2174
2175 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002176 * Obtains the state of this {@code Call}.
2177 *
2178 * @return A state value, chosen from the {@code STATE_*} constants.
2179 */
2180 public int getState() {
2181 return mState;
2182 }
2183
2184 /**
Hall Liuef98bf82020-01-09 15:22:44 -08002185 * Returns the child {@link Call} in a generic conference that is currently active.
Hall Liu135e53aa2020-02-27 18:34:11 -08002186 *
2187 * A "generic conference" is the mechanism used to support two simultaneous calls on a device
2188 * in CDMA networks. It is effectively equivalent to having one call active and one call on hold
2189 * in GSM or IMS calls. This method returns the currently active call.
2190 *
2191 * In a generic conference, the network exposes the conference to us as a single call, and we
2192 * switch between talking to the two participants using a CDMA flash command. Since the network
2193 * exposes no additional information about the call, the only way we know which caller we're
2194 * currently talking to is by keeping track of the flash commands that we've sent to the
2195 * network.
2196 *
Hall Liuef98bf82020-01-09 15:22:44 -08002197 * For calls that are not generic conferences, or when the generic conference has more than
2198 * 2 children, returns {@code null}.
2199 * @see Details#PROPERTY_GENERIC_CONFERENCE
2200 * @return The active child call.
2201 */
2202 public @Nullable Call getGenericConferenceActiveChildCall() {
2203 if (mActiveGenericConferenceChild != null) {
2204 return mPhone.internalGetCallByTelecomId(mActiveGenericConferenceChild);
2205 }
2206 return null;
2207 }
2208
2209 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002210 * Obtains a list of canned, pre-configured message responses to present to the user as
Tyler Gunn434fc2c2020-10-06 14:23:54 -07002211 * ways of rejecting an incoming {@code Call} using via a text message.
2212 * <p>
2213 * <em>Note:</em> Since canned responses may be loaded from the file system, they are not
2214 * guaranteed to be present when this {@link Call} is first added to the {@link InCallService}
2215 * via {@link InCallService#onCallAdded(Call)}. The callback
2216 * {@link Call.Callback#onCannedTextResponsesLoaded(Call, List)} will be called when/if canned
2217 * responses for the call become available.
Ihab Awade63fadb2014-07-09 21:52:04 -07002218 *
2219 * @see #reject(boolean, String)
2220 *
2221 * @return A list of canned text message responses.
2222 */
2223 public List<String> getCannedTextResponses() {
2224 return mCannedTextResponses;
2225 }
2226
2227 /**
2228 * Obtains an object that can be used to display video from this {@code Call}.
2229 *
Andrew Lee50aca232014-07-22 16:41:54 -07002230 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002231 */
Andrew Lee50aca232014-07-22 16:41:54 -07002232 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002233 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07002234 }
2235
2236 /**
2237 * Obtains an object containing call details.
2238 *
2239 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
2240 * result may be {@code null}.
2241 */
2242 public Details getDetails() {
2243 return mDetails;
2244 }
2245
2246 /**
Hall Liu95d55872017-01-25 17:12:49 -08002247 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
2248 * receive RTT text data, as well as to change the RTT mode.
2249 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
2250 */
2251 public @Nullable RttCall getRttCall() {
2252 return mRttCall;
2253 }
2254
2255 /**
2256 * Returns whether this call has an active RTT connection.
2257 * @return true if there is a connection, false otherwise.
2258 */
2259 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08002260 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08002261 }
2262
2263 /**
Andrew Leeda80c872015-04-15 14:09:50 -07002264 * Registers a callback to this {@code Call}.
2265 *
2266 * @param callback A {@code Callback}.
2267 */
2268 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07002269 registerCallback(callback, new Handler());
2270 }
2271
2272 /**
2273 * Registers a callback to this {@code Call}.
2274 *
2275 * @param callback A {@code Callback}.
2276 * @param handler A handler which command and status changes will be delivered to.
2277 */
2278 public void registerCallback(Callback callback, Handler handler) {
2279 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07002280 // Don't allow new callback registration if the call is already being destroyed.
2281 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002282 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
2283 }
Andrew Leeda80c872015-04-15 14:09:50 -07002284 }
2285
2286 /**
2287 * Unregisters a callback from this {@code Call}.
2288 *
2289 * @param callback A {@code Callback}.
2290 */
2291 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002292 // Don't allow callback deregistration if the call is already being destroyed.
2293 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002294 for (CallbackRecord<Callback> record : mCallbackRecords) {
2295 if (record.getCallback() == callback) {
2296 mCallbackRecords.remove(record);
2297 break;
2298 }
2299 }
Andrew Leeda80c872015-04-15 14:09:50 -07002300 }
2301 }
2302
Santos Cordon3c20d632016-02-25 16:12:35 -08002303 @Override
2304 public String toString() {
2305 return new StringBuilder().
2306 append("Call [id: ").
2307 append(mTelecomCallId).
2308 append(", state: ").
2309 append(stateToString(mState)).
2310 append(", details: ").
2311 append(mDetails).
2312 append("]").toString();
2313 }
2314
2315 /**
2316 * @param state An integer value of a {@code STATE_*} constant.
2317 * @return A string representation of the value.
2318 */
2319 private static String stateToString(int state) {
2320 switch (state) {
2321 case STATE_NEW:
2322 return "NEW";
2323 case STATE_RINGING:
2324 return "RINGING";
2325 case STATE_DIALING:
2326 return "DIALING";
2327 case STATE_ACTIVE:
2328 return "ACTIVE";
2329 case STATE_HOLDING:
2330 return "HOLDING";
2331 case STATE_DISCONNECTED:
2332 return "DISCONNECTED";
2333 case STATE_CONNECTING:
2334 return "CONNECTING";
2335 case STATE_DISCONNECTING:
2336 return "DISCONNECTING";
2337 case STATE_SELECT_PHONE_ACCOUNT:
2338 return "SELECT_PHONE_ACCOUNT";
Hall Liu4e35b642019-10-14 17:50:45 -07002339 case STATE_SIMULATED_RINGING:
2340 return "SIMULATED_RINGING";
2341 case STATE_AUDIO_PROCESSING:
2342 return "AUDIO_PROCESSING";
Santos Cordon3c20d632016-02-25 16:12:35 -08002343 default:
2344 Log.w(Call.class, "Unknown state %d", state);
2345 return "UNKNOWN";
2346 }
2347 }
2348
Andrew Leeda80c872015-04-15 14:09:50 -07002349 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002350 * Adds a listener to this {@code Call}.
2351 *
2352 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002353 * @deprecated Use {@link #registerCallback} instead.
2354 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002355 */
Andrew Leeda80c872015-04-15 14:09:50 -07002356 @Deprecated
2357 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002358 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002359 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002360 }
2361
2362 /**
2363 * Removes a listener from this {@code Call}.
2364 *
2365 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002366 * @deprecated Use {@link #unregisterCallback} instead.
2367 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002368 */
Andrew Leeda80c872015-04-15 14:09:50 -07002369 @Deprecated
2370 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002371 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002372 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002373 }
2374
2375 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002376 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2377 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002378 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002379 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002380 mInCallAdapter = inCallAdapter;
2381 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002382 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002383 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002384 }
2385
2386 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002387 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002388 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002389 mPhone = phone;
2390 mTelecomCallId = telecomCallId;
2391 mInCallAdapter = inCallAdapter;
2392 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002393 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002394 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002395 }
2396
2397 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002398 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002399 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002400 }
2401
2402 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002403 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002404
Ihab Awade63fadb2014-07-09 21:52:04 -07002405 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002406 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002407 boolean detailsChanged = !Objects.equals(mDetails, details);
2408 if (detailsChanged) {
2409 mDetails = details;
2410 }
2411
2412 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002413 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2414 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2415 mCannedTextResponses =
2416 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002417 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002418 }
2419
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002420 IVideoProvider previousVideoProvider = mVideoCallImpl == null ? null :
2421 mVideoCallImpl.getVideoProvider();
2422 IVideoProvider newVideoProvider = parcelableCall.getVideoProvider();
2423
2424 // parcelableCall.isVideoCallProviderChanged is only true when we have a video provider
2425 // specified; so we should check if the actual IVideoProvider changes as well.
2426 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged()
2427 && !Objects.equals(previousVideoProvider, newVideoProvider);
Andrew Lee50aca232014-07-22 16:41:54 -07002428 if (videoCallChanged) {
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002429 if (mVideoCallImpl != null) {
2430 mVideoCallImpl.destroy();
2431 }
2432 mVideoCallImpl = parcelableCall.isVideoCallProviderChanged() ?
2433 parcelableCall.getVideoCallImpl(mCallingPackage, mTargetSdkVersion) : null;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002434 }
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002435
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002436 if (mVideoCallImpl != null) {
2437 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002438 }
2439
Santos Cordone3c507b2015-04-23 14:44:19 -07002440 int state = parcelableCall.getState();
Hall Liu31de23d2019-10-11 15:38:29 -07002441 if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2442 state = Call.STATE_RINGING;
2443 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002444 boolean stateChanged = mState != state;
2445 if (stateChanged) {
2446 mState = state;
2447 }
2448
Santos Cordon823fd3c2014-08-07 18:35:18 -07002449 String parentId = parcelableCall.getParentCallId();
2450 boolean parentChanged = !Objects.equals(mParentId, parentId);
2451 if (parentChanged) {
2452 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002453 }
2454
Santos Cordon823fd3c2014-08-07 18:35:18 -07002455 List<String> childCallIds = parcelableCall.getChildCallIds();
2456 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2457 if (childrenChanged) {
2458 mChildrenIds.clear();
2459 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2460 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002461 }
2462
Hall Liuef98bf82020-01-09 15:22:44 -08002463 String activeChildCallId = parcelableCall.getActiveChildCallId();
2464 boolean activeChildChanged = !Objects.equals(activeChildCallId,
2465 mActiveGenericConferenceChild);
2466 if (activeChildChanged) {
2467 mActiveGenericConferenceChild = activeChildCallId;
2468 }
2469
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002470 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2471 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2472 for (String otherId : conferenceableCallIds) {
2473 if (callIdMap.containsKey(otherId)) {
2474 conferenceableCalls.add(callIdMap.get(otherId));
2475 }
2476 }
2477
2478 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2479 mConferenceableCalls.clear();
2480 mConferenceableCalls.addAll(conferenceableCalls);
2481 fireConferenceableCallsChanged();
2482 }
2483
Hall Liu95d55872017-01-25 17:12:49 -08002484 boolean isRttChanged = false;
2485 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002486 if (parcelableCall.getIsRttCallChanged()
2487 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002488 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2489 InputStreamReader receiveStream = new InputStreamReader(
2490 new ParcelFileDescriptor.AutoCloseInputStream(
2491 parcelableRttCall.getReceiveStream()),
2492 StandardCharsets.UTF_8);
2493 OutputStreamWriter transmitStream = new OutputStreamWriter(
2494 new ParcelFileDescriptor.AutoCloseOutputStream(
2495 parcelableRttCall.getTransmitStream()),
2496 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002497 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002498 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2499 if (mRttCall == null) {
2500 isRttChanged = true;
2501 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2502 rttModeChanged = true;
2503 }
2504 mRttCall = newRttCall;
2505 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2506 && parcelableCall.getIsRttCallChanged()) {
2507 isRttChanged = true;
2508 mRttCall = null;
2509 }
2510
Ihab Awade63fadb2014-07-09 21:52:04 -07002511 // Now we fire updates, ensuring that any client who listens to any of these notifications
2512 // gets the most up-to-date state.
2513
2514 if (stateChanged) {
2515 fireStateChanged(mState);
2516 }
2517 if (detailsChanged) {
2518 fireDetailsChanged(mDetails);
2519 }
2520 if (cannedTextResponsesChanged) {
2521 fireCannedTextResponsesLoaded(mCannedTextResponses);
2522 }
Andrew Lee50aca232014-07-22 16:41:54 -07002523 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002524 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002525 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002526 if (parentChanged) {
2527 fireParentChanged(getParent());
2528 }
Hall Liuef98bf82020-01-09 15:22:44 -08002529 if (childrenChanged || activeChildChanged) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002530 fireChildrenChanged(getChildren());
2531 }
Hall Liu95d55872017-01-25 17:12:49 -08002532 if (isRttChanged) {
2533 fireOnIsRttChanged(mRttCall != null, mRttCall);
2534 }
2535 if (rttModeChanged) {
2536 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2537 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002538
2539 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2540 // remove ourselves from the Phone. Note that we do this after completing all state updates
2541 // so a client can cleanly transition all their UI to the state appropriate for a
2542 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2543 if (mState == STATE_DISCONNECTED) {
2544 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002545 }
2546 }
2547
2548 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002549 final void internalSetPostDialWait(String remaining) {
2550 mRemainingPostDialSequence = remaining;
2551 firePostDialWait(mRemainingPostDialSequence);
2552 }
2553
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002554 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002555 final void internalSetDisconnected() {
2556 if (mState != Call.STATE_DISCONNECTED) {
2557 mState = Call.STATE_DISCONNECTED;
2558 fireStateChanged(mState);
2559 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002560 }
2561 }
2562
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002563 /** {@hide} */
2564 final void internalOnConnectionEvent(String event, Bundle extras) {
2565 fireOnConnectionEvent(event, extras);
2566 }
2567
Hall Liu95d55872017-01-25 17:12:49 -08002568 /** {@hide} */
2569 final void internalOnRttUpgradeRequest(final int requestId) {
2570 for (CallbackRecord<Callback> record : mCallbackRecords) {
2571 final Call call = this;
2572 final Callback callback = record.getCallback();
2573 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2574 }
2575 }
2576
Hall Liu57006aa2017-02-06 10:49:48 -08002577 /** @hide */
2578 final void internalOnRttInitiationFailure(int reason) {
2579 for (CallbackRecord<Callback> record : mCallbackRecords) {
2580 final Call call = this;
2581 final Callback callback = record.getCallback();
2582 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2583 }
2584 }
2585
Sanket Padawe85291f62017-12-01 13:59:27 -08002586 /** {@hide} */
2587 final void internalOnHandoverFailed(int error) {
2588 for (CallbackRecord<Callback> record : mCallbackRecords) {
2589 final Call call = this;
2590 final Callback callback = record.getCallback();
2591 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2592 }
2593 }
2594
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002595 /** {@hide} */
2596 final void internalOnHandoverComplete() {
2597 for (CallbackRecord<Callback> record : mCallbackRecords) {
2598 final Call call = this;
2599 final Callback callback = record.getCallback();
2600 record.getHandler().post(() -> callback.onHandoverComplete(call));
2601 }
2602 }
2603
Andrew Lee011728f2015-04-23 15:47:06 -07002604 private void fireStateChanged(final int newState) {
2605 for (CallbackRecord<Callback> record : mCallbackRecords) {
2606 final Call call = this;
2607 final Callback callback = record.getCallback();
2608 record.getHandler().post(new Runnable() {
2609 @Override
2610 public void run() {
2611 callback.onStateChanged(call, newState);
2612 }
2613 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002614 }
2615 }
2616
Andrew Lee011728f2015-04-23 15:47:06 -07002617 private void fireParentChanged(final Call newParent) {
2618 for (CallbackRecord<Callback> record : mCallbackRecords) {
2619 final Call call = this;
2620 final Callback callback = record.getCallback();
2621 record.getHandler().post(new Runnable() {
2622 @Override
2623 public void run() {
2624 callback.onParentChanged(call, newParent);
2625 }
2626 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002627 }
2628 }
2629
Andrew Lee011728f2015-04-23 15:47:06 -07002630 private void fireChildrenChanged(final List<Call> children) {
2631 for (CallbackRecord<Callback> record : mCallbackRecords) {
2632 final Call call = this;
2633 final Callback callback = record.getCallback();
2634 record.getHandler().post(new Runnable() {
2635 @Override
2636 public void run() {
2637 callback.onChildrenChanged(call, children);
2638 }
2639 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002640 }
2641 }
2642
Andrew Lee011728f2015-04-23 15:47:06 -07002643 private void fireDetailsChanged(final Details details) {
2644 for (CallbackRecord<Callback> record : mCallbackRecords) {
2645 final Call call = this;
2646 final Callback callback = record.getCallback();
2647 record.getHandler().post(new Runnable() {
2648 @Override
2649 public void run() {
2650 callback.onDetailsChanged(call, details);
2651 }
2652 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002653 }
2654 }
2655
Andrew Lee011728f2015-04-23 15:47:06 -07002656 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2657 for (CallbackRecord<Callback> record : mCallbackRecords) {
2658 final Call call = this;
2659 final Callback callback = record.getCallback();
2660 record.getHandler().post(new Runnable() {
2661 @Override
2662 public void run() {
2663 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2664 }
2665 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002666 }
2667 }
2668
Andrew Lee011728f2015-04-23 15:47:06 -07002669 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2670 for (CallbackRecord<Callback> record : mCallbackRecords) {
2671 final Call call = this;
2672 final Callback callback = record.getCallback();
2673 record.getHandler().post(new Runnable() {
2674 @Override
2675 public void run() {
2676 callback.onVideoCallChanged(call, videoCall);
2677 }
2678 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002679 }
2680 }
2681
Andrew Lee011728f2015-04-23 15:47:06 -07002682 private void firePostDialWait(final String remainingPostDialSequence) {
2683 for (CallbackRecord<Callback> record : mCallbackRecords) {
2684 final Call call = this;
2685 final Callback callback = record.getCallback();
2686 record.getHandler().post(new Runnable() {
2687 @Override
2688 public void run() {
2689 callback.onPostDialWait(call, remainingPostDialSequence);
2690 }
2691 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002692 }
2693 }
2694
2695 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002696 /**
2697 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2698 * onCallRemoved callback, we remove this call from the Phone's record
2699 * only once all of the registered onCallDestroyed callbacks are executed.
2700 * All the callbacks get removed from our records as a part of this operation
2701 * since onCallDestroyed is the final callback.
2702 */
2703 final Call call = this;
2704 if (mCallbackRecords.isEmpty()) {
2705 // No callbacks registered, remove the call from Phone's record.
2706 mPhone.internalRemoveCall(call);
2707 }
2708 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002709 final Callback callback = record.getCallback();
2710 record.getHandler().post(new Runnable() {
2711 @Override
2712 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002713 boolean isFinalRemoval = false;
2714 RuntimeException toThrow = null;
2715 try {
2716 callback.onCallDestroyed(call);
2717 } catch (RuntimeException e) {
2718 toThrow = e;
2719 }
2720 synchronized(Call.this) {
2721 mCallbackRecords.remove(record);
2722 if (mCallbackRecords.isEmpty()) {
2723 isFinalRemoval = true;
2724 }
2725 }
2726 if (isFinalRemoval) {
2727 mPhone.internalRemoveCall(call);
2728 }
2729 if (toThrow != null) {
2730 throw toThrow;
2731 }
Andrew Lee011728f2015-04-23 15:47:06 -07002732 }
2733 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002734 }
2735 }
2736
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002737 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002738 for (CallbackRecord<Callback> record : mCallbackRecords) {
2739 final Call call = this;
2740 final Callback callback = record.getCallback();
2741 record.getHandler().post(new Runnable() {
2742 @Override
2743 public void run() {
2744 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2745 }
2746 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002747 }
2748 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002749
2750 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002751 * Notifies listeners of an incoming connection event.
2752 * <p>
2753 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2754 *
2755 * @param event
2756 * @param extras
2757 */
2758 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2759 for (CallbackRecord<Callback> record : mCallbackRecords) {
2760 final Call call = this;
2761 final Callback callback = record.getCallback();
2762 record.getHandler().post(new Runnable() {
2763 @Override
2764 public void run() {
2765 callback.onConnectionEvent(call, event, extras);
2766 }
2767 });
2768 }
2769 }
2770
2771 /**
Hall Liu95d55872017-01-25 17:12:49 -08002772 * Notifies listeners of an RTT on/off change
2773 *
2774 * @param enabled True if RTT is now enabled, false otherwise
2775 */
2776 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2777 for (CallbackRecord<Callback> record : mCallbackRecords) {
2778 final Call call = this;
2779 final Callback callback = record.getCallback();
2780 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2781 }
2782 }
2783
2784 /**
2785 * Notifies listeners of a RTT mode change
2786 *
2787 * @param mode The new RTT mode
2788 */
2789 private void fireOnRttModeChanged(final int mode) {
2790 for (CallbackRecord<Callback> record : mCallbackRecords) {
2791 final Call call = this;
2792 final Callback callback = record.getCallback();
2793 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2794 }
2795 }
2796
2797 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002798 * Determines if two bundles are equal.
2799 *
2800 * @param bundle The original bundle.
2801 * @param newBundle The bundle to compare with.
2802 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2803 */
2804 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2805 if (bundle == null || newBundle == null) {
2806 return bundle == newBundle;
2807 }
2808
2809 if (bundle.size() != newBundle.size()) {
2810 return false;
2811 }
2812
2813 for(String key : bundle.keySet()) {
2814 if (key != null) {
2815 final Object value = bundle.get(key);
2816 final Object newValue = newBundle.get(key);
2817 if (!Objects.equals(value, newValue)) {
2818 return false;
2819 }
2820 }
2821 }
2822 return true;
2823 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002824}