blob: 0469fa56e6485199337ed903fd8f45c383ca9271 [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
Tyler Gunnd11a3152015-03-18 13:09:14 -0700488 //******************************************************************************************
Ravi Palurif4b38e72020-02-05 12:35:41 +0530489 // Next CAPABILITY value: 0x10000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700490 //******************************************************************************************
491
492 /**
493 * Whether the call is currently a conference.
494 */
495 public static final int PROPERTY_CONFERENCE = 0x00000001;
496
497 /**
498 * Whether the call is a generic conference, where we do not know the precise state of
499 * participants in the conference (eg. on CDMA).
500 */
501 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
502
503 /**
504 * Whether the call is made while the device is in emergency callback mode.
505 */
506 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
507
508 /**
509 * Connection is using WIFI.
510 */
511 public static final int PROPERTY_WIFI = 0x00000008;
512
513 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700514 * When set, the UI should indicate to the user that a call is using high definition
515 * audio.
516 * <p>
517 * The underlying {@link ConnectionService} is responsible for reporting this
518 * property. It is important to note that this property is not intended to report the
519 * actual audio codec being used for a Call, but whether the call should be indicated
520 * to the user as high definition.
521 * <p>
522 * The Android Telephony stack reports this property for calls based on a number
523 * of factors, including which audio codec is used and whether a call is using an HD
524 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
525 * and in these cases this property will not be set for a call even if the underlying audio
526 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700527 */
528 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
529
Tony Maka68dcce2015-12-17 09:31:18 +0000530 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100531 * Whether the call is associated with the work profile.
532 */
533 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
534
535 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700536 * When set, indicates that this {@code Call} does not actually exist locally for the
537 * {@link ConnectionService}.
538 * <p>
539 * Consider, for example, a scenario where a user has two phones with the same phone number.
540 * When a user places a call on one device, the telephony stack can represent that call on
541 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700542 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700543 * <p>
544 * An {@link InCallService} will only see calls with this property if it has the
545 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
546 * in its manifest.
547 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700548 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700549 */
550 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
551
Brad Ebinger15847072016-05-18 11:08:36 -0700552 /**
553 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
554 */
555 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
556
Tyler Gunn24e18332017-02-10 09:42:49 -0800557 /**
558 * Indicates that the call is from a self-managed {@link ConnectionService}.
559 * <p>
560 * See also {@link Connection#PROPERTY_SELF_MANAGED}
561 */
562 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
563
Eric Erfanianec881872017-12-06 16:27:53 -0800564 /**
565 * Indicates the call used Assisted Dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700566 *
567 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanianec881872017-12-06 16:27:53 -0800568 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800569 public static final int PROPERTY_ASSISTED_DIALING = 0x00000200;
Eric Erfanianec881872017-12-06 16:27:53 -0800570
Hall Liue9041242018-02-09 16:40:03 -0800571 /**
572 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
573 * {@link RttCall} object that is used to send and receive text.
574 */
575 public static final int PROPERTY_RTT = 0x00000400;
576
Tyler Gunn5bd90852018-09-21 09:37:07 -0700577 /**
578 * Indicates that the call has been identified as the network as an emergency call. This
579 * property may be set for both incoming and outgoing calls which the network identifies as
580 * emergency calls.
581 */
582 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
583
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700584 /**
585 * Indicates that the call is using VoIP audio mode.
586 * <p>
587 * When this property is set, the {@link android.media.AudioManager} audio mode for this
588 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
589 * property is not set, the audio mode for this call will be
590 * {@link android.media.AudioManager#MODE_IN_CALL}.
591 * <p>
592 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
593 * <p>
594 * You can use this property to determine whether an un-answered incoming call or a held
595 * call will use VoIP audio mode (if the call does not currently have focus, the system
596 * audio mode may not reflect the mode the call will use).
597 */
598 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
599
Ravi Paluri80aa2142019-12-02 11:57:37 +0530600 /**
601 * Indicates that the call is an adhoc conference call. This property can be set for both
Grace Jia8587ee52020-07-10 15:42:32 -0700602 * incoming and outgoing calls. An adhoc conference call is formed using
603 * {@link #addConferenceParticipants(List)},
604 * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}, or
605 * {@link TelecomManager#startConference(List, Bundle)}, rather than by merging existing
606 * call using {@link #conference(Call)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530607 */
608 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 0x00002000;
609
Andrew Lee2378ea72015-04-29 14:38:11 -0700610 //******************************************************************************************
Ravi Paluri80aa2142019-12-02 11:57:37 +0530611 // Next PROPERTY value: 0x00004000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700612 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800613
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800614 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700615 private final Uri mHandle;
616 private final int mHandlePresentation;
617 private final String mCallerDisplayName;
618 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700619 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700620 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700621 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800622 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700623 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700624 private final long mConnectTimeMillis;
625 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700626 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700627 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700628 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700629 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700630 private final long mCreationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -0800631 private final String mContactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800632 private final @CallDirection int mCallDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700633 private final @Connection.VerificationStatus int mCallerNumberVerificationStatus;
Ihab Awade63fadb2014-07-09 21:52:04 -0700634
635 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800636 * Whether the supplied capabilities supports the specified capability.
637 *
638 * @param capabilities A bit field of capabilities.
639 * @param capability The capability to check capabilities for.
640 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800641 */
642 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800643 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800644 }
645
646 /**
647 * Whether the capabilities of this {@code Details} supports the specified capability.
648 *
649 * @param capability The capability to check capabilities for.
650 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800651 */
652 public boolean can(int capability) {
653 return can(mCallCapabilities, capability);
654 }
655
656 /**
657 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
658 *
659 * @param capabilities A capability bit field.
660 * @return A human readable string representation.
661 */
662 public static String capabilitiesToString(int capabilities) {
663 StringBuilder builder = new StringBuilder();
664 builder.append("[Capabilities:");
665 if (can(capabilities, CAPABILITY_HOLD)) {
666 builder.append(" CAPABILITY_HOLD");
667 }
668 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
669 builder.append(" CAPABILITY_SUPPORT_HOLD");
670 }
671 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
672 builder.append(" CAPABILITY_MERGE_CONFERENCE");
673 }
674 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
675 builder.append(" CAPABILITY_SWAP_CONFERENCE");
676 }
677 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
678 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
679 }
680 if (can(capabilities, CAPABILITY_MUTE)) {
681 builder.append(" CAPABILITY_MUTE");
682 }
683 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
684 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
685 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700686 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
687 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
688 }
689 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
690 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
691 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700692 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
693 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800694 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700695 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
696 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
697 }
698 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
699 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
700 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800701 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
702 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
703 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700704 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
705 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800706 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500707 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700708 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500709 }
Rekha Kumar07366812015-03-24 16:42:31 -0700710 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
711 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
712 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700713 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
714 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
715 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700716 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
717 builder.append(" CAPABILITY_CAN_PULL_CALL");
718 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530719 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
720 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
721 }
Ravi Paluri404babb2020-01-23 19:02:44 +0530722 if (can(capabilities, CAPABILITY_ADD_PARTICIPANT)) {
723 builder.append(" CAPABILITY_ADD_PARTICIPANT");
724 }
Ravi Palurif4b38e72020-02-05 12:35:41 +0530725 if (can(capabilities, CAPABILITY_TRANSFER)) {
726 builder.append(" CAPABILITY_TRANSFER");
727 }
728 if (can(capabilities, CAPABILITY_TRANSFER_CONSULTATIVE)) {
729 builder.append(" CAPABILITY_TRANSFER_CONSULTATIVE");
730 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800731 builder.append("]");
732 return builder.toString();
733 }
734
735 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700736 * Whether the supplied properties includes the specified property.
737 *
738 * @param properties A bit field of properties.
739 * @param property The property to check properties for.
740 * @return Whether the specified property is supported.
741 */
742 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800743 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700744 }
745
746 /**
747 * Whether the properties of this {@code Details} includes the specified property.
748 *
749 * @param property The property to check properties for.
750 * @return Whether the specified property is supported.
751 */
752 public boolean hasProperty(int property) {
753 return hasProperty(mCallProperties, property);
754 }
755
756 /**
757 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
758 *
759 * @param properties A property bit field.
760 * @return A human readable string representation.
761 */
762 public static String propertiesToString(int properties) {
763 StringBuilder builder = new StringBuilder();
764 builder.append("[Properties:");
765 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
766 builder.append(" PROPERTY_CONFERENCE");
767 }
768 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
769 builder.append(" PROPERTY_GENERIC_CONFERENCE");
770 }
771 if (hasProperty(properties, PROPERTY_WIFI)) {
772 builder.append(" PROPERTY_WIFI");
773 }
774 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
775 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
776 }
777 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700778 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700779 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700780 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
781 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
782 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700783 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700784 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
785 }
Tyler Gunnc9503d62020-01-27 10:30:51 -0800786 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800787 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
788 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700789 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
790 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
791 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700792 if (hasProperty(properties, PROPERTY_RTT)) {
793 builder.append(" PROPERTY_RTT");
794 }
795 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
796 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
797 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530798 if (hasProperty(properties, PROPERTY_IS_ADHOC_CONFERENCE)) {
799 builder.append(" PROPERTY_IS_ADHOC_CONFERENCE");
800 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700801 builder.append("]");
802 return builder.toString();
803 }
804
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800805 /** {@hide} */
Hall Liu31de23d2019-10-11 15:38:29 -0700806 @TestApi
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800807 public String getTelecomCallId() {
808 return mTelecomCallId;
809 }
810
Andrew Lee2378ea72015-04-29 14:38:11 -0700811 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700812 * @return The handle (e.g., phone number) to which the {@code Call} is currently
813 * connected.
814 */
815 public Uri getHandle() {
816 return mHandle;
817 }
818
819 /**
820 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700821 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700822 */
823 public int getHandlePresentation() {
824 return mHandlePresentation;
825 }
826
827 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800828 * The display name for the caller.
829 * <p>
830 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800831 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700832 * @return The display name for the caller.
833 */
834 public String getCallerDisplayName() {
835 return mCallerDisplayName;
836 }
837
838 /**
839 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700840 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700841 */
842 public int getCallerDisplayNamePresentation() {
843 return mCallerDisplayNamePresentation;
844 }
845
846 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700847 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
848 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700849 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700850 public PhoneAccountHandle getAccountHandle() {
851 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700852 }
853
854 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800855 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
856 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700857 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700858 public int getCallCapabilities() {
859 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700860 }
861
862 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700863 * @return A bitmask of the properties of the {@code Call}, as defined by the various
864 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700865 */
866 public int getCallProperties() {
867 return mCallProperties;
868 }
869
870 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800871 * @return a bitmask of the audio routes available for the call.
872 *
873 * @hide
874 */
875 public int getSupportedAudioRoutes() {
876 return mSupportedAudioRoutes;
877 }
878
879 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700880 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700881 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700882 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700883 public DisconnectCause getDisconnectCause() {
884 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700885 }
886
887 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700888 * Returns the time the {@link Call} connected (i.e. became active). This information is
889 * updated periodically, but user interfaces should not rely on this to display the "call
890 * time clock". For the time when the call was first added to Telecom, see
891 * {@link #getCreationTimeMillis()}.
892 *
893 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700894 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700895 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700896 return mConnectTimeMillis;
897 }
898
899 /**
900 * @return Information about any calling gateway the {@code Call} may be using.
901 */
902 public GatewayInfo getGatewayInfo() {
903 return mGatewayInfo;
904 }
905
Andrew Lee7a341382014-07-15 17:05:08 -0700906 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700907 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700908 */
909 public int getVideoState() {
910 return mVideoState;
911 }
912
Ihab Awad5d0410f2014-07-30 10:07:40 -0700913 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700914 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700915 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700916 */
917 public StatusHints getStatusHints() {
918 return mStatusHints;
919 }
920
Nancy Chen10798dc2014-08-08 14:00:25 -0700921 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700922 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700923 */
924 public Bundle getExtras() {
925 return mExtras;
926 }
927
Santos Cordon6b7f9552015-05-27 17:21:45 -0700928 /**
929 * @return The extras used with the original intent to place this call.
930 */
931 public Bundle getIntentExtras() {
932 return mIntentExtras;
933 }
934
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700935 /**
936 * Returns the time when the call was first created and added to Telecom. This is the same
937 * time that is logged as the start time in the Call Log (see
938 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
939 * (became active), see {@link #getConnectTimeMillis()}.
940 *
941 * @return The creation time of the call, in millis since the epoch.
942 */
943 public long getCreationTimeMillis() {
944 return mCreationTimeMillis;
945 }
946
Tyler Gunnd081f042018-12-04 12:56:45 -0800947 /**
Hall Liuef98bf82020-01-09 15:22:44 -0800948 * Returns the name of the caller on the remote end, as derived from a
949 * {@link android.provider.ContactsContract} lookup of the call's handle.
950 * @return The name of the caller, or {@code null} if the lookup is not yet complete, if
951 * there's no contacts entry for the caller, or if the {@link InCallService} does
952 * not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
953 */
954 public @Nullable String getContactDisplayName() {
955 return mContactDisplayName;
956 }
957
958 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -0800959 * Indicates whether the call is an incoming or outgoing call.
960 * @return The call's direction.
961 */
962 public @CallDirection int getCallDirection() {
963 return mCallDirection;
964 }
965
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700966 /**
967 * Gets the verification status for the phone number of an incoming call as identified in
968 * ATIS-1000082.
969 * @return the verification status.
970 */
971 public @Connection.VerificationStatus int getCallerNumberVerificationStatus() {
972 return mCallerNumberVerificationStatus;
973 }
974
Ihab Awade63fadb2014-07-09 21:52:04 -0700975 @Override
976 public boolean equals(Object o) {
977 if (o instanceof Details) {
978 Details d = (Details) o;
979 return
980 Objects.equals(mHandle, d.mHandle) &&
981 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
982 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
983 Objects.equals(mCallerDisplayNamePresentation,
984 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700985 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700986 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700987 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700988 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700989 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700990 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700991 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700992 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700993 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700994 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -0800995 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Hall Liuef98bf82020-01-09 15:22:44 -0800996 Objects.equals(mContactDisplayName, d.mContactDisplayName) &&
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700997 Objects.equals(mCallDirection, d.mCallDirection) &&
998 Objects.equals(mCallerNumberVerificationStatus,
999 d.mCallerNumberVerificationStatus);
Ihab Awade63fadb2014-07-09 21:52:04 -07001000 }
1001 return false;
1002 }
1003
1004 @Override
1005 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001006 return Objects.hash(mHandle,
1007 mHandlePresentation,
1008 mCallerDisplayName,
1009 mCallerDisplayNamePresentation,
1010 mAccountHandle,
1011 mCallCapabilities,
1012 mCallProperties,
1013 mDisconnectCause,
1014 mConnectTimeMillis,
1015 mGatewayInfo,
1016 mVideoState,
1017 mStatusHints,
1018 mExtras,
1019 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001020 mCreationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001021 mContactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001022 mCallDirection,
1023 mCallerNumberVerificationStatus);
Ihab Awade63fadb2014-07-09 21:52:04 -07001024 }
1025
1026 /** {@hide} */
1027 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001028 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -07001029 Uri handle,
1030 int handlePresentation,
1031 String callerDisplayName,
1032 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -07001033 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -07001034 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -07001035 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001036 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -07001037 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -07001038 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -07001039 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -07001040 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -07001041 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001042 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001043 long creationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001044 String contactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001045 int callDirection,
1046 int callerNumberVerificationStatus) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001047 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001048 mHandle = handle;
1049 mHandlePresentation = handlePresentation;
1050 mCallerDisplayName = callerDisplayName;
1051 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -07001052 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -07001053 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -07001054 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001055 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -07001056 mConnectTimeMillis = connectTimeMillis;
1057 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -07001058 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -07001059 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -07001060 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001061 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001062 mCreationTimeMillis = creationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -08001063 mContactDisplayName = contactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -08001064 mCallDirection = callDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001065 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
Ihab Awade63fadb2014-07-09 21:52:04 -07001066 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001067
1068 /** {@hide} */
1069 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
1070 return new Details(
1071 parcelableCall.getId(),
1072 parcelableCall.getHandle(),
1073 parcelableCall.getHandlePresentation(),
1074 parcelableCall.getCallerDisplayName(),
1075 parcelableCall.getCallerDisplayNamePresentation(),
1076 parcelableCall.getAccountHandle(),
1077 parcelableCall.getCapabilities(),
1078 parcelableCall.getProperties(),
1079 parcelableCall.getDisconnectCause(),
1080 parcelableCall.getConnectTimeMillis(),
1081 parcelableCall.getGatewayInfo(),
1082 parcelableCall.getVideoState(),
1083 parcelableCall.getStatusHints(),
1084 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001085 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -08001086 parcelableCall.getCreationTimeMillis(),
Hall Liuef98bf82020-01-09 15:22:44 -08001087 parcelableCall.getContactDisplayName(),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001088 parcelableCall.getCallDirection(),
1089 parcelableCall.getCallerNumberVerificationStatus());
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001090 }
Santos Cordon3c20d632016-02-25 16:12:35 -08001091
1092 @Override
1093 public String toString() {
1094 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001095 sb.append("[id: ");
1096 sb.append(mTelecomCallId);
1097 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -08001098 sb.append(mAccountHandle);
1099 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001100 sb.append(Log.piiHandle(mHandle));
1101 sb.append(", hdlPres: ");
1102 sb.append(mHandlePresentation);
1103 sb.append(", videoState: ");
1104 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -08001105 sb.append(", caps: ");
1106 sb.append(capabilitiesToString(mCallCapabilities));
1107 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001108 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001109 sb.append("]");
1110 return sb.toString();
1111 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001112 }
1113
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001114 /**
1115 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1116 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1117 * implementation.
1118 * <p>
1119 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1120 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1121 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1122 * {@link Callback} implementation, if desired.
1123 * <p>
1124 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1125 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1126 * (typically in {@link InCallService#onCallRemoved(Call)}).
1127 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1128 * reach your implementation of {@link Callback}, so it is important to register your callback
1129 * as soon as your {@link InCallService} is notified of a new call via
1130 * {@link InCallService#onCallAdded(Call)}.
1131 */
Andrew Leeda80c872015-04-15 14:09:50 -07001132 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001133 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001134 * @hide
1135 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001136 @IntDef(prefix = { "HANDOVER_" },
1137 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001138 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001139 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001140 @Retention(RetentionPolicy.SOURCE)
1141 public @interface HandoverFailureErrors {}
1142
1143 /**
1144 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001145 * to handover the call to rejects the handover request.
1146 * <p>
1147 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1148 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1149 * {@code null} {@link Connection} from
1150 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1151 * ConnectionRequest)}.
1152 * <p>
1153 * For more information on call handovers, see
1154 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001155 */
1156 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1157
1158 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001159 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1160 * is initiated but the source or destination app does not support handover.
1161 * <p>
1162 * Will be returned when a handover is requested via
1163 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1164 * {@link PhoneAccountHandle} does not declare
1165 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1166 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1167 * {@link Details#getAccountHandle()}) does not declare
1168 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1169 * <p>
1170 * For more information on call handovers, see
1171 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001172 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001173 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001174
1175 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001176 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1177 * user rejects the handover request.
1178 * <p>
1179 * For more information on call handovers, see
1180 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001181 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001182 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001183
Sanket Padawe85291f62017-12-01 13:59:27 -08001184 /**
1185 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1186 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001187 * <p>
1188 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1189 * called on an emergency call, or if any other call is an emergency call.
1190 * <p>
1191 * Handovers are not permitted while there are ongoing emergency calls.
1192 * <p>
1193 * For more information on call handovers, see
1194 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001195 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001196 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001197
Tyler Gunn9d127732018-03-02 15:45:51 -08001198 /**
1199 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1200 * fails for an unknown reason.
1201 * <p>
1202 * For more information on call handovers, see
1203 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1204 */
1205 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001206
1207 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001208 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1209 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001210 * @param call The {@code Call} invoking this method.
1211 * @param state The new state of the {@code Call}.
1212 */
1213 public void onStateChanged(Call call, int state) {}
1214
1215 /**
1216 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1217 *
1218 * @param call The {@code Call} invoking this method.
1219 * @param parent The new parent of the {@code Call}.
1220 */
1221 public void onParentChanged(Call call, Call parent) {}
1222
1223 /**
1224 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1225 *
1226 * @param call The {@code Call} invoking this method.
1227 * @param children The new children of the {@code Call}.
1228 */
1229 public void onChildrenChanged(Call call, List<Call> children) {}
1230
1231 /**
1232 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1233 *
1234 * @param call The {@code Call} invoking this method.
1235 * @param details A {@code Details} object describing the {@code Call}.
1236 */
1237 public void onDetailsChanged(Call call, Details details) {}
1238
1239 /**
1240 * Invoked when the text messages that can be used as responses to the incoming
1241 * {@code Call} are loaded from the relevant database.
1242 * See {@link #getCannedTextResponses()}.
1243 *
1244 * @param call The {@code Call} invoking this method.
1245 * @param cannedTextResponses The text messages useable as responses.
1246 */
1247 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1248
1249 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001250 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1251 * character. This causes the post-dial signals to stop pending user confirmation. An
1252 * implementation should present this choice to the user and invoke
1253 * {@link #postDialContinue(boolean)} when the user makes the choice.
1254 *
1255 * @param call The {@code Call} invoking this method.
1256 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1257 */
1258 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1259
1260 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001261 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001262 *
1263 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001264 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001265 */
Andrew Lee50aca232014-07-22 16:41:54 -07001266 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001267
1268 /**
1269 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1270 * up their UI for the {@code Call} in response to state transitions. Specifically,
1271 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1272 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1273 * clients should wait for this method to be invoked.
1274 *
1275 * @param call The {@code Call} being destroyed.
1276 */
1277 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001278
1279 /**
1280 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1281 * conferenced.
1282 *
1283 * @param call The {@code Call} being updated.
1284 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1285 * conferenced.
1286 */
1287 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001288
1289 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001290 * Invoked when a {@link Call} receives an event from its associated {@link Connection} or
1291 * {@link Conference}.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001292 * <p>
1293 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1294 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1295 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1296 * possible that a {@link ConnectionService} has defined its own Connection events which a
1297 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001298 * <p>
Tyler Gunn5567d742019-10-31 13:04:37 -07001299 * See {@link Connection#sendConnectionEvent(String, Bundle)},
1300 * {@link Conference#sendConferenceEvent(String, Bundle)}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001301 *
1302 * @param call The {@code Call} receiving the event.
1303 * @param event The event.
1304 * @param extras Extras associated with the connection event.
1305 */
1306 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001307
1308 /**
1309 * Invoked when the RTT mode changes for this call.
1310 * @param call The call whose RTT mode has changed.
1311 * @param mode the new RTT mode, one of
1312 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1313 * or {@link RttCall#RTT_MODE_VCO}
1314 */
1315 public void onRttModeChanged(Call call, int mode) {}
1316
1317 /**
1318 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1319 * @param call The call whose RTT status has changed.
1320 * @param enabled whether RTT is now enabled or disabled
1321 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1322 * on, null otherwise.
1323 */
1324 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1325
1326 /**
1327 * Invoked when the remote end of the connection has requested that an RTT communication
1328 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1329 * with the same ID that this method is invoked with.
1330 * @param call The call which the RTT request was placed on
1331 * @param id The ID of the request.
1332 */
1333 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001334
1335 /**
1336 * Invoked when the RTT session failed to initiate for some reason, including rejection
1337 * by the remote party.
1338 * @param call The call which the RTT initiation failure occurred on.
1339 * @param reason One of the status codes defined in
1340 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1341 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1342 */
1343 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001344
1345 /**
1346 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1347 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001348 * <p>
1349 * For a full discussion of the handover process and the APIs involved, see
1350 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1351 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001352 * @param call The call which had initiated handover.
1353 */
1354 public void onHandoverComplete(Call call) {}
1355
1356 /**
1357 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1358 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001359 * <p>
1360 * For a full discussion of the handover process and the APIs involved, see
1361 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1362 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001363 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001364 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001365 */
1366 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001367 }
1368
1369 /**
1370 * A class that holds the state that describes the state of the RTT channel to the remote
1371 * party, if it is active.
1372 */
1373 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001374 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001375 @Retention(RetentionPolicy.SOURCE)
1376 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1377 public @interface RttAudioMode {}
1378
1379 /**
1380 * For metrics use. Default value in the proto.
1381 * @hide
1382 */
1383 public static final int RTT_MODE_INVALID = 0;
1384
1385 /**
1386 * Indicates that there should be a bidirectional audio stream between the two parties
1387 * on the call.
1388 */
1389 public static final int RTT_MODE_FULL = 1;
1390
1391 /**
1392 * Indicates that the local user should be able to hear the audio stream from the remote
1393 * user, but not vice versa. Equivalent to muting the microphone.
1394 */
1395 public static final int RTT_MODE_HCO = 2;
1396
1397 /**
1398 * Indicates that the remote user should be able to hear the audio stream from the local
1399 * user, but not vice versa. Equivalent to setting the volume to zero.
1400 */
1401 public static final int RTT_MODE_VCO = 3;
1402
1403 private static final int READ_BUFFER_SIZE = 1000;
1404
1405 private InputStreamReader mReceiveStream;
1406 private OutputStreamWriter mTransmitStream;
1407 private int mRttMode;
1408 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001409 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001410 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1411
1412 /**
1413 * @hide
1414 */
Hall Liu57006aa2017-02-06 10:49:48 -08001415 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1416 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1417 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001418 mReceiveStream = receiveStream;
1419 mTransmitStream = transmitStream;
1420 mRttMode = mode;
1421 mInCallAdapter = inCallAdapter;
1422 }
1423
1424 /**
1425 * Returns the current RTT audio mode.
1426 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1427 * {@link #RTT_MODE_HCO}.
1428 */
1429 public int getRttAudioMode() {
1430 return mRttMode;
1431 }
1432
1433 /**
1434 * Sets the RTT audio mode. The requested mode change will be communicated through
1435 * {@link Callback#onRttModeChanged(Call, int)}.
1436 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1437 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1438 */
1439 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001440 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001441 }
1442
1443 /**
1444 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1445 * RTT transmits text in real-time, this method should be called once for each character
1446 * the user enters into the device.
1447 *
1448 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1449 * lead to interleaved text.
1450 * @param input The message to send to the remote user.
1451 */
1452 public void write(String input) throws IOException {
1453 mTransmitStream.write(input);
1454 mTransmitStream.flush();
1455 }
1456
1457 /**
1458 * Reads a string from the remote user, blocking if there is no data available. Returns
1459 * {@code null} if the RTT conversation has been terminated and there is no further data
1460 * to read.
1461 *
1462 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1463 * lead to interleaved text.
1464 * @return A string containing text sent by the remote user, or {@code null} if the
1465 * conversation has been terminated or if there was an error while reading.
1466 */
Hall Liub1c8a772017-07-17 17:04:41 -07001467 public String read() {
1468 try {
1469 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1470 if (numRead < 0) {
1471 return null;
1472 }
1473 return new String(mReadBuffer, 0, numRead);
1474 } catch (IOException e) {
1475 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001476 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001477 }
Hall Liuffa4a812017-03-02 16:11:00 -08001478 }
1479
1480 /**
1481 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1482 * be read.
1483 * @return A string containing text entered by the user, or {@code null} if the user has
1484 * not entered any new text yet.
1485 */
1486 public String readImmediately() throws IOException {
1487 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001488 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1489 if (numRead < 0) {
1490 return null;
1491 }
1492 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001493 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001494 return null;
1495 }
1496 }
Hall Liue9041242018-02-09 16:40:03 -08001497
1498 /**
1499 * Closes the underlying file descriptors
1500 * @hide
1501 */
1502 public void close() {
1503 try {
1504 mReceiveStream.close();
1505 } catch (IOException e) {
1506 // ignore
1507 }
1508 try {
1509 mTransmitStream.close();
1510 } catch (IOException e) {
1511 // ignore
1512 }
1513 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001514 }
1515
Andrew Leeda80c872015-04-15 14:09:50 -07001516 /**
1517 * @deprecated Use {@code Call.Callback} instead.
1518 * @hide
1519 */
1520 @Deprecated
1521 @SystemApi
1522 public static abstract class Listener extends Callback { }
1523
Ihab Awade63fadb2014-07-09 21:52:04 -07001524 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001525 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001526 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001527 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001528 private final List<Call> mChildren = new ArrayList<>();
1529 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001530 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001531 private final List<Call> mConferenceableCalls = new ArrayList<>();
1532 private final List<Call> mUnmodifiableConferenceableCalls =
1533 Collections.unmodifiableList(mConferenceableCalls);
1534
Santos Cordon823fd3c2014-08-07 18:35:18 -07001535 private boolean mChildrenCached;
1536 private String mParentId = null;
Hall Liuef98bf82020-01-09 15:22:44 -08001537 private String mActiveGenericConferenceChild = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001538 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001539 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001540 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001541 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001542 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001543 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001544 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001545 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001546 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001547
1548 /**
1549 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1550 *
1551 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1552 * remaining or this {@code Call} is not in a post-dial state.
1553 */
1554 public String getRemainingPostDialSequence() {
1555 return mRemainingPostDialSequence;
1556 }
1557
1558 /**
1559 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001560 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001561 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001562 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001563 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001564 }
1565
1566 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301567 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1568 *
1569 * @param address The address to which the call will be deflected.
1570 */
1571 public void deflect(Uri address) {
1572 mInCallAdapter.deflectCall(mTelecomCallId, address);
1573 }
1574
1575 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001576 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1577 *
1578 * @param rejectWithMessage Whether to reject with a text message.
1579 * @param textMessage An optional text message with which to respond.
1580 */
1581 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001582 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001583 }
1584
1585 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001586 * Instructs the {@link ConnectionService} providing this {@link #STATE_RINGING} call that the
1587 * user has chosen to reject the call and has indicated a reason why the call is being rejected.
1588 *
1589 * @param rejectReason the reason the call is being rejected.
1590 */
1591 public void reject(@RejectReason int rejectReason) {
1592 mInCallAdapter.rejectCall(mTelecomCallId, rejectReason);
1593 }
1594
1595 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05301596 * Instructs this {@code Call} to be transferred to another number.
1597 *
1598 * @param targetNumber The address to which the call will be transferred.
Tyler Gunn460360d2020-07-29 10:21:45 -07001599 * @param isConfirmationRequired if {@code true} it will initiate a confirmed transfer,
1600 * if {@code false}, it will initiate an unconfirmed transfer.
Ravi Palurif4b38e72020-02-05 12:35:41 +05301601 *
1602 * @hide
1603 */
1604 public void transfer(@NonNull Uri targetNumber, boolean isConfirmationRequired) {
1605 mInCallAdapter.transferCall(mTelecomCallId, targetNumber, isConfirmationRequired);
1606 }
1607
1608 /**
1609 * Instructs this {@code Call} to be transferred to another ongoing call.
1610 * This will initiate CONSULTATIVE transfer.
1611 * @param toCall The other ongoing {@code Call} to which this call will be transferred.
1612 *
1613 * @hide
1614 */
1615 public void transfer(@NonNull android.telecom.Call toCall) {
1616 mInCallAdapter.transferCall(mTelecomCallId, toCall.mTelecomCallId);
1617 }
1618
1619 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001620 * Instructs this {@code Call} to disconnect.
1621 */
1622 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001623 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001624 }
1625
1626 /**
1627 * Instructs this {@code Call} to go on hold.
1628 */
1629 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001630 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001631 }
1632
1633 /**
1634 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1635 */
1636 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001637 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001638 }
1639
1640 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001641 * Instructs Telecom to put the call into the background audio processing state.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001642 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001643 * This method can be called either when the call is in {@link #STATE_RINGING} or
1644 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1645 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1646 * order to capture and play audio on the call stream.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001647 * <p>
Hall Liu6dfa2492019-10-01 17:20:39 -07001648 * This method can only be called by the default dialer app.
Tyler Gunn460b7d42020-05-15 10:19:32 -07001649 * <p>
1650 * Apps built with SDK version {@link android.os.Build.VERSION_CODES#R} or later which are using
1651 * the microphone as part of audio processing should specify the foreground service type using
1652 * the attribute {@link android.R.attr#foregroundServiceType} in the {@link InCallService}
1653 * service element of the app's manifest file.
1654 * The {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_MICROPHONE} attribute should be specified.
1655 * @see <a href="https://developer.android.com/preview/privacy/foreground-service-types">
1656 * the Android Developer Site</a> for more information.
Hall Liu6dfa2492019-10-01 17:20:39 -07001657 * @hide
1658 */
1659 @SystemApi
1660 @TestApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001661 public void enterBackgroundAudioProcessing() {
1662 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1663 throw new IllegalStateException("Call must be active or ringing");
1664 }
1665 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1666 }
1667
1668 /**
1669 * Instructs Telecom to come out of the background audio processing state requested by
1670 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1671 *
1672 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1673 *
1674 * @param shouldRing If true, Telecom will put the call into the
1675 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1676 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1677 * immediately.
1678 * @hide
1679 */
1680 @SystemApi
1681 @TestApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001682 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1683 if (mState != STATE_AUDIO_PROCESSING) {
1684 throw new IllegalStateException("Call must in the audio processing state");
1685 }
1686 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1687 }
1688
1689 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001690 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1691 *
1692 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1693 *
1694 * @param digit A character representing the DTMF digit for which to play the tone. This
1695 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1696 */
1697 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001698 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001699 }
1700
1701 /**
1702 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1703 * currently playing.
1704 *
1705 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1706 * currently playing, this method will do nothing.
1707 */
1708 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001709 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001710 }
1711
1712 /**
1713 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1714 *
1715 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1716 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001717 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001718 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001719 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1720 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001721 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001722 * {@code Call} will pause playing the tones and notify callbacks via
1723 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001724 * should display to the user an indication of this state and an affordance to continue
1725 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1726 * app should invoke the {@link #postDialContinue(boolean)} method.
1727 *
1728 * @param proceed Whether or not to continue with the post-dial sequence.
1729 */
1730 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001731 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001732 }
1733
1734 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001735 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001736 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001737 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001738 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1739 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001740
1741 }
1742
1743 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001744 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001745 *
1746 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001747 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001748 public void conference(Call callToConferenceWith) {
1749 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001750 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001751 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001752 }
1753
1754 /**
1755 * Instructs this {@code Call} to split from any conference call with which it may be
1756 * connected.
1757 */
1758 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001759 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001760 }
1761
1762 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001763 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001764 */
1765 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001766 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001767 }
1768
1769 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001770 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001771 */
1772 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001773 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001774 }
1775
1776 /**
Ravi Paluri404babb2020-01-23 19:02:44 +05301777 * Pulls participants to existing call by forming a conference call.
1778 * See {@link Details#CAPABILITY_ADD_PARTICIPANT}.
1779 *
1780 * @param participants participants to be pulled to existing call.
1781 */
1782 public void addConferenceParticipants(@NonNull List<Uri> participants) {
1783 mInCallAdapter.addConferenceParticipants(mTelecomCallId, participants);
1784 }
1785
1786 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001787 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1788 * device.
1789 * <p>
1790 * Calls to this method are ignored if the call does not have the
1791 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1792 * <p>
1793 * An {@link InCallService} will only see calls which support this method if it has the
1794 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1795 * in its manifest.
1796 */
1797 public void pullExternalCall() {
1798 // If this isn't an external call, ignore the request.
1799 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1800 return;
1801 }
1802
1803 mInCallAdapter.pullExternalCall(mTelecomCallId);
1804 }
1805
1806 /**
1807 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1808 * the {@link ConnectionService}.
1809 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001810 * Call events are used to communicate point in time information from an {@link InCallService}
1811 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1812 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1813 * {@link ConnectionService}.
1814 * <p>
1815 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1816 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1817 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001818 * Events are exposed to {@link ConnectionService} implementations via
1819 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1820 * <p>
1821 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001822 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1823 * ignore some events altogether.
1824 * <p>
1825 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1826 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1827 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1828 * they define their own event types in this namespace. When defining a custom event type,
1829 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1830 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1831 * <p>
1832 * When defining events and the associated extras, it is important to keep their behavior
1833 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1834 * events/extras should me maintained to ensure backwards compatibility with older
1835 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001836 *
1837 * @param event The connection event.
1838 * @param extras Bundle containing extra information associated with the event.
1839 */
1840 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001841 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001842 }
1843
1844 /**
Hall Liu95d55872017-01-25 17:12:49 -08001845 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1846 * guaranteed, and notification of success will be via the
1847 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1848 */
1849 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001850 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001851 }
1852
1853 /**
1854 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1855 * callback.
1856 * The ID used here should be the same as the ID that was received via the callback.
1857 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1858 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1859 */
1860 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001861 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001862 }
1863
1864 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001865 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1866 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1867 * handover.
1868 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001869 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1870 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1871 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1872 * is referred to as the source of the handover, and the video calling app is referred to as the
1873 * destination.
1874 * <p>
1875 * When considering a handover scenario the device this method is called on is considered the
1876 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1877 * other device is considered the <em>receiving</em> device.
1878 * <p>
1879 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1880 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1881 * and invoke
1882 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1883 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1884 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1885 * At this point the app should display UI to indicate to the user that a call
1886 * handover is in process.
1887 * <p>
1888 * The destination app is responsible for communicating the handover request from the
1889 * <em>initiating</em> device to the <em>receiving</em> device.
1890 * <p>
1891 * When the app on the <em>receiving</em> device receives the handover request, it calls
1892 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1893 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1894 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1895 * choose whether they want to continue their call in the destination app.
1896 * <p>
1897 * When the destination app on the <em>receiving</em> device calls
1898 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1899 * {@link ConnectionService} and call
1900 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1901 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1902 * {@link Connection} to represent the handover call.
1903 * <p>
1904 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1905 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1906 * original call. If the user rejects the handover, the app calls
1907 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1908 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1909 * <p>
1910 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1911 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1912 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1913 * <p>
1914 * Errors in the handover process are reported to the {@link InCallService} via
1915 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1916 * the involved {@link ConnectionService}s via
1917 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001918 *
1919 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1920 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001921 * @param videoState Indicates the video state desired after the handover (see the
1922 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001923 * @param extras Bundle containing extra information to be passed to the
1924 * {@link ConnectionService}
1925 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001926 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1927 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001928 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1929 }
1930
1931 /**
Hall Liu95d55872017-01-25 17:12:49 -08001932 * Terminate the RTT session on this call. The resulting state change will be notified via
1933 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1934 */
1935 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001936 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001937 }
1938
1939 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001940 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1941 * added.
1942 * <p>
1943 * No assumptions should be made as to how an In-Call UI or service will handle these
1944 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1945 *
1946 * @param extras The extras to add.
1947 */
1948 public final void putExtras(Bundle extras) {
1949 if (extras == null) {
1950 return;
1951 }
1952
1953 if (mExtras == null) {
1954 mExtras = new Bundle();
1955 }
1956 mExtras.putAll(extras);
1957 mInCallAdapter.putExtras(mTelecomCallId, extras);
1958 }
1959
1960 /**
1961 * Adds a boolean extra to this {@link Call}.
1962 *
1963 * @param key The extra key.
1964 * @param value The value.
1965 * @hide
1966 */
1967 public final void putExtra(String key, boolean value) {
1968 if (mExtras == null) {
1969 mExtras = new Bundle();
1970 }
1971 mExtras.putBoolean(key, value);
1972 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1973 }
1974
1975 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001976 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001977 *
1978 * @param key The extra key.
1979 * @param value The value.
1980 * @hide
1981 */
1982 public final void putExtra(String key, int value) {
1983 if (mExtras == null) {
1984 mExtras = new Bundle();
1985 }
1986 mExtras.putInt(key, value);
1987 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1988 }
1989
1990 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001991 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001992 *
1993 * @param key The extra key.
1994 * @param value The value.
1995 * @hide
1996 */
1997 public final void putExtra(String key, String value) {
1998 if (mExtras == null) {
1999 mExtras = new Bundle();
2000 }
2001 mExtras.putString(key, value);
2002 mInCallAdapter.putExtra(mTelecomCallId, key, value);
2003 }
2004
2005 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002006 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002007 *
2008 * @param keys The keys of the extras to remove.
2009 */
2010 public final void removeExtras(List<String> keys) {
2011 if (mExtras != null) {
2012 for (String key : keys) {
2013 mExtras.remove(key);
2014 }
2015 if (mExtras.size() == 0) {
2016 mExtras = null;
2017 }
2018 }
2019 mInCallAdapter.removeExtras(mTelecomCallId, keys);
2020 }
2021
2022 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002023 * Removes extras from this {@link Call}.
2024 *
2025 * @param keys The keys of the extras to remove.
2026 */
2027 public final void removeExtras(String ... keys) {
2028 removeExtras(Arrays.asList(keys));
2029 }
2030
2031 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002032 * Obtains the parent of this {@code Call} in a conference, if any.
2033 *
2034 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
2035 * child of any conference {@code Call}s.
2036 */
2037 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002038 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002039 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002040 }
2041 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07002042 }
2043
2044 /**
2045 * Obtains the children of this conference {@code Call}, if any.
2046 *
2047 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
2048 * {@code List} otherwise.
2049 */
2050 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002051 if (!mChildrenCached) {
2052 mChildrenCached = true;
2053 mChildren.clear();
2054
2055 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002056 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002057 if (call == null) {
2058 // At least one child was still not found, so do not save true for "cached"
2059 mChildrenCached = false;
2060 } else {
2061 mChildren.add(call);
2062 }
2063 }
2064 }
2065
Ihab Awade63fadb2014-07-09 21:52:04 -07002066 return mUnmodifiableChildren;
2067 }
2068
2069 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002070 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
2071 *
2072 * @return The list of conferenceable {@code Call}s.
2073 */
2074 public List<Call> getConferenceableCalls() {
2075 return mUnmodifiableConferenceableCalls;
2076 }
2077
2078 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002079 * Obtains the state of this {@code Call}.
2080 *
2081 * @return A state value, chosen from the {@code STATE_*} constants.
2082 */
2083 public int getState() {
2084 return mState;
2085 }
2086
2087 /**
Hall Liuef98bf82020-01-09 15:22:44 -08002088 * Returns the child {@link Call} in a generic conference that is currently active.
Hall Liu135e53aa2020-02-27 18:34:11 -08002089 *
2090 * A "generic conference" is the mechanism used to support two simultaneous calls on a device
2091 * in CDMA networks. It is effectively equivalent to having one call active and one call on hold
2092 * in GSM or IMS calls. This method returns the currently active call.
2093 *
2094 * In a generic conference, the network exposes the conference to us as a single call, and we
2095 * switch between talking to the two participants using a CDMA flash command. Since the network
2096 * exposes no additional information about the call, the only way we know which caller we're
2097 * currently talking to is by keeping track of the flash commands that we've sent to the
2098 * network.
2099 *
Hall Liuef98bf82020-01-09 15:22:44 -08002100 * For calls that are not generic conferences, or when the generic conference has more than
2101 * 2 children, returns {@code null}.
2102 * @see Details#PROPERTY_GENERIC_CONFERENCE
2103 * @return The active child call.
2104 */
2105 public @Nullable Call getGenericConferenceActiveChildCall() {
2106 if (mActiveGenericConferenceChild != null) {
2107 return mPhone.internalGetCallByTelecomId(mActiveGenericConferenceChild);
2108 }
2109 return null;
2110 }
2111
2112 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002113 * Obtains a list of canned, pre-configured message responses to present to the user as
2114 * ways of rejecting this {@code Call} using via a text message.
2115 *
2116 * @see #reject(boolean, String)
2117 *
2118 * @return A list of canned text message responses.
2119 */
2120 public List<String> getCannedTextResponses() {
2121 return mCannedTextResponses;
2122 }
2123
2124 /**
2125 * Obtains an object that can be used to display video from this {@code Call}.
2126 *
Andrew Lee50aca232014-07-22 16:41:54 -07002127 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002128 */
Andrew Lee50aca232014-07-22 16:41:54 -07002129 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002130 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07002131 }
2132
2133 /**
2134 * Obtains an object containing call details.
2135 *
2136 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
2137 * result may be {@code null}.
2138 */
2139 public Details getDetails() {
2140 return mDetails;
2141 }
2142
2143 /**
Hall Liu95d55872017-01-25 17:12:49 -08002144 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
2145 * receive RTT text data, as well as to change the RTT mode.
2146 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
2147 */
2148 public @Nullable RttCall getRttCall() {
2149 return mRttCall;
2150 }
2151
2152 /**
2153 * Returns whether this call has an active RTT connection.
2154 * @return true if there is a connection, false otherwise.
2155 */
2156 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08002157 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08002158 }
2159
2160 /**
Andrew Leeda80c872015-04-15 14:09:50 -07002161 * Registers a callback to this {@code Call}.
2162 *
2163 * @param callback A {@code Callback}.
2164 */
2165 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07002166 registerCallback(callback, new Handler());
2167 }
2168
2169 /**
2170 * Registers a callback to this {@code Call}.
2171 *
2172 * @param callback A {@code Callback}.
2173 * @param handler A handler which command and status changes will be delivered to.
2174 */
2175 public void registerCallback(Callback callback, Handler handler) {
2176 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07002177 // Don't allow new callback registration if the call is already being destroyed.
2178 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002179 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
2180 }
Andrew Leeda80c872015-04-15 14:09:50 -07002181 }
2182
2183 /**
2184 * Unregisters a callback from this {@code Call}.
2185 *
2186 * @param callback A {@code Callback}.
2187 */
2188 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002189 // Don't allow callback deregistration if the call is already being destroyed.
2190 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002191 for (CallbackRecord<Callback> record : mCallbackRecords) {
2192 if (record.getCallback() == callback) {
2193 mCallbackRecords.remove(record);
2194 break;
2195 }
2196 }
Andrew Leeda80c872015-04-15 14:09:50 -07002197 }
2198 }
2199
Santos Cordon3c20d632016-02-25 16:12:35 -08002200 @Override
2201 public String toString() {
2202 return new StringBuilder().
2203 append("Call [id: ").
2204 append(mTelecomCallId).
2205 append(", state: ").
2206 append(stateToString(mState)).
2207 append(", details: ").
2208 append(mDetails).
2209 append("]").toString();
2210 }
2211
2212 /**
2213 * @param state An integer value of a {@code STATE_*} constant.
2214 * @return A string representation of the value.
2215 */
2216 private static String stateToString(int state) {
2217 switch (state) {
2218 case STATE_NEW:
2219 return "NEW";
2220 case STATE_RINGING:
2221 return "RINGING";
2222 case STATE_DIALING:
2223 return "DIALING";
2224 case STATE_ACTIVE:
2225 return "ACTIVE";
2226 case STATE_HOLDING:
2227 return "HOLDING";
2228 case STATE_DISCONNECTED:
2229 return "DISCONNECTED";
2230 case STATE_CONNECTING:
2231 return "CONNECTING";
2232 case STATE_DISCONNECTING:
2233 return "DISCONNECTING";
2234 case STATE_SELECT_PHONE_ACCOUNT:
2235 return "SELECT_PHONE_ACCOUNT";
Hall Liu4e35b642019-10-14 17:50:45 -07002236 case STATE_SIMULATED_RINGING:
2237 return "SIMULATED_RINGING";
2238 case STATE_AUDIO_PROCESSING:
2239 return "AUDIO_PROCESSING";
Santos Cordon3c20d632016-02-25 16:12:35 -08002240 default:
2241 Log.w(Call.class, "Unknown state %d", state);
2242 return "UNKNOWN";
2243 }
2244 }
2245
Andrew Leeda80c872015-04-15 14:09:50 -07002246 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002247 * Adds a listener to this {@code Call}.
2248 *
2249 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002250 * @deprecated Use {@link #registerCallback} instead.
2251 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002252 */
Andrew Leeda80c872015-04-15 14:09:50 -07002253 @Deprecated
2254 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002255 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002256 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002257 }
2258
2259 /**
2260 * Removes a listener from this {@code Call}.
2261 *
2262 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002263 * @deprecated Use {@link #unregisterCallback} instead.
2264 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002265 */
Andrew Leeda80c872015-04-15 14:09:50 -07002266 @Deprecated
2267 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002268 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002269 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002270 }
2271
2272 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002273 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2274 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002275 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002276 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002277 mInCallAdapter = inCallAdapter;
2278 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002279 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002280 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002281 }
2282
2283 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002284 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002285 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002286 mPhone = phone;
2287 mTelecomCallId = telecomCallId;
2288 mInCallAdapter = inCallAdapter;
2289 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002290 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002291 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002292 }
2293
2294 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002295 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002296 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002297 }
2298
2299 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002300 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002301
Ihab Awade63fadb2014-07-09 21:52:04 -07002302 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002303 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002304 boolean detailsChanged = !Objects.equals(mDetails, details);
2305 if (detailsChanged) {
2306 mDetails = details;
2307 }
2308
2309 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002310 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2311 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2312 mCannedTextResponses =
2313 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002314 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002315 }
2316
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002317 IVideoProvider previousVideoProvider = mVideoCallImpl == null ? null :
2318 mVideoCallImpl.getVideoProvider();
2319 IVideoProvider newVideoProvider = parcelableCall.getVideoProvider();
2320
2321 // parcelableCall.isVideoCallProviderChanged is only true when we have a video provider
2322 // specified; so we should check if the actual IVideoProvider changes as well.
2323 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged()
2324 && !Objects.equals(previousVideoProvider, newVideoProvider);
Andrew Lee50aca232014-07-22 16:41:54 -07002325 if (videoCallChanged) {
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002326 if (mVideoCallImpl != null) {
2327 mVideoCallImpl.destroy();
2328 }
2329 mVideoCallImpl = parcelableCall.isVideoCallProviderChanged() ?
2330 parcelableCall.getVideoCallImpl(mCallingPackage, mTargetSdkVersion) : null;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002331 }
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002332
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002333 if (mVideoCallImpl != null) {
2334 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002335 }
2336
Santos Cordone3c507b2015-04-23 14:44:19 -07002337 int state = parcelableCall.getState();
Hall Liu31de23d2019-10-11 15:38:29 -07002338 if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2339 state = Call.STATE_RINGING;
2340 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002341 boolean stateChanged = mState != state;
2342 if (stateChanged) {
2343 mState = state;
2344 }
2345
Santos Cordon823fd3c2014-08-07 18:35:18 -07002346 String parentId = parcelableCall.getParentCallId();
2347 boolean parentChanged = !Objects.equals(mParentId, parentId);
2348 if (parentChanged) {
2349 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002350 }
2351
Santos Cordon823fd3c2014-08-07 18:35:18 -07002352 List<String> childCallIds = parcelableCall.getChildCallIds();
2353 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2354 if (childrenChanged) {
2355 mChildrenIds.clear();
2356 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2357 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002358 }
2359
Hall Liuef98bf82020-01-09 15:22:44 -08002360 String activeChildCallId = parcelableCall.getActiveChildCallId();
2361 boolean activeChildChanged = !Objects.equals(activeChildCallId,
2362 mActiveGenericConferenceChild);
2363 if (activeChildChanged) {
2364 mActiveGenericConferenceChild = activeChildCallId;
2365 }
2366
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002367 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2368 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2369 for (String otherId : conferenceableCallIds) {
2370 if (callIdMap.containsKey(otherId)) {
2371 conferenceableCalls.add(callIdMap.get(otherId));
2372 }
2373 }
2374
2375 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2376 mConferenceableCalls.clear();
2377 mConferenceableCalls.addAll(conferenceableCalls);
2378 fireConferenceableCallsChanged();
2379 }
2380
Hall Liu95d55872017-01-25 17:12:49 -08002381 boolean isRttChanged = false;
2382 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002383 if (parcelableCall.getIsRttCallChanged()
2384 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002385 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2386 InputStreamReader receiveStream = new InputStreamReader(
2387 new ParcelFileDescriptor.AutoCloseInputStream(
2388 parcelableRttCall.getReceiveStream()),
2389 StandardCharsets.UTF_8);
2390 OutputStreamWriter transmitStream = new OutputStreamWriter(
2391 new ParcelFileDescriptor.AutoCloseOutputStream(
2392 parcelableRttCall.getTransmitStream()),
2393 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002394 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002395 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2396 if (mRttCall == null) {
2397 isRttChanged = true;
2398 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2399 rttModeChanged = true;
2400 }
2401 mRttCall = newRttCall;
2402 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2403 && parcelableCall.getIsRttCallChanged()) {
2404 isRttChanged = true;
2405 mRttCall = null;
2406 }
2407
Ihab Awade63fadb2014-07-09 21:52:04 -07002408 // Now we fire updates, ensuring that any client who listens to any of these notifications
2409 // gets the most up-to-date state.
2410
2411 if (stateChanged) {
2412 fireStateChanged(mState);
2413 }
2414 if (detailsChanged) {
2415 fireDetailsChanged(mDetails);
2416 }
2417 if (cannedTextResponsesChanged) {
2418 fireCannedTextResponsesLoaded(mCannedTextResponses);
2419 }
Andrew Lee50aca232014-07-22 16:41:54 -07002420 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002421 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002422 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002423 if (parentChanged) {
2424 fireParentChanged(getParent());
2425 }
Hall Liuef98bf82020-01-09 15:22:44 -08002426 if (childrenChanged || activeChildChanged) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002427 fireChildrenChanged(getChildren());
2428 }
Hall Liu95d55872017-01-25 17:12:49 -08002429 if (isRttChanged) {
2430 fireOnIsRttChanged(mRttCall != null, mRttCall);
2431 }
2432 if (rttModeChanged) {
2433 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2434 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002435
2436 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2437 // remove ourselves from the Phone. Note that we do this after completing all state updates
2438 // so a client can cleanly transition all their UI to the state appropriate for a
2439 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2440 if (mState == STATE_DISCONNECTED) {
2441 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002442 }
2443 }
2444
2445 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002446 final void internalSetPostDialWait(String remaining) {
2447 mRemainingPostDialSequence = remaining;
2448 firePostDialWait(mRemainingPostDialSequence);
2449 }
2450
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002451 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002452 final void internalSetDisconnected() {
2453 if (mState != Call.STATE_DISCONNECTED) {
2454 mState = Call.STATE_DISCONNECTED;
2455 fireStateChanged(mState);
2456 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002457 }
2458 }
2459
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002460 /** {@hide} */
2461 final void internalOnConnectionEvent(String event, Bundle extras) {
2462 fireOnConnectionEvent(event, extras);
2463 }
2464
Hall Liu95d55872017-01-25 17:12:49 -08002465 /** {@hide} */
2466 final void internalOnRttUpgradeRequest(final int requestId) {
2467 for (CallbackRecord<Callback> record : mCallbackRecords) {
2468 final Call call = this;
2469 final Callback callback = record.getCallback();
2470 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2471 }
2472 }
2473
Hall Liu57006aa2017-02-06 10:49:48 -08002474 /** @hide */
2475 final void internalOnRttInitiationFailure(int reason) {
2476 for (CallbackRecord<Callback> record : mCallbackRecords) {
2477 final Call call = this;
2478 final Callback callback = record.getCallback();
2479 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2480 }
2481 }
2482
Sanket Padawe85291f62017-12-01 13:59:27 -08002483 /** {@hide} */
2484 final void internalOnHandoverFailed(int error) {
2485 for (CallbackRecord<Callback> record : mCallbackRecords) {
2486 final Call call = this;
2487 final Callback callback = record.getCallback();
2488 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2489 }
2490 }
2491
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002492 /** {@hide} */
2493 final void internalOnHandoverComplete() {
2494 for (CallbackRecord<Callback> record : mCallbackRecords) {
2495 final Call call = this;
2496 final Callback callback = record.getCallback();
2497 record.getHandler().post(() -> callback.onHandoverComplete(call));
2498 }
2499 }
2500
Andrew Lee011728f2015-04-23 15:47:06 -07002501 private void fireStateChanged(final int newState) {
2502 for (CallbackRecord<Callback> record : mCallbackRecords) {
2503 final Call call = this;
2504 final Callback callback = record.getCallback();
2505 record.getHandler().post(new Runnable() {
2506 @Override
2507 public void run() {
2508 callback.onStateChanged(call, newState);
2509 }
2510 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002511 }
2512 }
2513
Andrew Lee011728f2015-04-23 15:47:06 -07002514 private void fireParentChanged(final Call newParent) {
2515 for (CallbackRecord<Callback> record : mCallbackRecords) {
2516 final Call call = this;
2517 final Callback callback = record.getCallback();
2518 record.getHandler().post(new Runnable() {
2519 @Override
2520 public void run() {
2521 callback.onParentChanged(call, newParent);
2522 }
2523 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002524 }
2525 }
2526
Andrew Lee011728f2015-04-23 15:47:06 -07002527 private void fireChildrenChanged(final List<Call> children) {
2528 for (CallbackRecord<Callback> record : mCallbackRecords) {
2529 final Call call = this;
2530 final Callback callback = record.getCallback();
2531 record.getHandler().post(new Runnable() {
2532 @Override
2533 public void run() {
2534 callback.onChildrenChanged(call, children);
2535 }
2536 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002537 }
2538 }
2539
Andrew Lee011728f2015-04-23 15:47:06 -07002540 private void fireDetailsChanged(final Details details) {
2541 for (CallbackRecord<Callback> record : mCallbackRecords) {
2542 final Call call = this;
2543 final Callback callback = record.getCallback();
2544 record.getHandler().post(new Runnable() {
2545 @Override
2546 public void run() {
2547 callback.onDetailsChanged(call, details);
2548 }
2549 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002550 }
2551 }
2552
Andrew Lee011728f2015-04-23 15:47:06 -07002553 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2554 for (CallbackRecord<Callback> record : mCallbackRecords) {
2555 final Call call = this;
2556 final Callback callback = record.getCallback();
2557 record.getHandler().post(new Runnable() {
2558 @Override
2559 public void run() {
2560 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2561 }
2562 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002563 }
2564 }
2565
Andrew Lee011728f2015-04-23 15:47:06 -07002566 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2567 for (CallbackRecord<Callback> record : mCallbackRecords) {
2568 final Call call = this;
2569 final Callback callback = record.getCallback();
2570 record.getHandler().post(new Runnable() {
2571 @Override
2572 public void run() {
2573 callback.onVideoCallChanged(call, videoCall);
2574 }
2575 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002576 }
2577 }
2578
Andrew Lee011728f2015-04-23 15:47:06 -07002579 private void firePostDialWait(final String remainingPostDialSequence) {
2580 for (CallbackRecord<Callback> record : mCallbackRecords) {
2581 final Call call = this;
2582 final Callback callback = record.getCallback();
2583 record.getHandler().post(new Runnable() {
2584 @Override
2585 public void run() {
2586 callback.onPostDialWait(call, remainingPostDialSequence);
2587 }
2588 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002589 }
2590 }
2591
2592 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002593 /**
2594 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2595 * onCallRemoved callback, we remove this call from the Phone's record
2596 * only once all of the registered onCallDestroyed callbacks are executed.
2597 * All the callbacks get removed from our records as a part of this operation
2598 * since onCallDestroyed is the final callback.
2599 */
2600 final Call call = this;
2601 if (mCallbackRecords.isEmpty()) {
2602 // No callbacks registered, remove the call from Phone's record.
2603 mPhone.internalRemoveCall(call);
2604 }
2605 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002606 final Callback callback = record.getCallback();
2607 record.getHandler().post(new Runnable() {
2608 @Override
2609 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002610 boolean isFinalRemoval = false;
2611 RuntimeException toThrow = null;
2612 try {
2613 callback.onCallDestroyed(call);
2614 } catch (RuntimeException e) {
2615 toThrow = e;
2616 }
2617 synchronized(Call.this) {
2618 mCallbackRecords.remove(record);
2619 if (mCallbackRecords.isEmpty()) {
2620 isFinalRemoval = true;
2621 }
2622 }
2623 if (isFinalRemoval) {
2624 mPhone.internalRemoveCall(call);
2625 }
2626 if (toThrow != null) {
2627 throw toThrow;
2628 }
Andrew Lee011728f2015-04-23 15:47:06 -07002629 }
2630 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002631 }
2632 }
2633
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002634 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002635 for (CallbackRecord<Callback> record : mCallbackRecords) {
2636 final Call call = this;
2637 final Callback callback = record.getCallback();
2638 record.getHandler().post(new Runnable() {
2639 @Override
2640 public void run() {
2641 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2642 }
2643 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002644 }
2645 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002646
2647 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002648 * Notifies listeners of an incoming connection event.
2649 * <p>
2650 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2651 *
2652 * @param event
2653 * @param extras
2654 */
2655 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2656 for (CallbackRecord<Callback> record : mCallbackRecords) {
2657 final Call call = this;
2658 final Callback callback = record.getCallback();
2659 record.getHandler().post(new Runnable() {
2660 @Override
2661 public void run() {
2662 callback.onConnectionEvent(call, event, extras);
2663 }
2664 });
2665 }
2666 }
2667
2668 /**
Hall Liu95d55872017-01-25 17:12:49 -08002669 * Notifies listeners of an RTT on/off change
2670 *
2671 * @param enabled True if RTT is now enabled, false otherwise
2672 */
2673 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2674 for (CallbackRecord<Callback> record : mCallbackRecords) {
2675 final Call call = this;
2676 final Callback callback = record.getCallback();
2677 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2678 }
2679 }
2680
2681 /**
2682 * Notifies listeners of a RTT mode change
2683 *
2684 * @param mode The new RTT mode
2685 */
2686 private void fireOnRttModeChanged(final int mode) {
2687 for (CallbackRecord<Callback> record : mCallbackRecords) {
2688 final Call call = this;
2689 final Callback callback = record.getCallback();
2690 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2691 }
2692 }
2693
2694 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002695 * Determines if two bundles are equal.
2696 *
2697 * @param bundle The original bundle.
2698 * @param newBundle The bundle to compare with.
2699 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2700 */
2701 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2702 if (bundle == null || newBundle == null) {
2703 return bundle == newBundle;
2704 }
2705
2706 if (bundle.size() != newBundle.size()) {
2707 return false;
2708 }
2709
2710 for(String key : bundle.keySet()) {
2711 if (key != null) {
2712 final Object value = bundle.get(key);
2713 final Object newValue = newBundle.get(key);
2714 if (!Objects.equals(value, newValue)) {
2715 return false;
2716 }
2717 }
2718 }
2719 return true;
2720 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002721}