blob: 5e71416a0510a90864f26e064805df9c016190b7 [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.
515 * See also {@link Connection#PROPERTY_ASSISTED_DIALING_USED}
516 * @hide
517 */
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} */
731 public String getTelecomCallId() {
732 return mTelecomCallId;
733 }
734
Andrew Lee2378ea72015-04-29 14:38:11 -0700735 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700736 * @return The handle (e.g., phone number) to which the {@code Call} is currently
737 * connected.
738 */
739 public Uri getHandle() {
740 return mHandle;
741 }
742
743 /**
744 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700745 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700746 */
747 public int getHandlePresentation() {
748 return mHandlePresentation;
749 }
750
751 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800752 * The display name for the caller.
753 * <p>
754 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800755 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700756 * @return The display name for the caller.
757 */
758 public String getCallerDisplayName() {
759 return mCallerDisplayName;
760 }
761
762 /**
763 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700764 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700765 */
766 public int getCallerDisplayNamePresentation() {
767 return mCallerDisplayNamePresentation;
768 }
769
770 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700771 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
772 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700773 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700774 public PhoneAccountHandle getAccountHandle() {
775 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700776 }
777
778 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800779 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
780 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700781 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700782 public int getCallCapabilities() {
783 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700784 }
785
786 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700787 * @return A bitmask of the properties of the {@code Call}, as defined by the various
788 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700789 */
790 public int getCallProperties() {
791 return mCallProperties;
792 }
793
794 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800795 * @return a bitmask of the audio routes available for the call.
796 *
797 * @hide
798 */
799 public int getSupportedAudioRoutes() {
800 return mSupportedAudioRoutes;
801 }
802
803 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700804 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700805 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700806 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700807 public DisconnectCause getDisconnectCause() {
808 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700809 }
810
811 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700812 * Returns the time the {@link Call} connected (i.e. became active). This information is
813 * updated periodically, but user interfaces should not rely on this to display the "call
814 * time clock". For the time when the call was first added to Telecom, see
815 * {@link #getCreationTimeMillis()}.
816 *
817 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700818 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700819 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700820 return mConnectTimeMillis;
821 }
822
823 /**
824 * @return Information about any calling gateway the {@code Call} may be using.
825 */
826 public GatewayInfo getGatewayInfo() {
827 return mGatewayInfo;
828 }
829
Andrew Lee7a341382014-07-15 17:05:08 -0700830 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700831 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700832 */
833 public int getVideoState() {
834 return mVideoState;
835 }
836
Ihab Awad5d0410f2014-07-30 10:07:40 -0700837 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700838 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700839 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700840 */
841 public StatusHints getStatusHints() {
842 return mStatusHints;
843 }
844
Nancy Chen10798dc2014-08-08 14:00:25 -0700845 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700846 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700847 */
848 public Bundle getExtras() {
849 return mExtras;
850 }
851
Santos Cordon6b7f9552015-05-27 17:21:45 -0700852 /**
853 * @return The extras used with the original intent to place this call.
854 */
855 public Bundle getIntentExtras() {
856 return mIntentExtras;
857 }
858
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700859 /**
860 * Returns the time when the call was first created and added to Telecom. This is the same
861 * time that is logged as the start time in the Call Log (see
862 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
863 * (became active), see {@link #getConnectTimeMillis()}.
864 *
865 * @return The creation time of the call, in millis since the epoch.
866 */
867 public long getCreationTimeMillis() {
868 return mCreationTimeMillis;
869 }
870
Tyler Gunnd081f042018-12-04 12:56:45 -0800871 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -0800872 * Indicates whether the call is an incoming or outgoing call.
873 * @return The call's direction.
874 */
875 public @CallDirection int getCallDirection() {
876 return mCallDirection;
877 }
878
Ihab Awade63fadb2014-07-09 21:52:04 -0700879 @Override
880 public boolean equals(Object o) {
881 if (o instanceof Details) {
882 Details d = (Details) o;
883 return
884 Objects.equals(mHandle, d.mHandle) &&
885 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
886 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
887 Objects.equals(mCallerDisplayNamePresentation,
888 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700889 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700890 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700891 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700892 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700893 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700894 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700895 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700896 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700897 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700898 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -0800899 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Tyler Gunn94f8f112018-12-17 09:56:11 -0800900 Objects.equals(mCallDirection, d.mCallDirection);
Ihab Awade63fadb2014-07-09 21:52:04 -0700901 }
902 return false;
903 }
904
905 @Override
906 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700907 return Objects.hash(mHandle,
908 mHandlePresentation,
909 mCallerDisplayName,
910 mCallerDisplayNamePresentation,
911 mAccountHandle,
912 mCallCapabilities,
913 mCallProperties,
914 mDisconnectCause,
915 mConnectTimeMillis,
916 mGatewayInfo,
917 mVideoState,
918 mStatusHints,
919 mExtras,
920 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -0800921 mCreationTimeMillis,
Tyler Gunn94f8f112018-12-17 09:56:11 -0800922 mCallDirection);
Ihab Awade63fadb2014-07-09 21:52:04 -0700923 }
924
925 /** {@hide} */
926 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800927 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700928 Uri handle,
929 int handlePresentation,
930 String callerDisplayName,
931 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700932 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700933 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700934 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700935 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700936 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700937 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700938 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700939 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700940 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700941 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -0800942 long creationTimeMillis,
Tyler Gunn94f8f112018-12-17 09:56:11 -0800943 int callDirection) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800944 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700945 mHandle = handle;
946 mHandlePresentation = handlePresentation;
947 mCallerDisplayName = callerDisplayName;
948 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700949 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700950 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700951 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700952 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700953 mConnectTimeMillis = connectTimeMillis;
954 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700955 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700956 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700957 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700958 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700959 mCreationTimeMillis = creationTimeMillis;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800960 mCallDirection = callDirection;
Ihab Awade63fadb2014-07-09 21:52:04 -0700961 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800962
963 /** {@hide} */
964 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
965 return new Details(
966 parcelableCall.getId(),
967 parcelableCall.getHandle(),
968 parcelableCall.getHandlePresentation(),
969 parcelableCall.getCallerDisplayName(),
970 parcelableCall.getCallerDisplayNamePresentation(),
971 parcelableCall.getAccountHandle(),
972 parcelableCall.getCapabilities(),
973 parcelableCall.getProperties(),
974 parcelableCall.getDisconnectCause(),
975 parcelableCall.getConnectTimeMillis(),
976 parcelableCall.getGatewayInfo(),
977 parcelableCall.getVideoState(),
978 parcelableCall.getStatusHints(),
979 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700980 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -0800981 parcelableCall.getCreationTimeMillis(),
Tyler Gunn94f8f112018-12-17 09:56:11 -0800982 parcelableCall.getCallDirection());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800983 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800984
985 @Override
986 public String toString() {
987 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -0800988 sb.append("[id: ");
989 sb.append(mTelecomCallId);
990 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -0800991 sb.append(mAccountHandle);
992 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -0800993 sb.append(Log.piiHandle(mHandle));
994 sb.append(", hdlPres: ");
995 sb.append(mHandlePresentation);
996 sb.append(", videoState: ");
997 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -0800998 sb.append(", caps: ");
999 sb.append(capabilitiesToString(mCallCapabilities));
1000 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001001 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001002 sb.append("]");
1003 return sb.toString();
1004 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001005 }
1006
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001007 /**
1008 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1009 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1010 * implementation.
1011 * <p>
1012 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1013 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1014 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1015 * {@link Callback} implementation, if desired.
1016 * <p>
1017 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1018 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1019 * (typically in {@link InCallService#onCallRemoved(Call)}).
1020 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1021 * reach your implementation of {@link Callback}, so it is important to register your callback
1022 * as soon as your {@link InCallService} is notified of a new call via
1023 * {@link InCallService#onCallAdded(Call)}.
1024 */
Andrew Leeda80c872015-04-15 14:09:50 -07001025 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001026 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001027 * @hide
1028 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001029 @IntDef(prefix = { "HANDOVER_" },
1030 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001031 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001032 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001033 @Retention(RetentionPolicy.SOURCE)
1034 public @interface HandoverFailureErrors {}
1035
1036 /**
1037 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001038 * to handover the call to rejects the handover request.
1039 * <p>
1040 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1041 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1042 * {@code null} {@link Connection} from
1043 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1044 * ConnectionRequest)}.
1045 * <p>
1046 * For more information on call handovers, see
1047 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001048 */
1049 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1050
1051 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001052 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1053 * is initiated but the source or destination app does not support handover.
1054 * <p>
1055 * Will be returned when a handover is requested via
1056 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1057 * {@link PhoneAccountHandle} does not declare
1058 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1059 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1060 * {@link Details#getAccountHandle()}) does not declare
1061 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1062 * <p>
1063 * For more information on call handovers, see
1064 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001065 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001066 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001067
1068 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001069 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1070 * user rejects the handover request.
1071 * <p>
1072 * For more information on call handovers, see
1073 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001074 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001075 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001076
Sanket Padawe85291f62017-12-01 13:59:27 -08001077 /**
1078 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1079 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001080 * <p>
1081 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1082 * called on an emergency call, or if any other call is an emergency call.
1083 * <p>
1084 * Handovers are not permitted while there are ongoing emergency calls.
1085 * <p>
1086 * For more information on call handovers, see
1087 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001088 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001089 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001090
Tyler Gunn9d127732018-03-02 15:45:51 -08001091 /**
1092 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1093 * fails for an unknown reason.
1094 * <p>
1095 * For more information on call handovers, see
1096 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1097 */
1098 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001099
1100 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001101 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1102 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001103 * @param call The {@code Call} invoking this method.
1104 * @param state The new state of the {@code Call}.
1105 */
1106 public void onStateChanged(Call call, int state) {}
1107
1108 /**
1109 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1110 *
1111 * @param call The {@code Call} invoking this method.
1112 * @param parent The new parent of the {@code Call}.
1113 */
1114 public void onParentChanged(Call call, Call parent) {}
1115
1116 /**
1117 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1118 *
1119 * @param call The {@code Call} invoking this method.
1120 * @param children The new children of the {@code Call}.
1121 */
1122 public void onChildrenChanged(Call call, List<Call> children) {}
1123
1124 /**
1125 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1126 *
1127 * @param call The {@code Call} invoking this method.
1128 * @param details A {@code Details} object describing the {@code Call}.
1129 */
1130 public void onDetailsChanged(Call call, Details details) {}
1131
1132 /**
1133 * Invoked when the text messages that can be used as responses to the incoming
1134 * {@code Call} are loaded from the relevant database.
1135 * See {@link #getCannedTextResponses()}.
1136 *
1137 * @param call The {@code Call} invoking this method.
1138 * @param cannedTextResponses The text messages useable as responses.
1139 */
1140 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1141
1142 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001143 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1144 * character. This causes the post-dial signals to stop pending user confirmation. An
1145 * implementation should present this choice to the user and invoke
1146 * {@link #postDialContinue(boolean)} when the user makes the choice.
1147 *
1148 * @param call The {@code Call} invoking this method.
1149 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1150 */
1151 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1152
1153 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001154 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001155 *
1156 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001157 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001158 */
Andrew Lee50aca232014-07-22 16:41:54 -07001159 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001160
1161 /**
1162 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1163 * up their UI for the {@code Call} in response to state transitions. Specifically,
1164 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1165 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1166 * clients should wait for this method to be invoked.
1167 *
1168 * @param call The {@code Call} being destroyed.
1169 */
1170 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001171
1172 /**
1173 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1174 * conferenced.
1175 *
1176 * @param call The {@code Call} being updated.
1177 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1178 * conferenced.
1179 */
1180 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001181
1182 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001183 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
1184 * <p>
1185 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1186 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1187 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1188 * possible that a {@link ConnectionService} has defined its own Connection events which a
1189 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001190 * <p>
1191 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
1192 *
1193 * @param call The {@code Call} receiving the event.
1194 * @param event The event.
1195 * @param extras Extras associated with the connection event.
1196 */
1197 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001198
1199 /**
1200 * Invoked when the RTT mode changes for this call.
1201 * @param call The call whose RTT mode has changed.
1202 * @param mode the new RTT mode, one of
1203 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1204 * or {@link RttCall#RTT_MODE_VCO}
1205 */
1206 public void onRttModeChanged(Call call, int mode) {}
1207
1208 /**
1209 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1210 * @param call The call whose RTT status has changed.
1211 * @param enabled whether RTT is now enabled or disabled
1212 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1213 * on, null otherwise.
1214 */
1215 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1216
1217 /**
1218 * Invoked when the remote end of the connection has requested that an RTT communication
1219 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1220 * with the same ID that this method is invoked with.
1221 * @param call The call which the RTT request was placed on
1222 * @param id The ID of the request.
1223 */
1224 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001225
1226 /**
1227 * Invoked when the RTT session failed to initiate for some reason, including rejection
1228 * by the remote party.
1229 * @param call The call which the RTT initiation failure occurred on.
1230 * @param reason One of the status codes defined in
1231 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1232 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1233 */
1234 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001235
1236 /**
1237 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1238 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001239 * <p>
1240 * For a full discussion of the handover process and the APIs involved, see
1241 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1242 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001243 * @param call The call which had initiated handover.
1244 */
1245 public void onHandoverComplete(Call call) {}
1246
1247 /**
1248 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1249 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001250 * <p>
1251 * For a full discussion of the handover process and the APIs involved, see
1252 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1253 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001254 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001255 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001256 */
1257 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001258 }
1259
1260 /**
1261 * A class that holds the state that describes the state of the RTT channel to the remote
1262 * party, if it is active.
1263 */
1264 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001265 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001266 @Retention(RetentionPolicy.SOURCE)
1267 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1268 public @interface RttAudioMode {}
1269
1270 /**
1271 * For metrics use. Default value in the proto.
1272 * @hide
1273 */
1274 public static final int RTT_MODE_INVALID = 0;
1275
1276 /**
1277 * Indicates that there should be a bidirectional audio stream between the two parties
1278 * on the call.
1279 */
1280 public static final int RTT_MODE_FULL = 1;
1281
1282 /**
1283 * Indicates that the local user should be able to hear the audio stream from the remote
1284 * user, but not vice versa. Equivalent to muting the microphone.
1285 */
1286 public static final int RTT_MODE_HCO = 2;
1287
1288 /**
1289 * Indicates that the remote user should be able to hear the audio stream from the local
1290 * user, but not vice versa. Equivalent to setting the volume to zero.
1291 */
1292 public static final int RTT_MODE_VCO = 3;
1293
1294 private static final int READ_BUFFER_SIZE = 1000;
1295
1296 private InputStreamReader mReceiveStream;
1297 private OutputStreamWriter mTransmitStream;
1298 private int mRttMode;
1299 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001300 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001301 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1302
1303 /**
1304 * @hide
1305 */
Hall Liu57006aa2017-02-06 10:49:48 -08001306 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1307 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1308 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001309 mReceiveStream = receiveStream;
1310 mTransmitStream = transmitStream;
1311 mRttMode = mode;
1312 mInCallAdapter = inCallAdapter;
1313 }
1314
1315 /**
1316 * Returns the current RTT audio mode.
1317 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1318 * {@link #RTT_MODE_HCO}.
1319 */
1320 public int getRttAudioMode() {
1321 return mRttMode;
1322 }
1323
1324 /**
1325 * Sets the RTT audio mode. The requested mode change will be communicated through
1326 * {@link Callback#onRttModeChanged(Call, int)}.
1327 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1328 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1329 */
1330 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001331 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001332 }
1333
1334 /**
1335 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1336 * RTT transmits text in real-time, this method should be called once for each character
1337 * the user enters into the device.
1338 *
1339 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1340 * lead to interleaved text.
1341 * @param input The message to send to the remote user.
1342 */
1343 public void write(String input) throws IOException {
1344 mTransmitStream.write(input);
1345 mTransmitStream.flush();
1346 }
1347
1348 /**
1349 * Reads a string from the remote user, blocking if there is no data available. Returns
1350 * {@code null} if the RTT conversation has been terminated and there is no further data
1351 * to read.
1352 *
1353 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1354 * lead to interleaved text.
1355 * @return A string containing text sent by the remote user, or {@code null} if the
1356 * conversation has been terminated or if there was an error while reading.
1357 */
Hall Liub1c8a772017-07-17 17:04:41 -07001358 public String read() {
1359 try {
1360 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1361 if (numRead < 0) {
1362 return null;
1363 }
1364 return new String(mReadBuffer, 0, numRead);
1365 } catch (IOException e) {
1366 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001367 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001368 }
Hall Liuffa4a812017-03-02 16:11:00 -08001369 }
1370
1371 /**
1372 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1373 * be read.
1374 * @return A string containing text entered by the user, or {@code null} if the user has
1375 * not entered any new text yet.
1376 */
1377 public String readImmediately() throws IOException {
1378 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001379 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1380 if (numRead < 0) {
1381 return null;
1382 }
1383 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001384 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001385 return null;
1386 }
1387 }
Hall Liue9041242018-02-09 16:40:03 -08001388
1389 /**
1390 * Closes the underlying file descriptors
1391 * @hide
1392 */
1393 public void close() {
1394 try {
1395 mReceiveStream.close();
1396 } catch (IOException e) {
1397 // ignore
1398 }
1399 try {
1400 mTransmitStream.close();
1401 } catch (IOException e) {
1402 // ignore
1403 }
1404 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001405 }
1406
Andrew Leeda80c872015-04-15 14:09:50 -07001407 /**
1408 * @deprecated Use {@code Call.Callback} instead.
1409 * @hide
1410 */
1411 @Deprecated
1412 @SystemApi
1413 public static abstract class Listener extends Callback { }
1414
Ihab Awade63fadb2014-07-09 21:52:04 -07001415 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001416 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001417 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001418 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001419 private final List<Call> mChildren = new ArrayList<>();
1420 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001421 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001422 private final List<Call> mConferenceableCalls = new ArrayList<>();
1423 private final List<Call> mUnmodifiableConferenceableCalls =
1424 Collections.unmodifiableList(mConferenceableCalls);
1425
Santos Cordon823fd3c2014-08-07 18:35:18 -07001426 private boolean mChildrenCached;
1427 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001428 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001429 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001430 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001431 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001432 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001433 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001434 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001435 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001436 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001437
1438 /**
1439 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1440 *
1441 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1442 * remaining or this {@code Call} is not in a post-dial state.
1443 */
1444 public String getRemainingPostDialSequence() {
1445 return mRemainingPostDialSequence;
1446 }
1447
1448 /**
1449 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001450 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001451 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001452 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001453 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001454 }
1455
1456 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301457 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1458 *
1459 * @param address The address to which the call will be deflected.
1460 */
1461 public void deflect(Uri address) {
1462 mInCallAdapter.deflectCall(mTelecomCallId, address);
1463 }
1464
1465 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001466 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1467 *
1468 * @param rejectWithMessage Whether to reject with a text message.
1469 * @param textMessage An optional text message with which to respond.
1470 */
1471 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001472 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001473 }
1474
1475 /**
1476 * Instructs this {@code Call} to disconnect.
1477 */
1478 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001479 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001480 }
1481
1482 /**
1483 * Instructs this {@code Call} to go on hold.
1484 */
1485 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001486 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001487 }
1488
1489 /**
1490 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1491 */
1492 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001493 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001494 }
1495
1496 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001497 * Instructs Telecom to put the call into the background audio processing state.
1498 *
1499 * This method can be called either when the call is in {@link #STATE_RINGING} or
1500 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1501 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1502 * order to capture and play audio on the call stream.
1503 *
1504 * This method can only be called by the default dialer app.
1505 * @hide
1506 */
1507 @SystemApi
1508 @TestApi
1509 //@RequiresPermission(android.Manifest.permission.BACKGROUND_CALL_AUDIO)
1510 public void enterBackgroundAudioProcessing() {
1511 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1512 throw new IllegalStateException("Call must be active or ringing");
1513 }
1514 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1515 }
1516
1517 /**
1518 * Instructs Telecom to come out of the background audio processing state requested by
1519 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1520 *
1521 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1522 *
1523 * @param shouldRing If true, Telecom will put the call into the
1524 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1525 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1526 * immediately.
1527 * @hide
1528 */
1529 @SystemApi
1530 @TestApi
1531 //@RequiresPermission(android.Manifest.permission.BACKGROUND_CALL_AUDIO)
1532 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1533 if (mState != STATE_AUDIO_PROCESSING) {
1534 throw new IllegalStateException("Call must in the audio processing state");
1535 }
1536 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1537 }
1538
1539 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001540 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1541 *
1542 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1543 *
1544 * @param digit A character representing the DTMF digit for which to play the tone. This
1545 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1546 */
1547 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001548 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001549 }
1550
1551 /**
1552 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1553 * currently playing.
1554 *
1555 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1556 * currently playing, this method will do nothing.
1557 */
1558 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001559 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001560 }
1561
1562 /**
1563 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1564 *
1565 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1566 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001567 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001568 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001569 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1570 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001571 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001572 * {@code Call} will pause playing the tones and notify callbacks via
1573 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001574 * should display to the user an indication of this state and an affordance to continue
1575 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1576 * app should invoke the {@link #postDialContinue(boolean)} method.
1577 *
1578 * @param proceed Whether or not to continue with the post-dial sequence.
1579 */
1580 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001581 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001582 }
1583
1584 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001585 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001586 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001587 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001588 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1589 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001590
1591 }
1592
1593 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001594 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001595 *
1596 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001597 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001598 public void conference(Call callToConferenceWith) {
1599 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001600 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001601 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001602 }
1603
1604 /**
1605 * Instructs this {@code Call} to split from any conference call with which it may be
1606 * connected.
1607 */
1608 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001609 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001610 }
1611
1612 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001613 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001614 */
1615 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001616 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001617 }
1618
1619 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001620 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001621 */
1622 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001623 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001624 }
1625
1626 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001627 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1628 * device.
1629 * <p>
1630 * Calls to this method are ignored if the call does not have the
1631 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1632 * <p>
1633 * An {@link InCallService} will only see calls which support this method if it has the
1634 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1635 * in its manifest.
1636 */
1637 public void pullExternalCall() {
1638 // If this isn't an external call, ignore the request.
1639 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1640 return;
1641 }
1642
1643 mInCallAdapter.pullExternalCall(mTelecomCallId);
1644 }
1645
1646 /**
1647 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1648 * the {@link ConnectionService}.
1649 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001650 * Call events are used to communicate point in time information from an {@link InCallService}
1651 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1652 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1653 * {@link ConnectionService}.
1654 * <p>
1655 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1656 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1657 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001658 * Events are exposed to {@link ConnectionService} implementations via
1659 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1660 * <p>
1661 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001662 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1663 * ignore some events altogether.
1664 * <p>
1665 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1666 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1667 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1668 * they define their own event types in this namespace. When defining a custom event type,
1669 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1670 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1671 * <p>
1672 * When defining events and the associated extras, it is important to keep their behavior
1673 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1674 * events/extras should me maintained to ensure backwards compatibility with older
1675 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001676 *
1677 * @param event The connection event.
1678 * @param extras Bundle containing extra information associated with the event.
1679 */
1680 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001681 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001682 }
1683
1684 /**
Hall Liu95d55872017-01-25 17:12:49 -08001685 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1686 * guaranteed, and notification of success will be via the
1687 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1688 */
1689 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001690 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001691 }
1692
1693 /**
1694 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1695 * callback.
1696 * The ID used here should be the same as the ID that was received via the callback.
1697 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1698 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1699 */
1700 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001701 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001702 }
1703
1704 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001705 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1706 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1707 * handover.
1708 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001709 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1710 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1711 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1712 * is referred to as the source of the handover, and the video calling app is referred to as the
1713 * destination.
1714 * <p>
1715 * When considering a handover scenario the device this method is called on is considered the
1716 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1717 * other device is considered the <em>receiving</em> device.
1718 * <p>
1719 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1720 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1721 * and invoke
1722 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1723 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1724 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1725 * At this point the app should display UI to indicate to the user that a call
1726 * handover is in process.
1727 * <p>
1728 * The destination app is responsible for communicating the handover request from the
1729 * <em>initiating</em> device to the <em>receiving</em> device.
1730 * <p>
1731 * When the app on the <em>receiving</em> device receives the handover request, it calls
1732 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1733 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1734 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1735 * choose whether they want to continue their call in the destination app.
1736 * <p>
1737 * When the destination app on the <em>receiving</em> device calls
1738 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1739 * {@link ConnectionService} and call
1740 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1741 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1742 * {@link Connection} to represent the handover call.
1743 * <p>
1744 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1745 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1746 * original call. If the user rejects the handover, the app calls
1747 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1748 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1749 * <p>
1750 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1751 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1752 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1753 * <p>
1754 * Errors in the handover process are reported to the {@link InCallService} via
1755 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1756 * the involved {@link ConnectionService}s via
1757 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001758 *
1759 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1760 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001761 * @param videoState Indicates the video state desired after the handover (see the
1762 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001763 * @param extras Bundle containing extra information to be passed to the
1764 * {@link ConnectionService}
1765 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001766 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1767 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001768 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1769 }
1770
1771 /**
Hall Liu95d55872017-01-25 17:12:49 -08001772 * Terminate the RTT session on this call. The resulting state change will be notified via
1773 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1774 */
1775 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001776 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001777 }
1778
1779 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001780 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1781 * added.
1782 * <p>
1783 * No assumptions should be made as to how an In-Call UI or service will handle these
1784 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1785 *
1786 * @param extras The extras to add.
1787 */
1788 public final void putExtras(Bundle extras) {
1789 if (extras == null) {
1790 return;
1791 }
1792
1793 if (mExtras == null) {
1794 mExtras = new Bundle();
1795 }
1796 mExtras.putAll(extras);
1797 mInCallAdapter.putExtras(mTelecomCallId, extras);
1798 }
1799
1800 /**
1801 * Adds a boolean extra to this {@link Call}.
1802 *
1803 * @param key The extra key.
1804 * @param value The value.
1805 * @hide
1806 */
1807 public final void putExtra(String key, boolean value) {
1808 if (mExtras == null) {
1809 mExtras = new Bundle();
1810 }
1811 mExtras.putBoolean(key, value);
1812 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1813 }
1814
1815 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001816 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001817 *
1818 * @param key The extra key.
1819 * @param value The value.
1820 * @hide
1821 */
1822 public final void putExtra(String key, int value) {
1823 if (mExtras == null) {
1824 mExtras = new Bundle();
1825 }
1826 mExtras.putInt(key, value);
1827 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1828 }
1829
1830 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001831 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001832 *
1833 * @param key The extra key.
1834 * @param value The value.
1835 * @hide
1836 */
1837 public final void putExtra(String key, String value) {
1838 if (mExtras == null) {
1839 mExtras = new Bundle();
1840 }
1841 mExtras.putString(key, value);
1842 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1843 }
1844
1845 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001846 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001847 *
1848 * @param keys The keys of the extras to remove.
1849 */
1850 public final void removeExtras(List<String> keys) {
1851 if (mExtras != null) {
1852 for (String key : keys) {
1853 mExtras.remove(key);
1854 }
1855 if (mExtras.size() == 0) {
1856 mExtras = null;
1857 }
1858 }
1859 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1860 }
1861
1862 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001863 * Removes extras from this {@link Call}.
1864 *
1865 * @param keys The keys of the extras to remove.
1866 */
1867 public final void removeExtras(String ... keys) {
1868 removeExtras(Arrays.asList(keys));
1869 }
1870
1871 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001872 * Obtains the parent of this {@code Call} in a conference, if any.
1873 *
1874 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1875 * child of any conference {@code Call}s.
1876 */
1877 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001878 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001879 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001880 }
1881 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001882 }
1883
1884 /**
1885 * Obtains the children of this conference {@code Call}, if any.
1886 *
1887 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1888 * {@code List} otherwise.
1889 */
1890 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001891 if (!mChildrenCached) {
1892 mChildrenCached = true;
1893 mChildren.clear();
1894
1895 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001896 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001897 if (call == null) {
1898 // At least one child was still not found, so do not save true for "cached"
1899 mChildrenCached = false;
1900 } else {
1901 mChildren.add(call);
1902 }
1903 }
1904 }
1905
Ihab Awade63fadb2014-07-09 21:52:04 -07001906 return mUnmodifiableChildren;
1907 }
1908
1909 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001910 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1911 *
1912 * @return The list of conferenceable {@code Call}s.
1913 */
1914 public List<Call> getConferenceableCalls() {
1915 return mUnmodifiableConferenceableCalls;
1916 }
1917
1918 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001919 * Obtains the state of this {@code Call}.
1920 *
1921 * @return A state value, chosen from the {@code STATE_*} constants.
1922 */
1923 public int getState() {
1924 return mState;
1925 }
1926
1927 /**
1928 * Obtains a list of canned, pre-configured message responses to present to the user as
1929 * ways of rejecting this {@code Call} using via a text message.
1930 *
1931 * @see #reject(boolean, String)
1932 *
1933 * @return A list of canned text message responses.
1934 */
1935 public List<String> getCannedTextResponses() {
1936 return mCannedTextResponses;
1937 }
1938
1939 /**
1940 * Obtains an object that can be used to display video from this {@code Call}.
1941 *
Andrew Lee50aca232014-07-22 16:41:54 -07001942 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001943 */
Andrew Lee50aca232014-07-22 16:41:54 -07001944 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001945 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001946 }
1947
1948 /**
1949 * Obtains an object containing call details.
1950 *
1951 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1952 * result may be {@code null}.
1953 */
1954 public Details getDetails() {
1955 return mDetails;
1956 }
1957
1958 /**
Hall Liu95d55872017-01-25 17:12:49 -08001959 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1960 * receive RTT text data, as well as to change the RTT mode.
1961 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1962 */
1963 public @Nullable RttCall getRttCall() {
1964 return mRttCall;
1965 }
1966
1967 /**
1968 * Returns whether this call has an active RTT connection.
1969 * @return true if there is a connection, false otherwise.
1970 */
1971 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08001972 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08001973 }
1974
1975 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001976 * Registers a callback to this {@code Call}.
1977 *
1978 * @param callback A {@code Callback}.
1979 */
1980 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001981 registerCallback(callback, new Handler());
1982 }
1983
1984 /**
1985 * Registers a callback to this {@code Call}.
1986 *
1987 * @param callback A {@code Callback}.
1988 * @param handler A handler which command and status changes will be delivered to.
1989 */
1990 public void registerCallback(Callback callback, Handler handler) {
1991 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001992 // Don't allow new callback registration if the call is already being destroyed.
1993 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001994 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1995 }
Andrew Leeda80c872015-04-15 14:09:50 -07001996 }
1997
1998 /**
1999 * Unregisters a callback from this {@code Call}.
2000 *
2001 * @param callback A {@code Callback}.
2002 */
2003 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002004 // Don't allow callback deregistration if the call is already being destroyed.
2005 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002006 for (CallbackRecord<Callback> record : mCallbackRecords) {
2007 if (record.getCallback() == callback) {
2008 mCallbackRecords.remove(record);
2009 break;
2010 }
2011 }
Andrew Leeda80c872015-04-15 14:09:50 -07002012 }
2013 }
2014
Santos Cordon3c20d632016-02-25 16:12:35 -08002015 @Override
2016 public String toString() {
2017 return new StringBuilder().
2018 append("Call [id: ").
2019 append(mTelecomCallId).
2020 append(", state: ").
2021 append(stateToString(mState)).
2022 append(", details: ").
2023 append(mDetails).
2024 append("]").toString();
2025 }
2026
2027 /**
2028 * @param state An integer value of a {@code STATE_*} constant.
2029 * @return A string representation of the value.
2030 */
2031 private static String stateToString(int state) {
2032 switch (state) {
2033 case STATE_NEW:
2034 return "NEW";
2035 case STATE_RINGING:
2036 return "RINGING";
2037 case STATE_DIALING:
2038 return "DIALING";
2039 case STATE_ACTIVE:
2040 return "ACTIVE";
2041 case STATE_HOLDING:
2042 return "HOLDING";
2043 case STATE_DISCONNECTED:
2044 return "DISCONNECTED";
2045 case STATE_CONNECTING:
2046 return "CONNECTING";
2047 case STATE_DISCONNECTING:
2048 return "DISCONNECTING";
2049 case STATE_SELECT_PHONE_ACCOUNT:
2050 return "SELECT_PHONE_ACCOUNT";
2051 default:
2052 Log.w(Call.class, "Unknown state %d", state);
2053 return "UNKNOWN";
2054 }
2055 }
2056
Andrew Leeda80c872015-04-15 14:09:50 -07002057 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002058 * Adds a listener to this {@code Call}.
2059 *
2060 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002061 * @deprecated Use {@link #registerCallback} instead.
2062 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002063 */
Andrew Leeda80c872015-04-15 14:09:50 -07002064 @Deprecated
2065 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002066 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002067 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002068 }
2069
2070 /**
2071 * Removes a listener from this {@code Call}.
2072 *
2073 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002074 * @deprecated Use {@link #unregisterCallback} instead.
2075 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002076 */
Andrew Leeda80c872015-04-15 14:09:50 -07002077 @Deprecated
2078 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002079 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002080 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002081 }
2082
2083 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002084 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2085 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002086 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002087 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002088 mInCallAdapter = inCallAdapter;
2089 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002090 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002091 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002092 }
2093
2094 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002095 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002096 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002097 mPhone = phone;
2098 mTelecomCallId = telecomCallId;
2099 mInCallAdapter = inCallAdapter;
2100 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002101 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002102 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002103 }
2104
2105 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002106 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002107 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002108 }
2109
2110 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002111 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002112
Ihab Awade63fadb2014-07-09 21:52:04 -07002113 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002114 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002115 boolean detailsChanged = !Objects.equals(mDetails, details);
2116 if (detailsChanged) {
2117 mDetails = details;
2118 }
2119
2120 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002121 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2122 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2123 mCannedTextResponses =
2124 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002125 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002126 }
2127
Tyler Gunn159f35c2017-03-02 09:28:37 -08002128 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
2129 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07002130 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002131 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07002132 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002133 mVideoCallImpl = newVideoCallImpl;
2134 }
2135 if (mVideoCallImpl != null) {
2136 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002137 }
2138
Santos Cordone3c507b2015-04-23 14:44:19 -07002139 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07002140 boolean stateChanged = mState != state;
2141 if (stateChanged) {
2142 mState = state;
2143 }
2144
Santos Cordon823fd3c2014-08-07 18:35:18 -07002145 String parentId = parcelableCall.getParentCallId();
2146 boolean parentChanged = !Objects.equals(mParentId, parentId);
2147 if (parentChanged) {
2148 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002149 }
2150
Santos Cordon823fd3c2014-08-07 18:35:18 -07002151 List<String> childCallIds = parcelableCall.getChildCallIds();
2152 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2153 if (childrenChanged) {
2154 mChildrenIds.clear();
2155 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2156 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002157 }
2158
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002159 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2160 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2161 for (String otherId : conferenceableCallIds) {
2162 if (callIdMap.containsKey(otherId)) {
2163 conferenceableCalls.add(callIdMap.get(otherId));
2164 }
2165 }
2166
2167 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2168 mConferenceableCalls.clear();
2169 mConferenceableCalls.addAll(conferenceableCalls);
2170 fireConferenceableCallsChanged();
2171 }
2172
Hall Liu95d55872017-01-25 17:12:49 -08002173 boolean isRttChanged = false;
2174 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002175 if (parcelableCall.getIsRttCallChanged()
2176 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002177 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2178 InputStreamReader receiveStream = new InputStreamReader(
2179 new ParcelFileDescriptor.AutoCloseInputStream(
2180 parcelableRttCall.getReceiveStream()),
2181 StandardCharsets.UTF_8);
2182 OutputStreamWriter transmitStream = new OutputStreamWriter(
2183 new ParcelFileDescriptor.AutoCloseOutputStream(
2184 parcelableRttCall.getTransmitStream()),
2185 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002186 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002187 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2188 if (mRttCall == null) {
2189 isRttChanged = true;
2190 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2191 rttModeChanged = true;
2192 }
2193 mRttCall = newRttCall;
2194 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2195 && parcelableCall.getIsRttCallChanged()) {
2196 isRttChanged = true;
2197 mRttCall = null;
2198 }
2199
Ihab Awade63fadb2014-07-09 21:52:04 -07002200 // Now we fire updates, ensuring that any client who listens to any of these notifications
2201 // gets the most up-to-date state.
2202
2203 if (stateChanged) {
2204 fireStateChanged(mState);
2205 }
2206 if (detailsChanged) {
2207 fireDetailsChanged(mDetails);
2208 }
2209 if (cannedTextResponsesChanged) {
2210 fireCannedTextResponsesLoaded(mCannedTextResponses);
2211 }
Andrew Lee50aca232014-07-22 16:41:54 -07002212 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002213 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002214 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002215 if (parentChanged) {
2216 fireParentChanged(getParent());
2217 }
2218 if (childrenChanged) {
2219 fireChildrenChanged(getChildren());
2220 }
Hall Liu95d55872017-01-25 17:12:49 -08002221 if (isRttChanged) {
2222 fireOnIsRttChanged(mRttCall != null, mRttCall);
2223 }
2224 if (rttModeChanged) {
2225 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2226 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002227
2228 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2229 // remove ourselves from the Phone. Note that we do this after completing all state updates
2230 // so a client can cleanly transition all their UI to the state appropriate for a
2231 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2232 if (mState == STATE_DISCONNECTED) {
2233 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002234 }
2235 }
2236
2237 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002238 final void internalSetPostDialWait(String remaining) {
2239 mRemainingPostDialSequence = remaining;
2240 firePostDialWait(mRemainingPostDialSequence);
2241 }
2242
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002243 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002244 final void internalSetDisconnected() {
2245 if (mState != Call.STATE_DISCONNECTED) {
2246 mState = Call.STATE_DISCONNECTED;
2247 fireStateChanged(mState);
2248 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002249 }
2250 }
2251
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002252 /** {@hide} */
2253 final void internalOnConnectionEvent(String event, Bundle extras) {
2254 fireOnConnectionEvent(event, extras);
2255 }
2256
Hall Liu95d55872017-01-25 17:12:49 -08002257 /** {@hide} */
2258 final void internalOnRttUpgradeRequest(final int requestId) {
2259 for (CallbackRecord<Callback> record : mCallbackRecords) {
2260 final Call call = this;
2261 final Callback callback = record.getCallback();
2262 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2263 }
2264 }
2265
Hall Liu57006aa2017-02-06 10:49:48 -08002266 /** @hide */
2267 final void internalOnRttInitiationFailure(int reason) {
2268 for (CallbackRecord<Callback> record : mCallbackRecords) {
2269 final Call call = this;
2270 final Callback callback = record.getCallback();
2271 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2272 }
2273 }
2274
Sanket Padawe85291f62017-12-01 13:59:27 -08002275 /** {@hide} */
2276 final void internalOnHandoverFailed(int error) {
2277 for (CallbackRecord<Callback> record : mCallbackRecords) {
2278 final Call call = this;
2279 final Callback callback = record.getCallback();
2280 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2281 }
2282 }
2283
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002284 /** {@hide} */
2285 final void internalOnHandoverComplete() {
2286 for (CallbackRecord<Callback> record : mCallbackRecords) {
2287 final Call call = this;
2288 final Callback callback = record.getCallback();
2289 record.getHandler().post(() -> callback.onHandoverComplete(call));
2290 }
2291 }
2292
Andrew Lee011728f2015-04-23 15:47:06 -07002293 private void fireStateChanged(final int newState) {
2294 for (CallbackRecord<Callback> record : mCallbackRecords) {
2295 final Call call = this;
2296 final Callback callback = record.getCallback();
2297 record.getHandler().post(new Runnable() {
2298 @Override
2299 public void run() {
2300 callback.onStateChanged(call, newState);
2301 }
2302 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002303 }
2304 }
2305
Andrew Lee011728f2015-04-23 15:47:06 -07002306 private void fireParentChanged(final Call newParent) {
2307 for (CallbackRecord<Callback> record : mCallbackRecords) {
2308 final Call call = this;
2309 final Callback callback = record.getCallback();
2310 record.getHandler().post(new Runnable() {
2311 @Override
2312 public void run() {
2313 callback.onParentChanged(call, newParent);
2314 }
2315 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002316 }
2317 }
2318
Andrew Lee011728f2015-04-23 15:47:06 -07002319 private void fireChildrenChanged(final List<Call> children) {
2320 for (CallbackRecord<Callback> record : mCallbackRecords) {
2321 final Call call = this;
2322 final Callback callback = record.getCallback();
2323 record.getHandler().post(new Runnable() {
2324 @Override
2325 public void run() {
2326 callback.onChildrenChanged(call, children);
2327 }
2328 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002329 }
2330 }
2331
Andrew Lee011728f2015-04-23 15:47:06 -07002332 private void fireDetailsChanged(final Details details) {
2333 for (CallbackRecord<Callback> record : mCallbackRecords) {
2334 final Call call = this;
2335 final Callback callback = record.getCallback();
2336 record.getHandler().post(new Runnable() {
2337 @Override
2338 public void run() {
2339 callback.onDetailsChanged(call, details);
2340 }
2341 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002342 }
2343 }
2344
Andrew Lee011728f2015-04-23 15:47:06 -07002345 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2346 for (CallbackRecord<Callback> record : mCallbackRecords) {
2347 final Call call = this;
2348 final Callback callback = record.getCallback();
2349 record.getHandler().post(new Runnable() {
2350 @Override
2351 public void run() {
2352 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2353 }
2354 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002355 }
2356 }
2357
Andrew Lee011728f2015-04-23 15:47:06 -07002358 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2359 for (CallbackRecord<Callback> record : mCallbackRecords) {
2360 final Call call = this;
2361 final Callback callback = record.getCallback();
2362 record.getHandler().post(new Runnable() {
2363 @Override
2364 public void run() {
2365 callback.onVideoCallChanged(call, videoCall);
2366 }
2367 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002368 }
2369 }
2370
Andrew Lee011728f2015-04-23 15:47:06 -07002371 private void firePostDialWait(final String remainingPostDialSequence) {
2372 for (CallbackRecord<Callback> record : mCallbackRecords) {
2373 final Call call = this;
2374 final Callback callback = record.getCallback();
2375 record.getHandler().post(new Runnable() {
2376 @Override
2377 public void run() {
2378 callback.onPostDialWait(call, remainingPostDialSequence);
2379 }
2380 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002381 }
2382 }
2383
2384 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002385 /**
2386 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2387 * onCallRemoved callback, we remove this call from the Phone's record
2388 * only once all of the registered onCallDestroyed callbacks are executed.
2389 * All the callbacks get removed from our records as a part of this operation
2390 * since onCallDestroyed is the final callback.
2391 */
2392 final Call call = this;
2393 if (mCallbackRecords.isEmpty()) {
2394 // No callbacks registered, remove the call from Phone's record.
2395 mPhone.internalRemoveCall(call);
2396 }
2397 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002398 final Callback callback = record.getCallback();
2399 record.getHandler().post(new Runnable() {
2400 @Override
2401 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002402 boolean isFinalRemoval = false;
2403 RuntimeException toThrow = null;
2404 try {
2405 callback.onCallDestroyed(call);
2406 } catch (RuntimeException e) {
2407 toThrow = e;
2408 }
2409 synchronized(Call.this) {
2410 mCallbackRecords.remove(record);
2411 if (mCallbackRecords.isEmpty()) {
2412 isFinalRemoval = true;
2413 }
2414 }
2415 if (isFinalRemoval) {
2416 mPhone.internalRemoveCall(call);
2417 }
2418 if (toThrow != null) {
2419 throw toThrow;
2420 }
Andrew Lee011728f2015-04-23 15:47:06 -07002421 }
2422 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002423 }
2424 }
2425
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002426 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002427 for (CallbackRecord<Callback> record : mCallbackRecords) {
2428 final Call call = this;
2429 final Callback callback = record.getCallback();
2430 record.getHandler().post(new Runnable() {
2431 @Override
2432 public void run() {
2433 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2434 }
2435 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002436 }
2437 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002438
2439 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002440 * Notifies listeners of an incoming connection event.
2441 * <p>
2442 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2443 *
2444 * @param event
2445 * @param extras
2446 */
2447 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2448 for (CallbackRecord<Callback> record : mCallbackRecords) {
2449 final Call call = this;
2450 final Callback callback = record.getCallback();
2451 record.getHandler().post(new Runnable() {
2452 @Override
2453 public void run() {
2454 callback.onConnectionEvent(call, event, extras);
2455 }
2456 });
2457 }
2458 }
2459
2460 /**
Hall Liu95d55872017-01-25 17:12:49 -08002461 * Notifies listeners of an RTT on/off change
2462 *
2463 * @param enabled True if RTT is now enabled, false otherwise
2464 */
2465 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2466 for (CallbackRecord<Callback> record : mCallbackRecords) {
2467 final Call call = this;
2468 final Callback callback = record.getCallback();
2469 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2470 }
2471 }
2472
2473 /**
2474 * Notifies listeners of a RTT mode change
2475 *
2476 * @param mode The new RTT mode
2477 */
2478 private void fireOnRttModeChanged(final int mode) {
2479 for (CallbackRecord<Callback> record : mCallbackRecords) {
2480 final Call call = this;
2481 final Callback callback = record.getCallback();
2482 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2483 }
2484 }
2485
2486 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002487 * Determines if two bundles are equal.
2488 *
2489 * @param bundle The original bundle.
2490 * @param newBundle The bundle to compare with.
2491 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2492 */
2493 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2494 if (bundle == null || newBundle == null) {
2495 return bundle == newBundle;
2496 }
2497
2498 if (bundle.size() != newBundle.size()) {
2499 return false;
2500 }
2501
2502 for(String key : bundle.keySet()) {
2503 if (key != null) {
2504 final Object value = bundle.get(key);
2505 final Object newValue = newBundle.get(key);
2506 if (!Objects.equals(value, newValue)) {
2507 return false;
2508 }
2509 }
2510 }
2511 return true;
2512 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002513}