blob: 24b40460066b99adff832e5b09d2928c44740d1d [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;
20import android.annotation.Nullable;
Andrew Leeda80c872015-04-15 14:09:50 -070021import android.annotation.SystemApi;
Hall Liu6dfa2492019-10-01 17:20:39 -070022import android.annotation.TestApi;
Mathew Inwood42346d12018-08-01 11:33:05 +010023import android.annotation.UnsupportedAppUsage;
Ihab Awade63fadb2014-07-09 21:52:04 -070024import android.net.Uri;
Tyler Gunn6e3ecc42018-11-12 11:30:56 -080025import android.os.Build;
Nancy Chen10798dc2014-08-08 14:00:25 -070026import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070027import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080028import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070029
Hall Liu95d55872017-01-25 17:12:49 -080030import java.io.IOException;
31import java.io.InputStreamReader;
32import java.io.OutputStreamWriter;
Hall Liu95d55872017-01-25 17:12:49 -080033import java.lang.annotation.Retention;
34import java.lang.annotation.RetentionPolicy;
35import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070036import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070037import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070038import java.util.Collections;
39import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070040import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070041import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070042import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070043
44/**
45 * Represents an ongoing phone call that the in-call app should present to the user.
46 */
47public final class Call {
48 /**
49 * The state of a {@code Call} when newly created.
50 */
51 public static final int STATE_NEW = 0;
52
53 /**
54 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
55 */
56 public static final int STATE_DIALING = 1;
57
58 /**
59 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
60 */
61 public static final int STATE_RINGING = 2;
62
63 /**
64 * The state of a {@code Call} when in a holding state.
65 */
66 public static final int STATE_HOLDING = 3;
67
68 /**
69 * The state of a {@code Call} when actively supporting conversation.
70 */
71 public static final int STATE_ACTIVE = 4;
72
73 /**
74 * The state of a {@code Call} when no further voice or other communication is being
75 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
76 * is no longer active, and the local data transport has or inevitably will release resources
77 * associated with this {@code Call}.
78 */
79 public static final int STATE_DISCONNECTED = 7;
80
Nancy Chen5da0fd52014-07-08 14:16:17 -070081 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070082 * The state of an outgoing {@code Call} when waiting on user to select a
83 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070084 */
Santos Cordone3c507b2015-04-23 14:44:19 -070085 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
86
87 /**
88 * @hide
89 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
90 */
91 @Deprecated
92 @SystemApi
93 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070094
Nancy Chene20930f2014-08-07 16:17:21 -070095 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070096 * The initial state of an outgoing {@code Call}.
97 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
98 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070099 */
100 public static final int STATE_CONNECTING = 9;
101
Nancy Chen513c8922014-09-17 14:47:20 -0700102 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700103 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
104 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
105 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
106 */
107 public static final int STATE_DISCONNECTING = 10;
108
109 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700110 * The state of an external call which is in the process of being pulled from a remote device to
111 * the local device.
112 * <p>
113 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
114 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
115 * <p>
116 * An {@link InCallService} will only see this state if it has the
117 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
118 * manifest.
119 */
120 public static final int STATE_PULLING_CALL = 11;
121
122 /**
Hall Liu6dfa2492019-10-01 17:20:39 -0700123 * The state of a call that is active with the network, but the audio from the call is
124 * being intercepted by an app on the local device. Telecom does not hold audio focus in this
125 * state, and the call will be invisible to the user except for a persistent notification.
126 */
127 public static final int STATE_AUDIO_PROCESSING = 12;
128
129 /**
130 * The state of a call that is being presented to the user after being in
131 * {@link #STATE_AUDIO_PROCESSING}. The call is still active with the network in this case, and
132 * Telecom will hold audio focus and play a ringtone if appropriate.
133 */
134 public static final int STATE_SIMULATED_RINGING = 13;
135
136 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700137 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
138 * extras. Used to pass the phone accounts to display on the front end to the user in order to
139 * select phone accounts to (for example) place a call.
Hall Liu34d9e242018-11-21 17:05:58 -0800140 * @deprecated Use the list from {@link #EXTRA_SUGGESTED_PHONE_ACCOUNTS} instead.
Nancy Chen513c8922014-09-17 14:47:20 -0700141 */
Hall Liu34d9e242018-11-21 17:05:58 -0800142 @Deprecated
Nancy Chen513c8922014-09-17 14:47:20 -0700143 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
144
mike dooley4af561f2016-12-20 08:55:17 -0800145 /**
Hall Liu34d9e242018-11-21 17:05:58 -0800146 * Key for extra used to pass along a list of {@link PhoneAccountSuggestion}s to the in-call
147 * UI when a call enters the {@link #STATE_SELECT_PHONE_ACCOUNT} state. The list included here
148 * will have the same length and be in the same order as the list passed with
149 * {@link #AVAILABLE_PHONE_ACCOUNTS}.
150 */
151 public static final String EXTRA_SUGGESTED_PHONE_ACCOUNTS =
152 "android.telecom.extra.SUGGESTED_PHONE_ACCOUNTS";
153
154 /**
mike dooley91217422017-03-09 12:58:42 -0800155 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
156 * when the last outgoing emergency call was made. This is used to identify potential emergency
157 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800158 */
159 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
160 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
161
Usman Abdullahb0dc29a2019-03-06 15:54:56 -0800162
163 /**
164 * Extra key used to indicate whether a {@link CallScreeningService} has requested to silence
165 * the ringtone for a call. If the {@link InCallService} declares
166 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} in its manifest, it should not
167 * play a ringtone for an incoming call with this extra key set.
168 */
169 public static final String EXTRA_SILENT_RINGING_REQUESTED =
170 "android.telecom.extra.SILENT_RINGING_REQUESTED";
171
Tyler Gunn8bf76572017-04-06 15:30:08 -0700172 /**
173 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
174 * Telecom that the user has requested that the current {@link Call} should be handed over
175 * to another {@link ConnectionService}.
176 * <p>
177 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
178 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
179 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700180 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
181 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700182 */
183 public static final String EVENT_REQUEST_HANDOVER =
184 "android.telecom.event.REQUEST_HANDOVER";
185
186 /**
187 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
188 * {@link PhoneAccountHandle} to which a call should be handed over to.
189 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700190 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
191 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700192 */
193 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
194 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
195
196 /**
197 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
198 * video state of the call when it is handed over to the new {@link PhoneAccount}.
199 * <p>
200 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
201 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
202 * {@link VideoProfile#STATE_TX_ENABLED}.
203 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700204 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
205 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700206 */
207 public static final String EXTRA_HANDOVER_VIDEO_STATE =
208 "android.telecom.extra.HANDOVER_VIDEO_STATE";
209
210 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700211 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
212 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
213 * information to the handover {@link ConnectionService} specified by
214 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
215 * <p>
216 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
217 * {@link ConnectionService} via the request extras when
218 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
219 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700220 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700221 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
222 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700223 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700224 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700225
226 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700227 * Call event sent from Telecom to the handover {@link ConnectionService} via
228 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
229 * to the {@link ConnectionService} has completed successfully.
230 * <p>
231 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700232 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700233 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
234 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700235 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700236 public static final String EVENT_HANDOVER_COMPLETE =
237 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700238
239 /**
240 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
241 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
242 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
243 * {@code null}.
244 * <p>
245 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
246 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700247 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
248 * APIs instead.
Tyler Gunn34a2b312017-06-23 08:32:00 -0700249 */
250 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
251 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
252
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700253 /**
254 * Call event sent from Telecom to the handover {@link ConnectionService} via
255 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
256 * to the {@link ConnectionService} has failed.
257 * <p>
258 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
259 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700260 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
261 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700262 */
263 public static final String EVENT_HANDOVER_FAILED =
264 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700265
Ihab Awade63fadb2014-07-09 21:52:04 -0700266 public static class Details {
Tyler Gunn94f8f112018-12-17 09:56:11 -0800267 /** @hide */
268 @Retention(RetentionPolicy.SOURCE)
269 @IntDef(
270 prefix = { "DIRECTION_" },
271 value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
272 public @interface CallDirection {}
273
274 /**
275 * Indicates that the call is neither and incoming nor an outgoing call. This can be the
276 * case for calls reported directly by a {@link ConnectionService} in special cases such as
277 * call handovers.
278 */
279 public static final int DIRECTION_UNKNOWN = -1;
280
281 /**
282 * Indicates that the call is an incoming call.
283 */
284 public static final int DIRECTION_INCOMING = 0;
285
286 /**
287 * Indicates that the call is an outgoing call.
288 */
289 public static final int DIRECTION_OUTGOING = 1;
290
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800291
292 /** Call can currently be put on hold or unheld. */
293 public static final int CAPABILITY_HOLD = 0x00000001;
294
295 /** Call supports the hold feature. */
296 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
297
298 /**
299 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
300 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
301 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
302 * capability allows a merge button to be shown while the conference call is in the foreground
303 * of the in-call UI.
304 * <p>
305 * This is only intended for use by a {@link Conference}.
306 */
307 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
308
309 /**
310 * Calls within a conference can be swapped between foreground and background.
311 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
312 * <p>
313 * This is only intended for use by a {@link Conference}.
314 */
315 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
316
317 /**
318 * @hide
319 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700320 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800321
322 /** Call supports responding via text option. */
323 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
324
325 /** Call can be muted. */
326 public static final int CAPABILITY_MUTE = 0x00000040;
327
328 /**
329 * Call supports conference call management. This capability only applies to {@link Conference}
330 * calls which can have {@link Connection}s as children.
331 */
332 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
333
334 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700335 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800336 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700337 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800338
339 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700340 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800341 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700342 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800343
344 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700345 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800346 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700347 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700348 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800349
350 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700351 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800352 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700353 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
354
355 /**
356 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700357 */
358 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
359
360 /**
361 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700362 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700363 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700364 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800365
366 /**
367 * Call is able to be separated from its parent {@code Conference}, if any.
368 */
369 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
370
371 /**
372 * Call is able to be individually disconnected when in a {@code Conference}.
373 */
374 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
375
376 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500377 * Speed up audio setup for MT call.
378 * @hide
379 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700380 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
381
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700382 /**
383 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700384 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800385 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
386 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
387 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700388 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800389 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700390 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
391
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700392 /**
393 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700394 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700395 */
396 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
397
Bryce Lee81901682015-08-28 16:38:02 -0700398 /**
399 * Call sends responses through connection.
400 * @hide
401 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800402 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
403
404 /**
405 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
406 * <p>
407 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
408 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
409 * downgraded from a video call back to a VideoState of
410 * {@link VideoProfile#STATE_AUDIO_ONLY}.
411 * <p>
412 * Intuitively, a call which can be downgraded to audio should also have local and remote
413 * video
414 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
415 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
416 */
417 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700418
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700419 /**
420 * When set for an external call, indicates that this {@code Call} can be pulled from a
421 * remote device to the current device.
422 * <p>
423 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
424 * <p>
425 * An {@link InCallService} will only see calls with this capability if it has the
426 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
427 * in its manifest.
428 * <p>
429 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700430 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700431 */
432 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
433
Pooja Jaind34698d2017-12-28 14:15:31 +0530434 /** Call supports the deflect feature. */
435 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
436
Tyler Gunnd11a3152015-03-18 13:09:14 -0700437 //******************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530438 // Next CAPABILITY value: 0x02000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700439 //******************************************************************************************
440
441 /**
442 * Whether the call is currently a conference.
443 */
444 public static final int PROPERTY_CONFERENCE = 0x00000001;
445
446 /**
447 * Whether the call is a generic conference, where we do not know the precise state of
448 * participants in the conference (eg. on CDMA).
449 */
450 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
451
452 /**
453 * Whether the call is made while the device is in emergency callback mode.
454 */
455 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
456
457 /**
458 * Connection is using WIFI.
459 */
460 public static final int PROPERTY_WIFI = 0x00000008;
461
462 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700463 * When set, the UI should indicate to the user that a call is using high definition
464 * audio.
465 * <p>
466 * The underlying {@link ConnectionService} is responsible for reporting this
467 * property. It is important to note that this property is not intended to report the
468 * actual audio codec being used for a Call, but whether the call should be indicated
469 * to the user as high definition.
470 * <p>
471 * The Android Telephony stack reports this property for calls based on a number
472 * of factors, including which audio codec is used and whether a call is using an HD
473 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
474 * and in these cases this property will not be set for a call even if the underlying audio
475 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700476 */
477 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
478
Tony Maka68dcce2015-12-17 09:31:18 +0000479 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100480 * Whether the call is associated with the work profile.
481 */
482 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
483
484 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700485 * When set, indicates that this {@code Call} does not actually exist locally for the
486 * {@link ConnectionService}.
487 * <p>
488 * Consider, for example, a scenario where a user has two phones with the same phone number.
489 * When a user places a call on one device, the telephony stack can represent that call on
490 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700491 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700492 * <p>
493 * An {@link InCallService} will only see calls with this property if it has the
494 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
495 * in its manifest.
496 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700497 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700498 */
499 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
500
Brad Ebinger15847072016-05-18 11:08:36 -0700501 /**
502 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
503 */
504 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
505
Tyler Gunn24e18332017-02-10 09:42:49 -0800506 /**
507 * Indicates that the call is from a self-managed {@link ConnectionService}.
508 * <p>
509 * See also {@link Connection#PROPERTY_SELF_MANAGED}
510 */
511 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
512
Eric Erfanianec881872017-12-06 16:27:53 -0800513 /**
514 * Indicates the call used Assisted Dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700515 *
516 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanianec881872017-12-06 16:27:53 -0800517 */
518 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
519
Hall Liue9041242018-02-09 16:40:03 -0800520 /**
521 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
522 * {@link RttCall} object that is used to send and receive text.
523 */
524 public static final int PROPERTY_RTT = 0x00000400;
525
Tyler Gunn5bd90852018-09-21 09:37:07 -0700526 /**
527 * Indicates that the call has been identified as the network as an emergency call. This
528 * property may be set for both incoming and outgoing calls which the network identifies as
529 * emergency calls.
530 */
531 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
532
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700533 /**
534 * Indicates that the call is using VoIP audio mode.
535 * <p>
536 * When this property is set, the {@link android.media.AudioManager} audio mode for this
537 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
538 * property is not set, the audio mode for this call will be
539 * {@link android.media.AudioManager#MODE_IN_CALL}.
540 * <p>
541 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
542 * <p>
543 * You can use this property to determine whether an un-answered incoming call or a held
544 * call will use VoIP audio mode (if the call does not currently have focus, the system
545 * audio mode may not reflect the mode the call will use).
546 */
547 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
548
Andrew Lee2378ea72015-04-29 14:38:11 -0700549 //******************************************************************************************
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700550 // Next PROPERTY value: 0x00002000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700551 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800552
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800553 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700554 private final Uri mHandle;
555 private final int mHandlePresentation;
556 private final String mCallerDisplayName;
557 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700558 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700559 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700560 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800561 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700562 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700563 private final long mConnectTimeMillis;
564 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700565 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700566 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700567 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700568 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700569 private final long mCreationTimeMillis;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800570 private final @CallDirection int mCallDirection;
Ihab Awade63fadb2014-07-09 21:52:04 -0700571
572 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800573 * Whether the supplied capabilities supports the specified capability.
574 *
575 * @param capabilities A bit field of capabilities.
576 * @param capability The capability to check capabilities for.
577 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800578 */
579 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800580 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800581 }
582
583 /**
584 * Whether the capabilities of this {@code Details} supports the specified capability.
585 *
586 * @param capability The capability to check capabilities for.
587 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800588 */
589 public boolean can(int capability) {
590 return can(mCallCapabilities, capability);
591 }
592
593 /**
594 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
595 *
596 * @param capabilities A capability bit field.
597 * @return A human readable string representation.
598 */
599 public static String capabilitiesToString(int capabilities) {
600 StringBuilder builder = new StringBuilder();
601 builder.append("[Capabilities:");
602 if (can(capabilities, CAPABILITY_HOLD)) {
603 builder.append(" CAPABILITY_HOLD");
604 }
605 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
606 builder.append(" CAPABILITY_SUPPORT_HOLD");
607 }
608 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
609 builder.append(" CAPABILITY_MERGE_CONFERENCE");
610 }
611 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
612 builder.append(" CAPABILITY_SWAP_CONFERENCE");
613 }
614 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
615 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
616 }
617 if (can(capabilities, CAPABILITY_MUTE)) {
618 builder.append(" CAPABILITY_MUTE");
619 }
620 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
621 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
622 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700623 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
624 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
625 }
626 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
627 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
628 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700629 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
630 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800631 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700632 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
633 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
634 }
635 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
636 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
637 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800638 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
639 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
640 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700641 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
642 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800643 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500644 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700645 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500646 }
Rekha Kumar07366812015-03-24 16:42:31 -0700647 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
648 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
649 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700650 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
651 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
652 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700653 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
654 builder.append(" CAPABILITY_CAN_PULL_CALL");
655 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530656 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
657 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
658 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800659 builder.append("]");
660 return builder.toString();
661 }
662
663 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700664 * Whether the supplied properties includes the specified property.
665 *
666 * @param properties A bit field of properties.
667 * @param property The property to check properties for.
668 * @return Whether the specified property is supported.
669 */
670 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800671 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700672 }
673
674 /**
675 * Whether the properties of this {@code Details} includes the specified property.
676 *
677 * @param property The property to check properties for.
678 * @return Whether the specified property is supported.
679 */
680 public boolean hasProperty(int property) {
681 return hasProperty(mCallProperties, property);
682 }
683
684 /**
685 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
686 *
687 * @param properties A property bit field.
688 * @return A human readable string representation.
689 */
690 public static String propertiesToString(int properties) {
691 StringBuilder builder = new StringBuilder();
692 builder.append("[Properties:");
693 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
694 builder.append(" PROPERTY_CONFERENCE");
695 }
696 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
697 builder.append(" PROPERTY_GENERIC_CONFERENCE");
698 }
699 if (hasProperty(properties, PROPERTY_WIFI)) {
700 builder.append(" PROPERTY_WIFI");
701 }
702 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
703 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
704 }
705 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700706 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700707 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700708 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
709 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
710 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700711 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700712 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
713 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700714 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800715 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
716 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700717 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
718 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
719 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700720 if (hasProperty(properties, PROPERTY_RTT)) {
721 builder.append(" PROPERTY_RTT");
722 }
723 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
724 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
725 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700726 builder.append("]");
727 return builder.toString();
728 }
729
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800730 /** {@hide} */
Hall Liu31de23d2019-10-11 15:38:29 -0700731 @TestApi
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800732 public String getTelecomCallId() {
733 return mTelecomCallId;
734 }
735
Andrew Lee2378ea72015-04-29 14:38:11 -0700736 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700737 * @return The handle (e.g., phone number) to which the {@code Call} is currently
738 * connected.
739 */
740 public Uri getHandle() {
741 return mHandle;
742 }
743
744 /**
745 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700746 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700747 */
748 public int getHandlePresentation() {
749 return mHandlePresentation;
750 }
751
752 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800753 * The display name for the caller.
754 * <p>
755 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800756 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700757 * @return The display name for the caller.
758 */
759 public String getCallerDisplayName() {
760 return mCallerDisplayName;
761 }
762
763 /**
764 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700765 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700766 */
767 public int getCallerDisplayNamePresentation() {
768 return mCallerDisplayNamePresentation;
769 }
770
771 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700772 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
773 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700774 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700775 public PhoneAccountHandle getAccountHandle() {
776 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700777 }
778
779 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800780 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
781 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700782 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700783 public int getCallCapabilities() {
784 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700785 }
786
787 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700788 * @return A bitmask of the properties of the {@code Call}, as defined by the various
789 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700790 */
791 public int getCallProperties() {
792 return mCallProperties;
793 }
794
795 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800796 * @return a bitmask of the audio routes available for the call.
797 *
798 * @hide
799 */
800 public int getSupportedAudioRoutes() {
801 return mSupportedAudioRoutes;
802 }
803
804 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700805 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700806 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700807 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700808 public DisconnectCause getDisconnectCause() {
809 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700810 }
811
812 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700813 * Returns the time the {@link Call} connected (i.e. became active). This information is
814 * updated periodically, but user interfaces should not rely on this to display the "call
815 * time clock". For the time when the call was first added to Telecom, see
816 * {@link #getCreationTimeMillis()}.
817 *
818 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700819 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700820 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700821 return mConnectTimeMillis;
822 }
823
824 /**
825 * @return Information about any calling gateway the {@code Call} may be using.
826 */
827 public GatewayInfo getGatewayInfo() {
828 return mGatewayInfo;
829 }
830
Andrew Lee7a341382014-07-15 17:05:08 -0700831 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700832 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700833 */
834 public int getVideoState() {
835 return mVideoState;
836 }
837
Ihab Awad5d0410f2014-07-30 10:07:40 -0700838 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700839 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700840 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700841 */
842 public StatusHints getStatusHints() {
843 return mStatusHints;
844 }
845
Nancy Chen10798dc2014-08-08 14:00:25 -0700846 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700847 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700848 */
849 public Bundle getExtras() {
850 return mExtras;
851 }
852
Santos Cordon6b7f9552015-05-27 17:21:45 -0700853 /**
854 * @return The extras used with the original intent to place this call.
855 */
856 public Bundle getIntentExtras() {
857 return mIntentExtras;
858 }
859
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700860 /**
861 * Returns the time when the call was first created and added to Telecom. This is the same
862 * time that is logged as the start time in the Call Log (see
863 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
864 * (became active), see {@link #getConnectTimeMillis()}.
865 *
866 * @return The creation time of the call, in millis since the epoch.
867 */
868 public long getCreationTimeMillis() {
869 return mCreationTimeMillis;
870 }
871
Tyler Gunnd081f042018-12-04 12:56:45 -0800872 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -0800873 * Indicates whether the call is an incoming or outgoing call.
874 * @return The call's direction.
875 */
876 public @CallDirection int getCallDirection() {
877 return mCallDirection;
878 }
879
Ihab Awade63fadb2014-07-09 21:52:04 -0700880 @Override
881 public boolean equals(Object o) {
882 if (o instanceof Details) {
883 Details d = (Details) o;
884 return
885 Objects.equals(mHandle, d.mHandle) &&
886 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
887 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
888 Objects.equals(mCallerDisplayNamePresentation,
889 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700890 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700891 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700892 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700893 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700894 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700895 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700896 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700897 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700898 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700899 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -0800900 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Tyler Gunn94f8f112018-12-17 09:56:11 -0800901 Objects.equals(mCallDirection, d.mCallDirection);
Ihab Awade63fadb2014-07-09 21:52:04 -0700902 }
903 return false;
904 }
905
906 @Override
907 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700908 return Objects.hash(mHandle,
909 mHandlePresentation,
910 mCallerDisplayName,
911 mCallerDisplayNamePresentation,
912 mAccountHandle,
913 mCallCapabilities,
914 mCallProperties,
915 mDisconnectCause,
916 mConnectTimeMillis,
917 mGatewayInfo,
918 mVideoState,
919 mStatusHints,
920 mExtras,
921 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -0800922 mCreationTimeMillis,
Tyler Gunn94f8f112018-12-17 09:56:11 -0800923 mCallDirection);
Ihab Awade63fadb2014-07-09 21:52:04 -0700924 }
925
926 /** {@hide} */
927 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800928 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700929 Uri handle,
930 int handlePresentation,
931 String callerDisplayName,
932 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700933 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700934 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700935 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700936 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700937 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700938 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700939 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700940 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700941 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700942 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -0800943 long creationTimeMillis,
Tyler Gunn94f8f112018-12-17 09:56:11 -0800944 int callDirection) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800945 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700946 mHandle = handle;
947 mHandlePresentation = handlePresentation;
948 mCallerDisplayName = callerDisplayName;
949 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700950 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700951 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700952 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700953 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700954 mConnectTimeMillis = connectTimeMillis;
955 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700956 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700957 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700958 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700959 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700960 mCreationTimeMillis = creationTimeMillis;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800961 mCallDirection = callDirection;
Ihab Awade63fadb2014-07-09 21:52:04 -0700962 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800963
964 /** {@hide} */
965 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
966 return new Details(
967 parcelableCall.getId(),
968 parcelableCall.getHandle(),
969 parcelableCall.getHandlePresentation(),
970 parcelableCall.getCallerDisplayName(),
971 parcelableCall.getCallerDisplayNamePresentation(),
972 parcelableCall.getAccountHandle(),
973 parcelableCall.getCapabilities(),
974 parcelableCall.getProperties(),
975 parcelableCall.getDisconnectCause(),
976 parcelableCall.getConnectTimeMillis(),
977 parcelableCall.getGatewayInfo(),
978 parcelableCall.getVideoState(),
979 parcelableCall.getStatusHints(),
980 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700981 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -0800982 parcelableCall.getCreationTimeMillis(),
Tyler Gunn94f8f112018-12-17 09:56:11 -0800983 parcelableCall.getCallDirection());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800984 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800985
986 @Override
987 public String toString() {
988 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -0800989 sb.append("[id: ");
990 sb.append(mTelecomCallId);
991 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -0800992 sb.append(mAccountHandle);
993 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -0800994 sb.append(Log.piiHandle(mHandle));
995 sb.append(", hdlPres: ");
996 sb.append(mHandlePresentation);
997 sb.append(", videoState: ");
998 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -0800999 sb.append(", caps: ");
1000 sb.append(capabilitiesToString(mCallCapabilities));
1001 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001002 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001003 sb.append("]");
1004 return sb.toString();
1005 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001006 }
1007
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001008 /**
1009 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1010 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1011 * implementation.
1012 * <p>
1013 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1014 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1015 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1016 * {@link Callback} implementation, if desired.
1017 * <p>
1018 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1019 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1020 * (typically in {@link InCallService#onCallRemoved(Call)}).
1021 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1022 * reach your implementation of {@link Callback}, so it is important to register your callback
1023 * as soon as your {@link InCallService} is notified of a new call via
1024 * {@link InCallService#onCallAdded(Call)}.
1025 */
Andrew Leeda80c872015-04-15 14:09:50 -07001026 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001027 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001028 * @hide
1029 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001030 @IntDef(prefix = { "HANDOVER_" },
1031 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001032 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001033 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001034 @Retention(RetentionPolicy.SOURCE)
1035 public @interface HandoverFailureErrors {}
1036
1037 /**
1038 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001039 * to handover the call to rejects the handover request.
1040 * <p>
1041 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1042 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1043 * {@code null} {@link Connection} from
1044 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1045 * ConnectionRequest)}.
1046 * <p>
1047 * For more information on call handovers, see
1048 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001049 */
1050 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1051
1052 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001053 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1054 * is initiated but the source or destination app does not support handover.
1055 * <p>
1056 * Will be returned when a handover is requested via
1057 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1058 * {@link PhoneAccountHandle} does not declare
1059 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1060 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1061 * {@link Details#getAccountHandle()}) does not declare
1062 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1063 * <p>
1064 * For more information on call handovers, see
1065 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001066 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001067 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001068
1069 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001070 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1071 * user rejects the handover request.
1072 * <p>
1073 * For more information on call handovers, see
1074 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001075 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001076 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001077
Sanket Padawe85291f62017-12-01 13:59:27 -08001078 /**
1079 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1080 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001081 * <p>
1082 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1083 * called on an emergency call, or if any other call is an emergency call.
1084 * <p>
1085 * Handovers are not permitted while there are ongoing emergency calls.
1086 * <p>
1087 * For more information on call handovers, see
1088 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001089 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001090 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001091
Tyler Gunn9d127732018-03-02 15:45:51 -08001092 /**
1093 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1094 * fails for an unknown reason.
1095 * <p>
1096 * For more information on call handovers, see
1097 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1098 */
1099 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001100
1101 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001102 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1103 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001104 * @param call The {@code Call} invoking this method.
1105 * @param state The new state of the {@code Call}.
1106 */
1107 public void onStateChanged(Call call, int state) {}
1108
1109 /**
1110 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1111 *
1112 * @param call The {@code Call} invoking this method.
1113 * @param parent The new parent of the {@code Call}.
1114 */
1115 public void onParentChanged(Call call, Call parent) {}
1116
1117 /**
1118 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1119 *
1120 * @param call The {@code Call} invoking this method.
1121 * @param children The new children of the {@code Call}.
1122 */
1123 public void onChildrenChanged(Call call, List<Call> children) {}
1124
1125 /**
1126 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1127 *
1128 * @param call The {@code Call} invoking this method.
1129 * @param details A {@code Details} object describing the {@code Call}.
1130 */
1131 public void onDetailsChanged(Call call, Details details) {}
1132
1133 /**
1134 * Invoked when the text messages that can be used as responses to the incoming
1135 * {@code Call} are loaded from the relevant database.
1136 * See {@link #getCannedTextResponses()}.
1137 *
1138 * @param call The {@code Call} invoking this method.
1139 * @param cannedTextResponses The text messages useable as responses.
1140 */
1141 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1142
1143 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001144 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1145 * character. This causes the post-dial signals to stop pending user confirmation. An
1146 * implementation should present this choice to the user and invoke
1147 * {@link #postDialContinue(boolean)} when the user makes the choice.
1148 *
1149 * @param call The {@code Call} invoking this method.
1150 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1151 */
1152 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1153
1154 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001155 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001156 *
1157 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001158 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001159 */
Andrew Lee50aca232014-07-22 16:41:54 -07001160 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001161
1162 /**
1163 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1164 * up their UI for the {@code Call} in response to state transitions. Specifically,
1165 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1166 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1167 * clients should wait for this method to be invoked.
1168 *
1169 * @param call The {@code Call} being destroyed.
1170 */
1171 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001172
1173 /**
1174 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1175 * conferenced.
1176 *
1177 * @param call The {@code Call} being updated.
1178 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1179 * conferenced.
1180 */
1181 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001182
1183 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001184 * Invoked when a {@link Call} receives an event from its associated {@link Connection} or
1185 * {@link Conference}.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001186 * <p>
1187 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1188 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1189 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1190 * possible that a {@link ConnectionService} has defined its own Connection events which a
1191 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001192 * <p>
Tyler Gunn5567d742019-10-31 13:04:37 -07001193 * See {@link Connection#sendConnectionEvent(String, Bundle)},
1194 * {@link Conference#sendConferenceEvent(String, Bundle)}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001195 *
1196 * @param call The {@code Call} receiving the event.
1197 * @param event The event.
1198 * @param extras Extras associated with the connection event.
1199 */
1200 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001201
1202 /**
1203 * Invoked when the RTT mode changes for this call.
1204 * @param call The call whose RTT mode has changed.
1205 * @param mode the new RTT mode, one of
1206 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1207 * or {@link RttCall#RTT_MODE_VCO}
1208 */
1209 public void onRttModeChanged(Call call, int mode) {}
1210
1211 /**
1212 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1213 * @param call The call whose RTT status has changed.
1214 * @param enabled whether RTT is now enabled or disabled
1215 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1216 * on, null otherwise.
1217 */
1218 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1219
1220 /**
1221 * Invoked when the remote end of the connection has requested that an RTT communication
1222 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1223 * with the same ID that this method is invoked with.
1224 * @param call The call which the RTT request was placed on
1225 * @param id The ID of the request.
1226 */
1227 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001228
1229 /**
1230 * Invoked when the RTT session failed to initiate for some reason, including rejection
1231 * by the remote party.
1232 * @param call The call which the RTT initiation failure occurred on.
1233 * @param reason One of the status codes defined in
1234 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1235 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1236 */
1237 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001238
1239 /**
1240 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1241 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001242 * <p>
1243 * For a full discussion of the handover process and the APIs involved, see
1244 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1245 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001246 * @param call The call which had initiated handover.
1247 */
1248 public void onHandoverComplete(Call call) {}
1249
1250 /**
1251 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1252 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001253 * <p>
1254 * For a full discussion of the handover process and the APIs involved, see
1255 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1256 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001257 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001258 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001259 */
1260 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001261 }
1262
1263 /**
1264 * A class that holds the state that describes the state of the RTT channel to the remote
1265 * party, if it is active.
1266 */
1267 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001268 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001269 @Retention(RetentionPolicy.SOURCE)
1270 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1271 public @interface RttAudioMode {}
1272
1273 /**
1274 * For metrics use. Default value in the proto.
1275 * @hide
1276 */
1277 public static final int RTT_MODE_INVALID = 0;
1278
1279 /**
1280 * Indicates that there should be a bidirectional audio stream between the two parties
1281 * on the call.
1282 */
1283 public static final int RTT_MODE_FULL = 1;
1284
1285 /**
1286 * Indicates that the local user should be able to hear the audio stream from the remote
1287 * user, but not vice versa. Equivalent to muting the microphone.
1288 */
1289 public static final int RTT_MODE_HCO = 2;
1290
1291 /**
1292 * Indicates that the remote user should be able to hear the audio stream from the local
1293 * user, but not vice versa. Equivalent to setting the volume to zero.
1294 */
1295 public static final int RTT_MODE_VCO = 3;
1296
1297 private static final int READ_BUFFER_SIZE = 1000;
1298
1299 private InputStreamReader mReceiveStream;
1300 private OutputStreamWriter mTransmitStream;
1301 private int mRttMode;
1302 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001303 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001304 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1305
1306 /**
1307 * @hide
1308 */
Hall Liu57006aa2017-02-06 10:49:48 -08001309 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1310 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1311 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001312 mReceiveStream = receiveStream;
1313 mTransmitStream = transmitStream;
1314 mRttMode = mode;
1315 mInCallAdapter = inCallAdapter;
1316 }
1317
1318 /**
1319 * Returns the current RTT audio mode.
1320 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1321 * {@link #RTT_MODE_HCO}.
1322 */
1323 public int getRttAudioMode() {
1324 return mRttMode;
1325 }
1326
1327 /**
1328 * Sets the RTT audio mode. The requested mode change will be communicated through
1329 * {@link Callback#onRttModeChanged(Call, int)}.
1330 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1331 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1332 */
1333 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001334 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001335 }
1336
1337 /**
1338 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1339 * RTT transmits text in real-time, this method should be called once for each character
1340 * the user enters into the device.
1341 *
1342 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1343 * lead to interleaved text.
1344 * @param input The message to send to the remote user.
1345 */
1346 public void write(String input) throws IOException {
1347 mTransmitStream.write(input);
1348 mTransmitStream.flush();
1349 }
1350
1351 /**
1352 * Reads a string from the remote user, blocking if there is no data available. Returns
1353 * {@code null} if the RTT conversation has been terminated and there is no further data
1354 * to read.
1355 *
1356 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1357 * lead to interleaved text.
1358 * @return A string containing text sent by the remote user, or {@code null} if the
1359 * conversation has been terminated or if there was an error while reading.
1360 */
Hall Liub1c8a772017-07-17 17:04:41 -07001361 public String read() {
1362 try {
1363 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1364 if (numRead < 0) {
1365 return null;
1366 }
1367 return new String(mReadBuffer, 0, numRead);
1368 } catch (IOException e) {
1369 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001370 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001371 }
Hall Liuffa4a812017-03-02 16:11:00 -08001372 }
1373
1374 /**
1375 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1376 * be read.
1377 * @return A string containing text entered by the user, or {@code null} if the user has
1378 * not entered any new text yet.
1379 */
1380 public String readImmediately() throws IOException {
1381 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001382 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1383 if (numRead < 0) {
1384 return null;
1385 }
1386 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001387 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001388 return null;
1389 }
1390 }
Hall Liue9041242018-02-09 16:40:03 -08001391
1392 /**
1393 * Closes the underlying file descriptors
1394 * @hide
1395 */
1396 public void close() {
1397 try {
1398 mReceiveStream.close();
1399 } catch (IOException e) {
1400 // ignore
1401 }
1402 try {
1403 mTransmitStream.close();
1404 } catch (IOException e) {
1405 // ignore
1406 }
1407 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001408 }
1409
Andrew Leeda80c872015-04-15 14:09:50 -07001410 /**
1411 * @deprecated Use {@code Call.Callback} instead.
1412 * @hide
1413 */
1414 @Deprecated
1415 @SystemApi
1416 public static abstract class Listener extends Callback { }
1417
Ihab Awade63fadb2014-07-09 21:52:04 -07001418 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001419 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001420 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001421 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001422 private final List<Call> mChildren = new ArrayList<>();
1423 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001424 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001425 private final List<Call> mConferenceableCalls = new ArrayList<>();
1426 private final List<Call> mUnmodifiableConferenceableCalls =
1427 Collections.unmodifiableList(mConferenceableCalls);
1428
Santos Cordon823fd3c2014-08-07 18:35:18 -07001429 private boolean mChildrenCached;
1430 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001431 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001432 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001433 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001434 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001435 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001436 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001437 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001438 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001439 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001440
1441 /**
1442 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1443 *
1444 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1445 * remaining or this {@code Call} is not in a post-dial state.
1446 */
1447 public String getRemainingPostDialSequence() {
1448 return mRemainingPostDialSequence;
1449 }
1450
1451 /**
1452 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001453 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001454 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001455 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001456 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001457 }
1458
1459 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301460 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1461 *
1462 * @param address The address to which the call will be deflected.
1463 */
1464 public void deflect(Uri address) {
1465 mInCallAdapter.deflectCall(mTelecomCallId, address);
1466 }
1467
1468 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001469 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1470 *
1471 * @param rejectWithMessage Whether to reject with a text message.
1472 * @param textMessage An optional text message with which to respond.
1473 */
1474 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001475 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001476 }
1477
1478 /**
1479 * Instructs this {@code Call} to disconnect.
1480 */
1481 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001482 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001483 }
1484
1485 /**
1486 * Instructs this {@code Call} to go on hold.
1487 */
1488 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001489 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001490 }
1491
1492 /**
1493 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1494 */
1495 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001496 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001497 }
1498
1499 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001500 * Instructs Telecom to put the call into the background audio processing state.
1501 *
1502 * This method can be called either when the call is in {@link #STATE_RINGING} or
1503 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1504 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1505 * order to capture and play audio on the call stream.
1506 *
1507 * This method can only be called by the default dialer app.
1508 * @hide
1509 */
1510 @SystemApi
1511 @TestApi
1512 //@RequiresPermission(android.Manifest.permission.BACKGROUND_CALL_AUDIO)
1513 public void enterBackgroundAudioProcessing() {
1514 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1515 throw new IllegalStateException("Call must be active or ringing");
1516 }
1517 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1518 }
1519
1520 /**
1521 * Instructs Telecom to come out of the background audio processing state requested by
1522 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1523 *
1524 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1525 *
1526 * @param shouldRing If true, Telecom will put the call into the
1527 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1528 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1529 * immediately.
1530 * @hide
1531 */
1532 @SystemApi
1533 @TestApi
1534 //@RequiresPermission(android.Manifest.permission.BACKGROUND_CALL_AUDIO)
1535 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1536 if (mState != STATE_AUDIO_PROCESSING) {
1537 throw new IllegalStateException("Call must in the audio processing state");
1538 }
1539 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1540 }
1541
1542 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001543 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1544 *
1545 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1546 *
1547 * @param digit A character representing the DTMF digit for which to play the tone. This
1548 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1549 */
1550 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001551 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001552 }
1553
1554 /**
1555 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1556 * currently playing.
1557 *
1558 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1559 * currently playing, this method will do nothing.
1560 */
1561 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001562 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001563 }
1564
1565 /**
1566 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1567 *
1568 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1569 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001570 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001571 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001572 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1573 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001574 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001575 * {@code Call} will pause playing the tones and notify callbacks via
1576 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001577 * should display to the user an indication of this state and an affordance to continue
1578 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1579 * app should invoke the {@link #postDialContinue(boolean)} method.
1580 *
1581 * @param proceed Whether or not to continue with the post-dial sequence.
1582 */
1583 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001584 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001585 }
1586
1587 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001588 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001589 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001590 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001591 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1592 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001593
1594 }
1595
1596 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001597 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001598 *
1599 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001600 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001601 public void conference(Call callToConferenceWith) {
1602 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001603 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001604 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001605 }
1606
1607 /**
1608 * Instructs this {@code Call} to split from any conference call with which it may be
1609 * connected.
1610 */
1611 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001612 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001613 }
1614
1615 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001616 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001617 */
1618 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001619 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001620 }
1621
1622 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001623 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001624 */
1625 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001626 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001627 }
1628
1629 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001630 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1631 * device.
1632 * <p>
1633 * Calls to this method are ignored if the call does not have the
1634 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1635 * <p>
1636 * An {@link InCallService} will only see calls which support this method if it has the
1637 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1638 * in its manifest.
1639 */
1640 public void pullExternalCall() {
1641 // If this isn't an external call, ignore the request.
1642 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1643 return;
1644 }
1645
1646 mInCallAdapter.pullExternalCall(mTelecomCallId);
1647 }
1648
1649 /**
1650 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1651 * the {@link ConnectionService}.
1652 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001653 * Call events are used to communicate point in time information from an {@link InCallService}
1654 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1655 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1656 * {@link ConnectionService}.
1657 * <p>
1658 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1659 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1660 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001661 * Events are exposed to {@link ConnectionService} implementations via
1662 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1663 * <p>
1664 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001665 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1666 * ignore some events altogether.
1667 * <p>
1668 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1669 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1670 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1671 * they define their own event types in this namespace. When defining a custom event type,
1672 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1673 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1674 * <p>
1675 * When defining events and the associated extras, it is important to keep their behavior
1676 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1677 * events/extras should me maintained to ensure backwards compatibility with older
1678 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001679 *
1680 * @param event The connection event.
1681 * @param extras Bundle containing extra information associated with the event.
1682 */
1683 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001684 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001685 }
1686
1687 /**
Hall Liu95d55872017-01-25 17:12:49 -08001688 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1689 * guaranteed, and notification of success will be via the
1690 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1691 */
1692 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001693 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001694 }
1695
1696 /**
1697 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1698 * callback.
1699 * The ID used here should be the same as the ID that was received via the callback.
1700 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1701 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1702 */
1703 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001704 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001705 }
1706
1707 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001708 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1709 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1710 * handover.
1711 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001712 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1713 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1714 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1715 * is referred to as the source of the handover, and the video calling app is referred to as the
1716 * destination.
1717 * <p>
1718 * When considering a handover scenario the device this method is called on is considered the
1719 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1720 * other device is considered the <em>receiving</em> device.
1721 * <p>
1722 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1723 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1724 * and invoke
1725 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1726 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1727 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1728 * At this point the app should display UI to indicate to the user that a call
1729 * handover is in process.
1730 * <p>
1731 * The destination app is responsible for communicating the handover request from the
1732 * <em>initiating</em> device to the <em>receiving</em> device.
1733 * <p>
1734 * When the app on the <em>receiving</em> device receives the handover request, it calls
1735 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1736 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1737 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1738 * choose whether they want to continue their call in the destination app.
1739 * <p>
1740 * When the destination app on the <em>receiving</em> device calls
1741 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1742 * {@link ConnectionService} and call
1743 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1744 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1745 * {@link Connection} to represent the handover call.
1746 * <p>
1747 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1748 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1749 * original call. If the user rejects the handover, the app calls
1750 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1751 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1752 * <p>
1753 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1754 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1755 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1756 * <p>
1757 * Errors in the handover process are reported to the {@link InCallService} via
1758 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1759 * the involved {@link ConnectionService}s via
1760 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001761 *
1762 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1763 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001764 * @param videoState Indicates the video state desired after the handover (see the
1765 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001766 * @param extras Bundle containing extra information to be passed to the
1767 * {@link ConnectionService}
1768 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001769 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1770 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001771 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1772 }
1773
1774 /**
Hall Liu95d55872017-01-25 17:12:49 -08001775 * Terminate the RTT session on this call. The resulting state change will be notified via
1776 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1777 */
1778 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001779 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001780 }
1781
1782 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001783 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1784 * added.
1785 * <p>
1786 * No assumptions should be made as to how an In-Call UI or service will handle these
1787 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1788 *
1789 * @param extras The extras to add.
1790 */
1791 public final void putExtras(Bundle extras) {
1792 if (extras == null) {
1793 return;
1794 }
1795
1796 if (mExtras == null) {
1797 mExtras = new Bundle();
1798 }
1799 mExtras.putAll(extras);
1800 mInCallAdapter.putExtras(mTelecomCallId, extras);
1801 }
1802
1803 /**
1804 * Adds a boolean extra to this {@link Call}.
1805 *
1806 * @param key The extra key.
1807 * @param value The value.
1808 * @hide
1809 */
1810 public final void putExtra(String key, boolean value) {
1811 if (mExtras == null) {
1812 mExtras = new Bundle();
1813 }
1814 mExtras.putBoolean(key, value);
1815 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1816 }
1817
1818 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001819 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001820 *
1821 * @param key The extra key.
1822 * @param value The value.
1823 * @hide
1824 */
1825 public final void putExtra(String key, int value) {
1826 if (mExtras == null) {
1827 mExtras = new Bundle();
1828 }
1829 mExtras.putInt(key, value);
1830 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1831 }
1832
1833 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001834 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001835 *
1836 * @param key The extra key.
1837 * @param value The value.
1838 * @hide
1839 */
1840 public final void putExtra(String key, String value) {
1841 if (mExtras == null) {
1842 mExtras = new Bundle();
1843 }
1844 mExtras.putString(key, value);
1845 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1846 }
1847
1848 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001849 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001850 *
1851 * @param keys The keys of the extras to remove.
1852 */
1853 public final void removeExtras(List<String> keys) {
1854 if (mExtras != null) {
1855 for (String key : keys) {
1856 mExtras.remove(key);
1857 }
1858 if (mExtras.size() == 0) {
1859 mExtras = null;
1860 }
1861 }
1862 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1863 }
1864
1865 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001866 * Removes extras from this {@link Call}.
1867 *
1868 * @param keys The keys of the extras to remove.
1869 */
1870 public final void removeExtras(String ... keys) {
1871 removeExtras(Arrays.asList(keys));
1872 }
1873
1874 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001875 * Obtains the parent of this {@code Call} in a conference, if any.
1876 *
1877 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1878 * child of any conference {@code Call}s.
1879 */
1880 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001881 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001882 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001883 }
1884 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001885 }
1886
1887 /**
1888 * Obtains the children of this conference {@code Call}, if any.
1889 *
1890 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1891 * {@code List} otherwise.
1892 */
1893 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001894 if (!mChildrenCached) {
1895 mChildrenCached = true;
1896 mChildren.clear();
1897
1898 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001899 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001900 if (call == null) {
1901 // At least one child was still not found, so do not save true for "cached"
1902 mChildrenCached = false;
1903 } else {
1904 mChildren.add(call);
1905 }
1906 }
1907 }
1908
Ihab Awade63fadb2014-07-09 21:52:04 -07001909 return mUnmodifiableChildren;
1910 }
1911
1912 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001913 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1914 *
1915 * @return The list of conferenceable {@code Call}s.
1916 */
1917 public List<Call> getConferenceableCalls() {
1918 return mUnmodifiableConferenceableCalls;
1919 }
1920
1921 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001922 * Obtains the state of this {@code Call}.
1923 *
1924 * @return A state value, chosen from the {@code STATE_*} constants.
1925 */
1926 public int getState() {
1927 return mState;
1928 }
1929
1930 /**
1931 * Obtains a list of canned, pre-configured message responses to present to the user as
1932 * ways of rejecting this {@code Call} using via a text message.
1933 *
1934 * @see #reject(boolean, String)
1935 *
1936 * @return A list of canned text message responses.
1937 */
1938 public List<String> getCannedTextResponses() {
1939 return mCannedTextResponses;
1940 }
1941
1942 /**
1943 * Obtains an object that can be used to display video from this {@code Call}.
1944 *
Andrew Lee50aca232014-07-22 16:41:54 -07001945 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001946 */
Andrew Lee50aca232014-07-22 16:41:54 -07001947 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001948 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001949 }
1950
1951 /**
1952 * Obtains an object containing call details.
1953 *
1954 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1955 * result may be {@code null}.
1956 */
1957 public Details getDetails() {
1958 return mDetails;
1959 }
1960
1961 /**
Hall Liu95d55872017-01-25 17:12:49 -08001962 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1963 * receive RTT text data, as well as to change the RTT mode.
1964 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1965 */
1966 public @Nullable RttCall getRttCall() {
1967 return mRttCall;
1968 }
1969
1970 /**
1971 * Returns whether this call has an active RTT connection.
1972 * @return true if there is a connection, false otherwise.
1973 */
1974 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08001975 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08001976 }
1977
1978 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001979 * Registers a callback to this {@code Call}.
1980 *
1981 * @param callback A {@code Callback}.
1982 */
1983 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001984 registerCallback(callback, new Handler());
1985 }
1986
1987 /**
1988 * Registers a callback to this {@code Call}.
1989 *
1990 * @param callback A {@code Callback}.
1991 * @param handler A handler which command and status changes will be delivered to.
1992 */
1993 public void registerCallback(Callback callback, Handler handler) {
1994 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001995 // Don't allow new callback registration if the call is already being destroyed.
1996 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001997 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1998 }
Andrew Leeda80c872015-04-15 14:09:50 -07001999 }
2000
2001 /**
2002 * Unregisters a callback from this {@code Call}.
2003 *
2004 * @param callback A {@code Callback}.
2005 */
2006 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002007 // Don't allow callback deregistration if the call is already being destroyed.
2008 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002009 for (CallbackRecord<Callback> record : mCallbackRecords) {
2010 if (record.getCallback() == callback) {
2011 mCallbackRecords.remove(record);
2012 break;
2013 }
2014 }
Andrew Leeda80c872015-04-15 14:09:50 -07002015 }
2016 }
2017
Santos Cordon3c20d632016-02-25 16:12:35 -08002018 @Override
2019 public String toString() {
2020 return new StringBuilder().
2021 append("Call [id: ").
2022 append(mTelecomCallId).
2023 append(", state: ").
2024 append(stateToString(mState)).
2025 append(", details: ").
2026 append(mDetails).
2027 append("]").toString();
2028 }
2029
2030 /**
2031 * @param state An integer value of a {@code STATE_*} constant.
2032 * @return A string representation of the value.
2033 */
2034 private static String stateToString(int state) {
2035 switch (state) {
2036 case STATE_NEW:
2037 return "NEW";
2038 case STATE_RINGING:
2039 return "RINGING";
2040 case STATE_DIALING:
2041 return "DIALING";
2042 case STATE_ACTIVE:
2043 return "ACTIVE";
2044 case STATE_HOLDING:
2045 return "HOLDING";
2046 case STATE_DISCONNECTED:
2047 return "DISCONNECTED";
2048 case STATE_CONNECTING:
2049 return "CONNECTING";
2050 case STATE_DISCONNECTING:
2051 return "DISCONNECTING";
2052 case STATE_SELECT_PHONE_ACCOUNT:
2053 return "SELECT_PHONE_ACCOUNT";
Hall Liu4e35b642019-10-14 17:50:45 -07002054 case STATE_SIMULATED_RINGING:
2055 return "SIMULATED_RINGING";
2056 case STATE_AUDIO_PROCESSING:
2057 return "AUDIO_PROCESSING";
Santos Cordon3c20d632016-02-25 16:12:35 -08002058 default:
2059 Log.w(Call.class, "Unknown state %d", state);
2060 return "UNKNOWN";
2061 }
2062 }
2063
Andrew Leeda80c872015-04-15 14:09:50 -07002064 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002065 * Adds a listener to this {@code Call}.
2066 *
2067 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002068 * @deprecated Use {@link #registerCallback} instead.
2069 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002070 */
Andrew Leeda80c872015-04-15 14:09:50 -07002071 @Deprecated
2072 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002073 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002074 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002075 }
2076
2077 /**
2078 * Removes a listener from this {@code Call}.
2079 *
2080 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002081 * @deprecated Use {@link #unregisterCallback} instead.
2082 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002083 */
Andrew Leeda80c872015-04-15 14:09:50 -07002084 @Deprecated
2085 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002086 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002087 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002088 }
2089
2090 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002091 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2092 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002093 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002094 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002095 mInCallAdapter = inCallAdapter;
2096 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002097 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002098 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002099 }
2100
2101 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002102 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002103 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002104 mPhone = phone;
2105 mTelecomCallId = telecomCallId;
2106 mInCallAdapter = inCallAdapter;
2107 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002108 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002109 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002110 }
2111
2112 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002113 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002114 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002115 }
2116
2117 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002118 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002119
Ihab Awade63fadb2014-07-09 21:52:04 -07002120 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002121 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002122 boolean detailsChanged = !Objects.equals(mDetails, details);
2123 if (detailsChanged) {
2124 mDetails = details;
2125 }
2126
2127 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002128 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2129 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2130 mCannedTextResponses =
2131 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002132 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002133 }
2134
Tyler Gunn159f35c2017-03-02 09:28:37 -08002135 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
2136 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07002137 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002138 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07002139 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002140 mVideoCallImpl = newVideoCallImpl;
2141 }
2142 if (mVideoCallImpl != null) {
2143 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002144 }
2145
Santos Cordone3c507b2015-04-23 14:44:19 -07002146 int state = parcelableCall.getState();
Hall Liu31de23d2019-10-11 15:38:29 -07002147 if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2148 state = Call.STATE_RINGING;
2149 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002150 boolean stateChanged = mState != state;
2151 if (stateChanged) {
2152 mState = state;
2153 }
2154
Santos Cordon823fd3c2014-08-07 18:35:18 -07002155 String parentId = parcelableCall.getParentCallId();
2156 boolean parentChanged = !Objects.equals(mParentId, parentId);
2157 if (parentChanged) {
2158 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002159 }
2160
Santos Cordon823fd3c2014-08-07 18:35:18 -07002161 List<String> childCallIds = parcelableCall.getChildCallIds();
2162 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2163 if (childrenChanged) {
2164 mChildrenIds.clear();
2165 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2166 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002167 }
2168
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002169 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2170 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2171 for (String otherId : conferenceableCallIds) {
2172 if (callIdMap.containsKey(otherId)) {
2173 conferenceableCalls.add(callIdMap.get(otherId));
2174 }
2175 }
2176
2177 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2178 mConferenceableCalls.clear();
2179 mConferenceableCalls.addAll(conferenceableCalls);
2180 fireConferenceableCallsChanged();
2181 }
2182
Hall Liu95d55872017-01-25 17:12:49 -08002183 boolean isRttChanged = false;
2184 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002185 if (parcelableCall.getIsRttCallChanged()
2186 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002187 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2188 InputStreamReader receiveStream = new InputStreamReader(
2189 new ParcelFileDescriptor.AutoCloseInputStream(
2190 parcelableRttCall.getReceiveStream()),
2191 StandardCharsets.UTF_8);
2192 OutputStreamWriter transmitStream = new OutputStreamWriter(
2193 new ParcelFileDescriptor.AutoCloseOutputStream(
2194 parcelableRttCall.getTransmitStream()),
2195 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002196 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002197 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2198 if (mRttCall == null) {
2199 isRttChanged = true;
2200 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2201 rttModeChanged = true;
2202 }
2203 mRttCall = newRttCall;
2204 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2205 && parcelableCall.getIsRttCallChanged()) {
2206 isRttChanged = true;
2207 mRttCall = null;
2208 }
2209
Ihab Awade63fadb2014-07-09 21:52:04 -07002210 // Now we fire updates, ensuring that any client who listens to any of these notifications
2211 // gets the most up-to-date state.
2212
2213 if (stateChanged) {
2214 fireStateChanged(mState);
2215 }
2216 if (detailsChanged) {
2217 fireDetailsChanged(mDetails);
2218 }
2219 if (cannedTextResponsesChanged) {
2220 fireCannedTextResponsesLoaded(mCannedTextResponses);
2221 }
Andrew Lee50aca232014-07-22 16:41:54 -07002222 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002223 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002224 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002225 if (parentChanged) {
2226 fireParentChanged(getParent());
2227 }
2228 if (childrenChanged) {
2229 fireChildrenChanged(getChildren());
2230 }
Hall Liu95d55872017-01-25 17:12:49 -08002231 if (isRttChanged) {
2232 fireOnIsRttChanged(mRttCall != null, mRttCall);
2233 }
2234 if (rttModeChanged) {
2235 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2236 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002237
2238 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2239 // remove ourselves from the Phone. Note that we do this after completing all state updates
2240 // so a client can cleanly transition all their UI to the state appropriate for a
2241 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2242 if (mState == STATE_DISCONNECTED) {
2243 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002244 }
2245 }
2246
2247 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002248 final void internalSetPostDialWait(String remaining) {
2249 mRemainingPostDialSequence = remaining;
2250 firePostDialWait(mRemainingPostDialSequence);
2251 }
2252
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002253 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002254 final void internalSetDisconnected() {
2255 if (mState != Call.STATE_DISCONNECTED) {
2256 mState = Call.STATE_DISCONNECTED;
2257 fireStateChanged(mState);
2258 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002259 }
2260 }
2261
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002262 /** {@hide} */
2263 final void internalOnConnectionEvent(String event, Bundle extras) {
2264 fireOnConnectionEvent(event, extras);
2265 }
2266
Hall Liu95d55872017-01-25 17:12:49 -08002267 /** {@hide} */
2268 final void internalOnRttUpgradeRequest(final int requestId) {
2269 for (CallbackRecord<Callback> record : mCallbackRecords) {
2270 final Call call = this;
2271 final Callback callback = record.getCallback();
2272 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2273 }
2274 }
2275
Hall Liu57006aa2017-02-06 10:49:48 -08002276 /** @hide */
2277 final void internalOnRttInitiationFailure(int reason) {
2278 for (CallbackRecord<Callback> record : mCallbackRecords) {
2279 final Call call = this;
2280 final Callback callback = record.getCallback();
2281 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2282 }
2283 }
2284
Sanket Padawe85291f62017-12-01 13:59:27 -08002285 /** {@hide} */
2286 final void internalOnHandoverFailed(int error) {
2287 for (CallbackRecord<Callback> record : mCallbackRecords) {
2288 final Call call = this;
2289 final Callback callback = record.getCallback();
2290 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2291 }
2292 }
2293
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002294 /** {@hide} */
2295 final void internalOnHandoverComplete() {
2296 for (CallbackRecord<Callback> record : mCallbackRecords) {
2297 final Call call = this;
2298 final Callback callback = record.getCallback();
2299 record.getHandler().post(() -> callback.onHandoverComplete(call));
2300 }
2301 }
2302
Andrew Lee011728f2015-04-23 15:47:06 -07002303 private void fireStateChanged(final int newState) {
2304 for (CallbackRecord<Callback> record : mCallbackRecords) {
2305 final Call call = this;
2306 final Callback callback = record.getCallback();
2307 record.getHandler().post(new Runnable() {
2308 @Override
2309 public void run() {
2310 callback.onStateChanged(call, newState);
2311 }
2312 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002313 }
2314 }
2315
Andrew Lee011728f2015-04-23 15:47:06 -07002316 private void fireParentChanged(final Call newParent) {
2317 for (CallbackRecord<Callback> record : mCallbackRecords) {
2318 final Call call = this;
2319 final Callback callback = record.getCallback();
2320 record.getHandler().post(new Runnable() {
2321 @Override
2322 public void run() {
2323 callback.onParentChanged(call, newParent);
2324 }
2325 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002326 }
2327 }
2328
Andrew Lee011728f2015-04-23 15:47:06 -07002329 private void fireChildrenChanged(final List<Call> children) {
2330 for (CallbackRecord<Callback> record : mCallbackRecords) {
2331 final Call call = this;
2332 final Callback callback = record.getCallback();
2333 record.getHandler().post(new Runnable() {
2334 @Override
2335 public void run() {
2336 callback.onChildrenChanged(call, children);
2337 }
2338 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002339 }
2340 }
2341
Andrew Lee011728f2015-04-23 15:47:06 -07002342 private void fireDetailsChanged(final Details details) {
2343 for (CallbackRecord<Callback> record : mCallbackRecords) {
2344 final Call call = this;
2345 final Callback callback = record.getCallback();
2346 record.getHandler().post(new Runnable() {
2347 @Override
2348 public void run() {
2349 callback.onDetailsChanged(call, details);
2350 }
2351 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002352 }
2353 }
2354
Andrew Lee011728f2015-04-23 15:47:06 -07002355 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2356 for (CallbackRecord<Callback> record : mCallbackRecords) {
2357 final Call call = this;
2358 final Callback callback = record.getCallback();
2359 record.getHandler().post(new Runnable() {
2360 @Override
2361 public void run() {
2362 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2363 }
2364 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002365 }
2366 }
2367
Andrew Lee011728f2015-04-23 15:47:06 -07002368 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2369 for (CallbackRecord<Callback> record : mCallbackRecords) {
2370 final Call call = this;
2371 final Callback callback = record.getCallback();
2372 record.getHandler().post(new Runnable() {
2373 @Override
2374 public void run() {
2375 callback.onVideoCallChanged(call, videoCall);
2376 }
2377 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002378 }
2379 }
2380
Andrew Lee011728f2015-04-23 15:47:06 -07002381 private void firePostDialWait(final String remainingPostDialSequence) {
2382 for (CallbackRecord<Callback> record : mCallbackRecords) {
2383 final Call call = this;
2384 final Callback callback = record.getCallback();
2385 record.getHandler().post(new Runnable() {
2386 @Override
2387 public void run() {
2388 callback.onPostDialWait(call, remainingPostDialSequence);
2389 }
2390 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002391 }
2392 }
2393
2394 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002395 /**
2396 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2397 * onCallRemoved callback, we remove this call from the Phone's record
2398 * only once all of the registered onCallDestroyed callbacks are executed.
2399 * All the callbacks get removed from our records as a part of this operation
2400 * since onCallDestroyed is the final callback.
2401 */
2402 final Call call = this;
2403 if (mCallbackRecords.isEmpty()) {
2404 // No callbacks registered, remove the call from Phone's record.
2405 mPhone.internalRemoveCall(call);
2406 }
2407 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002408 final Callback callback = record.getCallback();
2409 record.getHandler().post(new Runnable() {
2410 @Override
2411 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002412 boolean isFinalRemoval = false;
2413 RuntimeException toThrow = null;
2414 try {
2415 callback.onCallDestroyed(call);
2416 } catch (RuntimeException e) {
2417 toThrow = e;
2418 }
2419 synchronized(Call.this) {
2420 mCallbackRecords.remove(record);
2421 if (mCallbackRecords.isEmpty()) {
2422 isFinalRemoval = true;
2423 }
2424 }
2425 if (isFinalRemoval) {
2426 mPhone.internalRemoveCall(call);
2427 }
2428 if (toThrow != null) {
2429 throw toThrow;
2430 }
Andrew Lee011728f2015-04-23 15:47:06 -07002431 }
2432 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002433 }
2434 }
2435
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002436 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002437 for (CallbackRecord<Callback> record : mCallbackRecords) {
2438 final Call call = this;
2439 final Callback callback = record.getCallback();
2440 record.getHandler().post(new Runnable() {
2441 @Override
2442 public void run() {
2443 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2444 }
2445 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002446 }
2447 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002448
2449 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002450 * Notifies listeners of an incoming connection event.
2451 * <p>
2452 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2453 *
2454 * @param event
2455 * @param extras
2456 */
2457 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2458 for (CallbackRecord<Callback> record : mCallbackRecords) {
2459 final Call call = this;
2460 final Callback callback = record.getCallback();
2461 record.getHandler().post(new Runnable() {
2462 @Override
2463 public void run() {
2464 callback.onConnectionEvent(call, event, extras);
2465 }
2466 });
2467 }
2468 }
2469
2470 /**
Hall Liu95d55872017-01-25 17:12:49 -08002471 * Notifies listeners of an RTT on/off change
2472 *
2473 * @param enabled True if RTT is now enabled, false otherwise
2474 */
2475 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2476 for (CallbackRecord<Callback> record : mCallbackRecords) {
2477 final Call call = this;
2478 final Callback callback = record.getCallback();
2479 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2480 }
2481 }
2482
2483 /**
2484 * Notifies listeners of a RTT mode change
2485 *
2486 * @param mode The new RTT mode
2487 */
2488 private void fireOnRttModeChanged(final int mode) {
2489 for (CallbackRecord<Callback> record : mCallbackRecords) {
2490 final Call call = this;
2491 final Callback callback = record.getCallback();
2492 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2493 }
2494 }
2495
2496 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002497 * Determines if two bundles are equal.
2498 *
2499 * @param bundle The original bundle.
2500 * @param newBundle The bundle to compare with.
2501 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2502 */
2503 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2504 if (bundle == null || newBundle == null) {
2505 return bundle == newBundle;
2506 }
2507
2508 if (bundle.size() != newBundle.size()) {
2509 return false;
2510 }
2511
2512 for(String key : bundle.keySet()) {
2513 if (key != null) {
2514 final Object value = bundle.get(key);
2515 final Object newValue = newBundle.get(key);
2516 if (!Objects.equals(value, newValue)) {
2517 return false;
2518 }
2519 }
2520 }
2521 return true;
2522 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002523}