blob: babb709b104244c7d3790ba4ed244c44e3fd602b [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 Gunnfacfdee2020-01-23 13:10:37 -0800270
271 /**
272 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
273 * call because they have declined to answer it. This typically means that they are unable
274 * to answer the call at this time and would prefer it be sent to voicemail.
275 */
276 public static final int REJECT_REASON_DECLINED = 1;
277
278 /**
279 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
280 * call because it is an unwanted call. This allows the user to indicate that they are
281 * rejecting a call because it is likely a nuisance call.
282 */
283 public static final int REJECT_REASON_UNWANTED = 2;
284
285 /**
286 * @hide
287 */
288 @IntDef(prefix = { "REJECT_REASON_" },
289 value = {REJECT_REASON_DECLINED, REJECT_REASON_UNWANTED})
290 @Retention(RetentionPolicy.SOURCE)
291 public @interface RejectReason {};
292
Ihab Awade63fadb2014-07-09 21:52:04 -0700293 public static class Details {
Tyler Gunn94f8f112018-12-17 09:56:11 -0800294 /** @hide */
295 @Retention(RetentionPolicy.SOURCE)
296 @IntDef(
297 prefix = { "DIRECTION_" },
298 value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
299 public @interface CallDirection {}
300
301 /**
302 * Indicates that the call is neither and incoming nor an outgoing call. This can be the
303 * case for calls reported directly by a {@link ConnectionService} in special cases such as
304 * call handovers.
305 */
306 public static final int DIRECTION_UNKNOWN = -1;
307
308 /**
309 * Indicates that the call is an incoming call.
310 */
311 public static final int DIRECTION_INCOMING = 0;
312
313 /**
314 * Indicates that the call is an outgoing call.
315 */
316 public static final int DIRECTION_OUTGOING = 1;
317
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800318 /** Call can currently be put on hold or unheld. */
319 public static final int CAPABILITY_HOLD = 0x00000001;
320
321 /** Call supports the hold feature. */
322 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
323
324 /**
325 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
326 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
327 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
328 * capability allows a merge button to be shown while the conference call is in the foreground
329 * of the in-call UI.
330 * <p>
331 * This is only intended for use by a {@link Conference}.
332 */
333 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
334
335 /**
336 * Calls within a conference can be swapped between foreground and background.
337 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
338 * <p>
339 * This is only intended for use by a {@link Conference}.
340 */
341 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
342
343 /**
344 * @hide
345 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700346 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800347
348 /** Call supports responding via text option. */
349 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
350
351 /** Call can be muted. */
352 public static final int CAPABILITY_MUTE = 0x00000040;
353
354 /**
355 * Call supports conference call management. This capability only applies to {@link Conference}
356 * calls which can have {@link Connection}s as children.
357 */
358 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
359
360 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700361 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800362 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700363 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800364
365 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700366 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800367 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700368 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800369
370 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700371 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800372 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700373 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700374 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800375
376 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700377 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800378 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700379 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
380
381 /**
382 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700383 */
384 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
385
386 /**
387 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700388 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700389 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700390 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800391
392 /**
393 * Call is able to be separated from its parent {@code Conference}, if any.
394 */
395 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
396
397 /**
398 * Call is able to be individually disconnected when in a {@code Conference}.
399 */
400 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
401
402 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500403 * Speed up audio setup for MT call.
404 * @hide
405 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700406 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
407
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700408 /**
409 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700410 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800411 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
412 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
413 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700414 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800415 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700416 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
417
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700418 /**
419 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700420 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700421 */
422 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
423
Bryce Lee81901682015-08-28 16:38:02 -0700424 /**
425 * Call sends responses through connection.
426 * @hide
427 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800428 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
429
430 /**
431 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
432 * <p>
433 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
434 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
435 * downgraded from a video call back to a VideoState of
436 * {@link VideoProfile#STATE_AUDIO_ONLY}.
437 * <p>
438 * Intuitively, a call which can be downgraded to audio should also have local and remote
439 * video
440 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
441 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
442 */
443 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700444
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700445 /**
446 * When set for an external call, indicates that this {@code Call} can be pulled from a
447 * remote device to the current device.
448 * <p>
449 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
450 * <p>
451 * An {@link InCallService} will only see calls with this capability if it has the
452 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
453 * in its manifest.
454 * <p>
455 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700456 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700457 */
458 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
459
Pooja Jaind34698d2017-12-28 14:15:31 +0530460 /** Call supports the deflect feature. */
461 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
462
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800463 /**
464 * Call supports adding participants to the call via
Grace Jia8587ee52020-07-10 15:42:32 -0700465 * {@link #addConferenceParticipants(List)}. Once participants are added, the call becomes
466 * an adhoc conference call ({@link #PROPERTY_IS_ADHOC_CONFERENCE}).
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800467 */
Ravi Paluri404babb2020-01-23 19:02:44 +0530468 public static final int CAPABILITY_ADD_PARTICIPANT = 0x02000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530469
470 /**
471 * When set for a call, indicates that this {@code Call} can be transferred to another
472 * number.
Tyler Gunn460360d2020-07-29 10:21:45 -0700473 * Call supports the confirmed and unconfirmed call transfer feature.
Ravi Palurif4b38e72020-02-05 12:35:41 +0530474 *
475 * @hide
476 */
477 public static final int CAPABILITY_TRANSFER = 0x04000000;
478
479 /**
480 * When set for a call, indicates that this {@code Call} can be transferred to another
481 * ongoing call.
482 * Call supports the consultative call transfer feature.
483 *
484 * @hide
485 */
486 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x08000000;
487
Alvin Dey2f37d772018-05-18 23:16:10 +0530488 /**
489 * Indicates whether the remote party supports RTT or not to the UI.
490 */
491
492 public static final int CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT = 0x10000000;
493
Tyler Gunnd11a3152015-03-18 13:09:14 -0700494 //******************************************************************************************
Alvin Dey2f37d772018-05-18 23:16:10 +0530495 // Next CAPABILITY value: 0x20000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700496 //******************************************************************************************
497
498 /**
499 * Whether the call is currently a conference.
500 */
501 public static final int PROPERTY_CONFERENCE = 0x00000001;
502
503 /**
504 * Whether the call is a generic conference, where we do not know the precise state of
505 * participants in the conference (eg. on CDMA).
506 */
507 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
508
509 /**
510 * Whether the call is made while the device is in emergency callback mode.
511 */
512 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
513
514 /**
515 * Connection is using WIFI.
516 */
517 public static final int PROPERTY_WIFI = 0x00000008;
518
519 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700520 * When set, the UI should indicate to the user that a call is using high definition
521 * audio.
522 * <p>
523 * The underlying {@link ConnectionService} is responsible for reporting this
524 * property. It is important to note that this property is not intended to report the
525 * actual audio codec being used for a Call, but whether the call should be indicated
526 * to the user as high definition.
527 * <p>
528 * The Android Telephony stack reports this property for calls based on a number
529 * of factors, including which audio codec is used and whether a call is using an HD
530 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
531 * and in these cases this property will not be set for a call even if the underlying audio
532 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700533 */
534 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
535
Tony Maka68dcce2015-12-17 09:31:18 +0000536 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100537 * Whether the call is associated with the work profile.
538 */
539 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
540
541 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700542 * When set, indicates that this {@code Call} does not actually exist locally for the
543 * {@link ConnectionService}.
544 * <p>
545 * Consider, for example, a scenario where a user has two phones with the same phone number.
546 * When a user places a call on one device, the telephony stack can represent that call on
547 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700548 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700549 * <p>
550 * An {@link InCallService} will only see calls with this property if it has the
551 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
552 * in its manifest.
553 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700554 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700555 */
556 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
557
Brad Ebinger15847072016-05-18 11:08:36 -0700558 /**
559 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
560 */
561 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
562
Tyler Gunn24e18332017-02-10 09:42:49 -0800563 /**
564 * Indicates that the call is from a self-managed {@link ConnectionService}.
565 * <p>
566 * See also {@link Connection#PROPERTY_SELF_MANAGED}
567 */
568 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
569
Eric Erfanianec881872017-12-06 16:27:53 -0800570 /**
571 * Indicates the call used Assisted Dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700572 *
573 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanianec881872017-12-06 16:27:53 -0800574 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800575 public static final int PROPERTY_ASSISTED_DIALING = 0x00000200;
Eric Erfanianec881872017-12-06 16:27:53 -0800576
Hall Liue9041242018-02-09 16:40:03 -0800577 /**
578 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
579 * {@link RttCall} object that is used to send and receive text.
580 */
581 public static final int PROPERTY_RTT = 0x00000400;
582
Tyler Gunn5bd90852018-09-21 09:37:07 -0700583 /**
584 * Indicates that the call has been identified as the network as an emergency call. This
585 * property may be set for both incoming and outgoing calls which the network identifies as
586 * emergency calls.
587 */
588 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
589
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700590 /**
591 * Indicates that the call is using VoIP audio mode.
592 * <p>
593 * When this property is set, the {@link android.media.AudioManager} audio mode for this
594 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
595 * property is not set, the audio mode for this call will be
596 * {@link android.media.AudioManager#MODE_IN_CALL}.
597 * <p>
598 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
599 * <p>
600 * You can use this property to determine whether an un-answered incoming call or a held
601 * call will use VoIP audio mode (if the call does not currently have focus, the system
602 * audio mode may not reflect the mode the call will use).
603 */
604 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
605
Ravi Paluri80aa2142019-12-02 11:57:37 +0530606 /**
607 * Indicates that the call is an adhoc conference call. This property can be set for both
Grace Jia8587ee52020-07-10 15:42:32 -0700608 * incoming and outgoing calls. An adhoc conference call is formed using
609 * {@link #addConferenceParticipants(List)},
610 * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}, or
611 * {@link TelecomManager#startConference(List, Bundle)}, rather than by merging existing
612 * call using {@link #conference(Call)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530613 */
614 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 0x00002000;
615
Andrew Lee2378ea72015-04-29 14:38:11 -0700616 //******************************************************************************************
Ravi Paluri80aa2142019-12-02 11:57:37 +0530617 // Next PROPERTY value: 0x00004000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700618 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800619
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800620 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700621 private final Uri mHandle;
622 private final int mHandlePresentation;
623 private final String mCallerDisplayName;
624 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700625 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700626 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700627 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800628 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700629 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700630 private final long mConnectTimeMillis;
631 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700632 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700633 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700634 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700635 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700636 private final long mCreationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -0800637 private final String mContactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800638 private final @CallDirection int mCallDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700639 private final @Connection.VerificationStatus int mCallerNumberVerificationStatus;
Ihab Awade63fadb2014-07-09 21:52:04 -0700640
641 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800642 * Whether the supplied capabilities supports the specified capability.
643 *
644 * @param capabilities A bit field of capabilities.
645 * @param capability The capability to check capabilities for.
646 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800647 */
648 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800649 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800650 }
651
652 /**
653 * Whether the capabilities of this {@code Details} supports the specified capability.
654 *
655 * @param capability The capability to check capabilities for.
656 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800657 */
658 public boolean can(int capability) {
659 return can(mCallCapabilities, capability);
660 }
661
662 /**
663 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
664 *
665 * @param capabilities A capability bit field.
666 * @return A human readable string representation.
667 */
668 public static String capabilitiesToString(int capabilities) {
669 StringBuilder builder = new StringBuilder();
670 builder.append("[Capabilities:");
671 if (can(capabilities, CAPABILITY_HOLD)) {
672 builder.append(" CAPABILITY_HOLD");
673 }
674 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
675 builder.append(" CAPABILITY_SUPPORT_HOLD");
676 }
677 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
678 builder.append(" CAPABILITY_MERGE_CONFERENCE");
679 }
680 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
681 builder.append(" CAPABILITY_SWAP_CONFERENCE");
682 }
683 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
684 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
685 }
686 if (can(capabilities, CAPABILITY_MUTE)) {
687 builder.append(" CAPABILITY_MUTE");
688 }
689 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
690 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
691 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700692 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
693 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
694 }
695 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
696 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
697 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700698 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
699 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800700 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700701 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
702 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
703 }
704 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
705 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
706 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800707 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
708 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
709 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700710 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
711 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800712 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500713 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700714 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500715 }
Rekha Kumar07366812015-03-24 16:42:31 -0700716 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
717 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
718 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700719 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
720 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
721 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700722 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
723 builder.append(" CAPABILITY_CAN_PULL_CALL");
724 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530725 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
726 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
727 }
Ravi Paluri404babb2020-01-23 19:02:44 +0530728 if (can(capabilities, CAPABILITY_ADD_PARTICIPANT)) {
729 builder.append(" CAPABILITY_ADD_PARTICIPANT");
730 }
Ravi Palurif4b38e72020-02-05 12:35:41 +0530731 if (can(capabilities, CAPABILITY_TRANSFER)) {
732 builder.append(" CAPABILITY_TRANSFER");
733 }
734 if (can(capabilities, CAPABILITY_TRANSFER_CONSULTATIVE)) {
735 builder.append(" CAPABILITY_TRANSFER_CONSULTATIVE");
736 }
Alvin Dey2f37d772018-05-18 23:16:10 +0530737 if (can(capabilities, CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT)) {
738 builder.append(" CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT");
739 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800740 builder.append("]");
741 return builder.toString();
742 }
743
744 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700745 * Whether the supplied properties includes the specified property.
746 *
747 * @param properties A bit field of properties.
748 * @param property The property to check properties for.
749 * @return Whether the specified property is supported.
750 */
751 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800752 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700753 }
754
755 /**
756 * Whether the properties of this {@code Details} includes the specified property.
757 *
758 * @param property The property to check properties for.
759 * @return Whether the specified property is supported.
760 */
761 public boolean hasProperty(int property) {
762 return hasProperty(mCallProperties, property);
763 }
764
765 /**
766 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
767 *
768 * @param properties A property bit field.
769 * @return A human readable string representation.
770 */
771 public static String propertiesToString(int properties) {
772 StringBuilder builder = new StringBuilder();
773 builder.append("[Properties:");
774 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
775 builder.append(" PROPERTY_CONFERENCE");
776 }
777 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
778 builder.append(" PROPERTY_GENERIC_CONFERENCE");
779 }
780 if (hasProperty(properties, PROPERTY_WIFI)) {
781 builder.append(" PROPERTY_WIFI");
782 }
783 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
784 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
785 }
786 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700787 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700788 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700789 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
790 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
791 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700792 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700793 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
794 }
Tyler Gunnc9503d62020-01-27 10:30:51 -0800795 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800796 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
797 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700798 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
799 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
800 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700801 if (hasProperty(properties, PROPERTY_RTT)) {
802 builder.append(" PROPERTY_RTT");
803 }
804 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
805 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
806 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530807 if (hasProperty(properties, PROPERTY_IS_ADHOC_CONFERENCE)) {
808 builder.append(" PROPERTY_IS_ADHOC_CONFERENCE");
809 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700810 builder.append("]");
811 return builder.toString();
812 }
813
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800814 /** {@hide} */
Hall Liu31de23d2019-10-11 15:38:29 -0700815 @TestApi
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800816 public String getTelecomCallId() {
817 return mTelecomCallId;
818 }
819
Andrew Lee2378ea72015-04-29 14:38:11 -0700820 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700821 * @return The handle (e.g., phone number) to which the {@code Call} is currently
822 * connected.
823 */
824 public Uri getHandle() {
825 return mHandle;
826 }
827
828 /**
829 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700830 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700831 */
832 public int getHandlePresentation() {
833 return mHandlePresentation;
834 }
835
836 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800837 * The display name for the caller.
838 * <p>
839 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800840 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700841 * @return The display name for the caller.
842 */
843 public String getCallerDisplayName() {
844 return mCallerDisplayName;
845 }
846
847 /**
848 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700849 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700850 */
851 public int getCallerDisplayNamePresentation() {
852 return mCallerDisplayNamePresentation;
853 }
854
855 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700856 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
857 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700858 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700859 public PhoneAccountHandle getAccountHandle() {
860 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700861 }
862
863 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800864 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
865 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700866 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700867 public int getCallCapabilities() {
868 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700869 }
870
871 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700872 * @return A bitmask of the properties of the {@code Call}, as defined by the various
873 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700874 */
875 public int getCallProperties() {
876 return mCallProperties;
877 }
878
879 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800880 * @return a bitmask of the audio routes available for the call.
881 *
882 * @hide
883 */
884 public int getSupportedAudioRoutes() {
885 return mSupportedAudioRoutes;
886 }
887
888 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700889 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700890 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700891 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700892 public DisconnectCause getDisconnectCause() {
893 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700894 }
895
896 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700897 * Returns the time the {@link Call} connected (i.e. became active). This information is
898 * updated periodically, but user interfaces should not rely on this to display the "call
899 * time clock". For the time when the call was first added to Telecom, see
900 * {@link #getCreationTimeMillis()}.
901 *
902 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700903 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700904 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700905 return mConnectTimeMillis;
906 }
907
908 /**
909 * @return Information about any calling gateway the {@code Call} may be using.
910 */
911 public GatewayInfo getGatewayInfo() {
912 return mGatewayInfo;
913 }
914
Andrew Lee7a341382014-07-15 17:05:08 -0700915 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700916 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700917 */
918 public int getVideoState() {
919 return mVideoState;
920 }
921
Ihab Awad5d0410f2014-07-30 10:07:40 -0700922 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700923 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700924 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700925 */
926 public StatusHints getStatusHints() {
927 return mStatusHints;
928 }
929
Nancy Chen10798dc2014-08-08 14:00:25 -0700930 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700931 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700932 */
933 public Bundle getExtras() {
934 return mExtras;
935 }
936
Santos Cordon6b7f9552015-05-27 17:21:45 -0700937 /**
938 * @return The extras used with the original intent to place this call.
939 */
940 public Bundle getIntentExtras() {
941 return mIntentExtras;
942 }
943
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700944 /**
945 * Returns the time when the call was first created and added to Telecom. This is the same
946 * time that is logged as the start time in the Call Log (see
947 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
948 * (became active), see {@link #getConnectTimeMillis()}.
949 *
950 * @return The creation time of the call, in millis since the epoch.
951 */
952 public long getCreationTimeMillis() {
953 return mCreationTimeMillis;
954 }
955
Tyler Gunnd081f042018-12-04 12:56:45 -0800956 /**
Hall Liuef98bf82020-01-09 15:22:44 -0800957 * Returns the name of the caller on the remote end, as derived from a
958 * {@link android.provider.ContactsContract} lookup of the call's handle.
959 * @return The name of the caller, or {@code null} if the lookup is not yet complete, if
960 * there's no contacts entry for the caller, or if the {@link InCallService} does
961 * not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
962 */
963 public @Nullable String getContactDisplayName() {
964 return mContactDisplayName;
965 }
966
967 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -0800968 * Indicates whether the call is an incoming or outgoing call.
969 * @return The call's direction.
970 */
971 public @CallDirection int getCallDirection() {
972 return mCallDirection;
973 }
974
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700975 /**
976 * Gets the verification status for the phone number of an incoming call as identified in
977 * ATIS-1000082.
Tyler Gunn9c642492020-10-08 13:37:03 -0700978 * <p>
979 * For incoming calls, the number verification status indicates whether the device was
980 * able to verify the authenticity of the calling number using the STIR process outlined
981 * in ATIS-1000082. {@link Connection#VERIFICATION_STATUS_NOT_VERIFIED} indicates that
982 * the network was not able to use STIR to verify the caller's number (i.e. nothing is
983 * known regarding the authenticity of the number.
984 * {@link Connection#VERIFICATION_STATUS_PASSED} indicates that the network was able to
985 * use STIR to verify the caller's number. This indicates that the network has a high
986 * degree of confidence that the incoming call actually originated from the indicated
987 * number. {@link Connection#VERIFICATION_STATUS_FAILED} indicates that the network's
988 * STIR verification did not pass. This indicates that the incoming call may not
989 * actually be from the indicated number. This could occur if, for example, the caller
990 * is using an impersonated phone number.
991 * <p>
992 * A {@link CallScreeningService} can use this information to help determine if an
993 * incoming call is potentially an unwanted call. A verification status of
994 * {@link Connection#VERIFICATION_STATUS_FAILED} indicates that an incoming call may not
995 * actually be from the number indicated on the call (i.e. impersonated number) and that it
996 * should potentially be blocked. Likewise,
997 * {@link Connection#VERIFICATION_STATUS_PASSED} can be used as a positive signal to
998 * help clarify that the incoming call is originating from the indicated number and it
999 * is less likely to be an undesirable call.
1000 * <p>
1001 * An {@link InCallService} can use this information to provide a visual indicator to the
1002 * user regarding the verification status of a call and to help identify calls from
1003 * potentially impersonated numbers.
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001004 * @return the verification status.
1005 */
1006 public @Connection.VerificationStatus int getCallerNumberVerificationStatus() {
1007 return mCallerNumberVerificationStatus;
1008 }
1009
Ihab Awade63fadb2014-07-09 21:52:04 -07001010 @Override
1011 public boolean equals(Object o) {
1012 if (o instanceof Details) {
1013 Details d = (Details) o;
1014 return
1015 Objects.equals(mHandle, d.mHandle) &&
1016 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
1017 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
1018 Objects.equals(mCallerDisplayNamePresentation,
1019 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -07001020 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -07001021 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -07001022 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001023 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -07001024 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -07001025 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -07001026 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -07001027 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001028 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001029 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -08001030 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Hall Liuef98bf82020-01-09 15:22:44 -08001031 Objects.equals(mContactDisplayName, d.mContactDisplayName) &&
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001032 Objects.equals(mCallDirection, d.mCallDirection) &&
1033 Objects.equals(mCallerNumberVerificationStatus,
1034 d.mCallerNumberVerificationStatus);
Ihab Awade63fadb2014-07-09 21:52:04 -07001035 }
1036 return false;
1037 }
1038
1039 @Override
1040 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001041 return Objects.hash(mHandle,
1042 mHandlePresentation,
1043 mCallerDisplayName,
1044 mCallerDisplayNamePresentation,
1045 mAccountHandle,
1046 mCallCapabilities,
1047 mCallProperties,
1048 mDisconnectCause,
1049 mConnectTimeMillis,
1050 mGatewayInfo,
1051 mVideoState,
1052 mStatusHints,
1053 mExtras,
1054 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001055 mCreationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001056 mContactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001057 mCallDirection,
1058 mCallerNumberVerificationStatus);
Ihab Awade63fadb2014-07-09 21:52:04 -07001059 }
1060
1061 /** {@hide} */
1062 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001063 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -07001064 Uri handle,
1065 int handlePresentation,
1066 String callerDisplayName,
1067 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -07001068 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -07001069 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -07001070 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001071 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -07001072 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -07001073 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -07001074 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -07001075 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -07001076 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001077 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001078 long creationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001079 String contactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001080 int callDirection,
1081 int callerNumberVerificationStatus) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001082 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001083 mHandle = handle;
1084 mHandlePresentation = handlePresentation;
1085 mCallerDisplayName = callerDisplayName;
1086 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -07001087 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -07001088 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -07001089 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001090 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -07001091 mConnectTimeMillis = connectTimeMillis;
1092 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -07001093 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -07001094 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -07001095 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001096 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001097 mCreationTimeMillis = creationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -08001098 mContactDisplayName = contactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -08001099 mCallDirection = callDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001100 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
Ihab Awade63fadb2014-07-09 21:52:04 -07001101 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001102
1103 /** {@hide} */
1104 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
1105 return new Details(
1106 parcelableCall.getId(),
1107 parcelableCall.getHandle(),
1108 parcelableCall.getHandlePresentation(),
1109 parcelableCall.getCallerDisplayName(),
1110 parcelableCall.getCallerDisplayNamePresentation(),
1111 parcelableCall.getAccountHandle(),
1112 parcelableCall.getCapabilities(),
1113 parcelableCall.getProperties(),
1114 parcelableCall.getDisconnectCause(),
1115 parcelableCall.getConnectTimeMillis(),
1116 parcelableCall.getGatewayInfo(),
1117 parcelableCall.getVideoState(),
1118 parcelableCall.getStatusHints(),
1119 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001120 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -08001121 parcelableCall.getCreationTimeMillis(),
Hall Liuef98bf82020-01-09 15:22:44 -08001122 parcelableCall.getContactDisplayName(),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001123 parcelableCall.getCallDirection(),
1124 parcelableCall.getCallerNumberVerificationStatus());
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001125 }
Santos Cordon3c20d632016-02-25 16:12:35 -08001126
1127 @Override
1128 public String toString() {
1129 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001130 sb.append("[id: ");
1131 sb.append(mTelecomCallId);
1132 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -08001133 sb.append(mAccountHandle);
1134 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001135 sb.append(Log.piiHandle(mHandle));
1136 sb.append(", hdlPres: ");
1137 sb.append(mHandlePresentation);
1138 sb.append(", videoState: ");
1139 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -08001140 sb.append(", caps: ");
1141 sb.append(capabilitiesToString(mCallCapabilities));
1142 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001143 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001144 sb.append("]");
1145 return sb.toString();
1146 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001147 }
1148
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001149 /**
1150 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1151 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1152 * implementation.
1153 * <p>
1154 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1155 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1156 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1157 * {@link Callback} implementation, if desired.
1158 * <p>
1159 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1160 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1161 * (typically in {@link InCallService#onCallRemoved(Call)}).
1162 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1163 * reach your implementation of {@link Callback}, so it is important to register your callback
1164 * as soon as your {@link InCallService} is notified of a new call via
1165 * {@link InCallService#onCallAdded(Call)}.
1166 */
Andrew Leeda80c872015-04-15 14:09:50 -07001167 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001168 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001169 * @hide
1170 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001171 @IntDef(prefix = { "HANDOVER_" },
1172 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001173 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001174 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001175 @Retention(RetentionPolicy.SOURCE)
1176 public @interface HandoverFailureErrors {}
1177
1178 /**
1179 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001180 * to handover the call to rejects the handover request.
1181 * <p>
1182 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1183 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1184 * {@code null} {@link Connection} from
1185 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1186 * ConnectionRequest)}.
1187 * <p>
1188 * For more information on call handovers, see
1189 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001190 */
1191 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1192
1193 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001194 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1195 * is initiated but the source or destination app does not support handover.
1196 * <p>
1197 * Will be returned when a handover is requested via
1198 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1199 * {@link PhoneAccountHandle} does not declare
1200 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1201 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1202 * {@link Details#getAccountHandle()}) does not declare
1203 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1204 * <p>
1205 * For more information on call handovers, see
1206 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001207 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001208 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001209
1210 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001211 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1212 * user rejects the handover request.
1213 * <p>
1214 * For more information on call handovers, see
1215 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001216 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001217 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001218
Sanket Padawe85291f62017-12-01 13:59:27 -08001219 /**
1220 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1221 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001222 * <p>
1223 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1224 * called on an emergency call, or if any other call is an emergency call.
1225 * <p>
1226 * Handovers are not permitted while there are ongoing emergency calls.
1227 * <p>
1228 * For more information on call handovers, see
1229 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001230 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001231 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001232
Tyler Gunn9d127732018-03-02 15:45:51 -08001233 /**
1234 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1235 * fails for an unknown reason.
1236 * <p>
1237 * For more information on call handovers, see
1238 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1239 */
1240 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001241
1242 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001243 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1244 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001245 * @param call The {@code Call} invoking this method.
1246 * @param state The new state of the {@code Call}.
1247 */
1248 public void onStateChanged(Call call, int state) {}
1249
1250 /**
1251 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1252 *
1253 * @param call The {@code Call} invoking this method.
1254 * @param parent The new parent of the {@code Call}.
1255 */
1256 public void onParentChanged(Call call, Call parent) {}
1257
1258 /**
1259 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1260 *
1261 * @param call The {@code Call} invoking this method.
1262 * @param children The new children of the {@code Call}.
1263 */
1264 public void onChildrenChanged(Call call, List<Call> children) {}
1265
1266 /**
1267 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1268 *
1269 * @param call The {@code Call} invoking this method.
1270 * @param details A {@code Details} object describing the {@code Call}.
1271 */
1272 public void onDetailsChanged(Call call, Details details) {}
1273
1274 /**
1275 * Invoked when the text messages that can be used as responses to the incoming
1276 * {@code Call} are loaded from the relevant database.
1277 * See {@link #getCannedTextResponses()}.
1278 *
1279 * @param call The {@code Call} invoking this method.
1280 * @param cannedTextResponses The text messages useable as responses.
1281 */
1282 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1283
1284 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001285 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1286 * character. This causes the post-dial signals to stop pending user confirmation. An
1287 * implementation should present this choice to the user and invoke
1288 * {@link #postDialContinue(boolean)} when the user makes the choice.
1289 *
1290 * @param call The {@code Call} invoking this method.
1291 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1292 */
1293 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1294
1295 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001296 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001297 *
1298 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001299 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001300 */
Andrew Lee50aca232014-07-22 16:41:54 -07001301 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001302
1303 /**
1304 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1305 * up their UI for the {@code Call} in response to state transitions. Specifically,
1306 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1307 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1308 * clients should wait for this method to be invoked.
1309 *
1310 * @param call The {@code Call} being destroyed.
1311 */
1312 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001313
1314 /**
1315 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1316 * conferenced.
1317 *
1318 * @param call The {@code Call} being updated.
1319 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1320 * conferenced.
1321 */
1322 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001323
1324 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001325 * Invoked when a {@link Call} receives an event from its associated {@link Connection} or
1326 * {@link Conference}.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001327 * <p>
1328 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1329 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1330 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1331 * possible that a {@link ConnectionService} has defined its own Connection events which a
1332 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001333 * <p>
Tyler Gunn5567d742019-10-31 13:04:37 -07001334 * See {@link Connection#sendConnectionEvent(String, Bundle)},
1335 * {@link Conference#sendConferenceEvent(String, Bundle)}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001336 *
1337 * @param call The {@code Call} receiving the event.
1338 * @param event The event.
1339 * @param extras Extras associated with the connection event.
1340 */
1341 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001342
1343 /**
1344 * Invoked when the RTT mode changes for this call.
1345 * @param call The call whose RTT mode has changed.
1346 * @param mode the new RTT mode, one of
1347 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1348 * or {@link RttCall#RTT_MODE_VCO}
1349 */
1350 public void onRttModeChanged(Call call, int mode) {}
1351
1352 /**
1353 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1354 * @param call The call whose RTT status has changed.
1355 * @param enabled whether RTT is now enabled or disabled
1356 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1357 * on, null otherwise.
1358 */
1359 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1360
1361 /**
1362 * Invoked when the remote end of the connection has requested that an RTT communication
1363 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1364 * with the same ID that this method is invoked with.
1365 * @param call The call which the RTT request was placed on
1366 * @param id The ID of the request.
1367 */
1368 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001369
1370 /**
1371 * Invoked when the RTT session failed to initiate for some reason, including rejection
1372 * by the remote party.
1373 * @param call The call which the RTT initiation failure occurred on.
1374 * @param reason One of the status codes defined in
1375 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1376 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1377 */
1378 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001379
1380 /**
1381 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1382 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001383 * <p>
1384 * For a full discussion of the handover process and the APIs involved, see
1385 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1386 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001387 * @param call The call which had initiated handover.
1388 */
1389 public void onHandoverComplete(Call call) {}
1390
1391 /**
1392 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1393 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001394 * <p>
1395 * For a full discussion of the handover process and the APIs involved, see
1396 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1397 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001398 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001399 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001400 */
1401 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001402 }
1403
1404 /**
1405 * A class that holds the state that describes the state of the RTT channel to the remote
1406 * party, if it is active.
1407 */
1408 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001409 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001410 @Retention(RetentionPolicy.SOURCE)
1411 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1412 public @interface RttAudioMode {}
1413
1414 /**
1415 * For metrics use. Default value in the proto.
1416 * @hide
1417 */
1418 public static final int RTT_MODE_INVALID = 0;
1419
1420 /**
1421 * Indicates that there should be a bidirectional audio stream between the two parties
1422 * on the call.
1423 */
1424 public static final int RTT_MODE_FULL = 1;
1425
1426 /**
1427 * Indicates that the local user should be able to hear the audio stream from the remote
1428 * user, but not vice versa. Equivalent to muting the microphone.
1429 */
1430 public static final int RTT_MODE_HCO = 2;
1431
1432 /**
1433 * Indicates that the remote user should be able to hear the audio stream from the local
1434 * user, but not vice versa. Equivalent to setting the volume to zero.
1435 */
1436 public static final int RTT_MODE_VCO = 3;
1437
1438 private static final int READ_BUFFER_SIZE = 1000;
1439
1440 private InputStreamReader mReceiveStream;
1441 private OutputStreamWriter mTransmitStream;
1442 private int mRttMode;
1443 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001444 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001445 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1446
1447 /**
1448 * @hide
1449 */
Hall Liu57006aa2017-02-06 10:49:48 -08001450 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1451 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1452 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001453 mReceiveStream = receiveStream;
1454 mTransmitStream = transmitStream;
1455 mRttMode = mode;
1456 mInCallAdapter = inCallAdapter;
1457 }
1458
1459 /**
1460 * Returns the current RTT audio mode.
1461 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1462 * {@link #RTT_MODE_HCO}.
1463 */
1464 public int getRttAudioMode() {
1465 return mRttMode;
1466 }
1467
1468 /**
1469 * Sets the RTT audio mode. The requested mode change will be communicated through
1470 * {@link Callback#onRttModeChanged(Call, int)}.
1471 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1472 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1473 */
1474 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001475 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001476 }
1477
1478 /**
1479 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
Hall Liudc46c852020-10-29 16:15:33 -07001480 * RTT transmits text in real-time, this method should be called once for each user action.
1481 * For example, when the user enters text as discrete characters using the keyboard, this
1482 * method should be called once for each character. However, if the user enters text by
1483 * pasting or autocomplete, the entire contents of the pasted or autocompleted text should
1484 * be sent in one call to this method.
Hall Liu95d55872017-01-25 17:12:49 -08001485 *
1486 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1487 * lead to interleaved text.
1488 * @param input The message to send to the remote user.
1489 */
1490 public void write(String input) throws IOException {
1491 mTransmitStream.write(input);
1492 mTransmitStream.flush();
1493 }
1494
1495 /**
1496 * Reads a string from the remote user, blocking if there is no data available. Returns
1497 * {@code null} if the RTT conversation has been terminated and there is no further data
1498 * to read.
1499 *
1500 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1501 * lead to interleaved text.
1502 * @return A string containing text sent by the remote user, or {@code null} if the
1503 * conversation has been terminated or if there was an error while reading.
1504 */
Hall Liub1c8a772017-07-17 17:04:41 -07001505 public String read() {
1506 try {
1507 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1508 if (numRead < 0) {
1509 return null;
1510 }
1511 return new String(mReadBuffer, 0, numRead);
1512 } catch (IOException e) {
1513 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001514 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001515 }
Hall Liuffa4a812017-03-02 16:11:00 -08001516 }
1517
1518 /**
1519 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1520 * be read.
1521 * @return A string containing text entered by the user, or {@code null} if the user has
1522 * not entered any new text yet.
1523 */
1524 public String readImmediately() throws IOException {
1525 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001526 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1527 if (numRead < 0) {
1528 return null;
1529 }
1530 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001531 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001532 return null;
1533 }
1534 }
Hall Liue9041242018-02-09 16:40:03 -08001535
1536 /**
1537 * Closes the underlying file descriptors
1538 * @hide
1539 */
1540 public void close() {
1541 try {
1542 mReceiveStream.close();
1543 } catch (IOException e) {
1544 // ignore
1545 }
1546 try {
1547 mTransmitStream.close();
1548 } catch (IOException e) {
1549 // ignore
1550 }
1551 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001552 }
1553
Andrew Leeda80c872015-04-15 14:09:50 -07001554 /**
1555 * @deprecated Use {@code Call.Callback} instead.
1556 * @hide
1557 */
1558 @Deprecated
1559 @SystemApi
1560 public static abstract class Listener extends Callback { }
1561
Ihab Awade63fadb2014-07-09 21:52:04 -07001562 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001563 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001564 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001565 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001566 private final List<Call> mChildren = new ArrayList<>();
1567 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001568 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001569 private final List<Call> mConferenceableCalls = new ArrayList<>();
1570 private final List<Call> mUnmodifiableConferenceableCalls =
1571 Collections.unmodifiableList(mConferenceableCalls);
1572
Santos Cordon823fd3c2014-08-07 18:35:18 -07001573 private boolean mChildrenCached;
1574 private String mParentId = null;
Hall Liuef98bf82020-01-09 15:22:44 -08001575 private String mActiveGenericConferenceChild = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001576 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001577 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001578 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001579 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001580 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001581 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001582 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001583 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001584 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001585
1586 /**
1587 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1588 *
1589 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1590 * remaining or this {@code Call} is not in a post-dial state.
1591 */
1592 public String getRemainingPostDialSequence() {
1593 return mRemainingPostDialSequence;
1594 }
1595
1596 /**
1597 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001598 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001599 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001600 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001601 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001602 }
1603
1604 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301605 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1606 *
1607 * @param address The address to which the call will be deflected.
1608 */
1609 public void deflect(Uri address) {
1610 mInCallAdapter.deflectCall(mTelecomCallId, address);
1611 }
1612
1613 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001614 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1615 *
1616 * @param rejectWithMessage Whether to reject with a text message.
1617 * @param textMessage An optional text message with which to respond.
1618 */
1619 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001620 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001621 }
1622
1623 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001624 * Instructs the {@link ConnectionService} providing this {@link #STATE_RINGING} call that the
1625 * user has chosen to reject the call and has indicated a reason why the call is being rejected.
1626 *
1627 * @param rejectReason the reason the call is being rejected.
1628 */
1629 public void reject(@RejectReason int rejectReason) {
1630 mInCallAdapter.rejectCall(mTelecomCallId, rejectReason);
1631 }
1632
1633 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05301634 * Instructs this {@code Call} to be transferred to another number.
1635 *
1636 * @param targetNumber The address to which the call will be transferred.
Tyler Gunn460360d2020-07-29 10:21:45 -07001637 * @param isConfirmationRequired if {@code true} it will initiate a confirmed transfer,
1638 * if {@code false}, it will initiate an unconfirmed transfer.
Ravi Palurif4b38e72020-02-05 12:35:41 +05301639 *
1640 * @hide
1641 */
1642 public void transfer(@NonNull Uri targetNumber, boolean isConfirmationRequired) {
1643 mInCallAdapter.transferCall(mTelecomCallId, targetNumber, isConfirmationRequired);
1644 }
1645
1646 /**
1647 * Instructs this {@code Call} to be transferred to another ongoing call.
1648 * This will initiate CONSULTATIVE transfer.
1649 * @param toCall The other ongoing {@code Call} to which this call will be transferred.
1650 *
1651 * @hide
1652 */
1653 public void transfer(@NonNull android.telecom.Call toCall) {
1654 mInCallAdapter.transferCall(mTelecomCallId, toCall.mTelecomCallId);
1655 }
1656
1657 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001658 * Instructs this {@code Call} to disconnect.
1659 */
1660 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001661 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001662 }
1663
1664 /**
1665 * Instructs this {@code Call} to go on hold.
1666 */
1667 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001668 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001669 }
1670
1671 /**
1672 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1673 */
1674 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001675 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001676 }
1677
1678 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001679 * Instructs Telecom to put the call into the background audio processing state.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001680 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001681 * This method can be called either when the call is in {@link #STATE_RINGING} or
1682 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1683 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1684 * order to capture and play audio on the call stream.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001685 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001686 * This method can only be called by the default dialer app.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001687 * <p>
1688 * Apps built with SDK version {@link android.os.Build.VERSION_CODES#R} or later which are using
1689 * the microphone as part of audio processing should specify the foreground service type using
1690 * the attribute {@link android.R.attr#foregroundServiceType} in the {@link InCallService}
1691 * service element of the app's manifest file.
1692 * The {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_MICROPHONE} attribute should be specified.
1693 * @see <a href="https://developer.android.com/preview/privacy/foreground-service-types">
1694 * the Android Developer Site</a> for more information.
Hall Liu6dfa2492019-10-01 17:20:39 -07001695 * @hide
1696 */
1697 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001698 public void enterBackgroundAudioProcessing() {
1699 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1700 throw new IllegalStateException("Call must be active or ringing");
1701 }
1702 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1703 }
1704
1705 /**
1706 * Instructs Telecom to come out of the background audio processing state requested by
1707 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1708 *
1709 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1710 *
1711 * @param shouldRing If true, Telecom will put the call into the
1712 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1713 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1714 * immediately.
1715 * @hide
1716 */
1717 @SystemApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001718 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1719 if (mState != STATE_AUDIO_PROCESSING) {
1720 throw new IllegalStateException("Call must in the audio processing state");
1721 }
1722 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1723 }
1724
1725 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001726 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1727 *
1728 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1729 *
1730 * @param digit A character representing the DTMF digit for which to play the tone. This
1731 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1732 */
1733 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001734 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001735 }
1736
1737 /**
1738 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1739 * currently playing.
1740 *
1741 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1742 * currently playing, this method will do nothing.
1743 */
1744 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001745 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001746 }
1747
1748 /**
1749 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1750 *
1751 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1752 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001753 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001754 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001755 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1756 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001757 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001758 * {@code Call} will pause playing the tones and notify callbacks via
1759 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001760 * should display to the user an indication of this state and an affordance to continue
1761 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1762 * app should invoke the {@link #postDialContinue(boolean)} method.
1763 *
1764 * @param proceed Whether or not to continue with the post-dial sequence.
1765 */
1766 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001767 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001768 }
1769
1770 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001771 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001772 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001773 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001774 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1775 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001776
1777 }
1778
1779 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001780 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001781 *
1782 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001783 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001784 public void conference(Call callToConferenceWith) {
1785 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001786 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001787 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001788 }
1789
1790 /**
1791 * Instructs this {@code Call} to split from any conference call with which it may be
1792 * connected.
1793 */
1794 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001795 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001796 }
1797
1798 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001799 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001800 */
1801 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001802 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001803 }
1804
1805 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001806 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001807 */
1808 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001809 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001810 }
1811
1812 /**
Ravi Paluri404babb2020-01-23 19:02:44 +05301813 * Pulls participants to existing call by forming a conference call.
1814 * See {@link Details#CAPABILITY_ADD_PARTICIPANT}.
1815 *
1816 * @param participants participants to be pulled to existing call.
1817 */
1818 public void addConferenceParticipants(@NonNull List<Uri> participants) {
1819 mInCallAdapter.addConferenceParticipants(mTelecomCallId, participants);
1820 }
1821
1822 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001823 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1824 * device.
1825 * <p>
1826 * Calls to this method are ignored if the call does not have the
1827 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1828 * <p>
1829 * An {@link InCallService} will only see calls which support this method if it has the
1830 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1831 * in its manifest.
1832 */
1833 public void pullExternalCall() {
1834 // If this isn't an external call, ignore the request.
1835 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1836 return;
1837 }
1838
1839 mInCallAdapter.pullExternalCall(mTelecomCallId);
1840 }
1841
1842 /**
1843 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1844 * the {@link ConnectionService}.
1845 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001846 * Call events are used to communicate point in time information from an {@link InCallService}
1847 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1848 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1849 * {@link ConnectionService}.
1850 * <p>
1851 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1852 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1853 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001854 * Events are exposed to {@link ConnectionService} implementations via
1855 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1856 * <p>
1857 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001858 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1859 * ignore some events altogether.
1860 * <p>
1861 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1862 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1863 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1864 * they define their own event types in this namespace. When defining a custom event type,
1865 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1866 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1867 * <p>
1868 * When defining events and the associated extras, it is important to keep their behavior
1869 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1870 * events/extras should me maintained to ensure backwards compatibility with older
1871 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001872 *
1873 * @param event The connection event.
1874 * @param extras Bundle containing extra information associated with the event.
1875 */
1876 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001877 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001878 }
1879
1880 /**
Hall Liu95d55872017-01-25 17:12:49 -08001881 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1882 * guaranteed, and notification of success will be via the
1883 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1884 */
1885 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001886 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001887 }
1888
1889 /**
1890 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1891 * callback.
1892 * The ID used here should be the same as the ID that was received via the callback.
1893 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1894 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1895 */
1896 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001897 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001898 }
1899
1900 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001901 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1902 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1903 * handover.
1904 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001905 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1906 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1907 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1908 * is referred to as the source of the handover, and the video calling app is referred to as the
1909 * destination.
1910 * <p>
1911 * When considering a handover scenario the device this method is called on is considered the
1912 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1913 * other device is considered the <em>receiving</em> device.
1914 * <p>
1915 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1916 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1917 * and invoke
1918 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1919 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1920 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1921 * At this point the app should display UI to indicate to the user that a call
1922 * handover is in process.
1923 * <p>
1924 * The destination app is responsible for communicating the handover request from the
1925 * <em>initiating</em> device to the <em>receiving</em> device.
1926 * <p>
1927 * When the app on the <em>receiving</em> device receives the handover request, it calls
1928 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1929 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1930 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1931 * choose whether they want to continue their call in the destination app.
1932 * <p>
1933 * When the destination app on the <em>receiving</em> device calls
1934 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1935 * {@link ConnectionService} and call
1936 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1937 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1938 * {@link Connection} to represent the handover call.
1939 * <p>
1940 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1941 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1942 * original call. If the user rejects the handover, the app calls
1943 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1944 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1945 * <p>
1946 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1947 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1948 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1949 * <p>
1950 * Errors in the handover process are reported to the {@link InCallService} via
1951 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1952 * the involved {@link ConnectionService}s via
1953 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001954 *
1955 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1956 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001957 * @param videoState Indicates the video state desired after the handover (see the
1958 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001959 * @param extras Bundle containing extra information to be passed to the
1960 * {@link ConnectionService}
1961 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001962 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1963 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001964 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1965 }
1966
1967 /**
Hall Liu95d55872017-01-25 17:12:49 -08001968 * Terminate the RTT session on this call. The resulting state change will be notified via
1969 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1970 */
1971 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001972 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001973 }
1974
1975 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001976 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1977 * added.
1978 * <p>
1979 * No assumptions should be made as to how an In-Call UI or service will handle these
1980 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1981 *
1982 * @param extras The extras to add.
1983 */
1984 public final void putExtras(Bundle extras) {
1985 if (extras == null) {
1986 return;
1987 }
1988
1989 if (mExtras == null) {
1990 mExtras = new Bundle();
1991 }
1992 mExtras.putAll(extras);
1993 mInCallAdapter.putExtras(mTelecomCallId, extras);
1994 }
1995
1996 /**
1997 * Adds a boolean extra to this {@link Call}.
1998 *
1999 * @param key The extra key.
2000 * @param value The value.
2001 * @hide
2002 */
2003 public final void putExtra(String key, boolean value) {
2004 if (mExtras == null) {
2005 mExtras = new Bundle();
2006 }
2007 mExtras.putBoolean(key, value);
2008 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2009 }
2010
2011 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002012 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002013 *
2014 * @param key The extra key.
2015 * @param value The value.
2016 * @hide
2017 */
2018 public final void putExtra(String key, int value) {
2019 if (mExtras == null) {
2020 mExtras = new Bundle();
2021 }
2022 mExtras.putInt(key, value);
2023 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2024 }
2025
2026 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002027 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002028 *
2029 * @param key The extra key.
2030 * @param value The value.
2031 * @hide
2032 */
2033 public final void putExtra(String key, String value) {
2034 if (mExtras == null) {
2035 mExtras = new Bundle();
2036 }
2037 mExtras.putString(key, value);
2038 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2039 }
2040
2041 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002042 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002043 *
2044 * @param keys The keys of the extras to remove.
2045 */
2046 public final void removeExtras(List<String> keys) {
2047 if (mExtras != null) {
2048 for (String key : keys) {
2049 mExtras.remove(key);
2050 }
2051 if (mExtras.size() == 0) {
2052 mExtras = null;
2053 }
2054 }
2055 mInCallAdapter.removeExtras(mTelecomCallId, keys);
2056 }
2057
2058 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002059 * Removes extras from this {@link Call}.
2060 *
2061 * @param keys The keys of the extras to remove.
2062 */
2063 public final void removeExtras(String ... keys) {
2064 removeExtras(Arrays.asList(keys));
2065 }
2066
2067 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002068 * Obtains the parent of this {@code Call} in a conference, if any.
2069 *
2070 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
2071 * child of any conference {@code Call}s.
2072 */
2073 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002074 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002075 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002076 }
2077 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07002078 }
2079
2080 /**
2081 * Obtains the children of this conference {@code Call}, if any.
2082 *
2083 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
2084 * {@code List} otherwise.
2085 */
2086 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002087 if (!mChildrenCached) {
2088 mChildrenCached = true;
2089 mChildren.clear();
2090
2091 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002092 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002093 if (call == null) {
2094 // At least one child was still not found, so do not save true for "cached"
2095 mChildrenCached = false;
2096 } else {
2097 mChildren.add(call);
2098 }
2099 }
2100 }
2101
Ihab Awade63fadb2014-07-09 21:52:04 -07002102 return mUnmodifiableChildren;
2103 }
2104
2105 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002106 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
2107 *
2108 * @return The list of conferenceable {@code Call}s.
2109 */
2110 public List<Call> getConferenceableCalls() {
2111 return mUnmodifiableConferenceableCalls;
2112 }
2113
2114 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002115 * Obtains the state of this {@code Call}.
2116 *
2117 * @return A state value, chosen from the {@code STATE_*} constants.
2118 */
2119 public int getState() {
2120 return mState;
2121 }
2122
2123 /**
Hall Liuef98bf82020-01-09 15:22:44 -08002124 * Returns the child {@link Call} in a generic conference that is currently active.
Hall Liu135e53aa2020-02-27 18:34:11 -08002125 *
2126 * A "generic conference" is the mechanism used to support two simultaneous calls on a device
2127 * in CDMA networks. It is effectively equivalent to having one call active and one call on hold
2128 * in GSM or IMS calls. This method returns the currently active call.
2129 *
2130 * In a generic conference, the network exposes the conference to us as a single call, and we
2131 * switch between talking to the two participants using a CDMA flash command. Since the network
2132 * exposes no additional information about the call, the only way we know which caller we're
2133 * currently talking to is by keeping track of the flash commands that we've sent to the
2134 * network.
2135 *
Hall Liuef98bf82020-01-09 15:22:44 -08002136 * For calls that are not generic conferences, or when the generic conference has more than
2137 * 2 children, returns {@code null}.
2138 * @see Details#PROPERTY_GENERIC_CONFERENCE
2139 * @return The active child call.
2140 */
2141 public @Nullable Call getGenericConferenceActiveChildCall() {
2142 if (mActiveGenericConferenceChild != null) {
2143 return mPhone.internalGetCallByTelecomId(mActiveGenericConferenceChild);
2144 }
2145 return null;
2146 }
2147
2148 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002149 * Obtains a list of canned, pre-configured message responses to present to the user as
Tyler Gunn434fc2c2020-10-06 14:23:54 -07002150 * ways of rejecting an incoming {@code Call} using via a text message.
2151 * <p>
2152 * <em>Note:</em> Since canned responses may be loaded from the file system, they are not
2153 * guaranteed to be present when this {@link Call} is first added to the {@link InCallService}
2154 * via {@link InCallService#onCallAdded(Call)}. The callback
2155 * {@link Call.Callback#onCannedTextResponsesLoaded(Call, List)} will be called when/if canned
2156 * responses for the call become available.
Ihab Awade63fadb2014-07-09 21:52:04 -07002157 *
2158 * @see #reject(boolean, String)
2159 *
2160 * @return A list of canned text message responses.
2161 */
2162 public List<String> getCannedTextResponses() {
2163 return mCannedTextResponses;
2164 }
2165
2166 /**
2167 * Obtains an object that can be used to display video from this {@code Call}.
2168 *
Andrew Lee50aca232014-07-22 16:41:54 -07002169 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002170 */
Andrew Lee50aca232014-07-22 16:41:54 -07002171 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002172 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07002173 }
2174
2175 /**
2176 * Obtains an object containing call details.
2177 *
2178 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
2179 * result may be {@code null}.
2180 */
2181 public Details getDetails() {
2182 return mDetails;
2183 }
2184
2185 /**
Hall Liu95d55872017-01-25 17:12:49 -08002186 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
2187 * receive RTT text data, as well as to change the RTT mode.
2188 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
2189 */
2190 public @Nullable RttCall getRttCall() {
2191 return mRttCall;
2192 }
2193
2194 /**
2195 * Returns whether this call has an active RTT connection.
2196 * @return true if there is a connection, false otherwise.
2197 */
2198 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08002199 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08002200 }
2201
2202 /**
Andrew Leeda80c872015-04-15 14:09:50 -07002203 * Registers a callback to this {@code Call}.
2204 *
2205 * @param callback A {@code Callback}.
2206 */
2207 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07002208 registerCallback(callback, new Handler());
2209 }
2210
2211 /**
2212 * Registers a callback to this {@code Call}.
2213 *
2214 * @param callback A {@code Callback}.
2215 * @param handler A handler which command and status changes will be delivered to.
2216 */
2217 public void registerCallback(Callback callback, Handler handler) {
2218 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07002219 // Don't allow new callback registration if the call is already being destroyed.
2220 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002221 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
2222 }
Andrew Leeda80c872015-04-15 14:09:50 -07002223 }
2224
2225 /**
2226 * Unregisters a callback from this {@code Call}.
2227 *
2228 * @param callback A {@code Callback}.
2229 */
2230 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002231 // Don't allow callback deregistration if the call is already being destroyed.
2232 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002233 for (CallbackRecord<Callback> record : mCallbackRecords) {
2234 if (record.getCallback() == callback) {
2235 mCallbackRecords.remove(record);
2236 break;
2237 }
2238 }
Andrew Leeda80c872015-04-15 14:09:50 -07002239 }
2240 }
2241
Santos Cordon3c20d632016-02-25 16:12:35 -08002242 @Override
2243 public String toString() {
2244 return new StringBuilder().
2245 append("Call [id: ").
2246 append(mTelecomCallId).
2247 append(", state: ").
2248 append(stateToString(mState)).
2249 append(", details: ").
2250 append(mDetails).
2251 append("]").toString();
2252 }
2253
2254 /**
2255 * @param state An integer value of a {@code STATE_*} constant.
2256 * @return A string representation of the value.
2257 */
2258 private static String stateToString(int state) {
2259 switch (state) {
2260 case STATE_NEW:
2261 return "NEW";
2262 case STATE_RINGING:
2263 return "RINGING";
2264 case STATE_DIALING:
2265 return "DIALING";
2266 case STATE_ACTIVE:
2267 return "ACTIVE";
2268 case STATE_HOLDING:
2269 return "HOLDING";
2270 case STATE_DISCONNECTED:
2271 return "DISCONNECTED";
2272 case STATE_CONNECTING:
2273 return "CONNECTING";
2274 case STATE_DISCONNECTING:
2275 return "DISCONNECTING";
2276 case STATE_SELECT_PHONE_ACCOUNT:
2277 return "SELECT_PHONE_ACCOUNT";
Hall Liu4e35b642019-10-14 17:50:45 -07002278 case STATE_SIMULATED_RINGING:
2279 return "SIMULATED_RINGING";
2280 case STATE_AUDIO_PROCESSING:
2281 return "AUDIO_PROCESSING";
Santos Cordon3c20d632016-02-25 16:12:35 -08002282 default:
2283 Log.w(Call.class, "Unknown state %d", state);
2284 return "UNKNOWN";
2285 }
2286 }
2287
Andrew Leeda80c872015-04-15 14:09:50 -07002288 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002289 * Adds a listener to this {@code Call}.
2290 *
2291 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002292 * @deprecated Use {@link #registerCallback} instead.
2293 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002294 */
Andrew Leeda80c872015-04-15 14:09:50 -07002295 @Deprecated
2296 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002297 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002298 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002299 }
2300
2301 /**
2302 * Removes a listener from this {@code Call}.
2303 *
2304 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002305 * @deprecated Use {@link #unregisterCallback} instead.
2306 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002307 */
Andrew Leeda80c872015-04-15 14:09:50 -07002308 @Deprecated
2309 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002310 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002311 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002312 }
2313
2314 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002315 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2316 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002317 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002318 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002319 mInCallAdapter = inCallAdapter;
2320 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002321 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002322 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002323 }
2324
2325 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002326 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002327 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002328 mPhone = phone;
2329 mTelecomCallId = telecomCallId;
2330 mInCallAdapter = inCallAdapter;
2331 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002332 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002333 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002334 }
2335
2336 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002337 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002338 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002339 }
2340
2341 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002342 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002343
Ihab Awade63fadb2014-07-09 21:52:04 -07002344 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002345 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002346 boolean detailsChanged = !Objects.equals(mDetails, details);
2347 if (detailsChanged) {
2348 mDetails = details;
2349 }
2350
2351 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002352 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2353 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2354 mCannedTextResponses =
2355 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002356 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002357 }
2358
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002359 IVideoProvider previousVideoProvider = mVideoCallImpl == null ? null :
2360 mVideoCallImpl.getVideoProvider();
2361 IVideoProvider newVideoProvider = parcelableCall.getVideoProvider();
2362
2363 // parcelableCall.isVideoCallProviderChanged is only true when we have a video provider
2364 // specified; so we should check if the actual IVideoProvider changes as well.
2365 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged()
2366 && !Objects.equals(previousVideoProvider, newVideoProvider);
Andrew Lee50aca232014-07-22 16:41:54 -07002367 if (videoCallChanged) {
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002368 if (mVideoCallImpl != null) {
2369 mVideoCallImpl.destroy();
2370 }
2371 mVideoCallImpl = parcelableCall.isVideoCallProviderChanged() ?
2372 parcelableCall.getVideoCallImpl(mCallingPackage, mTargetSdkVersion) : null;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002373 }
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002374
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002375 if (mVideoCallImpl != null) {
2376 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002377 }
2378
Santos Cordone3c507b2015-04-23 14:44:19 -07002379 int state = parcelableCall.getState();
Hall Liu31de23d2019-10-11 15:38:29 -07002380 if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2381 state = Call.STATE_RINGING;
2382 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002383 boolean stateChanged = mState != state;
2384 if (stateChanged) {
2385 mState = state;
2386 }
2387
Santos Cordon823fd3c2014-08-07 18:35:18 -07002388 String parentId = parcelableCall.getParentCallId();
2389 boolean parentChanged = !Objects.equals(mParentId, parentId);
2390 if (parentChanged) {
2391 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002392 }
2393
Santos Cordon823fd3c2014-08-07 18:35:18 -07002394 List<String> childCallIds = parcelableCall.getChildCallIds();
2395 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2396 if (childrenChanged) {
2397 mChildrenIds.clear();
2398 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2399 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002400 }
2401
Hall Liuef98bf82020-01-09 15:22:44 -08002402 String activeChildCallId = parcelableCall.getActiveChildCallId();
2403 boolean activeChildChanged = !Objects.equals(activeChildCallId,
2404 mActiveGenericConferenceChild);
2405 if (activeChildChanged) {
2406 mActiveGenericConferenceChild = activeChildCallId;
2407 }
2408
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002409 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2410 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2411 for (String otherId : conferenceableCallIds) {
2412 if (callIdMap.containsKey(otherId)) {
2413 conferenceableCalls.add(callIdMap.get(otherId));
2414 }
2415 }
2416
2417 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2418 mConferenceableCalls.clear();
2419 mConferenceableCalls.addAll(conferenceableCalls);
2420 fireConferenceableCallsChanged();
2421 }
2422
Hall Liu95d55872017-01-25 17:12:49 -08002423 boolean isRttChanged = false;
2424 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002425 if (parcelableCall.getIsRttCallChanged()
2426 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002427 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2428 InputStreamReader receiveStream = new InputStreamReader(
2429 new ParcelFileDescriptor.AutoCloseInputStream(
2430 parcelableRttCall.getReceiveStream()),
2431 StandardCharsets.UTF_8);
2432 OutputStreamWriter transmitStream = new OutputStreamWriter(
2433 new ParcelFileDescriptor.AutoCloseOutputStream(
2434 parcelableRttCall.getTransmitStream()),
2435 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002436 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002437 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2438 if (mRttCall == null) {
2439 isRttChanged = true;
2440 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2441 rttModeChanged = true;
2442 }
2443 mRttCall = newRttCall;
2444 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2445 && parcelableCall.getIsRttCallChanged()) {
2446 isRttChanged = true;
2447 mRttCall = null;
2448 }
2449
Ihab Awade63fadb2014-07-09 21:52:04 -07002450 // Now we fire updates, ensuring that any client who listens to any of these notifications
2451 // gets the most up-to-date state.
2452
2453 if (stateChanged) {
2454 fireStateChanged(mState);
2455 }
2456 if (detailsChanged) {
2457 fireDetailsChanged(mDetails);
2458 }
2459 if (cannedTextResponsesChanged) {
2460 fireCannedTextResponsesLoaded(mCannedTextResponses);
2461 }
Andrew Lee50aca232014-07-22 16:41:54 -07002462 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002463 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002464 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002465 if (parentChanged) {
2466 fireParentChanged(getParent());
2467 }
Hall Liuef98bf82020-01-09 15:22:44 -08002468 if (childrenChanged || activeChildChanged) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002469 fireChildrenChanged(getChildren());
2470 }
Hall Liu95d55872017-01-25 17:12:49 -08002471 if (isRttChanged) {
2472 fireOnIsRttChanged(mRttCall != null, mRttCall);
2473 }
2474 if (rttModeChanged) {
2475 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2476 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002477
2478 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2479 // remove ourselves from the Phone. Note that we do this after completing all state updates
2480 // so a client can cleanly transition all their UI to the state appropriate for a
2481 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2482 if (mState == STATE_DISCONNECTED) {
2483 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002484 }
2485 }
2486
2487 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002488 final void internalSetPostDialWait(String remaining) {
2489 mRemainingPostDialSequence = remaining;
2490 firePostDialWait(mRemainingPostDialSequence);
2491 }
2492
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002493 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002494 final void internalSetDisconnected() {
2495 if (mState != Call.STATE_DISCONNECTED) {
2496 mState = Call.STATE_DISCONNECTED;
2497 fireStateChanged(mState);
2498 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002499 }
2500 }
2501
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002502 /** {@hide} */
2503 final void internalOnConnectionEvent(String event, Bundle extras) {
2504 fireOnConnectionEvent(event, extras);
2505 }
2506
Hall Liu95d55872017-01-25 17:12:49 -08002507 /** {@hide} */
2508 final void internalOnRttUpgradeRequest(final int requestId) {
2509 for (CallbackRecord<Callback> record : mCallbackRecords) {
2510 final Call call = this;
2511 final Callback callback = record.getCallback();
2512 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2513 }
2514 }
2515
Hall Liu57006aa2017-02-06 10:49:48 -08002516 /** @hide */
2517 final void internalOnRttInitiationFailure(int reason) {
2518 for (CallbackRecord<Callback> record : mCallbackRecords) {
2519 final Call call = this;
2520 final Callback callback = record.getCallback();
2521 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2522 }
2523 }
2524
Sanket Padawe85291f62017-12-01 13:59:27 -08002525 /** {@hide} */
2526 final void internalOnHandoverFailed(int error) {
2527 for (CallbackRecord<Callback> record : mCallbackRecords) {
2528 final Call call = this;
2529 final Callback callback = record.getCallback();
2530 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2531 }
2532 }
2533
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002534 /** {@hide} */
2535 final void internalOnHandoverComplete() {
2536 for (CallbackRecord<Callback> record : mCallbackRecords) {
2537 final Call call = this;
2538 final Callback callback = record.getCallback();
2539 record.getHandler().post(() -> callback.onHandoverComplete(call));
2540 }
2541 }
2542
Andrew Lee011728f2015-04-23 15:47:06 -07002543 private void fireStateChanged(final int newState) {
2544 for (CallbackRecord<Callback> record : mCallbackRecords) {
2545 final Call call = this;
2546 final Callback callback = record.getCallback();
2547 record.getHandler().post(new Runnable() {
2548 @Override
2549 public void run() {
2550 callback.onStateChanged(call, newState);
2551 }
2552 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002553 }
2554 }
2555
Andrew Lee011728f2015-04-23 15:47:06 -07002556 private void fireParentChanged(final Call newParent) {
2557 for (CallbackRecord<Callback> record : mCallbackRecords) {
2558 final Call call = this;
2559 final Callback callback = record.getCallback();
2560 record.getHandler().post(new Runnable() {
2561 @Override
2562 public void run() {
2563 callback.onParentChanged(call, newParent);
2564 }
2565 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002566 }
2567 }
2568
Andrew Lee011728f2015-04-23 15:47:06 -07002569 private void fireChildrenChanged(final List<Call> children) {
2570 for (CallbackRecord<Callback> record : mCallbackRecords) {
2571 final Call call = this;
2572 final Callback callback = record.getCallback();
2573 record.getHandler().post(new Runnable() {
2574 @Override
2575 public void run() {
2576 callback.onChildrenChanged(call, children);
2577 }
2578 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002579 }
2580 }
2581
Andrew Lee011728f2015-04-23 15:47:06 -07002582 private void fireDetailsChanged(final Details details) {
2583 for (CallbackRecord<Callback> record : mCallbackRecords) {
2584 final Call call = this;
2585 final Callback callback = record.getCallback();
2586 record.getHandler().post(new Runnable() {
2587 @Override
2588 public void run() {
2589 callback.onDetailsChanged(call, details);
2590 }
2591 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002592 }
2593 }
2594
Andrew Lee011728f2015-04-23 15:47:06 -07002595 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2596 for (CallbackRecord<Callback> record : mCallbackRecords) {
2597 final Call call = this;
2598 final Callback callback = record.getCallback();
2599 record.getHandler().post(new Runnable() {
2600 @Override
2601 public void run() {
2602 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2603 }
2604 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002605 }
2606 }
2607
Andrew Lee011728f2015-04-23 15:47:06 -07002608 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2609 for (CallbackRecord<Callback> record : mCallbackRecords) {
2610 final Call call = this;
2611 final Callback callback = record.getCallback();
2612 record.getHandler().post(new Runnable() {
2613 @Override
2614 public void run() {
2615 callback.onVideoCallChanged(call, videoCall);
2616 }
2617 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002618 }
2619 }
2620
Andrew Lee011728f2015-04-23 15:47:06 -07002621 private void firePostDialWait(final String remainingPostDialSequence) {
2622 for (CallbackRecord<Callback> record : mCallbackRecords) {
2623 final Call call = this;
2624 final Callback callback = record.getCallback();
2625 record.getHandler().post(new Runnable() {
2626 @Override
2627 public void run() {
2628 callback.onPostDialWait(call, remainingPostDialSequence);
2629 }
2630 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002631 }
2632 }
2633
2634 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002635 /**
2636 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2637 * onCallRemoved callback, we remove this call from the Phone's record
2638 * only once all of the registered onCallDestroyed callbacks are executed.
2639 * All the callbacks get removed from our records as a part of this operation
2640 * since onCallDestroyed is the final callback.
2641 */
2642 final Call call = this;
2643 if (mCallbackRecords.isEmpty()) {
2644 // No callbacks registered, remove the call from Phone's record.
2645 mPhone.internalRemoveCall(call);
2646 }
2647 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002648 final Callback callback = record.getCallback();
2649 record.getHandler().post(new Runnable() {
2650 @Override
2651 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002652 boolean isFinalRemoval = false;
2653 RuntimeException toThrow = null;
2654 try {
2655 callback.onCallDestroyed(call);
2656 } catch (RuntimeException e) {
2657 toThrow = e;
2658 }
2659 synchronized(Call.this) {
2660 mCallbackRecords.remove(record);
2661 if (mCallbackRecords.isEmpty()) {
2662 isFinalRemoval = true;
2663 }
2664 }
2665 if (isFinalRemoval) {
2666 mPhone.internalRemoveCall(call);
2667 }
2668 if (toThrow != null) {
2669 throw toThrow;
2670 }
Andrew Lee011728f2015-04-23 15:47:06 -07002671 }
2672 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002673 }
2674 }
2675
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002676 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002677 for (CallbackRecord<Callback> record : mCallbackRecords) {
2678 final Call call = this;
2679 final Callback callback = record.getCallback();
2680 record.getHandler().post(new Runnable() {
2681 @Override
2682 public void run() {
2683 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2684 }
2685 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002686 }
2687 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002688
2689 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002690 * Notifies listeners of an incoming connection event.
2691 * <p>
2692 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2693 *
2694 * @param event
2695 * @param extras
2696 */
2697 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2698 for (CallbackRecord<Callback> record : mCallbackRecords) {
2699 final Call call = this;
2700 final Callback callback = record.getCallback();
2701 record.getHandler().post(new Runnable() {
2702 @Override
2703 public void run() {
2704 callback.onConnectionEvent(call, event, extras);
2705 }
2706 });
2707 }
2708 }
2709
2710 /**
Hall Liu95d55872017-01-25 17:12:49 -08002711 * Notifies listeners of an RTT on/off change
2712 *
2713 * @param enabled True if RTT is now enabled, false otherwise
2714 */
2715 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2716 for (CallbackRecord<Callback> record : mCallbackRecords) {
2717 final Call call = this;
2718 final Callback callback = record.getCallback();
2719 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2720 }
2721 }
2722
2723 /**
2724 * Notifies listeners of a RTT mode change
2725 *
2726 * @param mode The new RTT mode
2727 */
2728 private void fireOnRttModeChanged(final int mode) {
2729 for (CallbackRecord<Callback> record : mCallbackRecords) {
2730 final Call call = this;
2731 final Callback callback = record.getCallback();
2732 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2733 }
2734 }
2735
2736 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002737 * Determines if two bundles are equal.
2738 *
2739 * @param bundle The original bundle.
2740 * @param newBundle The bundle to compare with.
2741 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2742 */
2743 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2744 if (bundle == null || newBundle == null) {
2745 return bundle == newBundle;
2746 }
2747
2748 if (bundle.size() != newBundle.size()) {
2749 return false;
2750 }
2751
2752 for(String key : bundle.keySet()) {
2753 if (key != null) {
2754 final Object value = bundle.get(key);
2755 final Object newValue = newBundle.get(key);
2756 if (!Objects.equals(value, newValue)) {
2757 return false;
2758 }
2759 }
2760 }
2761 return true;
2762 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002763}