blob: 38ec2b6e9c39ded664e7ebd0ebd561a5d161bb30 [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;
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -080028import android.os.IBinder;
Hall Liu95d55872017-01-25 17:12:49 -080029import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070030
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -080031import com.android.internal.telecom.IVideoProvider;
32
Hall Liu95d55872017-01-25 17:12:49 -080033import java.io.IOException;
34import java.io.InputStreamReader;
35import java.io.OutputStreamWriter;
Hall Liu95d55872017-01-25 17:12:49 -080036import java.lang.annotation.Retention;
37import java.lang.annotation.RetentionPolicy;
38import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070039import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070040import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070041import java.util.Collections;
42import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070043import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070044import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070045import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070046
47/**
48 * Represents an ongoing phone call that the in-call app should present to the user.
49 */
50public final class Call {
51 /**
52 * The state of a {@code Call} when newly created.
53 */
54 public static final int STATE_NEW = 0;
55
56 /**
57 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
58 */
59 public static final int STATE_DIALING = 1;
60
61 /**
62 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
63 */
64 public static final int STATE_RINGING = 2;
65
66 /**
67 * The state of a {@code Call} when in a holding state.
68 */
69 public static final int STATE_HOLDING = 3;
70
71 /**
72 * The state of a {@code Call} when actively supporting conversation.
73 */
74 public static final int STATE_ACTIVE = 4;
75
76 /**
77 * The state of a {@code Call} when no further voice or other communication is being
78 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
79 * is no longer active, and the local data transport has or inevitably will release resources
80 * associated with this {@code Call}.
81 */
82 public static final int STATE_DISCONNECTED = 7;
83
Nancy Chen5da0fd52014-07-08 14:16:17 -070084 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070085 * The state of an outgoing {@code Call} when waiting on user to select a
86 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070087 */
Santos Cordone3c507b2015-04-23 14:44:19 -070088 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
89
90 /**
91 * @hide
92 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
93 */
94 @Deprecated
95 @SystemApi
96 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070097
Nancy Chene20930f2014-08-07 16:17:21 -070098 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070099 * The initial state of an outgoing {@code Call}.
100 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
101 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -0700102 */
103 public static final int STATE_CONNECTING = 9;
104
Nancy Chen513c8922014-09-17 14:47:20 -0700105 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700106 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
107 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
108 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
109 */
110 public static final int STATE_DISCONNECTING = 10;
111
112 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700113 * The state of an external call which is in the process of being pulled from a remote device to
114 * the local device.
115 * <p>
116 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
117 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
118 * <p>
119 * An {@link InCallService} will only see this state if it has the
120 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
121 * manifest.
122 */
123 public static final int STATE_PULLING_CALL = 11;
124
125 /**
Hall Liu6dfa2492019-10-01 17:20:39 -0700126 * The state of a call that is active with the network, but the audio from the call is
127 * being intercepted by an app on the local device. Telecom does not hold audio focus in this
128 * state, and the call will be invisible to the user except for a persistent notification.
129 */
130 public static final int STATE_AUDIO_PROCESSING = 12;
131
132 /**
133 * The state of a call that is being presented to the user after being in
134 * {@link #STATE_AUDIO_PROCESSING}. The call is still active with the network in this case, and
135 * Telecom will hold audio focus and play a ringtone if appropriate.
136 */
137 public static final int STATE_SIMULATED_RINGING = 13;
138
139 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700140 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
141 * extras. Used to pass the phone accounts to display on the front end to the user in order to
142 * select phone accounts to (for example) place a call.
Hall Liu34d9e242018-11-21 17:05:58 -0800143 * @deprecated Use the list from {@link #EXTRA_SUGGESTED_PHONE_ACCOUNTS} instead.
Nancy Chen513c8922014-09-17 14:47:20 -0700144 */
Hall Liu34d9e242018-11-21 17:05:58 -0800145 @Deprecated
Nancy Chen513c8922014-09-17 14:47:20 -0700146 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
147
mike dooley4af561f2016-12-20 08:55:17 -0800148 /**
Hall Liu34d9e242018-11-21 17:05:58 -0800149 * Key for extra used to pass along a list of {@link PhoneAccountSuggestion}s to the in-call
150 * UI when a call enters the {@link #STATE_SELECT_PHONE_ACCOUNT} state. The list included here
151 * will have the same length and be in the same order as the list passed with
152 * {@link #AVAILABLE_PHONE_ACCOUNTS}.
153 */
154 public static final String EXTRA_SUGGESTED_PHONE_ACCOUNTS =
155 "android.telecom.extra.SUGGESTED_PHONE_ACCOUNTS";
156
157 /**
mike dooley91217422017-03-09 12:58:42 -0800158 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
159 * when the last outgoing emergency call was made. This is used to identify potential emergency
160 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800161 */
162 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
163 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
164
Usman Abdullahb0dc29a2019-03-06 15:54:56 -0800165
166 /**
167 * Extra key used to indicate whether a {@link CallScreeningService} has requested to silence
168 * the ringtone for a call. If the {@link InCallService} declares
169 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} in its manifest, it should not
170 * play a ringtone for an incoming call with this extra key set.
171 */
172 public static final String EXTRA_SILENT_RINGING_REQUESTED =
173 "android.telecom.extra.SILENT_RINGING_REQUESTED";
174
Tyler Gunn8bf76572017-04-06 15:30:08 -0700175 /**
176 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
177 * Telecom that the user has requested that the current {@link Call} should be handed over
178 * to another {@link ConnectionService}.
179 * <p>
180 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
181 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
182 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700183 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
184 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700185 */
186 public static final String EVENT_REQUEST_HANDOVER =
187 "android.telecom.event.REQUEST_HANDOVER";
188
189 /**
190 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
191 * {@link PhoneAccountHandle} to which a call should be handed over to.
192 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700193 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
194 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700195 */
196 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
197 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
198
199 /**
200 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
201 * video state of the call when it is handed over to the new {@link PhoneAccount}.
202 * <p>
203 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
204 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
205 * {@link VideoProfile#STATE_TX_ENABLED}.
206 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700207 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
208 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700209 */
210 public static final String EXTRA_HANDOVER_VIDEO_STATE =
211 "android.telecom.extra.HANDOVER_VIDEO_STATE";
212
213 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700214 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
215 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
216 * information to the handover {@link ConnectionService} specified by
217 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
218 * <p>
219 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
220 * {@link ConnectionService} via the request extras when
221 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
222 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700223 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700224 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
225 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700226 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700227 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700228
229 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700230 * Call event sent from Telecom to the handover {@link ConnectionService} via
231 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
232 * to the {@link ConnectionService} has completed successfully.
233 * <p>
234 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700235 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700236 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
237 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700238 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700239 public static final String EVENT_HANDOVER_COMPLETE =
240 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700241
242 /**
243 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
244 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
245 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
246 * {@code null}.
247 * <p>
248 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
249 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700250 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
251 * APIs instead.
Tyler Gunn34a2b312017-06-23 08:32:00 -0700252 */
253 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
254 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
255
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700256 /**
257 * Call event sent from Telecom to the handover {@link ConnectionService} via
258 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
259 * to the {@link ConnectionService} has failed.
260 * <p>
261 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
262 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700263 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
264 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700265 */
266 public static final String EVENT_HANDOVER_FAILED =
267 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700268
Ihab Awade63fadb2014-07-09 21:52:04 -0700269 public static class Details {
Tyler Gunn94f8f112018-12-17 09:56:11 -0800270 /** @hide */
271 @Retention(RetentionPolicy.SOURCE)
272 @IntDef(
273 prefix = { "DIRECTION_" },
274 value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
275 public @interface CallDirection {}
276
277 /**
278 * Indicates that the call is neither and incoming nor an outgoing call. This can be the
279 * case for calls reported directly by a {@link ConnectionService} in special cases such as
280 * call handovers.
281 */
282 public static final int DIRECTION_UNKNOWN = -1;
283
284 /**
285 * Indicates that the call is an incoming call.
286 */
287 public static final int DIRECTION_INCOMING = 0;
288
289 /**
290 * Indicates that the call is an outgoing call.
291 */
292 public static final int DIRECTION_OUTGOING = 1;
293
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800294 /** Call can currently be put on hold or unheld. */
295 public static final int CAPABILITY_HOLD = 0x00000001;
296
297 /** Call supports the hold feature. */
298 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
299
300 /**
301 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
302 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
303 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
304 * capability allows a merge button to be shown while the conference call is in the foreground
305 * of the in-call UI.
306 * <p>
307 * This is only intended for use by a {@link Conference}.
308 */
309 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
310
311 /**
312 * Calls within a conference can be swapped between foreground and background.
313 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
314 * <p>
315 * This is only intended for use by a {@link Conference}.
316 */
317 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
318
319 /**
320 * @hide
321 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700322 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800323
324 /** Call supports responding via text option. */
325 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
326
327 /** Call can be muted. */
328 public static final int CAPABILITY_MUTE = 0x00000040;
329
330 /**
331 * Call supports conference call management. This capability only applies to {@link Conference}
332 * calls which can have {@link Connection}s as children.
333 */
334 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
335
336 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700337 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800338 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700339 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800340
341 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700342 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800343 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700344 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800345
346 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700347 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800348 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700349 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700350 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800351
352 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700353 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800354 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700355 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
356
357 /**
358 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700359 */
360 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
361
362 /**
363 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700364 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700365 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700366 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800367
368 /**
369 * Call is able to be separated from its parent {@code Conference}, if any.
370 */
371 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
372
373 /**
374 * Call is able to be individually disconnected when in a {@code Conference}.
375 */
376 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
377
378 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500379 * Speed up audio setup for MT call.
380 * @hide
381 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700382 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
383
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700384 /**
385 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700386 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800387 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
388 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
389 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700390 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800391 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700392 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
393
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700394 /**
395 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700396 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700397 */
398 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
399
Bryce Lee81901682015-08-28 16:38:02 -0700400 /**
401 * Call sends responses through connection.
402 * @hide
403 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800404 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
405
406 /**
407 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
408 * <p>
409 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
410 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
411 * downgraded from a video call back to a VideoState of
412 * {@link VideoProfile#STATE_AUDIO_ONLY}.
413 * <p>
414 * Intuitively, a call which can be downgraded to audio should also have local and remote
415 * video
416 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
417 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
418 */
419 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700420
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700421 /**
422 * When set for an external call, indicates that this {@code Call} can be pulled from a
423 * remote device to the current device.
424 * <p>
425 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
426 * <p>
427 * An {@link InCallService} will only see calls with this capability if it has the
428 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
429 * in its manifest.
430 * <p>
431 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700432 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700433 */
434 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
435
Pooja Jaind34698d2017-12-28 14:15:31 +0530436 /** Call supports the deflect feature. */
437 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
438
Tyler Gunnd11a3152015-03-18 13:09:14 -0700439 //******************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530440 // Next CAPABILITY value: 0x02000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700441 //******************************************************************************************
442
443 /**
444 * Whether the call is currently a conference.
445 */
446 public static final int PROPERTY_CONFERENCE = 0x00000001;
447
448 /**
449 * Whether the call is a generic conference, where we do not know the precise state of
450 * participants in the conference (eg. on CDMA).
451 */
452 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
453
454 /**
455 * Whether the call is made while the device is in emergency callback mode.
456 */
457 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
458
459 /**
460 * Connection is using WIFI.
461 */
462 public static final int PROPERTY_WIFI = 0x00000008;
463
464 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700465 * When set, the UI should indicate to the user that a call is using high definition
466 * audio.
467 * <p>
468 * The underlying {@link ConnectionService} is responsible for reporting this
469 * property. It is important to note that this property is not intended to report the
470 * actual audio codec being used for a Call, but whether the call should be indicated
471 * to the user as high definition.
472 * <p>
473 * The Android Telephony stack reports this property for calls based on a number
474 * of factors, including which audio codec is used and whether a call is using an HD
475 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
476 * and in these cases this property will not be set for a call even if the underlying audio
477 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700478 */
479 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
480
Tony Maka68dcce2015-12-17 09:31:18 +0000481 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100482 * Whether the call is associated with the work profile.
483 */
484 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
485
486 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700487 * When set, indicates that this {@code Call} does not actually exist locally for the
488 * {@link ConnectionService}.
489 * <p>
490 * Consider, for example, a scenario where a user has two phones with the same phone number.
491 * When a user places a call on one device, the telephony stack can represent that call on
492 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700493 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700494 * <p>
495 * An {@link InCallService} will only see calls with this property if it has the
496 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
497 * in its manifest.
498 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700499 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700500 */
501 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
502
Brad Ebinger15847072016-05-18 11:08:36 -0700503 /**
504 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
505 */
506 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
507
Tyler Gunn24e18332017-02-10 09:42:49 -0800508 /**
509 * Indicates that the call is from a self-managed {@link ConnectionService}.
510 * <p>
511 * See also {@link Connection#PROPERTY_SELF_MANAGED}
512 */
513 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
514
Eric Erfanianec881872017-12-06 16:27:53 -0800515 /**
516 * Indicates the call used Assisted Dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700517 *
518 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanianec881872017-12-06 16:27:53 -0800519 */
520 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
521
Hall Liue9041242018-02-09 16:40:03 -0800522 /**
523 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
524 * {@link RttCall} object that is used to send and receive text.
525 */
526 public static final int PROPERTY_RTT = 0x00000400;
527
Tyler Gunn5bd90852018-09-21 09:37:07 -0700528 /**
529 * Indicates that the call has been identified as the network as an emergency call. This
530 * property may be set for both incoming and outgoing calls which the network identifies as
531 * emergency calls.
532 */
533 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
534
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700535 /**
536 * Indicates that the call is using VoIP audio mode.
537 * <p>
538 * When this property is set, the {@link android.media.AudioManager} audio mode for this
539 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
540 * property is not set, the audio mode for this call will be
541 * {@link android.media.AudioManager#MODE_IN_CALL}.
542 * <p>
543 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
544 * <p>
545 * You can use this property to determine whether an un-answered incoming call or a held
546 * call will use VoIP audio mode (if the call does not currently have focus, the system
547 * audio mode may not reflect the mode the call will use).
548 */
549 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
550
Andrew Lee2378ea72015-04-29 14:38:11 -0700551 //******************************************************************************************
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700552 // Next PROPERTY value: 0x00002000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700553 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800554
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800555 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700556 private final Uri mHandle;
557 private final int mHandlePresentation;
558 private final String mCallerDisplayName;
559 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700560 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700561 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700562 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800563 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700564 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700565 private final long mConnectTimeMillis;
566 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700567 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700568 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700569 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700570 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700571 private final long mCreationTimeMillis;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800572 private final @CallDirection int mCallDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700573 private final @Connection.VerificationStatus int mCallerNumberVerificationStatus;
Ihab Awade63fadb2014-07-09 21:52:04 -0700574
575 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800576 * Whether the supplied capabilities supports the specified capability.
577 *
578 * @param capabilities A bit field of capabilities.
579 * @param capability The capability to check capabilities for.
580 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800581 */
582 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800583 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800584 }
585
586 /**
587 * Whether the capabilities of this {@code Details} supports the specified capability.
588 *
589 * @param capability The capability to check capabilities for.
590 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800591 */
592 public boolean can(int capability) {
593 return can(mCallCapabilities, capability);
594 }
595
596 /**
597 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
598 *
599 * @param capabilities A capability bit field.
600 * @return A human readable string representation.
601 */
602 public static String capabilitiesToString(int capabilities) {
603 StringBuilder builder = new StringBuilder();
604 builder.append("[Capabilities:");
605 if (can(capabilities, CAPABILITY_HOLD)) {
606 builder.append(" CAPABILITY_HOLD");
607 }
608 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
609 builder.append(" CAPABILITY_SUPPORT_HOLD");
610 }
611 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
612 builder.append(" CAPABILITY_MERGE_CONFERENCE");
613 }
614 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
615 builder.append(" CAPABILITY_SWAP_CONFERENCE");
616 }
617 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
618 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
619 }
620 if (can(capabilities, CAPABILITY_MUTE)) {
621 builder.append(" CAPABILITY_MUTE");
622 }
623 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
624 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
625 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700626 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
627 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
628 }
629 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
630 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
631 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700632 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
633 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800634 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700635 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
636 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
637 }
638 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
639 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
640 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800641 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
642 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
643 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700644 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
645 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800646 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500647 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700648 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500649 }
Rekha Kumar07366812015-03-24 16:42:31 -0700650 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
651 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
652 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700653 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
654 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
655 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700656 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
657 builder.append(" CAPABILITY_CAN_PULL_CALL");
658 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530659 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
660 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
661 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800662 builder.append("]");
663 return builder.toString();
664 }
665
666 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700667 * Whether the supplied properties includes the specified property.
668 *
669 * @param properties A bit field of properties.
670 * @param property The property to check properties for.
671 * @return Whether the specified property is supported.
672 */
673 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800674 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700675 }
676
677 /**
678 * Whether the properties of this {@code Details} includes the specified property.
679 *
680 * @param property The property to check properties for.
681 * @return Whether the specified property is supported.
682 */
683 public boolean hasProperty(int property) {
684 return hasProperty(mCallProperties, property);
685 }
686
687 /**
688 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
689 *
690 * @param properties A property bit field.
691 * @return A human readable string representation.
692 */
693 public static String propertiesToString(int properties) {
694 StringBuilder builder = new StringBuilder();
695 builder.append("[Properties:");
696 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
697 builder.append(" PROPERTY_CONFERENCE");
698 }
699 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
700 builder.append(" PROPERTY_GENERIC_CONFERENCE");
701 }
702 if (hasProperty(properties, PROPERTY_WIFI)) {
703 builder.append(" PROPERTY_WIFI");
704 }
705 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
706 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
707 }
708 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700709 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700710 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700711 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
712 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
713 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700714 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700715 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
716 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700717 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800718 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
719 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700720 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
721 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
722 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700723 if (hasProperty(properties, PROPERTY_RTT)) {
724 builder.append(" PROPERTY_RTT");
725 }
726 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
727 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
728 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700729 builder.append("]");
730 return builder.toString();
731 }
732
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800733 /** {@hide} */
Hall Liu31de23d2019-10-11 15:38:29 -0700734 @TestApi
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800735 public String getTelecomCallId() {
736 return mTelecomCallId;
737 }
738
Andrew Lee2378ea72015-04-29 14:38:11 -0700739 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700740 * @return The handle (e.g., phone number) to which the {@code Call} is currently
741 * connected.
742 */
743 public Uri getHandle() {
744 return mHandle;
745 }
746
747 /**
748 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700749 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700750 */
751 public int getHandlePresentation() {
752 return mHandlePresentation;
753 }
754
755 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800756 * The display name for the caller.
757 * <p>
758 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800759 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700760 * @return The display name for the caller.
761 */
762 public String getCallerDisplayName() {
763 return mCallerDisplayName;
764 }
765
766 /**
767 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700768 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700769 */
770 public int getCallerDisplayNamePresentation() {
771 return mCallerDisplayNamePresentation;
772 }
773
774 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700775 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
776 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700777 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700778 public PhoneAccountHandle getAccountHandle() {
779 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700780 }
781
782 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800783 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
784 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700785 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700786 public int getCallCapabilities() {
787 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700788 }
789
790 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700791 * @return A bitmask of the properties of the {@code Call}, as defined by the various
792 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700793 */
794 public int getCallProperties() {
795 return mCallProperties;
796 }
797
798 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800799 * @return a bitmask of the audio routes available for the call.
800 *
801 * @hide
802 */
803 public int getSupportedAudioRoutes() {
804 return mSupportedAudioRoutes;
805 }
806
807 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700808 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700809 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700810 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700811 public DisconnectCause getDisconnectCause() {
812 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700813 }
814
815 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700816 * Returns the time the {@link Call} connected (i.e. became active). This information is
817 * updated periodically, but user interfaces should not rely on this to display the "call
818 * time clock". For the time when the call was first added to Telecom, see
819 * {@link #getCreationTimeMillis()}.
820 *
821 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700822 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700823 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700824 return mConnectTimeMillis;
825 }
826
827 /**
828 * @return Information about any calling gateway the {@code Call} may be using.
829 */
830 public GatewayInfo getGatewayInfo() {
831 return mGatewayInfo;
832 }
833
Andrew Lee7a341382014-07-15 17:05:08 -0700834 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700835 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700836 */
837 public int getVideoState() {
838 return mVideoState;
839 }
840
Ihab Awad5d0410f2014-07-30 10:07:40 -0700841 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700842 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700843 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700844 */
845 public StatusHints getStatusHints() {
846 return mStatusHints;
847 }
848
Nancy Chen10798dc2014-08-08 14:00:25 -0700849 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700850 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700851 */
852 public Bundle getExtras() {
853 return mExtras;
854 }
855
Santos Cordon6b7f9552015-05-27 17:21:45 -0700856 /**
857 * @return The extras used with the original intent to place this call.
858 */
859 public Bundle getIntentExtras() {
860 return mIntentExtras;
861 }
862
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700863 /**
864 * Returns the time when the call was first created and added to Telecom. This is the same
865 * time that is logged as the start time in the Call Log (see
866 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
867 * (became active), see {@link #getConnectTimeMillis()}.
868 *
869 * @return The creation time of the call, in millis since the epoch.
870 */
871 public long getCreationTimeMillis() {
872 return mCreationTimeMillis;
873 }
874
Tyler Gunnd081f042018-12-04 12:56:45 -0800875 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -0800876 * Indicates whether the call is an incoming or outgoing call.
877 * @return The call's direction.
878 */
879 public @CallDirection int getCallDirection() {
880 return mCallDirection;
881 }
882
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700883 /**
884 * Gets the verification status for the phone number of an incoming call as identified in
885 * ATIS-1000082.
886 * @return the verification status.
887 */
888 public @Connection.VerificationStatus int getCallerNumberVerificationStatus() {
889 return mCallerNumberVerificationStatus;
890 }
891
Ihab Awade63fadb2014-07-09 21:52:04 -0700892 @Override
893 public boolean equals(Object o) {
894 if (o instanceof Details) {
895 Details d = (Details) o;
896 return
897 Objects.equals(mHandle, d.mHandle) &&
898 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
899 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
900 Objects.equals(mCallerDisplayNamePresentation,
901 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700902 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700903 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700904 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700905 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700906 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700907 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700908 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700909 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700910 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700911 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -0800912 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700913 Objects.equals(mCallDirection, d.mCallDirection) &&
914 Objects.equals(mCallerNumberVerificationStatus,
915 d.mCallerNumberVerificationStatus);
Ihab Awade63fadb2014-07-09 21:52:04 -0700916 }
917 return false;
918 }
919
920 @Override
921 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700922 return Objects.hash(mHandle,
923 mHandlePresentation,
924 mCallerDisplayName,
925 mCallerDisplayNamePresentation,
926 mAccountHandle,
927 mCallCapabilities,
928 mCallProperties,
929 mDisconnectCause,
930 mConnectTimeMillis,
931 mGatewayInfo,
932 mVideoState,
933 mStatusHints,
934 mExtras,
935 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -0800936 mCreationTimeMillis,
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700937 mCallDirection,
938 mCallerNumberVerificationStatus);
Ihab Awade63fadb2014-07-09 21:52:04 -0700939 }
940
941 /** {@hide} */
942 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800943 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700944 Uri handle,
945 int handlePresentation,
946 String callerDisplayName,
947 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700948 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700949 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700950 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700951 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700952 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700953 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700954 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700955 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700956 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700957 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -0800958 long creationTimeMillis,
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700959 int callDirection,
960 int callerNumberVerificationStatus) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800961 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700962 mHandle = handle;
963 mHandlePresentation = handlePresentation;
964 mCallerDisplayName = callerDisplayName;
965 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700966 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700967 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700968 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700969 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700970 mConnectTimeMillis = connectTimeMillis;
971 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700972 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700973 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700974 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700975 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700976 mCreationTimeMillis = creationTimeMillis;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800977 mCallDirection = callDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700978 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
Ihab Awade63fadb2014-07-09 21:52:04 -0700979 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800980
981 /** {@hide} */
982 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
983 return new Details(
984 parcelableCall.getId(),
985 parcelableCall.getHandle(),
986 parcelableCall.getHandlePresentation(),
987 parcelableCall.getCallerDisplayName(),
988 parcelableCall.getCallerDisplayNamePresentation(),
989 parcelableCall.getAccountHandle(),
990 parcelableCall.getCapabilities(),
991 parcelableCall.getProperties(),
992 parcelableCall.getDisconnectCause(),
993 parcelableCall.getConnectTimeMillis(),
994 parcelableCall.getGatewayInfo(),
995 parcelableCall.getVideoState(),
996 parcelableCall.getStatusHints(),
997 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700998 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -0800999 parcelableCall.getCreationTimeMillis(),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001000 parcelableCall.getCallDirection(),
1001 parcelableCall.getCallerNumberVerificationStatus());
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001002 }
Santos Cordon3c20d632016-02-25 16:12:35 -08001003
1004 @Override
1005 public String toString() {
1006 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001007 sb.append("[id: ");
1008 sb.append(mTelecomCallId);
1009 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -08001010 sb.append(mAccountHandle);
1011 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001012 sb.append(Log.piiHandle(mHandle));
1013 sb.append(", hdlPres: ");
1014 sb.append(mHandlePresentation);
1015 sb.append(", videoState: ");
1016 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -08001017 sb.append(", caps: ");
1018 sb.append(capabilitiesToString(mCallCapabilities));
1019 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001020 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001021 sb.append("]");
1022 return sb.toString();
1023 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001024 }
1025
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001026 /**
1027 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1028 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1029 * implementation.
1030 * <p>
1031 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1032 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1033 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1034 * {@link Callback} implementation, if desired.
1035 * <p>
1036 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1037 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1038 * (typically in {@link InCallService#onCallRemoved(Call)}).
1039 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1040 * reach your implementation of {@link Callback}, so it is important to register your callback
1041 * as soon as your {@link InCallService} is notified of a new call via
1042 * {@link InCallService#onCallAdded(Call)}.
1043 */
Andrew Leeda80c872015-04-15 14:09:50 -07001044 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001045 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001046 * @hide
1047 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001048 @IntDef(prefix = { "HANDOVER_" },
1049 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001050 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001051 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001052 @Retention(RetentionPolicy.SOURCE)
1053 public @interface HandoverFailureErrors {}
1054
1055 /**
1056 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001057 * to handover the call to rejects the handover request.
1058 * <p>
1059 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1060 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1061 * {@code null} {@link Connection} from
1062 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1063 * ConnectionRequest)}.
1064 * <p>
1065 * For more information on call handovers, see
1066 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001067 */
1068 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1069
1070 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001071 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1072 * is initiated but the source or destination app does not support handover.
1073 * <p>
1074 * Will be returned when a handover is requested via
1075 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1076 * {@link PhoneAccountHandle} does not declare
1077 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1078 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1079 * {@link Details#getAccountHandle()}) does not declare
1080 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1081 * <p>
1082 * For more information on call handovers, see
1083 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001084 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001085 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001086
1087 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001088 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1089 * user rejects the handover request.
1090 * <p>
1091 * For more information on call handovers, see
1092 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001093 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001094 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001095
Sanket Padawe85291f62017-12-01 13:59:27 -08001096 /**
1097 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1098 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001099 * <p>
1100 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1101 * called on an emergency call, or if any other call is an emergency call.
1102 * <p>
1103 * Handovers are not permitted while there are ongoing emergency calls.
1104 * <p>
1105 * For more information on call handovers, see
1106 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001107 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001108 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001109
Tyler Gunn9d127732018-03-02 15:45:51 -08001110 /**
1111 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1112 * fails for an unknown reason.
1113 * <p>
1114 * For more information on call handovers, see
1115 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1116 */
1117 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001118
1119 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001120 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1121 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001122 * @param call The {@code Call} invoking this method.
1123 * @param state The new state of the {@code Call}.
1124 */
1125 public void onStateChanged(Call call, int state) {}
1126
1127 /**
1128 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1129 *
1130 * @param call The {@code Call} invoking this method.
1131 * @param parent The new parent of the {@code Call}.
1132 */
1133 public void onParentChanged(Call call, Call parent) {}
1134
1135 /**
1136 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1137 *
1138 * @param call The {@code Call} invoking this method.
1139 * @param children The new children of the {@code Call}.
1140 */
1141 public void onChildrenChanged(Call call, List<Call> children) {}
1142
1143 /**
1144 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1145 *
1146 * @param call The {@code Call} invoking this method.
1147 * @param details A {@code Details} object describing the {@code Call}.
1148 */
1149 public void onDetailsChanged(Call call, Details details) {}
1150
1151 /**
1152 * Invoked when the text messages that can be used as responses to the incoming
1153 * {@code Call} are loaded from the relevant database.
1154 * See {@link #getCannedTextResponses()}.
1155 *
1156 * @param call The {@code Call} invoking this method.
1157 * @param cannedTextResponses The text messages useable as responses.
1158 */
1159 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1160
1161 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001162 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1163 * character. This causes the post-dial signals to stop pending user confirmation. An
1164 * implementation should present this choice to the user and invoke
1165 * {@link #postDialContinue(boolean)} when the user makes the choice.
1166 *
1167 * @param call The {@code Call} invoking this method.
1168 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1169 */
1170 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1171
1172 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001173 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001174 *
1175 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001176 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001177 */
Andrew Lee50aca232014-07-22 16:41:54 -07001178 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001179
1180 /**
1181 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1182 * up their UI for the {@code Call} in response to state transitions. Specifically,
1183 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1184 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1185 * clients should wait for this method to be invoked.
1186 *
1187 * @param call The {@code Call} being destroyed.
1188 */
1189 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001190
1191 /**
1192 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1193 * conferenced.
1194 *
1195 * @param call The {@code Call} being updated.
1196 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1197 * conferenced.
1198 */
1199 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001200
1201 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001202 * Invoked when a {@link Call} receives an event from its associated {@link Connection} or
1203 * {@link Conference}.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001204 * <p>
1205 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1206 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1207 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1208 * possible that a {@link ConnectionService} has defined its own Connection events which a
1209 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001210 * <p>
Tyler Gunn5567d742019-10-31 13:04:37 -07001211 * See {@link Connection#sendConnectionEvent(String, Bundle)},
1212 * {@link Conference#sendConferenceEvent(String, Bundle)}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001213 *
1214 * @param call The {@code Call} receiving the event.
1215 * @param event The event.
1216 * @param extras Extras associated with the connection event.
1217 */
1218 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001219
1220 /**
1221 * Invoked when the RTT mode changes for this call.
1222 * @param call The call whose RTT mode has changed.
1223 * @param mode the new RTT mode, one of
1224 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1225 * or {@link RttCall#RTT_MODE_VCO}
1226 */
1227 public void onRttModeChanged(Call call, int mode) {}
1228
1229 /**
1230 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1231 * @param call The call whose RTT status has changed.
1232 * @param enabled whether RTT is now enabled or disabled
1233 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1234 * on, null otherwise.
1235 */
1236 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1237
1238 /**
1239 * Invoked when the remote end of the connection has requested that an RTT communication
1240 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1241 * with the same ID that this method is invoked with.
1242 * @param call The call which the RTT request was placed on
1243 * @param id The ID of the request.
1244 */
1245 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001246
1247 /**
1248 * Invoked when the RTT session failed to initiate for some reason, including rejection
1249 * by the remote party.
1250 * @param call The call which the RTT initiation failure occurred on.
1251 * @param reason One of the status codes defined in
1252 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1253 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1254 */
1255 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001256
1257 /**
1258 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1259 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001260 * <p>
1261 * For a full discussion of the handover process and the APIs involved, see
1262 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1263 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001264 * @param call The call which had initiated handover.
1265 */
1266 public void onHandoverComplete(Call call) {}
1267
1268 /**
1269 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1270 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001271 * <p>
1272 * For a full discussion of the handover process and the APIs involved, see
1273 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1274 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001275 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001276 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001277 */
1278 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001279 }
1280
1281 /**
1282 * A class that holds the state that describes the state of the RTT channel to the remote
1283 * party, if it is active.
1284 */
1285 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001286 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001287 @Retention(RetentionPolicy.SOURCE)
1288 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1289 public @interface RttAudioMode {}
1290
1291 /**
1292 * For metrics use. Default value in the proto.
1293 * @hide
1294 */
1295 public static final int RTT_MODE_INVALID = 0;
1296
1297 /**
1298 * Indicates that there should be a bidirectional audio stream between the two parties
1299 * on the call.
1300 */
1301 public static final int RTT_MODE_FULL = 1;
1302
1303 /**
1304 * Indicates that the local user should be able to hear the audio stream from the remote
1305 * user, but not vice versa. Equivalent to muting the microphone.
1306 */
1307 public static final int RTT_MODE_HCO = 2;
1308
1309 /**
1310 * Indicates that the remote user should be able to hear the audio stream from the local
1311 * user, but not vice versa. Equivalent to setting the volume to zero.
1312 */
1313 public static final int RTT_MODE_VCO = 3;
1314
1315 private static final int READ_BUFFER_SIZE = 1000;
1316
1317 private InputStreamReader mReceiveStream;
1318 private OutputStreamWriter mTransmitStream;
1319 private int mRttMode;
1320 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001321 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001322 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1323
1324 /**
1325 * @hide
1326 */
Hall Liu57006aa2017-02-06 10:49:48 -08001327 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1328 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1329 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001330 mReceiveStream = receiveStream;
1331 mTransmitStream = transmitStream;
1332 mRttMode = mode;
1333 mInCallAdapter = inCallAdapter;
1334 }
1335
1336 /**
1337 * Returns the current RTT audio mode.
1338 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1339 * {@link #RTT_MODE_HCO}.
1340 */
1341 public int getRttAudioMode() {
1342 return mRttMode;
1343 }
1344
1345 /**
1346 * Sets the RTT audio mode. The requested mode change will be communicated through
1347 * {@link Callback#onRttModeChanged(Call, int)}.
1348 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1349 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1350 */
1351 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001352 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001353 }
1354
1355 /**
1356 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1357 * RTT transmits text in real-time, this method should be called once for each character
1358 * the user enters into the device.
1359 *
1360 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1361 * lead to interleaved text.
1362 * @param input The message to send to the remote user.
1363 */
1364 public void write(String input) throws IOException {
1365 mTransmitStream.write(input);
1366 mTransmitStream.flush();
1367 }
1368
1369 /**
1370 * Reads a string from the remote user, blocking if there is no data available. Returns
1371 * {@code null} if the RTT conversation has been terminated and there is no further data
1372 * to read.
1373 *
1374 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1375 * lead to interleaved text.
1376 * @return A string containing text sent by the remote user, or {@code null} if the
1377 * conversation has been terminated or if there was an error while reading.
1378 */
Hall Liub1c8a772017-07-17 17:04:41 -07001379 public String read() {
1380 try {
1381 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1382 if (numRead < 0) {
1383 return null;
1384 }
1385 return new String(mReadBuffer, 0, numRead);
1386 } catch (IOException e) {
1387 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001388 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001389 }
Hall Liuffa4a812017-03-02 16:11:00 -08001390 }
1391
1392 /**
1393 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1394 * be read.
1395 * @return A string containing text entered by the user, or {@code null} if the user has
1396 * not entered any new text yet.
1397 */
1398 public String readImmediately() throws IOException {
1399 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001400 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1401 if (numRead < 0) {
1402 return null;
1403 }
1404 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001405 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001406 return null;
1407 }
1408 }
Hall Liue9041242018-02-09 16:40:03 -08001409
1410 /**
1411 * Closes the underlying file descriptors
1412 * @hide
1413 */
1414 public void close() {
1415 try {
1416 mReceiveStream.close();
1417 } catch (IOException e) {
1418 // ignore
1419 }
1420 try {
1421 mTransmitStream.close();
1422 } catch (IOException e) {
1423 // ignore
1424 }
1425 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001426 }
1427
Andrew Leeda80c872015-04-15 14:09:50 -07001428 /**
1429 * @deprecated Use {@code Call.Callback} instead.
1430 * @hide
1431 */
1432 @Deprecated
1433 @SystemApi
1434 public static abstract class Listener extends Callback { }
1435
Ihab Awade63fadb2014-07-09 21:52:04 -07001436 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001437 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001438 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001439 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001440 private final List<Call> mChildren = new ArrayList<>();
1441 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001442 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001443 private final List<Call> mConferenceableCalls = new ArrayList<>();
1444 private final List<Call> mUnmodifiableConferenceableCalls =
1445 Collections.unmodifiableList(mConferenceableCalls);
1446
Santos Cordon823fd3c2014-08-07 18:35:18 -07001447 private boolean mChildrenCached;
1448 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001449 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001450 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001451 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001452 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001453 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001454 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001455 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001456 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001457 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001458
1459 /**
1460 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1461 *
1462 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1463 * remaining or this {@code Call} is not in a post-dial state.
1464 */
1465 public String getRemainingPostDialSequence() {
1466 return mRemainingPostDialSequence;
1467 }
1468
1469 /**
1470 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001471 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001472 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001473 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001474 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001475 }
1476
1477 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301478 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1479 *
1480 * @param address The address to which the call will be deflected.
1481 */
1482 public void deflect(Uri address) {
1483 mInCallAdapter.deflectCall(mTelecomCallId, address);
1484 }
1485
1486 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001487 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1488 *
1489 * @param rejectWithMessage Whether to reject with a text message.
1490 * @param textMessage An optional text message with which to respond.
1491 */
1492 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001493 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001494 }
1495
1496 /**
1497 * Instructs this {@code Call} to disconnect.
1498 */
1499 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001500 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001501 }
1502
1503 /**
1504 * Instructs this {@code Call} to go on hold.
1505 */
1506 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001507 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001508 }
1509
1510 /**
1511 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1512 */
1513 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001514 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001515 }
1516
1517 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001518 * Instructs Telecom to put the call into the background audio processing state.
1519 *
1520 * This method can be called either when the call is in {@link #STATE_RINGING} or
1521 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1522 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1523 * order to capture and play audio on the call stream.
1524 *
1525 * This method can only be called by the default dialer app.
1526 * @hide
1527 */
1528 @SystemApi
1529 @TestApi
1530 //@RequiresPermission(android.Manifest.permission.BACKGROUND_CALL_AUDIO)
1531 public void enterBackgroundAudioProcessing() {
1532 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1533 throw new IllegalStateException("Call must be active or ringing");
1534 }
1535 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1536 }
1537
1538 /**
1539 * Instructs Telecom to come out of the background audio processing state requested by
1540 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1541 *
1542 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1543 *
1544 * @param shouldRing If true, Telecom will put the call into the
1545 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1546 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1547 * immediately.
1548 * @hide
1549 */
1550 @SystemApi
1551 @TestApi
1552 //@RequiresPermission(android.Manifest.permission.BACKGROUND_CALL_AUDIO)
1553 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1554 if (mState != STATE_AUDIO_PROCESSING) {
1555 throw new IllegalStateException("Call must in the audio processing state");
1556 }
1557 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1558 }
1559
1560 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001561 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1562 *
1563 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1564 *
1565 * @param digit A character representing the DTMF digit for which to play the tone. This
1566 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1567 */
1568 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001569 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001570 }
1571
1572 /**
1573 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1574 * currently playing.
1575 *
1576 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1577 * currently playing, this method will do nothing.
1578 */
1579 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001580 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001581 }
1582
1583 /**
1584 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1585 *
1586 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1587 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001588 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001589 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001590 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1591 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001592 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001593 * {@code Call} will pause playing the tones and notify callbacks via
1594 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001595 * should display to the user an indication of this state and an affordance to continue
1596 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1597 * app should invoke the {@link #postDialContinue(boolean)} method.
1598 *
1599 * @param proceed Whether or not to continue with the post-dial sequence.
1600 */
1601 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001602 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001603 }
1604
1605 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001606 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001607 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001608 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001609 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1610 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001611
1612 }
1613
1614 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001615 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001616 *
1617 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001618 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001619 public void conference(Call callToConferenceWith) {
1620 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001621 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001622 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001623 }
1624
1625 /**
1626 * Instructs this {@code Call} to split from any conference call with which it may be
1627 * connected.
1628 */
1629 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001630 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001631 }
1632
1633 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001634 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001635 */
1636 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001637 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001638 }
1639
1640 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001641 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001642 */
1643 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001644 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001645 }
1646
1647 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001648 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1649 * device.
1650 * <p>
1651 * Calls to this method are ignored if the call does not have the
1652 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1653 * <p>
1654 * An {@link InCallService} will only see calls which support this method if it has the
1655 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1656 * in its manifest.
1657 */
1658 public void pullExternalCall() {
1659 // If this isn't an external call, ignore the request.
1660 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1661 return;
1662 }
1663
1664 mInCallAdapter.pullExternalCall(mTelecomCallId);
1665 }
1666
1667 /**
1668 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1669 * the {@link ConnectionService}.
1670 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001671 * Call events are used to communicate point in time information from an {@link InCallService}
1672 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1673 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1674 * {@link ConnectionService}.
1675 * <p>
1676 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1677 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1678 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001679 * Events are exposed to {@link ConnectionService} implementations via
1680 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1681 * <p>
1682 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001683 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1684 * ignore some events altogether.
1685 * <p>
1686 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1687 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1688 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1689 * they define their own event types in this namespace. When defining a custom event type,
1690 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1691 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1692 * <p>
1693 * When defining events and the associated extras, it is important to keep their behavior
1694 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1695 * events/extras should me maintained to ensure backwards compatibility with older
1696 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001697 *
1698 * @param event The connection event.
1699 * @param extras Bundle containing extra information associated with the event.
1700 */
1701 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001702 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001703 }
1704
1705 /**
Hall Liu95d55872017-01-25 17:12:49 -08001706 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1707 * guaranteed, and notification of success will be via the
1708 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1709 */
1710 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001711 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001712 }
1713
1714 /**
1715 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1716 * callback.
1717 * The ID used here should be the same as the ID that was received via the callback.
1718 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1719 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1720 */
1721 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001722 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001723 }
1724
1725 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001726 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1727 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1728 * handover.
1729 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001730 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1731 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1732 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1733 * is referred to as the source of the handover, and the video calling app is referred to as the
1734 * destination.
1735 * <p>
1736 * When considering a handover scenario the device this method is called on is considered the
1737 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1738 * other device is considered the <em>receiving</em> device.
1739 * <p>
1740 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1741 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1742 * and invoke
1743 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1744 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1745 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1746 * At this point the app should display UI to indicate to the user that a call
1747 * handover is in process.
1748 * <p>
1749 * The destination app is responsible for communicating the handover request from the
1750 * <em>initiating</em> device to the <em>receiving</em> device.
1751 * <p>
1752 * When the app on the <em>receiving</em> device receives the handover request, it calls
1753 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1754 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1755 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1756 * choose whether they want to continue their call in the destination app.
1757 * <p>
1758 * When the destination app on the <em>receiving</em> device calls
1759 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1760 * {@link ConnectionService} and call
1761 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1762 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1763 * {@link Connection} to represent the handover call.
1764 * <p>
1765 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1766 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1767 * original call. If the user rejects the handover, the app calls
1768 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1769 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1770 * <p>
1771 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1772 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1773 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1774 * <p>
1775 * Errors in the handover process are reported to the {@link InCallService} via
1776 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1777 * the involved {@link ConnectionService}s via
1778 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001779 *
1780 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1781 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001782 * @param videoState Indicates the video state desired after the handover (see the
1783 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001784 * @param extras Bundle containing extra information to be passed to the
1785 * {@link ConnectionService}
1786 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001787 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1788 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001789 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1790 }
1791
1792 /**
Hall Liu95d55872017-01-25 17:12:49 -08001793 * Terminate the RTT session on this call. The resulting state change will be notified via
1794 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1795 */
1796 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001797 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001798 }
1799
1800 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001801 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1802 * added.
1803 * <p>
1804 * No assumptions should be made as to how an In-Call UI or service will handle these
1805 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1806 *
1807 * @param extras The extras to add.
1808 */
1809 public final void putExtras(Bundle extras) {
1810 if (extras == null) {
1811 return;
1812 }
1813
1814 if (mExtras == null) {
1815 mExtras = new Bundle();
1816 }
1817 mExtras.putAll(extras);
1818 mInCallAdapter.putExtras(mTelecomCallId, extras);
1819 }
1820
1821 /**
1822 * Adds a boolean extra to this {@link Call}.
1823 *
1824 * @param key The extra key.
1825 * @param value The value.
1826 * @hide
1827 */
1828 public final void putExtra(String key, boolean value) {
1829 if (mExtras == null) {
1830 mExtras = new Bundle();
1831 }
1832 mExtras.putBoolean(key, value);
1833 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1834 }
1835
1836 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001837 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001838 *
1839 * @param key The extra key.
1840 * @param value The value.
1841 * @hide
1842 */
1843 public final void putExtra(String key, int value) {
1844 if (mExtras == null) {
1845 mExtras = new Bundle();
1846 }
1847 mExtras.putInt(key, value);
1848 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1849 }
1850
1851 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001852 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001853 *
1854 * @param key The extra key.
1855 * @param value The value.
1856 * @hide
1857 */
1858 public final void putExtra(String key, String value) {
1859 if (mExtras == null) {
1860 mExtras = new Bundle();
1861 }
1862 mExtras.putString(key, value);
1863 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1864 }
1865
1866 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001867 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001868 *
1869 * @param keys The keys of the extras to remove.
1870 */
1871 public final void removeExtras(List<String> keys) {
1872 if (mExtras != null) {
1873 for (String key : keys) {
1874 mExtras.remove(key);
1875 }
1876 if (mExtras.size() == 0) {
1877 mExtras = null;
1878 }
1879 }
1880 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1881 }
1882
1883 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001884 * Removes extras from this {@link Call}.
1885 *
1886 * @param keys The keys of the extras to remove.
1887 */
1888 public final void removeExtras(String ... keys) {
1889 removeExtras(Arrays.asList(keys));
1890 }
1891
1892 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001893 * Obtains the parent of this {@code Call} in a conference, if any.
1894 *
1895 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1896 * child of any conference {@code Call}s.
1897 */
1898 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001899 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001900 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001901 }
1902 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001903 }
1904
1905 /**
1906 * Obtains the children of this conference {@code Call}, if any.
1907 *
1908 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1909 * {@code List} otherwise.
1910 */
1911 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001912 if (!mChildrenCached) {
1913 mChildrenCached = true;
1914 mChildren.clear();
1915
1916 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001917 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001918 if (call == null) {
1919 // At least one child was still not found, so do not save true for "cached"
1920 mChildrenCached = false;
1921 } else {
1922 mChildren.add(call);
1923 }
1924 }
1925 }
1926
Ihab Awade63fadb2014-07-09 21:52:04 -07001927 return mUnmodifiableChildren;
1928 }
1929
1930 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001931 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1932 *
1933 * @return The list of conferenceable {@code Call}s.
1934 */
1935 public List<Call> getConferenceableCalls() {
1936 return mUnmodifiableConferenceableCalls;
1937 }
1938
1939 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001940 * Obtains the state of this {@code Call}.
1941 *
1942 * @return A state value, chosen from the {@code STATE_*} constants.
1943 */
1944 public int getState() {
1945 return mState;
1946 }
1947
1948 /**
1949 * Obtains a list of canned, pre-configured message responses to present to the user as
1950 * ways of rejecting this {@code Call} using via a text message.
1951 *
1952 * @see #reject(boolean, String)
1953 *
1954 * @return A list of canned text message responses.
1955 */
1956 public List<String> getCannedTextResponses() {
1957 return mCannedTextResponses;
1958 }
1959
1960 /**
1961 * Obtains an object that can be used to display video from this {@code Call}.
1962 *
Andrew Lee50aca232014-07-22 16:41:54 -07001963 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001964 */
Andrew Lee50aca232014-07-22 16:41:54 -07001965 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001966 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001967 }
1968
1969 /**
1970 * Obtains an object containing call details.
1971 *
1972 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1973 * result may be {@code null}.
1974 */
1975 public Details getDetails() {
1976 return mDetails;
1977 }
1978
1979 /**
Hall Liu95d55872017-01-25 17:12:49 -08001980 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1981 * receive RTT text data, as well as to change the RTT mode.
1982 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1983 */
1984 public @Nullable RttCall getRttCall() {
1985 return mRttCall;
1986 }
1987
1988 /**
1989 * Returns whether this call has an active RTT connection.
1990 * @return true if there is a connection, false otherwise.
1991 */
1992 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08001993 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08001994 }
1995
1996 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001997 * Registers a callback to this {@code Call}.
1998 *
1999 * @param callback A {@code Callback}.
2000 */
2001 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07002002 registerCallback(callback, new Handler());
2003 }
2004
2005 /**
2006 * Registers a callback to this {@code Call}.
2007 *
2008 * @param callback A {@code Callback}.
2009 * @param handler A handler which command and status changes will be delivered to.
2010 */
2011 public void registerCallback(Callback callback, Handler handler) {
2012 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07002013 // Don't allow new callback registration if the call is already being destroyed.
2014 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002015 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
2016 }
Andrew Leeda80c872015-04-15 14:09:50 -07002017 }
2018
2019 /**
2020 * Unregisters a callback from this {@code Call}.
2021 *
2022 * @param callback A {@code Callback}.
2023 */
2024 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002025 // Don't allow callback deregistration if the call is already being destroyed.
2026 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002027 for (CallbackRecord<Callback> record : mCallbackRecords) {
2028 if (record.getCallback() == callback) {
2029 mCallbackRecords.remove(record);
2030 break;
2031 }
2032 }
Andrew Leeda80c872015-04-15 14:09:50 -07002033 }
2034 }
2035
Santos Cordon3c20d632016-02-25 16:12:35 -08002036 @Override
2037 public String toString() {
2038 return new StringBuilder().
2039 append("Call [id: ").
2040 append(mTelecomCallId).
2041 append(", state: ").
2042 append(stateToString(mState)).
2043 append(", details: ").
2044 append(mDetails).
2045 append("]").toString();
2046 }
2047
2048 /**
2049 * @param state An integer value of a {@code STATE_*} constant.
2050 * @return A string representation of the value.
2051 */
2052 private static String stateToString(int state) {
2053 switch (state) {
2054 case STATE_NEW:
2055 return "NEW";
2056 case STATE_RINGING:
2057 return "RINGING";
2058 case STATE_DIALING:
2059 return "DIALING";
2060 case STATE_ACTIVE:
2061 return "ACTIVE";
2062 case STATE_HOLDING:
2063 return "HOLDING";
2064 case STATE_DISCONNECTED:
2065 return "DISCONNECTED";
2066 case STATE_CONNECTING:
2067 return "CONNECTING";
2068 case STATE_DISCONNECTING:
2069 return "DISCONNECTING";
2070 case STATE_SELECT_PHONE_ACCOUNT:
2071 return "SELECT_PHONE_ACCOUNT";
Hall Liu4e35b642019-10-14 17:50:45 -07002072 case STATE_SIMULATED_RINGING:
2073 return "SIMULATED_RINGING";
2074 case STATE_AUDIO_PROCESSING:
2075 return "AUDIO_PROCESSING";
Santos Cordon3c20d632016-02-25 16:12:35 -08002076 default:
2077 Log.w(Call.class, "Unknown state %d", state);
2078 return "UNKNOWN";
2079 }
2080 }
2081
Andrew Leeda80c872015-04-15 14:09:50 -07002082 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002083 * Adds a listener to this {@code Call}.
2084 *
2085 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002086 * @deprecated Use {@link #registerCallback} instead.
2087 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002088 */
Andrew Leeda80c872015-04-15 14:09:50 -07002089 @Deprecated
2090 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002091 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002092 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002093 }
2094
2095 /**
2096 * Removes a listener from this {@code Call}.
2097 *
2098 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002099 * @deprecated Use {@link #unregisterCallback} instead.
2100 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002101 */
Andrew Leeda80c872015-04-15 14:09:50 -07002102 @Deprecated
2103 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002104 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002105 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002106 }
2107
2108 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002109 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2110 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002111 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002112 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002113 mInCallAdapter = inCallAdapter;
2114 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002115 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002116 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002117 }
2118
2119 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002120 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002121 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002122 mPhone = phone;
2123 mTelecomCallId = telecomCallId;
2124 mInCallAdapter = inCallAdapter;
2125 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002126 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002127 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002128 }
2129
2130 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002131 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002132 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002133 }
2134
2135 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002136 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002137
Ihab Awade63fadb2014-07-09 21:52:04 -07002138 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002139 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002140 boolean detailsChanged = !Objects.equals(mDetails, details);
2141 if (detailsChanged) {
2142 mDetails = details;
2143 }
2144
2145 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002146 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2147 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2148 mCannedTextResponses =
2149 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002150 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002151 }
2152
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002153 IVideoProvider previousVideoProvider = mVideoCallImpl == null ? null :
2154 mVideoCallImpl.getVideoProvider();
2155 IVideoProvider newVideoProvider = parcelableCall.getVideoProvider();
2156
2157 // parcelableCall.isVideoCallProviderChanged is only true when we have a video provider
2158 // specified; so we should check if the actual IVideoProvider changes as well.
2159 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged()
2160 && !Objects.equals(previousVideoProvider, newVideoProvider);
Andrew Lee50aca232014-07-22 16:41:54 -07002161 if (videoCallChanged) {
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002162 if (mVideoCallImpl != null) {
2163 mVideoCallImpl.destroy();
2164 }
2165 mVideoCallImpl = parcelableCall.isVideoCallProviderChanged() ?
2166 parcelableCall.getVideoCallImpl(mCallingPackage, mTargetSdkVersion) : null;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002167 }
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002168
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002169 if (mVideoCallImpl != null) {
2170 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002171 }
2172
Santos Cordone3c507b2015-04-23 14:44:19 -07002173 int state = parcelableCall.getState();
Hall Liu31de23d2019-10-11 15:38:29 -07002174 if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2175 state = Call.STATE_RINGING;
2176 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002177 boolean stateChanged = mState != state;
2178 if (stateChanged) {
2179 mState = state;
2180 }
2181
Santos Cordon823fd3c2014-08-07 18:35:18 -07002182 String parentId = parcelableCall.getParentCallId();
2183 boolean parentChanged = !Objects.equals(mParentId, parentId);
2184 if (parentChanged) {
2185 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002186 }
2187
Santos Cordon823fd3c2014-08-07 18:35:18 -07002188 List<String> childCallIds = parcelableCall.getChildCallIds();
2189 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2190 if (childrenChanged) {
2191 mChildrenIds.clear();
2192 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2193 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002194 }
2195
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002196 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2197 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2198 for (String otherId : conferenceableCallIds) {
2199 if (callIdMap.containsKey(otherId)) {
2200 conferenceableCalls.add(callIdMap.get(otherId));
2201 }
2202 }
2203
2204 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2205 mConferenceableCalls.clear();
2206 mConferenceableCalls.addAll(conferenceableCalls);
2207 fireConferenceableCallsChanged();
2208 }
2209
Hall Liu95d55872017-01-25 17:12:49 -08002210 boolean isRttChanged = false;
2211 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002212 if (parcelableCall.getIsRttCallChanged()
2213 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002214 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2215 InputStreamReader receiveStream = new InputStreamReader(
2216 new ParcelFileDescriptor.AutoCloseInputStream(
2217 parcelableRttCall.getReceiveStream()),
2218 StandardCharsets.UTF_8);
2219 OutputStreamWriter transmitStream = new OutputStreamWriter(
2220 new ParcelFileDescriptor.AutoCloseOutputStream(
2221 parcelableRttCall.getTransmitStream()),
2222 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002223 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002224 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2225 if (mRttCall == null) {
2226 isRttChanged = true;
2227 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2228 rttModeChanged = true;
2229 }
2230 mRttCall = newRttCall;
2231 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2232 && parcelableCall.getIsRttCallChanged()) {
2233 isRttChanged = true;
2234 mRttCall = null;
2235 }
2236
Ihab Awade63fadb2014-07-09 21:52:04 -07002237 // Now we fire updates, ensuring that any client who listens to any of these notifications
2238 // gets the most up-to-date state.
2239
2240 if (stateChanged) {
2241 fireStateChanged(mState);
2242 }
2243 if (detailsChanged) {
2244 fireDetailsChanged(mDetails);
2245 }
2246 if (cannedTextResponsesChanged) {
2247 fireCannedTextResponsesLoaded(mCannedTextResponses);
2248 }
Andrew Lee50aca232014-07-22 16:41:54 -07002249 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002250 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002251 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002252 if (parentChanged) {
2253 fireParentChanged(getParent());
2254 }
2255 if (childrenChanged) {
2256 fireChildrenChanged(getChildren());
2257 }
Hall Liu95d55872017-01-25 17:12:49 -08002258 if (isRttChanged) {
2259 fireOnIsRttChanged(mRttCall != null, mRttCall);
2260 }
2261 if (rttModeChanged) {
2262 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2263 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002264
2265 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2266 // remove ourselves from the Phone. Note that we do this after completing all state updates
2267 // so a client can cleanly transition all their UI to the state appropriate for a
2268 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2269 if (mState == STATE_DISCONNECTED) {
2270 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002271 }
2272 }
2273
2274 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002275 final void internalSetPostDialWait(String remaining) {
2276 mRemainingPostDialSequence = remaining;
2277 firePostDialWait(mRemainingPostDialSequence);
2278 }
2279
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002280 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002281 final void internalSetDisconnected() {
2282 if (mState != Call.STATE_DISCONNECTED) {
2283 mState = Call.STATE_DISCONNECTED;
2284 fireStateChanged(mState);
2285 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002286 }
2287 }
2288
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002289 /** {@hide} */
2290 final void internalOnConnectionEvent(String event, Bundle extras) {
2291 fireOnConnectionEvent(event, extras);
2292 }
2293
Hall Liu95d55872017-01-25 17:12:49 -08002294 /** {@hide} */
2295 final void internalOnRttUpgradeRequest(final int requestId) {
2296 for (CallbackRecord<Callback> record : mCallbackRecords) {
2297 final Call call = this;
2298 final Callback callback = record.getCallback();
2299 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2300 }
2301 }
2302
Hall Liu57006aa2017-02-06 10:49:48 -08002303 /** @hide */
2304 final void internalOnRttInitiationFailure(int reason) {
2305 for (CallbackRecord<Callback> record : mCallbackRecords) {
2306 final Call call = this;
2307 final Callback callback = record.getCallback();
2308 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2309 }
2310 }
2311
Sanket Padawe85291f62017-12-01 13:59:27 -08002312 /** {@hide} */
2313 final void internalOnHandoverFailed(int error) {
2314 for (CallbackRecord<Callback> record : mCallbackRecords) {
2315 final Call call = this;
2316 final Callback callback = record.getCallback();
2317 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2318 }
2319 }
2320
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002321 /** {@hide} */
2322 final void internalOnHandoverComplete() {
2323 for (CallbackRecord<Callback> record : mCallbackRecords) {
2324 final Call call = this;
2325 final Callback callback = record.getCallback();
2326 record.getHandler().post(() -> callback.onHandoverComplete(call));
2327 }
2328 }
2329
Andrew Lee011728f2015-04-23 15:47:06 -07002330 private void fireStateChanged(final int newState) {
2331 for (CallbackRecord<Callback> record : mCallbackRecords) {
2332 final Call call = this;
2333 final Callback callback = record.getCallback();
2334 record.getHandler().post(new Runnable() {
2335 @Override
2336 public void run() {
2337 callback.onStateChanged(call, newState);
2338 }
2339 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002340 }
2341 }
2342
Andrew Lee011728f2015-04-23 15:47:06 -07002343 private void fireParentChanged(final Call newParent) {
2344 for (CallbackRecord<Callback> record : mCallbackRecords) {
2345 final Call call = this;
2346 final Callback callback = record.getCallback();
2347 record.getHandler().post(new Runnable() {
2348 @Override
2349 public void run() {
2350 callback.onParentChanged(call, newParent);
2351 }
2352 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002353 }
2354 }
2355
Andrew Lee011728f2015-04-23 15:47:06 -07002356 private void fireChildrenChanged(final List<Call> children) {
2357 for (CallbackRecord<Callback> record : mCallbackRecords) {
2358 final Call call = this;
2359 final Callback callback = record.getCallback();
2360 record.getHandler().post(new Runnable() {
2361 @Override
2362 public void run() {
2363 callback.onChildrenChanged(call, children);
2364 }
2365 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002366 }
2367 }
2368
Andrew Lee011728f2015-04-23 15:47:06 -07002369 private void fireDetailsChanged(final Details details) {
2370 for (CallbackRecord<Callback> record : mCallbackRecords) {
2371 final Call call = this;
2372 final Callback callback = record.getCallback();
2373 record.getHandler().post(new Runnable() {
2374 @Override
2375 public void run() {
2376 callback.onDetailsChanged(call, details);
2377 }
2378 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002379 }
2380 }
2381
Andrew Lee011728f2015-04-23 15:47:06 -07002382 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2383 for (CallbackRecord<Callback> record : mCallbackRecords) {
2384 final Call call = this;
2385 final Callback callback = record.getCallback();
2386 record.getHandler().post(new Runnable() {
2387 @Override
2388 public void run() {
2389 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2390 }
2391 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002392 }
2393 }
2394
Andrew Lee011728f2015-04-23 15:47:06 -07002395 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2396 for (CallbackRecord<Callback> record : mCallbackRecords) {
2397 final Call call = this;
2398 final Callback callback = record.getCallback();
2399 record.getHandler().post(new Runnable() {
2400 @Override
2401 public void run() {
2402 callback.onVideoCallChanged(call, videoCall);
2403 }
2404 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002405 }
2406 }
2407
Andrew Lee011728f2015-04-23 15:47:06 -07002408 private void firePostDialWait(final String remainingPostDialSequence) {
2409 for (CallbackRecord<Callback> record : mCallbackRecords) {
2410 final Call call = this;
2411 final Callback callback = record.getCallback();
2412 record.getHandler().post(new Runnable() {
2413 @Override
2414 public void run() {
2415 callback.onPostDialWait(call, remainingPostDialSequence);
2416 }
2417 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002418 }
2419 }
2420
2421 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002422 /**
2423 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2424 * onCallRemoved callback, we remove this call from the Phone's record
2425 * only once all of the registered onCallDestroyed callbacks are executed.
2426 * All the callbacks get removed from our records as a part of this operation
2427 * since onCallDestroyed is the final callback.
2428 */
2429 final Call call = this;
2430 if (mCallbackRecords.isEmpty()) {
2431 // No callbacks registered, remove the call from Phone's record.
2432 mPhone.internalRemoveCall(call);
2433 }
2434 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002435 final Callback callback = record.getCallback();
2436 record.getHandler().post(new Runnable() {
2437 @Override
2438 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002439 boolean isFinalRemoval = false;
2440 RuntimeException toThrow = null;
2441 try {
2442 callback.onCallDestroyed(call);
2443 } catch (RuntimeException e) {
2444 toThrow = e;
2445 }
2446 synchronized(Call.this) {
2447 mCallbackRecords.remove(record);
2448 if (mCallbackRecords.isEmpty()) {
2449 isFinalRemoval = true;
2450 }
2451 }
2452 if (isFinalRemoval) {
2453 mPhone.internalRemoveCall(call);
2454 }
2455 if (toThrow != null) {
2456 throw toThrow;
2457 }
Andrew Lee011728f2015-04-23 15:47:06 -07002458 }
2459 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002460 }
2461 }
2462
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002463 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002464 for (CallbackRecord<Callback> record : mCallbackRecords) {
2465 final Call call = this;
2466 final Callback callback = record.getCallback();
2467 record.getHandler().post(new Runnable() {
2468 @Override
2469 public void run() {
2470 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2471 }
2472 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002473 }
2474 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002475
2476 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002477 * Notifies listeners of an incoming connection event.
2478 * <p>
2479 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2480 *
2481 * @param event
2482 * @param extras
2483 */
2484 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2485 for (CallbackRecord<Callback> record : mCallbackRecords) {
2486 final Call call = this;
2487 final Callback callback = record.getCallback();
2488 record.getHandler().post(new Runnable() {
2489 @Override
2490 public void run() {
2491 callback.onConnectionEvent(call, event, extras);
2492 }
2493 });
2494 }
2495 }
2496
2497 /**
Hall Liu95d55872017-01-25 17:12:49 -08002498 * Notifies listeners of an RTT on/off change
2499 *
2500 * @param enabled True if RTT is now enabled, false otherwise
2501 */
2502 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2503 for (CallbackRecord<Callback> record : mCallbackRecords) {
2504 final Call call = this;
2505 final Callback callback = record.getCallback();
2506 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2507 }
2508 }
2509
2510 /**
2511 * Notifies listeners of a RTT mode change
2512 *
2513 * @param mode The new RTT mode
2514 */
2515 private void fireOnRttModeChanged(final int mode) {
2516 for (CallbackRecord<Callback> record : mCallbackRecords) {
2517 final Call call = this;
2518 final Callback callback = record.getCallback();
2519 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2520 }
2521 }
2522
2523 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002524 * Determines if two bundles are equal.
2525 *
2526 * @param bundle The original bundle.
2527 * @param newBundle The bundle to compare with.
2528 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2529 */
2530 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2531 if (bundle == null || newBundle == null) {
2532 return bundle == newBundle;
2533 }
2534
2535 if (bundle.size() != newBundle.size()) {
2536 return false;
2537 }
2538
2539 for(String key : bundle.keySet()) {
2540 if (key != null) {
2541 final Object value = bundle.get(key);
2542 final Object newValue = newBundle.get(key);
2543 if (!Objects.equals(value, newValue)) {
2544 return false;
2545 }
2546 }
2547 }
2548 return true;
2549 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002550}