blob: f54f8d1f5832488051e12cf1c3d281f8f7b3b3d4 [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;
Artur Satayev53ada2a2019-12-10 17:47:56 +000023import android.compat.annotation.UnsupportedAppUsage;
Ihab Awade63fadb2014-07-09 21:52:04 -070024import android.net.Uri;
Tyler Gunn6e3ecc42018-11-12 11:30:56 -080025import android.os.Build;
Nancy Chen10798dc2014-08-08 14:00:25 -070026import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070027import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080028import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070029
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -080030import com.android.internal.telecom.IVideoProvider;
31
Hall Liu95d55872017-01-25 17:12:49 -080032import java.io.IOException;
33import java.io.InputStreamReader;
34import java.io.OutputStreamWriter;
Hall Liu95d55872017-01-25 17:12:49 -080035import java.lang.annotation.Retention;
36import java.lang.annotation.RetentionPolicy;
37import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070038import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070039import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070040import java.util.Collections;
41import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070042import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070043import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070044import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070045
46/**
47 * Represents an ongoing phone call that the in-call app should present to the user.
48 */
49public final class Call {
50 /**
51 * The state of a {@code Call} when newly created.
52 */
53 public static final int STATE_NEW = 0;
54
55 /**
56 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
57 */
58 public static final int STATE_DIALING = 1;
59
60 /**
61 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
62 */
63 public static final int STATE_RINGING = 2;
64
65 /**
66 * The state of a {@code Call} when in a holding state.
67 */
68 public static final int STATE_HOLDING = 3;
69
70 /**
71 * The state of a {@code Call} when actively supporting conversation.
72 */
73 public static final int STATE_ACTIVE = 4;
74
75 /**
76 * The state of a {@code Call} when no further voice or other communication is being
77 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
78 * is no longer active, and the local data transport has or inevitably will release resources
79 * associated with this {@code Call}.
80 */
81 public static final int STATE_DISCONNECTED = 7;
82
Nancy Chen5da0fd52014-07-08 14:16:17 -070083 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070084 * The state of an outgoing {@code Call} when waiting on user to select a
85 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070086 */
Santos Cordone3c507b2015-04-23 14:44:19 -070087 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
88
89 /**
90 * @hide
91 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
92 */
93 @Deprecated
94 @SystemApi
95 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070096
Nancy Chene20930f2014-08-07 16:17:21 -070097 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070098 * The initial state of an outgoing {@code Call}.
99 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
100 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -0700101 */
102 public static final int STATE_CONNECTING = 9;
103
Nancy Chen513c8922014-09-17 14:47:20 -0700104 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700105 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
106 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
107 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
108 */
109 public static final int STATE_DISCONNECTING = 10;
110
111 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700112 * The state of an external call which is in the process of being pulled from a remote device to
113 * the local device.
114 * <p>
115 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
116 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
117 * <p>
118 * An {@link InCallService} will only see this state if it has the
119 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
120 * manifest.
121 */
122 public static final int STATE_PULLING_CALL = 11;
123
124 /**
Hall Liu6dfa2492019-10-01 17:20:39 -0700125 * The state of a call that is active with the network, but the audio from the call is
126 * being intercepted by an app on the local device. Telecom does not hold audio focus in this
127 * state, and the call will be invisible to the user except for a persistent notification.
128 */
129 public static final int STATE_AUDIO_PROCESSING = 12;
130
131 /**
132 * The state of a call that is being presented to the user after being in
133 * {@link #STATE_AUDIO_PROCESSING}. The call is still active with the network in this case, and
134 * Telecom will hold audio focus and play a ringtone if appropriate.
135 */
136 public static final int STATE_SIMULATED_RINGING = 13;
137
138 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700139 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
140 * extras. Used to pass the phone accounts to display on the front end to the user in order to
141 * select phone accounts to (for example) place a call.
Hall Liu34d9e242018-11-21 17:05:58 -0800142 * @deprecated Use the list from {@link #EXTRA_SUGGESTED_PHONE_ACCOUNTS} instead.
Nancy Chen513c8922014-09-17 14:47:20 -0700143 */
Hall Liu34d9e242018-11-21 17:05:58 -0800144 @Deprecated
Nancy Chen513c8922014-09-17 14:47:20 -0700145 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
146
mike dooley4af561f2016-12-20 08:55:17 -0800147 /**
Hall Liu34d9e242018-11-21 17:05:58 -0800148 * Key for extra used to pass along a list of {@link PhoneAccountSuggestion}s to the in-call
149 * UI when a call enters the {@link #STATE_SELECT_PHONE_ACCOUNT} state. The list included here
150 * will have the same length and be in the same order as the list passed with
151 * {@link #AVAILABLE_PHONE_ACCOUNTS}.
152 */
153 public static final String EXTRA_SUGGESTED_PHONE_ACCOUNTS =
154 "android.telecom.extra.SUGGESTED_PHONE_ACCOUNTS";
155
156 /**
mike dooley91217422017-03-09 12:58:42 -0800157 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
158 * when the last outgoing emergency call was made. This is used to identify potential emergency
159 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800160 */
161 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
162 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
163
Usman Abdullahb0dc29a2019-03-06 15:54:56 -0800164
165 /**
166 * Extra key used to indicate whether a {@link CallScreeningService} has requested to silence
167 * the ringtone for a call. If the {@link InCallService} declares
168 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} in its manifest, it should not
169 * play a ringtone for an incoming call with this extra key set.
170 */
171 public static final String EXTRA_SILENT_RINGING_REQUESTED =
172 "android.telecom.extra.SILENT_RINGING_REQUESTED";
173
Tyler Gunn8bf76572017-04-06 15:30:08 -0700174 /**
175 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
176 * Telecom that the user has requested that the current {@link Call} should be handed over
177 * to another {@link ConnectionService}.
178 * <p>
179 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
180 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
181 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700182 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
183 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700184 */
185 public static final String EVENT_REQUEST_HANDOVER =
186 "android.telecom.event.REQUEST_HANDOVER";
187
188 /**
189 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
190 * {@link PhoneAccountHandle} to which a call should be handed over to.
191 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700192 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
193 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700194 */
195 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
196 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
197
198 /**
199 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
200 * video state of the call when it is handed over to the new {@link PhoneAccount}.
201 * <p>
202 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
203 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
204 * {@link VideoProfile#STATE_TX_ENABLED}.
205 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700206 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
207 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700208 */
209 public static final String EXTRA_HANDOVER_VIDEO_STATE =
210 "android.telecom.extra.HANDOVER_VIDEO_STATE";
211
212 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700213 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
214 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
215 * information to the handover {@link ConnectionService} specified by
216 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
217 * <p>
218 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
219 * {@link ConnectionService} via the request extras when
220 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
221 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700222 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700223 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
224 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700225 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700226 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700227
228 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700229 * Call event sent from Telecom to the handover {@link ConnectionService} via
230 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
231 * to the {@link ConnectionService} has completed successfully.
232 * <p>
233 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700234 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700235 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
236 * APIs instead.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700237 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700238 public static final String EVENT_HANDOVER_COMPLETE =
239 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700240
241 /**
242 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
243 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
244 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
245 * {@code null}.
246 * <p>
247 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
248 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700249 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
250 * APIs instead.
Tyler Gunn34a2b312017-06-23 08:32:00 -0700251 */
252 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
253 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
254
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700255 /**
256 * Call event sent from Telecom to the handover {@link ConnectionService} via
257 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
258 * to the {@link ConnectionService} has failed.
259 * <p>
260 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
261 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700262 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
263 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700264 */
265 public static final String EVENT_HANDOVER_FAILED =
266 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700267
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800268
269 /**
270 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
271 * call because they have declined to answer it. This typically means that they are unable
272 * to answer the call at this time and would prefer it be sent to voicemail.
273 */
274 public static final int REJECT_REASON_DECLINED = 1;
275
276 /**
277 * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
278 * call because it is an unwanted call. This allows the user to indicate that they are
279 * rejecting a call because it is likely a nuisance call.
280 */
281 public static final int REJECT_REASON_UNWANTED = 2;
282
283 /**
284 * @hide
285 */
286 @IntDef(prefix = { "REJECT_REASON_" },
287 value = {REJECT_REASON_DECLINED, REJECT_REASON_UNWANTED})
288 @Retention(RetentionPolicy.SOURCE)
289 public @interface RejectReason {};
290
Ihab Awade63fadb2014-07-09 21:52:04 -0700291 public static class Details {
Tyler Gunn94f8f112018-12-17 09:56:11 -0800292 /** @hide */
293 @Retention(RetentionPolicy.SOURCE)
294 @IntDef(
295 prefix = { "DIRECTION_" },
296 value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
297 public @interface CallDirection {}
298
299 /**
300 * Indicates that the call is neither and incoming nor an outgoing call. This can be the
301 * case for calls reported directly by a {@link ConnectionService} in special cases such as
302 * call handovers.
303 */
304 public static final int DIRECTION_UNKNOWN = -1;
305
306 /**
307 * Indicates that the call is an incoming call.
308 */
309 public static final int DIRECTION_INCOMING = 0;
310
311 /**
312 * Indicates that the call is an outgoing call.
313 */
314 public static final int DIRECTION_OUTGOING = 1;
315
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800316 /** Call can currently be put on hold or unheld. */
317 public static final int CAPABILITY_HOLD = 0x00000001;
318
319 /** Call supports the hold feature. */
320 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
321
322 /**
323 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
324 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
325 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
326 * capability allows a merge button to be shown while the conference call is in the foreground
327 * of the in-call UI.
328 * <p>
329 * This is only intended for use by a {@link Conference}.
330 */
331 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
332
333 /**
334 * Calls within a conference can be swapped between foreground and background.
335 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
336 * <p>
337 * This is only intended for use by a {@link Conference}.
338 */
339 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
340
341 /**
342 * @hide
343 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700344 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800345
346 /** Call supports responding via text option. */
347 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
348
349 /** Call can be muted. */
350 public static final int CAPABILITY_MUTE = 0x00000040;
351
352 /**
353 * Call supports conference call management. This capability only applies to {@link Conference}
354 * calls which can have {@link Connection}s as children.
355 */
356 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
357
358 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700359 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800360 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700361 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800362
363 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700364 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800365 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700366 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800367
368 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700369 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800370 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700371 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700372 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800373
374 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700375 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800376 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700377 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
378
379 /**
380 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700381 */
382 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
383
384 /**
385 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700386 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700387 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700388 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800389
390 /**
391 * Call is able to be separated from its parent {@code Conference}, if any.
392 */
393 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
394
395 /**
396 * Call is able to be individually disconnected when in a {@code Conference}.
397 */
398 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
399
400 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500401 * Speed up audio setup for MT call.
402 * @hide
403 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700404 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
405
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700406 /**
407 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700408 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800409 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
410 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
411 * whether or not video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700412 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800413 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Rekha Kumar07366812015-03-24 16:42:31 -0700414 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
415
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700416 /**
417 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700418 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700419 */
420 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
421
Bryce Lee81901682015-08-28 16:38:02 -0700422 /**
423 * Call sends responses through connection.
424 * @hide
425 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800426 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
427
428 /**
429 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
430 * <p>
431 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
432 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
433 * downgraded from a video call back to a VideoState of
434 * {@link VideoProfile#STATE_AUDIO_ONLY}.
435 * <p>
436 * Intuitively, a call which can be downgraded to audio should also have local and remote
437 * video
438 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
439 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
440 */
441 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700442
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700443 /**
444 * When set for an external call, indicates that this {@code Call} can be pulled from a
445 * remote device to the current device.
446 * <p>
447 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
448 * <p>
449 * An {@link InCallService} will only see calls with this capability if it has the
450 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
451 * in its manifest.
452 * <p>
453 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700454 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700455 */
456 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
457
Pooja Jaind34698d2017-12-28 14:15:31 +0530458 /** Call supports the deflect feature. */
459 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
460
Tyler Gunnd11a3152015-03-18 13:09:14 -0700461 //******************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530462 // Next CAPABILITY value: 0x02000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700463 //******************************************************************************************
464
465 /**
466 * Whether the call is currently a conference.
467 */
468 public static final int PROPERTY_CONFERENCE = 0x00000001;
469
470 /**
471 * Whether the call is a generic conference, where we do not know the precise state of
472 * participants in the conference (eg. on CDMA).
473 */
474 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
475
476 /**
477 * Whether the call is made while the device is in emergency callback mode.
478 */
479 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
480
481 /**
482 * Connection is using WIFI.
483 */
484 public static final int PROPERTY_WIFI = 0x00000008;
485
486 /**
Tyler Gunn6b6ae552018-10-11 10:42:10 -0700487 * When set, the UI should indicate to the user that a call is using high definition
488 * audio.
489 * <p>
490 * The underlying {@link ConnectionService} is responsible for reporting this
491 * property. It is important to note that this property is not intended to report the
492 * actual audio codec being used for a Call, but whether the call should be indicated
493 * to the user as high definition.
494 * <p>
495 * The Android Telephony stack reports this property for calls based on a number
496 * of factors, including which audio codec is used and whether a call is using an HD
497 * codec end-to-end. Some mobile operators choose to suppress display of an HD indication,
498 * and in these cases this property will not be set for a call even if the underlying audio
499 * codec is in fact "high definition".
Andrew Lee2378ea72015-04-29 14:38:11 -0700500 */
501 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
502
Tony Maka68dcce2015-12-17 09:31:18 +0000503 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100504 * Whether the call is associated with the work profile.
505 */
506 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
507
508 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700509 * When set, indicates that this {@code Call} does not actually exist locally for the
510 * {@link ConnectionService}.
511 * <p>
512 * Consider, for example, a scenario where a user has two phones with the same phone number.
513 * When a user places a call on one device, the telephony stack can represent that call on
514 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700515 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700516 * <p>
517 * An {@link InCallService} will only see calls with this property if it has the
518 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
519 * in its manifest.
520 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700521 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700522 */
523 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
524
Brad Ebinger15847072016-05-18 11:08:36 -0700525 /**
526 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
527 */
528 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
529
Tyler Gunn24e18332017-02-10 09:42:49 -0800530 /**
531 * Indicates that the call is from a self-managed {@link ConnectionService}.
532 * <p>
533 * See also {@link Connection#PROPERTY_SELF_MANAGED}
534 */
535 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
536
Eric Erfanianec881872017-12-06 16:27:53 -0800537 /**
538 * Indicates the call used Assisted Dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700539 *
540 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanianec881872017-12-06 16:27:53 -0800541 */
542 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
543
Hall Liue9041242018-02-09 16:40:03 -0800544 /**
545 * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
546 * {@link RttCall} object that is used to send and receive text.
547 */
548 public static final int PROPERTY_RTT = 0x00000400;
549
Tyler Gunn5bd90852018-09-21 09:37:07 -0700550 /**
551 * Indicates that the call has been identified as the network as an emergency call. This
552 * property may be set for both incoming and outgoing calls which the network identifies as
553 * emergency calls.
554 */
555 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
556
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700557 /**
558 * Indicates that the call is using VoIP audio mode.
559 * <p>
560 * When this property is set, the {@link android.media.AudioManager} audio mode for this
561 * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}. When this
562 * property is not set, the audio mode for this call will be
563 * {@link android.media.AudioManager#MODE_IN_CALL}.
564 * <p>
565 * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
566 * <p>
567 * You can use this property to determine whether an un-answered incoming call or a held
568 * call will use VoIP audio mode (if the call does not currently have focus, the system
569 * audio mode may not reflect the mode the call will use).
570 */
571 public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
572
Ravi Paluri80aa2142019-12-02 11:57:37 +0530573 /**
574 * Indicates that the call is an adhoc conference call. This property can be set for both
575 * incoming and outgoing calls.
576 */
577 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 0x00002000;
578
Andrew Lee2378ea72015-04-29 14:38:11 -0700579 //******************************************************************************************
Ravi Paluri80aa2142019-12-02 11:57:37 +0530580 // Next PROPERTY value: 0x00004000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700581 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800582
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800583 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700584 private final Uri mHandle;
585 private final int mHandlePresentation;
586 private final String mCallerDisplayName;
587 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700588 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700589 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700590 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800591 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700592 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700593 private final long mConnectTimeMillis;
594 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700595 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700596 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700597 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700598 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700599 private final long mCreationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -0800600 private final String mContactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -0800601 private final @CallDirection int mCallDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700602 private final @Connection.VerificationStatus int mCallerNumberVerificationStatus;
Ihab Awade63fadb2014-07-09 21:52:04 -0700603
604 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800605 * Whether the supplied capabilities supports the specified capability.
606 *
607 * @param capabilities A bit field of capabilities.
608 * @param capability The capability to check capabilities for.
609 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800610 */
611 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800612 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800613 }
614
615 /**
616 * Whether the capabilities of this {@code Details} supports the specified capability.
617 *
618 * @param capability The capability to check capabilities for.
619 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800620 */
621 public boolean can(int capability) {
622 return can(mCallCapabilities, capability);
623 }
624
625 /**
626 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
627 *
628 * @param capabilities A capability bit field.
629 * @return A human readable string representation.
630 */
631 public static String capabilitiesToString(int capabilities) {
632 StringBuilder builder = new StringBuilder();
633 builder.append("[Capabilities:");
634 if (can(capabilities, CAPABILITY_HOLD)) {
635 builder.append(" CAPABILITY_HOLD");
636 }
637 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
638 builder.append(" CAPABILITY_SUPPORT_HOLD");
639 }
640 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
641 builder.append(" CAPABILITY_MERGE_CONFERENCE");
642 }
643 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
644 builder.append(" CAPABILITY_SWAP_CONFERENCE");
645 }
646 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
647 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
648 }
649 if (can(capabilities, CAPABILITY_MUTE)) {
650 builder.append(" CAPABILITY_MUTE");
651 }
652 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
653 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
654 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700655 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
656 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
657 }
658 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
659 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
660 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700661 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
662 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800663 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700664 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
665 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
666 }
667 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
668 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
669 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800670 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
671 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
672 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700673 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
674 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800675 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500676 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700677 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500678 }
Rekha Kumar07366812015-03-24 16:42:31 -0700679 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
680 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
681 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700682 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
683 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
684 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700685 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
686 builder.append(" CAPABILITY_CAN_PULL_CALL");
687 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530688 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
689 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
690 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800691 builder.append("]");
692 return builder.toString();
693 }
694
695 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700696 * Whether the supplied properties includes the specified property.
697 *
698 * @param properties A bit field of properties.
699 * @param property The property to check properties for.
700 * @return Whether the specified property is supported.
701 */
702 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800703 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700704 }
705
706 /**
707 * Whether the properties of this {@code Details} includes the specified property.
708 *
709 * @param property The property to check properties for.
710 * @return Whether the specified property is supported.
711 */
712 public boolean hasProperty(int property) {
713 return hasProperty(mCallProperties, property);
714 }
715
716 /**
717 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
718 *
719 * @param properties A property bit field.
720 * @return A human readable string representation.
721 */
722 public static String propertiesToString(int properties) {
723 StringBuilder builder = new StringBuilder();
724 builder.append("[Properties:");
725 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
726 builder.append(" PROPERTY_CONFERENCE");
727 }
728 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
729 builder.append(" PROPERTY_GENERIC_CONFERENCE");
730 }
731 if (hasProperty(properties, PROPERTY_WIFI)) {
732 builder.append(" PROPERTY_WIFI");
733 }
734 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
735 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
736 }
737 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700738 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700739 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700740 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
741 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
742 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700743 if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Brad Ebinger15847072016-05-18 11:08:36 -0700744 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
745 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700746 if (hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
Eric Erfanianec881872017-12-06 16:27:53 -0800747 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
748 }
Tyler Gunn5bd90852018-09-21 09:37:07 -0700749 if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
750 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
751 }
Tyler Gunn80a5e1e2018-06-22 15:52:27 -0700752 if (hasProperty(properties, PROPERTY_RTT)) {
753 builder.append(" PROPERTY_RTT");
754 }
755 if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
756 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
757 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530758 if (hasProperty(properties, PROPERTY_IS_ADHOC_CONFERENCE)) {
759 builder.append(" PROPERTY_IS_ADHOC_CONFERENCE");
760 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700761 builder.append("]");
762 return builder.toString();
763 }
764
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800765 /** {@hide} */
Hall Liu31de23d2019-10-11 15:38:29 -0700766 @TestApi
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800767 public String getTelecomCallId() {
768 return mTelecomCallId;
769 }
770
Andrew Lee2378ea72015-04-29 14:38:11 -0700771 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700772 * @return The handle (e.g., phone number) to which the {@code Call} is currently
773 * connected.
774 */
775 public Uri getHandle() {
776 return mHandle;
777 }
778
779 /**
780 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700781 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700782 */
783 public int getHandlePresentation() {
784 return mHandlePresentation;
785 }
786
787 /**
Tyler Gunnd081f042018-12-04 12:56:45 -0800788 * The display name for the caller.
789 * <p>
790 * This is the name as reported by the {@link ConnectionService} associated with this call.
Tyler Gunnd081f042018-12-04 12:56:45 -0800791 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700792 * @return The display name for the caller.
793 */
794 public String getCallerDisplayName() {
795 return mCallerDisplayName;
796 }
797
798 /**
799 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700800 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700801 */
802 public int getCallerDisplayNamePresentation() {
803 return mCallerDisplayNamePresentation;
804 }
805
806 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700807 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
808 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700809 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700810 public PhoneAccountHandle getAccountHandle() {
811 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700812 }
813
814 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800815 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
816 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700817 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700818 public int getCallCapabilities() {
819 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700820 }
821
822 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700823 * @return A bitmask of the properties of the {@code Call}, as defined by the various
824 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700825 */
826 public int getCallProperties() {
827 return mCallProperties;
828 }
829
830 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800831 * @return a bitmask of the audio routes available for the call.
832 *
833 * @hide
834 */
835 public int getSupportedAudioRoutes() {
836 return mSupportedAudioRoutes;
837 }
838
839 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700840 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700841 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700842 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700843 public DisconnectCause getDisconnectCause() {
844 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700845 }
846
847 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700848 * Returns the time the {@link Call} connected (i.e. became active). This information is
849 * updated periodically, but user interfaces should not rely on this to display the "call
850 * time clock". For the time when the call was first added to Telecom, see
851 * {@link #getCreationTimeMillis()}.
852 *
853 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700854 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700855 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700856 return mConnectTimeMillis;
857 }
858
859 /**
860 * @return Information about any calling gateway the {@code Call} may be using.
861 */
862 public GatewayInfo getGatewayInfo() {
863 return mGatewayInfo;
864 }
865
Andrew Lee7a341382014-07-15 17:05:08 -0700866 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700867 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700868 */
869 public int getVideoState() {
870 return mVideoState;
871 }
872
Ihab Awad5d0410f2014-07-30 10:07:40 -0700873 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700874 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700875 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700876 */
877 public StatusHints getStatusHints() {
878 return mStatusHints;
879 }
880
Nancy Chen10798dc2014-08-08 14:00:25 -0700881 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700882 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700883 */
884 public Bundle getExtras() {
885 return mExtras;
886 }
887
Santos Cordon6b7f9552015-05-27 17:21:45 -0700888 /**
889 * @return The extras used with the original intent to place this call.
890 */
891 public Bundle getIntentExtras() {
892 return mIntentExtras;
893 }
894
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700895 /**
896 * Returns the time when the call was first created and added to Telecom. This is the same
897 * time that is logged as the start time in the Call Log (see
898 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
899 * (became active), see {@link #getConnectTimeMillis()}.
900 *
901 * @return The creation time of the call, in millis since the epoch.
902 */
903 public long getCreationTimeMillis() {
904 return mCreationTimeMillis;
905 }
906
Tyler Gunnd081f042018-12-04 12:56:45 -0800907 /**
Hall Liuef98bf82020-01-09 15:22:44 -0800908 * Returns the name of the caller on the remote end, as derived from a
909 * {@link android.provider.ContactsContract} lookup of the call's handle.
910 * @return The name of the caller, or {@code null} if the lookup is not yet complete, if
911 * there's no contacts entry for the caller, or if the {@link InCallService} does
912 * not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
913 */
914 public @Nullable String getContactDisplayName() {
915 return mContactDisplayName;
916 }
917
918 /**
Tyler Gunn94f8f112018-12-17 09:56:11 -0800919 * Indicates whether the call is an incoming or outgoing call.
920 * @return The call's direction.
921 */
922 public @CallDirection int getCallDirection() {
923 return mCallDirection;
924 }
925
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700926 /**
927 * Gets the verification status for the phone number of an incoming call as identified in
928 * ATIS-1000082.
929 * @return the verification status.
930 */
931 public @Connection.VerificationStatus int getCallerNumberVerificationStatus() {
932 return mCallerNumberVerificationStatus;
933 }
934
Ihab Awade63fadb2014-07-09 21:52:04 -0700935 @Override
936 public boolean equals(Object o) {
937 if (o instanceof Details) {
938 Details d = (Details) o;
939 return
940 Objects.equals(mHandle, d.mHandle) &&
941 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
942 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
943 Objects.equals(mCallerDisplayNamePresentation,
944 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700945 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700946 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700947 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700948 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700949 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700950 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700951 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700952 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700953 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700954 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
Tyler Gunnd081f042018-12-04 12:56:45 -0800955 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
Hall Liuef98bf82020-01-09 15:22:44 -0800956 Objects.equals(mContactDisplayName, d.mContactDisplayName) &&
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700957 Objects.equals(mCallDirection, d.mCallDirection) &&
958 Objects.equals(mCallerNumberVerificationStatus,
959 d.mCallerNumberVerificationStatus);
Ihab Awade63fadb2014-07-09 21:52:04 -0700960 }
961 return false;
962 }
963
964 @Override
965 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700966 return Objects.hash(mHandle,
967 mHandlePresentation,
968 mCallerDisplayName,
969 mCallerDisplayNamePresentation,
970 mAccountHandle,
971 mCallCapabilities,
972 mCallProperties,
973 mDisconnectCause,
974 mConnectTimeMillis,
975 mGatewayInfo,
976 mVideoState,
977 mStatusHints,
978 mExtras,
979 mIntentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -0800980 mCreationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -0800981 mContactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700982 mCallDirection,
983 mCallerNumberVerificationStatus);
Ihab Awade63fadb2014-07-09 21:52:04 -0700984 }
985
986 /** {@hide} */
987 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800988 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700989 Uri handle,
990 int handlePresentation,
991 String callerDisplayName,
992 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700993 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700994 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700995 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700996 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700997 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700998 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700999 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -07001000 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -07001001 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001002 Bundle intentExtras,
Tyler Gunnd081f042018-12-04 12:56:45 -08001003 long creationTimeMillis,
Hall Liuef98bf82020-01-09 15:22:44 -08001004 String contactDisplayName,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001005 int callDirection,
1006 int callerNumberVerificationStatus) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001007 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001008 mHandle = handle;
1009 mHandlePresentation = handlePresentation;
1010 mCallerDisplayName = callerDisplayName;
1011 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -07001012 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -07001013 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -07001014 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001015 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -07001016 mConnectTimeMillis = connectTimeMillis;
1017 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -07001018 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -07001019 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -07001020 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001021 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001022 mCreationTimeMillis = creationTimeMillis;
Hall Liuef98bf82020-01-09 15:22:44 -08001023 mContactDisplayName = contactDisplayName;
Tyler Gunn94f8f112018-12-17 09:56:11 -08001024 mCallDirection = callDirection;
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001025 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
Ihab Awade63fadb2014-07-09 21:52:04 -07001026 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001027
1028 /** {@hide} */
1029 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
1030 return new Details(
1031 parcelableCall.getId(),
1032 parcelableCall.getHandle(),
1033 parcelableCall.getHandlePresentation(),
1034 parcelableCall.getCallerDisplayName(),
1035 parcelableCall.getCallerDisplayNamePresentation(),
1036 parcelableCall.getAccountHandle(),
1037 parcelableCall.getCapabilities(),
1038 parcelableCall.getProperties(),
1039 parcelableCall.getDisconnectCause(),
1040 parcelableCall.getConnectTimeMillis(),
1041 parcelableCall.getGatewayInfo(),
1042 parcelableCall.getVideoState(),
1043 parcelableCall.getStatusHints(),
1044 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -07001045 parcelableCall.getIntentExtras(),
Tyler Gunnd081f042018-12-04 12:56:45 -08001046 parcelableCall.getCreationTimeMillis(),
Hall Liuef98bf82020-01-09 15:22:44 -08001047 parcelableCall.getContactDisplayName(),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001048 parcelableCall.getCallDirection(),
1049 parcelableCall.getCallerNumberVerificationStatus());
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001050 }
Santos Cordon3c20d632016-02-25 16:12:35 -08001051
1052 @Override
1053 public String toString() {
1054 StringBuilder sb = new StringBuilder();
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001055 sb.append("[id: ");
1056 sb.append(mTelecomCallId);
1057 sb.append(", pa: ");
Santos Cordon3c20d632016-02-25 16:12:35 -08001058 sb.append(mAccountHandle);
1059 sb.append(", hdl: ");
Tyler Gunn3cd820f2018-11-30 14:21:18 -08001060 sb.append(Log.piiHandle(mHandle));
1061 sb.append(", hdlPres: ");
1062 sb.append(mHandlePresentation);
1063 sb.append(", videoState: ");
1064 sb.append(VideoProfile.videoStateToString(mVideoState));
Santos Cordon3c20d632016-02-25 16:12:35 -08001065 sb.append(", caps: ");
1066 sb.append(capabilitiesToString(mCallCapabilities));
1067 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -07001068 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -08001069 sb.append("]");
1070 return sb.toString();
1071 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001072 }
1073
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001074 /**
1075 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1076 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1077 * implementation.
1078 * <p>
1079 * You can handle these callbacks by extending the {@link Callback} class and overriding the
1080 * callbacks that your {@link InCallService} is interested in. The callback methods include the
1081 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1082 * {@link Callback} implementation, if desired.
1083 * <p>
1084 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
1085 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1086 * (typically in {@link InCallService#onCallRemoved(Call)}).
1087 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1088 * reach your implementation of {@link Callback}, so it is important to register your callback
1089 * as soon as your {@link InCallService} is notified of a new call via
1090 * {@link InCallService#onCallAdded(Call)}.
1091 */
Andrew Leeda80c872015-04-15 14:09:50 -07001092 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -07001093 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001094 * @hide
1095 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001096 @IntDef(prefix = { "HANDOVER_" },
1097 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
Tyler Gunn5c60d712018-03-16 09:53:44 -07001098 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
Tyler Gunn9d127732018-03-02 15:45:51 -08001099 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -07001100 @Retention(RetentionPolicy.SOURCE)
1101 public @interface HandoverFailureErrors {}
1102
1103 /**
1104 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -08001105 * to handover the call to rejects the handover request.
1106 * <p>
1107 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1108 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1109 * {@code null} {@link Connection} from
1110 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1111 * ConnectionRequest)}.
1112 * <p>
1113 * For more information on call handovers, see
1114 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001115 */
1116 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1117
1118 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001119 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1120 * is initiated but the source or destination app does not support handover.
1121 * <p>
1122 * Will be returned when a handover is requested via
1123 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1124 * {@link PhoneAccountHandle} does not declare
1125 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
1126 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1127 * {@link Details#getAccountHandle()}) does not declare
1128 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1129 * <p>
1130 * For more information on call handovers, see
1131 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001132 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001133 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001134
1135 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08001136 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1137 * user rejects the handover request.
1138 * <p>
1139 * For more information on call handovers, see
1140 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001141 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001142 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001143
Sanket Padawe85291f62017-12-01 13:59:27 -08001144 /**
1145 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1146 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -08001147 * <p>
1148 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1149 * called on an emergency call, or if any other call is an emergency call.
1150 * <p>
1151 * Handovers are not permitted while there are ongoing emergency calls.
1152 * <p>
1153 * For more information on call handovers, see
1154 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -08001155 */
Tyler Gunn5c60d712018-03-16 09:53:44 -07001156 public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -08001157
Tyler Gunn9d127732018-03-02 15:45:51 -08001158 /**
1159 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1160 * fails for an unknown reason.
1161 * <p>
1162 * For more information on call handovers, see
1163 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1164 */
1165 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -07001166
1167 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001168 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1169 *
Ihab Awade63fadb2014-07-09 21:52:04 -07001170 * @param call The {@code Call} invoking this method.
1171 * @param state The new state of the {@code Call}.
1172 */
1173 public void onStateChanged(Call call, int state) {}
1174
1175 /**
1176 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1177 *
1178 * @param call The {@code Call} invoking this method.
1179 * @param parent The new parent of the {@code Call}.
1180 */
1181 public void onParentChanged(Call call, Call parent) {}
1182
1183 /**
1184 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1185 *
1186 * @param call The {@code Call} invoking this method.
1187 * @param children The new children of the {@code Call}.
1188 */
1189 public void onChildrenChanged(Call call, List<Call> children) {}
1190
1191 /**
1192 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1193 *
1194 * @param call The {@code Call} invoking this method.
1195 * @param details A {@code Details} object describing the {@code Call}.
1196 */
1197 public void onDetailsChanged(Call call, Details details) {}
1198
1199 /**
1200 * Invoked when the text messages that can be used as responses to the incoming
1201 * {@code Call} are loaded from the relevant database.
1202 * See {@link #getCannedTextResponses()}.
1203 *
1204 * @param call The {@code Call} invoking this method.
1205 * @param cannedTextResponses The text messages useable as responses.
1206 */
1207 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1208
1209 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001210 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1211 * character. This causes the post-dial signals to stop pending user confirmation. An
1212 * implementation should present this choice to the user and invoke
1213 * {@link #postDialContinue(boolean)} when the user makes the choice.
1214 *
1215 * @param call The {@code Call} invoking this method.
1216 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1217 */
1218 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1219
1220 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001221 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001222 *
1223 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001224 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001225 */
Andrew Lee50aca232014-07-22 16:41:54 -07001226 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001227
1228 /**
1229 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1230 * up their UI for the {@code Call} in response to state transitions. Specifically,
1231 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1232 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1233 * clients should wait for this method to be invoked.
1234 *
1235 * @param call The {@code Call} being destroyed.
1236 */
1237 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001238
1239 /**
1240 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1241 * conferenced.
1242 *
1243 * @param call The {@code Call} being updated.
1244 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1245 * conferenced.
1246 */
1247 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001248
1249 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001250 * Invoked when a {@link Call} receives an event from its associated {@link Connection} or
1251 * {@link Conference}.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001252 * <p>
1253 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1254 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1255 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1256 * possible that a {@link ConnectionService} has defined its own Connection events which a
1257 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001258 * <p>
Tyler Gunn5567d742019-10-31 13:04:37 -07001259 * See {@link Connection#sendConnectionEvent(String, Bundle)},
1260 * {@link Conference#sendConferenceEvent(String, Bundle)}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001261 *
1262 * @param call The {@code Call} receiving the event.
1263 * @param event The event.
1264 * @param extras Extras associated with the connection event.
1265 */
1266 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001267
1268 /**
1269 * Invoked when the RTT mode changes for this call.
1270 * @param call The call whose RTT mode has changed.
1271 * @param mode the new RTT mode, one of
1272 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1273 * or {@link RttCall#RTT_MODE_VCO}
1274 */
1275 public void onRttModeChanged(Call call, int mode) {}
1276
1277 /**
1278 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1279 * @param call The call whose RTT status has changed.
1280 * @param enabled whether RTT is now enabled or disabled
1281 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1282 * on, null otherwise.
1283 */
1284 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1285
1286 /**
1287 * Invoked when the remote end of the connection has requested that an RTT communication
1288 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1289 * with the same ID that this method is invoked with.
1290 * @param call The call which the RTT request was placed on
1291 * @param id The ID of the request.
1292 */
1293 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001294
1295 /**
1296 * Invoked when the RTT session failed to initiate for some reason, including rejection
1297 * by the remote party.
1298 * @param call The call which the RTT initiation failure occurred on.
1299 * @param reason One of the status codes defined in
1300 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1301 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1302 */
1303 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001304
1305 /**
1306 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1307 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001308 * <p>
1309 * For a full discussion of the handover process and the APIs involved, see
1310 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1311 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001312 * @param call The call which had initiated handover.
1313 */
1314 public void onHandoverComplete(Call call) {}
1315
1316 /**
1317 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1318 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001319 * <p>
1320 * For a full discussion of the handover process and the APIs involved, see
1321 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1322 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001323 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001324 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001325 */
1326 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001327 }
1328
1329 /**
1330 * A class that holds the state that describes the state of the RTT channel to the remote
1331 * party, if it is active.
1332 */
1333 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001334 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001335 @Retention(RetentionPolicy.SOURCE)
1336 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1337 public @interface RttAudioMode {}
1338
1339 /**
1340 * For metrics use. Default value in the proto.
1341 * @hide
1342 */
1343 public static final int RTT_MODE_INVALID = 0;
1344
1345 /**
1346 * Indicates that there should be a bidirectional audio stream between the two parties
1347 * on the call.
1348 */
1349 public static final int RTT_MODE_FULL = 1;
1350
1351 /**
1352 * Indicates that the local user should be able to hear the audio stream from the remote
1353 * user, but not vice versa. Equivalent to muting the microphone.
1354 */
1355 public static final int RTT_MODE_HCO = 2;
1356
1357 /**
1358 * Indicates that the remote user should be able to hear the audio stream from the local
1359 * user, but not vice versa. Equivalent to setting the volume to zero.
1360 */
1361 public static final int RTT_MODE_VCO = 3;
1362
1363 private static final int READ_BUFFER_SIZE = 1000;
1364
1365 private InputStreamReader mReceiveStream;
1366 private OutputStreamWriter mTransmitStream;
1367 private int mRttMode;
1368 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001369 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001370 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1371
1372 /**
1373 * @hide
1374 */
Hall Liu57006aa2017-02-06 10:49:48 -08001375 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1376 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1377 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001378 mReceiveStream = receiveStream;
1379 mTransmitStream = transmitStream;
1380 mRttMode = mode;
1381 mInCallAdapter = inCallAdapter;
1382 }
1383
1384 /**
1385 * Returns the current RTT audio mode.
1386 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1387 * {@link #RTT_MODE_HCO}.
1388 */
1389 public int getRttAudioMode() {
1390 return mRttMode;
1391 }
1392
1393 /**
1394 * Sets the RTT audio mode. The requested mode change will be communicated through
1395 * {@link Callback#onRttModeChanged(Call, int)}.
1396 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1397 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1398 */
1399 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001400 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001401 }
1402
1403 /**
1404 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1405 * RTT transmits text in real-time, this method should be called once for each character
1406 * the user enters into the device.
1407 *
1408 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1409 * lead to interleaved text.
1410 * @param input The message to send to the remote user.
1411 */
1412 public void write(String input) throws IOException {
1413 mTransmitStream.write(input);
1414 mTransmitStream.flush();
1415 }
1416
1417 /**
1418 * Reads a string from the remote user, blocking if there is no data available. Returns
1419 * {@code null} if the RTT conversation has been terminated and there is no further data
1420 * to read.
1421 *
1422 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1423 * lead to interleaved text.
1424 * @return A string containing text sent by the remote user, or {@code null} if the
1425 * conversation has been terminated or if there was an error while reading.
1426 */
Hall Liub1c8a772017-07-17 17:04:41 -07001427 public String read() {
1428 try {
1429 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1430 if (numRead < 0) {
1431 return null;
1432 }
1433 return new String(mReadBuffer, 0, numRead);
1434 } catch (IOException e) {
1435 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001436 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001437 }
Hall Liuffa4a812017-03-02 16:11:00 -08001438 }
1439
1440 /**
1441 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1442 * be read.
1443 * @return A string containing text entered by the user, or {@code null} if the user has
1444 * not entered any new text yet.
1445 */
1446 public String readImmediately() throws IOException {
1447 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001448 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1449 if (numRead < 0) {
1450 return null;
1451 }
1452 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001453 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001454 return null;
1455 }
1456 }
Hall Liue9041242018-02-09 16:40:03 -08001457
1458 /**
1459 * Closes the underlying file descriptors
1460 * @hide
1461 */
1462 public void close() {
1463 try {
1464 mReceiveStream.close();
1465 } catch (IOException e) {
1466 // ignore
1467 }
1468 try {
1469 mTransmitStream.close();
1470 } catch (IOException e) {
1471 // ignore
1472 }
1473 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001474 }
1475
Andrew Leeda80c872015-04-15 14:09:50 -07001476 /**
1477 * @deprecated Use {@code Call.Callback} instead.
1478 * @hide
1479 */
1480 @Deprecated
1481 @SystemApi
1482 public static abstract class Listener extends Callback { }
1483
Ihab Awade63fadb2014-07-09 21:52:04 -07001484 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001485 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001486 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001487 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001488 private final List<Call> mChildren = new ArrayList<>();
1489 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001490 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001491 private final List<Call> mConferenceableCalls = new ArrayList<>();
1492 private final List<Call> mUnmodifiableConferenceableCalls =
1493 Collections.unmodifiableList(mConferenceableCalls);
1494
Santos Cordon823fd3c2014-08-07 18:35:18 -07001495 private boolean mChildrenCached;
1496 private String mParentId = null;
Hall Liuef98bf82020-01-09 15:22:44 -08001497 private String mActiveGenericConferenceChild = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001498 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001499 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001500 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001501 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001502 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001503 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001504 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001505 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001506 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001507
1508 /**
1509 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1510 *
1511 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1512 * remaining or this {@code Call} is not in a post-dial state.
1513 */
1514 public String getRemainingPostDialSequence() {
1515 return mRemainingPostDialSequence;
1516 }
1517
1518 /**
1519 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001520 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001521 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001522 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001523 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001524 }
1525
1526 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301527 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1528 *
1529 * @param address The address to which the call will be deflected.
1530 */
1531 public void deflect(Uri address) {
1532 mInCallAdapter.deflectCall(mTelecomCallId, address);
1533 }
1534
1535 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001536 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1537 *
1538 * @param rejectWithMessage Whether to reject with a text message.
1539 * @param textMessage An optional text message with which to respond.
1540 */
1541 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001542 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001543 }
1544
1545 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001546 * Instructs the {@link ConnectionService} providing this {@link #STATE_RINGING} call that the
1547 * user has chosen to reject the call and has indicated a reason why the call is being rejected.
1548 *
1549 * @param rejectReason the reason the call is being rejected.
1550 */
1551 public void reject(@RejectReason int rejectReason) {
1552 mInCallAdapter.rejectCall(mTelecomCallId, rejectReason);
1553 }
1554
1555 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001556 * Instructs this {@code Call} to disconnect.
1557 */
1558 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001559 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001560 }
1561
1562 /**
1563 * Instructs this {@code Call} to go on hold.
1564 */
1565 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001566 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001567 }
1568
1569 /**
1570 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1571 */
1572 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001573 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001574 }
1575
1576 /**
Hall Liu6dfa2492019-10-01 17:20:39 -07001577 * Instructs Telecom to put the call into the background audio processing state.
1578 *
1579 * This method can be called either when the call is in {@link #STATE_RINGING} or
1580 * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1581 * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1582 * order to capture and play audio on the call stream.
1583 *
1584 * This method can only be called by the default dialer app.
1585 * @hide
1586 */
1587 @SystemApi
1588 @TestApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001589 public void enterBackgroundAudioProcessing() {
1590 if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1591 throw new IllegalStateException("Call must be active or ringing");
1592 }
1593 mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1594 }
1595
1596 /**
1597 * Instructs Telecom to come out of the background audio processing state requested by
1598 * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1599 *
1600 * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1601 *
1602 * @param shouldRing If true, Telecom will put the call into the
1603 * {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1604 * a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1605 * immediately.
1606 * @hide
1607 */
1608 @SystemApi
1609 @TestApi
Hall Liu6dfa2492019-10-01 17:20:39 -07001610 public void exitBackgroundAudioProcessing(boolean shouldRing) {
1611 if (mState != STATE_AUDIO_PROCESSING) {
1612 throw new IllegalStateException("Call must in the audio processing state");
1613 }
1614 mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1615 }
1616
1617 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001618 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1619 *
1620 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1621 *
1622 * @param digit A character representing the DTMF digit for which to play the tone. This
1623 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1624 */
1625 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001626 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001627 }
1628
1629 /**
1630 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1631 * currently playing.
1632 *
1633 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1634 * currently playing, this method will do nothing.
1635 */
1636 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001637 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001638 }
1639
1640 /**
1641 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1642 *
1643 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1644 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001645 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001646 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001647 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1648 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001649 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001650 * {@code Call} will pause playing the tones and notify callbacks via
1651 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001652 * should display to the user an indication of this state and an affordance to continue
1653 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1654 * app should invoke the {@link #postDialContinue(boolean)} method.
1655 *
1656 * @param proceed Whether or not to continue with the post-dial sequence.
1657 */
1658 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001659 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001660 }
1661
1662 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001663 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001664 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001665 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001666 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1667 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001668
1669 }
1670
1671 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001672 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001673 *
1674 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001675 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001676 public void conference(Call callToConferenceWith) {
1677 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001678 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001679 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001680 }
1681
1682 /**
1683 * Instructs this {@code Call} to split from any conference call with which it may be
1684 * connected.
1685 */
1686 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001687 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001688 }
1689
1690 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001691 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001692 */
1693 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001694 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001695 }
1696
1697 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001698 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001699 */
1700 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001701 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001702 }
1703
1704 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001705 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1706 * device.
1707 * <p>
1708 * Calls to this method are ignored if the call does not have the
1709 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1710 * <p>
1711 * An {@link InCallService} will only see calls which support this method if it has the
1712 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1713 * in its manifest.
1714 */
1715 public void pullExternalCall() {
1716 // If this isn't an external call, ignore the request.
1717 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1718 return;
1719 }
1720
1721 mInCallAdapter.pullExternalCall(mTelecomCallId);
1722 }
1723
1724 /**
1725 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1726 * the {@link ConnectionService}.
1727 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001728 * Call events are used to communicate point in time information from an {@link InCallService}
1729 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1730 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1731 * {@link ConnectionService}.
1732 * <p>
1733 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1734 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1735 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001736 * Events are exposed to {@link ConnectionService} implementations via
1737 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1738 * <p>
1739 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001740 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1741 * ignore some events altogether.
1742 * <p>
1743 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1744 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1745 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1746 * they define their own event types in this namespace. When defining a custom event type,
1747 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1748 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1749 * <p>
1750 * When defining events and the associated extras, it is important to keep their behavior
1751 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1752 * events/extras should me maintained to ensure backwards compatibility with older
1753 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001754 *
1755 * @param event The connection event.
1756 * @param extras Bundle containing extra information associated with the event.
1757 */
1758 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001759 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001760 }
1761
1762 /**
Hall Liu95d55872017-01-25 17:12:49 -08001763 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1764 * guaranteed, and notification of success will be via the
1765 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1766 */
1767 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001768 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001769 }
1770
1771 /**
1772 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1773 * callback.
1774 * The ID used here should be the same as the ID that was received via the callback.
1775 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1776 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1777 */
1778 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001779 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001780 }
1781
1782 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001783 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1784 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1785 * handover.
1786 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001787 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1788 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1789 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1790 * is referred to as the source of the handover, and the video calling app is referred to as the
1791 * destination.
1792 * <p>
1793 * When considering a handover scenario the device this method is called on is considered the
1794 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1795 * other device is considered the <em>receiving</em> device.
1796 * <p>
1797 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1798 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1799 * and invoke
1800 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1801 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1802 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1803 * At this point the app should display UI to indicate to the user that a call
1804 * handover is in process.
1805 * <p>
1806 * The destination app is responsible for communicating the handover request from the
1807 * <em>initiating</em> device to the <em>receiving</em> device.
1808 * <p>
1809 * When the app on the <em>receiving</em> device receives the handover request, it calls
1810 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1811 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1812 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1813 * choose whether they want to continue their call in the destination app.
1814 * <p>
1815 * When the destination app on the <em>receiving</em> device calls
1816 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1817 * {@link ConnectionService} and call
1818 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1819 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1820 * {@link Connection} to represent the handover call.
1821 * <p>
1822 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1823 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1824 * original call. If the user rejects the handover, the app calls
1825 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1826 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1827 * <p>
1828 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1829 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1830 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1831 * <p>
1832 * Errors in the handover process are reported to the {@link InCallService} via
1833 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1834 * the involved {@link ConnectionService}s via
1835 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001836 *
1837 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1838 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001839 * @param videoState Indicates the video state desired after the handover (see the
1840 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001841 * @param extras Bundle containing extra information to be passed to the
1842 * {@link ConnectionService}
1843 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001844 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1845 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001846 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1847 }
1848
1849 /**
Hall Liu95d55872017-01-25 17:12:49 -08001850 * Terminate the RTT session on this call. The resulting state change will be notified via
1851 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1852 */
1853 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001854 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001855 }
1856
1857 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001858 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1859 * added.
1860 * <p>
1861 * No assumptions should be made as to how an In-Call UI or service will handle these
1862 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1863 *
1864 * @param extras The extras to add.
1865 */
1866 public final void putExtras(Bundle extras) {
1867 if (extras == null) {
1868 return;
1869 }
1870
1871 if (mExtras == null) {
1872 mExtras = new Bundle();
1873 }
1874 mExtras.putAll(extras);
1875 mInCallAdapter.putExtras(mTelecomCallId, extras);
1876 }
1877
1878 /**
1879 * Adds a boolean extra to this {@link Call}.
1880 *
1881 * @param key The extra key.
1882 * @param value The value.
1883 * @hide
1884 */
1885 public final void putExtra(String key, boolean value) {
1886 if (mExtras == null) {
1887 mExtras = new Bundle();
1888 }
1889 mExtras.putBoolean(key, value);
1890 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1891 }
1892
1893 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001894 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001895 *
1896 * @param key The extra key.
1897 * @param value The value.
1898 * @hide
1899 */
1900 public final void putExtra(String key, int value) {
1901 if (mExtras == null) {
1902 mExtras = new Bundle();
1903 }
1904 mExtras.putInt(key, value);
1905 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1906 }
1907
1908 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001909 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001910 *
1911 * @param key The extra key.
1912 * @param value The value.
1913 * @hide
1914 */
1915 public final void putExtra(String key, String value) {
1916 if (mExtras == null) {
1917 mExtras = new Bundle();
1918 }
1919 mExtras.putString(key, value);
1920 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1921 }
1922
1923 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001924 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001925 *
1926 * @param keys The keys of the extras to remove.
1927 */
1928 public final void removeExtras(List<String> keys) {
1929 if (mExtras != null) {
1930 for (String key : keys) {
1931 mExtras.remove(key);
1932 }
1933 if (mExtras.size() == 0) {
1934 mExtras = null;
1935 }
1936 }
1937 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1938 }
1939
1940 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001941 * Removes extras from this {@link Call}.
1942 *
1943 * @param keys The keys of the extras to remove.
1944 */
1945 public final void removeExtras(String ... keys) {
1946 removeExtras(Arrays.asList(keys));
1947 }
1948
1949 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001950 * Obtains the parent of this {@code Call} in a conference, if any.
1951 *
1952 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1953 * child of any conference {@code Call}s.
1954 */
1955 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001956 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001957 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001958 }
1959 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001960 }
1961
1962 /**
1963 * Obtains the children of this conference {@code Call}, if any.
1964 *
1965 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1966 * {@code List} otherwise.
1967 */
1968 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001969 if (!mChildrenCached) {
1970 mChildrenCached = true;
1971 mChildren.clear();
1972
1973 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001974 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001975 if (call == null) {
1976 // At least one child was still not found, so do not save true for "cached"
1977 mChildrenCached = false;
1978 } else {
1979 mChildren.add(call);
1980 }
1981 }
1982 }
1983
Ihab Awade63fadb2014-07-09 21:52:04 -07001984 return mUnmodifiableChildren;
1985 }
1986
1987 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001988 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1989 *
1990 * @return The list of conferenceable {@code Call}s.
1991 */
1992 public List<Call> getConferenceableCalls() {
1993 return mUnmodifiableConferenceableCalls;
1994 }
1995
1996 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001997 * Obtains the state of this {@code Call}.
1998 *
1999 * @return A state value, chosen from the {@code STATE_*} constants.
2000 */
2001 public int getState() {
2002 return mState;
2003 }
2004
2005 /**
Hall Liuef98bf82020-01-09 15:22:44 -08002006 * Returns the child {@link Call} in a generic conference that is currently active.
2007 * For calls that are not generic conferences, or when the generic conference has more than
2008 * 2 children, returns {@code null}.
2009 * @see Details#PROPERTY_GENERIC_CONFERENCE
2010 * @return The active child call.
2011 */
2012 public @Nullable Call getGenericConferenceActiveChildCall() {
2013 if (mActiveGenericConferenceChild != null) {
2014 return mPhone.internalGetCallByTelecomId(mActiveGenericConferenceChild);
2015 }
2016 return null;
2017 }
2018
2019 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002020 * Obtains a list of canned, pre-configured message responses to present to the user as
2021 * ways of rejecting this {@code Call} using via a text message.
2022 *
2023 * @see #reject(boolean, String)
2024 *
2025 * @return A list of canned text message responses.
2026 */
2027 public List<String> getCannedTextResponses() {
2028 return mCannedTextResponses;
2029 }
2030
2031 /**
2032 * Obtains an object that can be used to display video from this {@code Call}.
2033 *
Andrew Lee50aca232014-07-22 16:41:54 -07002034 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07002035 */
Andrew Lee50aca232014-07-22 16:41:54 -07002036 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002037 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07002038 }
2039
2040 /**
2041 * Obtains an object containing call details.
2042 *
2043 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
2044 * result may be {@code null}.
2045 */
2046 public Details getDetails() {
2047 return mDetails;
2048 }
2049
2050 /**
Hall Liu95d55872017-01-25 17:12:49 -08002051 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
2052 * receive RTT text data, as well as to change the RTT mode.
2053 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
2054 */
2055 public @Nullable RttCall getRttCall() {
2056 return mRttCall;
2057 }
2058
2059 /**
2060 * Returns whether this call has an active RTT connection.
2061 * @return true if there is a connection, false otherwise.
2062 */
2063 public boolean isRttActive() {
Hall Liue9041242018-02-09 16:40:03 -08002064 return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
Hall Liu95d55872017-01-25 17:12:49 -08002065 }
2066
2067 /**
Andrew Leeda80c872015-04-15 14:09:50 -07002068 * Registers a callback to this {@code Call}.
2069 *
2070 * @param callback A {@code Callback}.
2071 */
2072 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07002073 registerCallback(callback, new Handler());
2074 }
2075
2076 /**
2077 * Registers a callback to this {@code Call}.
2078 *
2079 * @param callback A {@code Callback}.
2080 * @param handler A handler which command and status changes will be delivered to.
2081 */
2082 public void registerCallback(Callback callback, Handler handler) {
2083 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07002084 // Don't allow new callback registration if the call is already being destroyed.
2085 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002086 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
2087 }
Andrew Leeda80c872015-04-15 14:09:50 -07002088 }
2089
2090 /**
2091 * Unregisters a callback from this {@code Call}.
2092 *
2093 * @param callback A {@code Callback}.
2094 */
2095 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07002096 // Don't allow callback deregistration if the call is already being destroyed.
2097 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07002098 for (CallbackRecord<Callback> record : mCallbackRecords) {
2099 if (record.getCallback() == callback) {
2100 mCallbackRecords.remove(record);
2101 break;
2102 }
2103 }
Andrew Leeda80c872015-04-15 14:09:50 -07002104 }
2105 }
2106
Santos Cordon3c20d632016-02-25 16:12:35 -08002107 @Override
2108 public String toString() {
2109 return new StringBuilder().
2110 append("Call [id: ").
2111 append(mTelecomCallId).
2112 append(", state: ").
2113 append(stateToString(mState)).
2114 append(", details: ").
2115 append(mDetails).
2116 append("]").toString();
2117 }
2118
2119 /**
2120 * @param state An integer value of a {@code STATE_*} constant.
2121 * @return A string representation of the value.
2122 */
2123 private static String stateToString(int state) {
2124 switch (state) {
2125 case STATE_NEW:
2126 return "NEW";
2127 case STATE_RINGING:
2128 return "RINGING";
2129 case STATE_DIALING:
2130 return "DIALING";
2131 case STATE_ACTIVE:
2132 return "ACTIVE";
2133 case STATE_HOLDING:
2134 return "HOLDING";
2135 case STATE_DISCONNECTED:
2136 return "DISCONNECTED";
2137 case STATE_CONNECTING:
2138 return "CONNECTING";
2139 case STATE_DISCONNECTING:
2140 return "DISCONNECTING";
2141 case STATE_SELECT_PHONE_ACCOUNT:
2142 return "SELECT_PHONE_ACCOUNT";
Hall Liu4e35b642019-10-14 17:50:45 -07002143 case STATE_SIMULATED_RINGING:
2144 return "SIMULATED_RINGING";
2145 case STATE_AUDIO_PROCESSING:
2146 return "AUDIO_PROCESSING";
Santos Cordon3c20d632016-02-25 16:12:35 -08002147 default:
2148 Log.w(Call.class, "Unknown state %d", state);
2149 return "UNKNOWN";
2150 }
2151 }
2152
Andrew Leeda80c872015-04-15 14:09:50 -07002153 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07002154 * Adds a listener to this {@code Call}.
2155 *
2156 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002157 * @deprecated Use {@link #registerCallback} instead.
2158 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002159 */
Andrew Leeda80c872015-04-15 14:09:50 -07002160 @Deprecated
2161 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002162 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002163 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002164 }
2165
2166 /**
2167 * Removes a listener from this {@code Call}.
2168 *
2169 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07002170 * @deprecated Use {@link #unregisterCallback} instead.
2171 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07002172 */
Andrew Leeda80c872015-04-15 14:09:50 -07002173 @Deprecated
2174 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07002175 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07002176 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07002177 }
2178
2179 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002180 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2181 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07002182 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002183 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002184 mInCallAdapter = inCallAdapter;
2185 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002186 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002187 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07002188 }
2189
2190 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08002191 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08002192 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002193 mPhone = phone;
2194 mTelecomCallId = telecomCallId;
2195 mInCallAdapter = inCallAdapter;
2196 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08002197 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002198 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07002199 }
2200
2201 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002202 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002203 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002204 }
2205
2206 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002207 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08002208
Ihab Awade63fadb2014-07-09 21:52:04 -07002209 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08002210 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07002211 boolean detailsChanged = !Objects.equals(mDetails, details);
2212 if (detailsChanged) {
2213 mDetails = details;
2214 }
2215
2216 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07002217 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2218 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2219 mCannedTextResponses =
2220 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07002221 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07002222 }
2223
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002224 IVideoProvider previousVideoProvider = mVideoCallImpl == null ? null :
2225 mVideoCallImpl.getVideoProvider();
2226 IVideoProvider newVideoProvider = parcelableCall.getVideoProvider();
2227
2228 // parcelableCall.isVideoCallProviderChanged is only true when we have a video provider
2229 // specified; so we should check if the actual IVideoProvider changes as well.
2230 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged()
2231 && !Objects.equals(previousVideoProvider, newVideoProvider);
Andrew Lee50aca232014-07-22 16:41:54 -07002232 if (videoCallChanged) {
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002233 if (mVideoCallImpl != null) {
2234 mVideoCallImpl.destroy();
2235 }
2236 mVideoCallImpl = parcelableCall.isVideoCallProviderChanged() ?
2237 parcelableCall.getVideoCallImpl(mCallingPackage, mTargetSdkVersion) : null;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002238 }
Tyler Gunnd1fdf3a2019-11-05 15:47:58 -08002239
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002240 if (mVideoCallImpl != null) {
2241 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07002242 }
2243
Santos Cordone3c507b2015-04-23 14:44:19 -07002244 int state = parcelableCall.getState();
Hall Liu31de23d2019-10-11 15:38:29 -07002245 if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2246 state = Call.STATE_RINGING;
2247 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002248 boolean stateChanged = mState != state;
2249 if (stateChanged) {
2250 mState = state;
2251 }
2252
Santos Cordon823fd3c2014-08-07 18:35:18 -07002253 String parentId = parcelableCall.getParentCallId();
2254 boolean parentChanged = !Objects.equals(mParentId, parentId);
2255 if (parentChanged) {
2256 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07002257 }
2258
Santos Cordon823fd3c2014-08-07 18:35:18 -07002259 List<String> childCallIds = parcelableCall.getChildCallIds();
2260 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2261 if (childrenChanged) {
2262 mChildrenIds.clear();
2263 mChildrenIds.addAll(parcelableCall.getChildCallIds());
2264 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07002265 }
2266
Hall Liuef98bf82020-01-09 15:22:44 -08002267 String activeChildCallId = parcelableCall.getActiveChildCallId();
2268 boolean activeChildChanged = !Objects.equals(activeChildCallId,
2269 mActiveGenericConferenceChild);
2270 if (activeChildChanged) {
2271 mActiveGenericConferenceChild = activeChildCallId;
2272 }
2273
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002274 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2275 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2276 for (String otherId : conferenceableCallIds) {
2277 if (callIdMap.containsKey(otherId)) {
2278 conferenceableCalls.add(callIdMap.get(otherId));
2279 }
2280 }
2281
2282 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2283 mConferenceableCalls.clear();
2284 mConferenceableCalls.addAll(conferenceableCalls);
2285 fireConferenceableCallsChanged();
2286 }
2287
Hall Liu95d55872017-01-25 17:12:49 -08002288 boolean isRttChanged = false;
2289 boolean rttModeChanged = false;
Hall Liue9041242018-02-09 16:40:03 -08002290 if (parcelableCall.getIsRttCallChanged()
2291 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
Hall Liu95d55872017-01-25 17:12:49 -08002292 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2293 InputStreamReader receiveStream = new InputStreamReader(
2294 new ParcelFileDescriptor.AutoCloseInputStream(
2295 parcelableRttCall.getReceiveStream()),
2296 StandardCharsets.UTF_8);
2297 OutputStreamWriter transmitStream = new OutputStreamWriter(
2298 new ParcelFileDescriptor.AutoCloseOutputStream(
2299 parcelableRttCall.getTransmitStream()),
2300 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08002301 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08002302 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2303 if (mRttCall == null) {
2304 isRttChanged = true;
2305 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2306 rttModeChanged = true;
2307 }
2308 mRttCall = newRttCall;
2309 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2310 && parcelableCall.getIsRttCallChanged()) {
2311 isRttChanged = true;
2312 mRttCall = null;
2313 }
2314
Ihab Awade63fadb2014-07-09 21:52:04 -07002315 // Now we fire updates, ensuring that any client who listens to any of these notifications
2316 // gets the most up-to-date state.
2317
2318 if (stateChanged) {
2319 fireStateChanged(mState);
2320 }
2321 if (detailsChanged) {
2322 fireDetailsChanged(mDetails);
2323 }
2324 if (cannedTextResponsesChanged) {
2325 fireCannedTextResponsesLoaded(mCannedTextResponses);
2326 }
Andrew Lee50aca232014-07-22 16:41:54 -07002327 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08002328 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002329 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002330 if (parentChanged) {
2331 fireParentChanged(getParent());
2332 }
Hall Liuef98bf82020-01-09 15:22:44 -08002333 if (childrenChanged || activeChildChanged) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002334 fireChildrenChanged(getChildren());
2335 }
Hall Liu95d55872017-01-25 17:12:49 -08002336 if (isRttChanged) {
2337 fireOnIsRttChanged(mRttCall != null, mRttCall);
2338 }
2339 if (rttModeChanged) {
2340 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2341 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002342
2343 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2344 // remove ourselves from the Phone. Note that we do this after completing all state updates
2345 // so a client can cleanly transition all their UI to the state appropriate for a
2346 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2347 if (mState == STATE_DISCONNECTED) {
2348 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002349 }
2350 }
2351
2352 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002353 final void internalSetPostDialWait(String remaining) {
2354 mRemainingPostDialSequence = remaining;
2355 firePostDialWait(mRemainingPostDialSequence);
2356 }
2357
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002358 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002359 final void internalSetDisconnected() {
2360 if (mState != Call.STATE_DISCONNECTED) {
2361 mState = Call.STATE_DISCONNECTED;
2362 fireStateChanged(mState);
2363 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002364 }
2365 }
2366
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002367 /** {@hide} */
2368 final void internalOnConnectionEvent(String event, Bundle extras) {
2369 fireOnConnectionEvent(event, extras);
2370 }
2371
Hall Liu95d55872017-01-25 17:12:49 -08002372 /** {@hide} */
2373 final void internalOnRttUpgradeRequest(final int requestId) {
2374 for (CallbackRecord<Callback> record : mCallbackRecords) {
2375 final Call call = this;
2376 final Callback callback = record.getCallback();
2377 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2378 }
2379 }
2380
Hall Liu57006aa2017-02-06 10:49:48 -08002381 /** @hide */
2382 final void internalOnRttInitiationFailure(int reason) {
2383 for (CallbackRecord<Callback> record : mCallbackRecords) {
2384 final Call call = this;
2385 final Callback callback = record.getCallback();
2386 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2387 }
2388 }
2389
Sanket Padawe85291f62017-12-01 13:59:27 -08002390 /** {@hide} */
2391 final void internalOnHandoverFailed(int error) {
2392 for (CallbackRecord<Callback> record : mCallbackRecords) {
2393 final Call call = this;
2394 final Callback callback = record.getCallback();
2395 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2396 }
2397 }
2398
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002399 /** {@hide} */
2400 final void internalOnHandoverComplete() {
2401 for (CallbackRecord<Callback> record : mCallbackRecords) {
2402 final Call call = this;
2403 final Callback callback = record.getCallback();
2404 record.getHandler().post(() -> callback.onHandoverComplete(call));
2405 }
2406 }
2407
Andrew Lee011728f2015-04-23 15:47:06 -07002408 private void fireStateChanged(final int newState) {
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.onStateChanged(call, newState);
2416 }
2417 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002418 }
2419 }
2420
Andrew Lee011728f2015-04-23 15:47:06 -07002421 private void fireParentChanged(final Call newParent) {
2422 for (CallbackRecord<Callback> record : mCallbackRecords) {
2423 final Call call = this;
2424 final Callback callback = record.getCallback();
2425 record.getHandler().post(new Runnable() {
2426 @Override
2427 public void run() {
2428 callback.onParentChanged(call, newParent);
2429 }
2430 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002431 }
2432 }
2433
Andrew Lee011728f2015-04-23 15:47:06 -07002434 private void fireChildrenChanged(final List<Call> children) {
2435 for (CallbackRecord<Callback> record : mCallbackRecords) {
2436 final Call call = this;
2437 final Callback callback = record.getCallback();
2438 record.getHandler().post(new Runnable() {
2439 @Override
2440 public void run() {
2441 callback.onChildrenChanged(call, children);
2442 }
2443 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002444 }
2445 }
2446
Andrew Lee011728f2015-04-23 15:47:06 -07002447 private void fireDetailsChanged(final Details details) {
2448 for (CallbackRecord<Callback> record : mCallbackRecords) {
2449 final Call call = this;
2450 final Callback callback = record.getCallback();
2451 record.getHandler().post(new Runnable() {
2452 @Override
2453 public void run() {
2454 callback.onDetailsChanged(call, details);
2455 }
2456 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002457 }
2458 }
2459
Andrew Lee011728f2015-04-23 15:47:06 -07002460 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2461 for (CallbackRecord<Callback> record : mCallbackRecords) {
2462 final Call call = this;
2463 final Callback callback = record.getCallback();
2464 record.getHandler().post(new Runnable() {
2465 @Override
2466 public void run() {
2467 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2468 }
2469 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002470 }
2471 }
2472
Andrew Lee011728f2015-04-23 15:47:06 -07002473 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2474 for (CallbackRecord<Callback> record : mCallbackRecords) {
2475 final Call call = this;
2476 final Callback callback = record.getCallback();
2477 record.getHandler().post(new Runnable() {
2478 @Override
2479 public void run() {
2480 callback.onVideoCallChanged(call, videoCall);
2481 }
2482 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002483 }
2484 }
2485
Andrew Lee011728f2015-04-23 15:47:06 -07002486 private void firePostDialWait(final String remainingPostDialSequence) {
2487 for (CallbackRecord<Callback> record : mCallbackRecords) {
2488 final Call call = this;
2489 final Callback callback = record.getCallback();
2490 record.getHandler().post(new Runnable() {
2491 @Override
2492 public void run() {
2493 callback.onPostDialWait(call, remainingPostDialSequence);
2494 }
2495 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002496 }
2497 }
2498
2499 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002500 /**
2501 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2502 * onCallRemoved callback, we remove this call from the Phone's record
2503 * only once all of the registered onCallDestroyed callbacks are executed.
2504 * All the callbacks get removed from our records as a part of this operation
2505 * since onCallDestroyed is the final callback.
2506 */
2507 final Call call = this;
2508 if (mCallbackRecords.isEmpty()) {
2509 // No callbacks registered, remove the call from Phone's record.
2510 mPhone.internalRemoveCall(call);
2511 }
2512 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002513 final Callback callback = record.getCallback();
2514 record.getHandler().post(new Runnable() {
2515 @Override
2516 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002517 boolean isFinalRemoval = false;
2518 RuntimeException toThrow = null;
2519 try {
2520 callback.onCallDestroyed(call);
2521 } catch (RuntimeException e) {
2522 toThrow = e;
2523 }
2524 synchronized(Call.this) {
2525 mCallbackRecords.remove(record);
2526 if (mCallbackRecords.isEmpty()) {
2527 isFinalRemoval = true;
2528 }
2529 }
2530 if (isFinalRemoval) {
2531 mPhone.internalRemoveCall(call);
2532 }
2533 if (toThrow != null) {
2534 throw toThrow;
2535 }
Andrew Lee011728f2015-04-23 15:47:06 -07002536 }
2537 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002538 }
2539 }
2540
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002541 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002542 for (CallbackRecord<Callback> record : mCallbackRecords) {
2543 final Call call = this;
2544 final Callback callback = record.getCallback();
2545 record.getHandler().post(new Runnable() {
2546 @Override
2547 public void run() {
2548 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2549 }
2550 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002551 }
2552 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002553
2554 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002555 * Notifies listeners of an incoming connection event.
2556 * <p>
2557 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2558 *
2559 * @param event
2560 * @param extras
2561 */
2562 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2563 for (CallbackRecord<Callback> record : mCallbackRecords) {
2564 final Call call = this;
2565 final Callback callback = record.getCallback();
2566 record.getHandler().post(new Runnable() {
2567 @Override
2568 public void run() {
2569 callback.onConnectionEvent(call, event, extras);
2570 }
2571 });
2572 }
2573 }
2574
2575 /**
Hall Liu95d55872017-01-25 17:12:49 -08002576 * Notifies listeners of an RTT on/off change
2577 *
2578 * @param enabled True if RTT is now enabled, false otherwise
2579 */
2580 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2581 for (CallbackRecord<Callback> record : mCallbackRecords) {
2582 final Call call = this;
2583 final Callback callback = record.getCallback();
2584 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2585 }
2586 }
2587
2588 /**
2589 * Notifies listeners of a RTT mode change
2590 *
2591 * @param mode The new RTT mode
2592 */
2593 private void fireOnRttModeChanged(final int mode) {
2594 for (CallbackRecord<Callback> record : mCallbackRecords) {
2595 final Call call = this;
2596 final Callback callback = record.getCallback();
2597 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2598 }
2599 }
2600
2601 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002602 * Determines if two bundles are equal.
2603 *
2604 * @param bundle The original bundle.
2605 * @param newBundle The bundle to compare with.
2606 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2607 */
2608 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2609 if (bundle == null || newBundle == null) {
2610 return bundle == newBundle;
2611 }
2612
2613 if (bundle.size() != newBundle.size()) {
2614 return false;
2615 }
2616
2617 for(String key : bundle.keySet()) {
2618 if (key != null) {
2619 final Object value = bundle.get(key);
2620 final Object newValue = newBundle.get(key);
2621 if (!Objects.equals(value, newValue)) {
2622 return false;
2623 }
2624 }
2625 }
2626 return true;
2627 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002628}