blob: 8c18518a6d6790c55c7c7cbe883bc7f4b81e8f5b [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;
Ihab Awade63fadb2014-07-09 21:52:04 -070022import android.net.Uri;
Nancy Chen10798dc2014-08-08 14:00:25 -070023import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070024import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080025import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070026
Hall Liu95d55872017-01-25 17:12:49 -080027import java.io.IOException;
28import java.io.InputStreamReader;
29import java.io.OutputStreamWriter;
Andrew Lee50aca232014-07-22 16:41:54 -070030import java.lang.String;
Hall Liu95d55872017-01-25 17:12:49 -080031import java.lang.annotation.Retention;
32import java.lang.annotation.RetentionPolicy;
33import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070034import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070035import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070036import java.util.Collections;
37import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070038import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070039import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070040import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070041
42/**
43 * Represents an ongoing phone call that the in-call app should present to the user.
44 */
45public final class Call {
46 /**
47 * The state of a {@code Call} when newly created.
48 */
49 public static final int STATE_NEW = 0;
50
51 /**
52 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
53 */
54 public static final int STATE_DIALING = 1;
55
56 /**
57 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
58 */
59 public static final int STATE_RINGING = 2;
60
61 /**
62 * The state of a {@code Call} when in a holding state.
63 */
64 public static final int STATE_HOLDING = 3;
65
66 /**
67 * The state of a {@code Call} when actively supporting conversation.
68 */
69 public static final int STATE_ACTIVE = 4;
70
71 /**
72 * The state of a {@code Call} when no further voice or other communication is being
73 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
74 * is no longer active, and the local data transport has or inevitably will release resources
75 * associated with this {@code Call}.
76 */
77 public static final int STATE_DISCONNECTED = 7;
78
Nancy Chen5da0fd52014-07-08 14:16:17 -070079 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070080 * The state of an outgoing {@code Call} when waiting on user to select a
81 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070082 */
Santos Cordone3c507b2015-04-23 14:44:19 -070083 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
84
85 /**
86 * @hide
87 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
88 */
89 @Deprecated
90 @SystemApi
91 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070092
Nancy Chene20930f2014-08-07 16:17:21 -070093 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070094 * The initial state of an outgoing {@code Call}.
95 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
96 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070097 */
98 public static final int STATE_CONNECTING = 9;
99
Nancy Chen513c8922014-09-17 14:47:20 -0700100 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700101 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
102 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
103 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
104 */
105 public static final int STATE_DISCONNECTING = 10;
106
107 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700108 * The state of an external call which is in the process of being pulled from a remote device to
109 * the local device.
110 * <p>
111 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
112 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
113 * <p>
114 * An {@link InCallService} will only see this state if it has the
115 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
116 * manifest.
117 */
118 public static final int STATE_PULLING_CALL = 11;
119
120 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700121 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
122 * extras. Used to pass the phone accounts to display on the front end to the user in order to
123 * select phone accounts to (for example) place a call.
Nancy Chen513c8922014-09-17 14:47:20 -0700124 */
125 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
126
mike dooley4af561f2016-12-20 08:55:17 -0800127 /**
mike dooley91217422017-03-09 12:58:42 -0800128 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
129 * when the last outgoing emergency call was made. This is used to identify potential emergency
130 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800131 */
132 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
133 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
134
Tyler Gunn8bf76572017-04-06 15:30:08 -0700135 /**
136 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
137 * Telecom that the user has requested that the current {@link Call} should be handed over
138 * to another {@link ConnectionService}.
139 * <p>
140 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
141 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
142 * @hide
143 */
144 public static final String EVENT_REQUEST_HANDOVER =
145 "android.telecom.event.REQUEST_HANDOVER";
146
147 /**
148 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
149 * {@link PhoneAccountHandle} to which a call should be handed over to.
150 * @hide
151 */
152 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
153 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
154
155 /**
156 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
157 * video state of the call when it is handed over to the new {@link PhoneAccount}.
158 * <p>
159 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
160 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
161 * {@link VideoProfile#STATE_TX_ENABLED}.
162 * @hide
163 */
164 public static final String EXTRA_HANDOVER_VIDEO_STATE =
165 "android.telecom.extra.HANDOVER_VIDEO_STATE";
166
167 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700168 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
169 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
170 * information to the handover {@link ConnectionService} specified by
171 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
172 * <p>
173 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
174 * {@link ConnectionService} via the request extras when
175 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
176 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700177 * @hide
178 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700179 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700180
181 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700182 * Call event sent from Telecom to the handover {@link ConnectionService} via
183 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
184 * to the {@link ConnectionService} has completed successfully.
185 * <p>
186 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700187 * @hide
188 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700189 public static final String EVENT_HANDOVER_COMPLETE =
190 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700191
192 /**
193 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
194 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
195 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
196 * {@code null}.
197 * <p>
198 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
199 * @hide
200 */
201 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
202 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
203
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700204 /**
205 * Call event sent from Telecom to the handover {@link ConnectionService} via
206 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
207 * to the {@link ConnectionService} has failed.
208 * <p>
209 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
210 * @hide
211 */
212 public static final String EVENT_HANDOVER_FAILED =
213 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700214
Ihab Awade63fadb2014-07-09 21:52:04 -0700215 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800216
217 /** Call can currently be put on hold or unheld. */
218 public static final int CAPABILITY_HOLD = 0x00000001;
219
220 /** Call supports the hold feature. */
221 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
222
223 /**
224 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
225 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
226 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
227 * capability allows a merge button to be shown while the conference call is in the foreground
228 * of the in-call UI.
229 * <p>
230 * This is only intended for use by a {@link Conference}.
231 */
232 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
233
234 /**
235 * Calls within a conference can be swapped between foreground and background.
236 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
237 * <p>
238 * This is only intended for use by a {@link Conference}.
239 */
240 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
241
242 /**
243 * @hide
244 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700245 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800246
247 /** Call supports responding via text option. */
248 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
249
250 /** Call can be muted. */
251 public static final int CAPABILITY_MUTE = 0x00000040;
252
253 /**
254 * Call supports conference call management. This capability only applies to {@link Conference}
255 * calls which can have {@link Connection}s as children.
256 */
257 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
258
259 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700260 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800261 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700262 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800263
264 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700265 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800266 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700267 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800268
269 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700270 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800271 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700272 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700273 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800274
275 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700276 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800277 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700278 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
279
280 /**
281 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700282 */
283 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
284
285 /**
286 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700287 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700288 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700289 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800290
291 /**
292 * Call is able to be separated from its parent {@code Conference}, if any.
293 */
294 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
295
296 /**
297 * Call is able to be individually disconnected when in a {@code Conference}.
298 */
299 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
300
301 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500302 * Speed up audio setup for MT call.
303 * @hide
304 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700305 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
306
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700307 /**
308 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700309 * @hide
310 */
311 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
312
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700313 /**
314 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700315 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700316 */
317 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
318
Bryce Lee81901682015-08-28 16:38:02 -0700319 /**
320 * Call sends responses through connection.
321 * @hide
322 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800323 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
324
325 /**
326 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
327 * <p>
328 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
329 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
330 * downgraded from a video call back to a VideoState of
331 * {@link VideoProfile#STATE_AUDIO_ONLY}.
332 * <p>
333 * Intuitively, a call which can be downgraded to audio should also have local and remote
334 * video
335 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
336 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
337 */
338 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700339
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700340 /**
341 * When set for an external call, indicates that this {@code Call} can be pulled from a
342 * remote device to the current device.
343 * <p>
344 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
345 * <p>
346 * An {@link InCallService} will only see calls with this capability if it has the
347 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
348 * in its manifest.
349 * <p>
350 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700351 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700352 */
353 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
354
Pooja Jaind34698d2017-12-28 14:15:31 +0530355 /** Call supports the deflect feature. */
356 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
357
Tyler Gunnd11a3152015-03-18 13:09:14 -0700358 //******************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530359 // Next CAPABILITY value: 0x02000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700360 //******************************************************************************************
361
362 /**
363 * Whether the call is currently a conference.
364 */
365 public static final int PROPERTY_CONFERENCE = 0x00000001;
366
367 /**
368 * Whether the call is a generic conference, where we do not know the precise state of
369 * participants in the conference (eg. on CDMA).
370 */
371 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
372
373 /**
374 * Whether the call is made while the device is in emergency callback mode.
375 */
376 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
377
378 /**
379 * Connection is using WIFI.
380 */
381 public static final int PROPERTY_WIFI = 0x00000008;
382
383 /**
384 * Call is using high definition audio.
385 */
386 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
387
Tony Maka68dcce2015-12-17 09:31:18 +0000388 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100389 * Whether the call is associated with the work profile.
390 */
391 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
392
393 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700394 * When set, indicates that this {@code Call} does not actually exist locally for the
395 * {@link ConnectionService}.
396 * <p>
397 * Consider, for example, a scenario where a user has two phones with the same phone number.
398 * When a user places a call on one device, the telephony stack can represent that call on
399 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700400 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700401 * <p>
402 * An {@link InCallService} will only see calls with this property if it has the
403 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
404 * in its manifest.
405 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700406 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700407 */
408 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
409
Brad Ebinger15847072016-05-18 11:08:36 -0700410 /**
411 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
412 */
413 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
414
Tyler Gunn24e18332017-02-10 09:42:49 -0800415 /**
416 * Indicates that the call is from a self-managed {@link ConnectionService}.
417 * <p>
418 * See also {@link Connection#PROPERTY_SELF_MANAGED}
419 */
420 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
421
Eric Erfanianec881872017-12-06 16:27:53 -0800422 /**
423 * Indicates the call used Assisted Dialing.
424 * See also {@link Connection#PROPERTY_ASSISTED_DIALING_USED}
Eric Erfanianec881872017-12-06 16:27:53 -0800425 */
426 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
427
Andrew Lee2378ea72015-04-29 14:38:11 -0700428 //******************************************************************************************
Eric Erfanianec881872017-12-06 16:27:53 -0800429 // Next PROPERTY value: 0x00000400
Tyler Gunnd11a3152015-03-18 13:09:14 -0700430 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800431
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800432 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700433 private final Uri mHandle;
434 private final int mHandlePresentation;
435 private final String mCallerDisplayName;
436 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700437 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700438 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700439 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800440 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700441 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700442 private final long mConnectTimeMillis;
443 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700444 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700445 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700446 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700447 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700448 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700449
450 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800451 * Whether the supplied capabilities supports the specified capability.
452 *
453 * @param capabilities A bit field of capabilities.
454 * @param capability The capability to check capabilities for.
455 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800456 */
457 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800458 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800459 }
460
461 /**
462 * Whether the capabilities of this {@code Details} supports the specified capability.
463 *
464 * @param capability The capability to check capabilities for.
465 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800466 */
467 public boolean can(int capability) {
468 return can(mCallCapabilities, capability);
469 }
470
471 /**
472 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
473 *
474 * @param capabilities A capability bit field.
475 * @return A human readable string representation.
476 */
477 public static String capabilitiesToString(int capabilities) {
478 StringBuilder builder = new StringBuilder();
479 builder.append("[Capabilities:");
480 if (can(capabilities, CAPABILITY_HOLD)) {
481 builder.append(" CAPABILITY_HOLD");
482 }
483 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
484 builder.append(" CAPABILITY_SUPPORT_HOLD");
485 }
486 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
487 builder.append(" CAPABILITY_MERGE_CONFERENCE");
488 }
489 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
490 builder.append(" CAPABILITY_SWAP_CONFERENCE");
491 }
492 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
493 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
494 }
495 if (can(capabilities, CAPABILITY_MUTE)) {
496 builder.append(" CAPABILITY_MUTE");
497 }
498 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
499 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
500 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700501 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
502 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
503 }
504 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
505 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
506 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700507 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
508 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800509 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700510 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
511 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
512 }
513 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
514 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
515 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800516 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
517 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
518 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700519 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
520 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800521 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500522 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700523 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500524 }
Rekha Kumar07366812015-03-24 16:42:31 -0700525 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
526 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
527 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700528 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
529 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
530 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700531 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
532 builder.append(" CAPABILITY_CAN_PULL_CALL");
533 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530534 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
535 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
536 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800537 builder.append("]");
538 return builder.toString();
539 }
540
541 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700542 * Whether the supplied properties includes the specified property.
543 *
544 * @param properties A bit field of properties.
545 * @param property The property to check properties for.
546 * @return Whether the specified property is supported.
547 */
548 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800549 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700550 }
551
552 /**
553 * Whether the properties of this {@code Details} includes the specified property.
554 *
555 * @param property The property to check properties for.
556 * @return Whether the specified property is supported.
557 */
558 public boolean hasProperty(int property) {
559 return hasProperty(mCallProperties, property);
560 }
561
562 /**
563 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
564 *
565 * @param properties A property bit field.
566 * @return A human readable string representation.
567 */
568 public static String propertiesToString(int properties) {
569 StringBuilder builder = new StringBuilder();
570 builder.append("[Properties:");
571 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
572 builder.append(" PROPERTY_CONFERENCE");
573 }
574 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
575 builder.append(" PROPERTY_GENERIC_CONFERENCE");
576 }
577 if (hasProperty(properties, PROPERTY_WIFI)) {
578 builder.append(" PROPERTY_WIFI");
579 }
580 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
581 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
582 }
583 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700584 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700585 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700586 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
587 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
588 }
Brad Ebinger15847072016-05-18 11:08:36 -0700589 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
590 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
591 }
Eric Erfanianec881872017-12-06 16:27:53 -0800592 if(hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
593 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
594 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700595 builder.append("]");
596 return builder.toString();
597 }
598
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800599 /** {@hide} */
600 public String getTelecomCallId() {
601 return mTelecomCallId;
602 }
603
Andrew Lee2378ea72015-04-29 14:38:11 -0700604 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700605 * @return The handle (e.g., phone number) to which the {@code Call} is currently
606 * connected.
607 */
608 public Uri getHandle() {
609 return mHandle;
610 }
611
612 /**
613 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700614 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700615 */
616 public int getHandlePresentation() {
617 return mHandlePresentation;
618 }
619
620 /**
621 * @return The display name for the caller.
622 */
623 public String getCallerDisplayName() {
624 return mCallerDisplayName;
625 }
626
627 /**
628 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700629 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700630 */
631 public int getCallerDisplayNamePresentation() {
632 return mCallerDisplayNamePresentation;
633 }
634
635 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700636 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
637 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700638 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700639 public PhoneAccountHandle getAccountHandle() {
640 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700641 }
642
643 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800644 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
645 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700646 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700647 public int getCallCapabilities() {
648 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700649 }
650
651 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700652 * @return A bitmask of the properties of the {@code Call}, as defined by the various
653 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700654 */
655 public int getCallProperties() {
656 return mCallProperties;
657 }
658
659 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800660 * @return a bitmask of the audio routes available for the call.
661 *
662 * @hide
663 */
664 public int getSupportedAudioRoutes() {
665 return mSupportedAudioRoutes;
666 }
667
668 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700669 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700670 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700671 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700672 public DisconnectCause getDisconnectCause() {
673 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700674 }
675
676 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700677 * Returns the time the {@link Call} connected (i.e. became active). This information is
678 * updated periodically, but user interfaces should not rely on this to display the "call
679 * time clock". For the time when the call was first added to Telecom, see
680 * {@link #getCreationTimeMillis()}.
681 *
682 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700683 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700684 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700685 return mConnectTimeMillis;
686 }
687
688 /**
689 * @return Information about any calling gateway the {@code Call} may be using.
690 */
691 public GatewayInfo getGatewayInfo() {
692 return mGatewayInfo;
693 }
694
Andrew Lee7a341382014-07-15 17:05:08 -0700695 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700696 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700697 */
698 public int getVideoState() {
699 return mVideoState;
700 }
701
Ihab Awad5d0410f2014-07-30 10:07:40 -0700702 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700703 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700704 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700705 */
706 public StatusHints getStatusHints() {
707 return mStatusHints;
708 }
709
Nancy Chen10798dc2014-08-08 14:00:25 -0700710 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700711 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700712 */
713 public Bundle getExtras() {
714 return mExtras;
715 }
716
Santos Cordon6b7f9552015-05-27 17:21:45 -0700717 /**
718 * @return The extras used with the original intent to place this call.
719 */
720 public Bundle getIntentExtras() {
721 return mIntentExtras;
722 }
723
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700724 /**
725 * Returns the time when the call was first created and added to Telecom. This is the same
726 * time that is logged as the start time in the Call Log (see
727 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
728 * (became active), see {@link #getConnectTimeMillis()}.
729 *
730 * @return The creation time of the call, in millis since the epoch.
731 */
732 public long getCreationTimeMillis() {
733 return mCreationTimeMillis;
734 }
735
Ihab Awade63fadb2014-07-09 21:52:04 -0700736 @Override
737 public boolean equals(Object o) {
738 if (o instanceof Details) {
739 Details d = (Details) o;
740 return
741 Objects.equals(mHandle, d.mHandle) &&
742 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
743 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
744 Objects.equals(mCallerDisplayNamePresentation,
745 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700746 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700747 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700748 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700749 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700750 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700751 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700752 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700753 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700754 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700755 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
756 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700757 }
758 return false;
759 }
760
761 @Override
762 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700763 return Objects.hash(mHandle,
764 mHandlePresentation,
765 mCallerDisplayName,
766 mCallerDisplayNamePresentation,
767 mAccountHandle,
768 mCallCapabilities,
769 mCallProperties,
770 mDisconnectCause,
771 mConnectTimeMillis,
772 mGatewayInfo,
773 mVideoState,
774 mStatusHints,
775 mExtras,
776 mIntentExtras,
777 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700778 }
779
780 /** {@hide} */
781 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800782 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700783 Uri handle,
784 int handlePresentation,
785 String callerDisplayName,
786 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700787 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700788 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700789 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700790 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700791 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700792 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700793 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700794 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700795 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700796 Bundle intentExtras,
797 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800798 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700799 mHandle = handle;
800 mHandlePresentation = handlePresentation;
801 mCallerDisplayName = callerDisplayName;
802 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700803 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700804 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700805 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700806 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700807 mConnectTimeMillis = connectTimeMillis;
808 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700809 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700810 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700811 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700812 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700813 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700814 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800815
816 /** {@hide} */
817 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
818 return new Details(
819 parcelableCall.getId(),
820 parcelableCall.getHandle(),
821 parcelableCall.getHandlePresentation(),
822 parcelableCall.getCallerDisplayName(),
823 parcelableCall.getCallerDisplayNamePresentation(),
824 parcelableCall.getAccountHandle(),
825 parcelableCall.getCapabilities(),
826 parcelableCall.getProperties(),
827 parcelableCall.getDisconnectCause(),
828 parcelableCall.getConnectTimeMillis(),
829 parcelableCall.getGatewayInfo(),
830 parcelableCall.getVideoState(),
831 parcelableCall.getStatusHints(),
832 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700833 parcelableCall.getIntentExtras(),
834 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800835 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800836
837 @Override
838 public String toString() {
839 StringBuilder sb = new StringBuilder();
840 sb.append("[pa: ");
841 sb.append(mAccountHandle);
842 sb.append(", hdl: ");
843 sb.append(Log.pii(mHandle));
844 sb.append(", caps: ");
845 sb.append(capabilitiesToString(mCallCapabilities));
846 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700847 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800848 sb.append("]");
849 return sb.toString();
850 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700851 }
852
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700853 /**
854 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
855 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
856 * implementation.
857 * <p>
858 * You can handle these callbacks by extending the {@link Callback} class and overriding the
859 * callbacks that your {@link InCallService} is interested in. The callback methods include the
860 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
861 * {@link Callback} implementation, if desired.
862 * <p>
863 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
864 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
865 * (typically in {@link InCallService#onCallRemoved(Call)}).
866 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
867 * reach your implementation of {@link Callback}, so it is important to register your callback
868 * as soon as your {@link InCallService} is notified of a new call via
869 * {@link InCallService#onCallAdded(Call)}.
870 */
Andrew Leeda80c872015-04-15 14:09:50 -0700871 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700872 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -0700873 * @hide
874 */
875 @IntDef({HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_DEST_NOT_SUPPORTED,
Sanket Padawe85291f62017-12-01 13:59:27 -0800876 HANDOVER_FAILURE_DEST_INVALID_PERM, HANDOVER_FAILURE_DEST_USER_REJECTED,
877 HANDOVER_FAILURE_ONGOING_EMERG_CALL})
Sanket Padawea8eddd42017-11-03 11:07:35 -0700878 @Retention(RetentionPolicy.SOURCE)
879 public @interface HandoverFailureErrors {}
880
881 /**
882 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
883 * to handover the call rejects handover.
884 */
885 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
886
887 /**
888 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there is
889 * an error associated with unsupported handover.
890 */
891 public static final int HANDOVER_FAILURE_DEST_NOT_SUPPORTED = 2;
892
893 /**
894 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
895 * are some permission errors associated with APIs doing handover.
896 */
897 public static final int HANDOVER_FAILURE_DEST_INVALID_PERM = 3;
898
899 /**
900 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when user
901 * rejects handover.
902 */
903 public static final int HANDOVER_FAILURE_DEST_USER_REJECTED = 4;
904
Sanket Padawe85291f62017-12-01 13:59:27 -0800905 /**
906 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
907 * is ongoing emergency call.
908 */
909 public static final int HANDOVER_FAILURE_ONGOING_EMERG_CALL = 5;
910
Sanket Padawea8eddd42017-11-03 11:07:35 -0700911
912 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700913 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
914 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700915 * @param call The {@code Call} invoking this method.
916 * @param state The new state of the {@code Call}.
917 */
918 public void onStateChanged(Call call, int state) {}
919
920 /**
921 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
922 *
923 * @param call The {@code Call} invoking this method.
924 * @param parent The new parent of the {@code Call}.
925 */
926 public void onParentChanged(Call call, Call parent) {}
927
928 /**
929 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
930 *
931 * @param call The {@code Call} invoking this method.
932 * @param children The new children of the {@code Call}.
933 */
934 public void onChildrenChanged(Call call, List<Call> children) {}
935
936 /**
937 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
938 *
939 * @param call The {@code Call} invoking this method.
940 * @param details A {@code Details} object describing the {@code Call}.
941 */
942 public void onDetailsChanged(Call call, Details details) {}
943
944 /**
945 * Invoked when the text messages that can be used as responses to the incoming
946 * {@code Call} are loaded from the relevant database.
947 * See {@link #getCannedTextResponses()}.
948 *
949 * @param call The {@code Call} invoking this method.
950 * @param cannedTextResponses The text messages useable as responses.
951 */
952 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
953
954 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700955 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
956 * character. This causes the post-dial signals to stop pending user confirmation. An
957 * implementation should present this choice to the user and invoke
958 * {@link #postDialContinue(boolean)} when the user makes the choice.
959 *
960 * @param call The {@code Call} invoking this method.
961 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
962 */
963 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
964
965 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700966 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700967 *
968 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700969 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700970 */
Andrew Lee50aca232014-07-22 16:41:54 -0700971 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700972
973 /**
974 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
975 * up their UI for the {@code Call} in response to state transitions. Specifically,
976 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
977 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
978 * clients should wait for this method to be invoked.
979 *
980 * @param call The {@code Call} being destroyed.
981 */
982 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700983
984 /**
985 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
986 * conferenced.
987 *
988 * @param call The {@code Call} being updated.
989 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
990 * conferenced.
991 */
992 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700993
994 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700995 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
996 * <p>
997 * Where possible, the Call should make an attempt to handle {@link Connection} events which
998 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
999 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1000 * possible that a {@link ConnectionService} has defined its own Connection events which a
1001 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001002 * <p>
1003 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
1004 *
1005 * @param call The {@code Call} receiving the event.
1006 * @param event The event.
1007 * @param extras Extras associated with the connection event.
1008 */
1009 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001010
1011 /**
1012 * Invoked when the RTT mode changes for this call.
1013 * @param call The call whose RTT mode has changed.
1014 * @param mode the new RTT mode, one of
1015 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1016 * or {@link RttCall#RTT_MODE_VCO}
1017 */
1018 public void onRttModeChanged(Call call, int mode) {}
1019
1020 /**
1021 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1022 * @param call The call whose RTT status has changed.
1023 * @param enabled whether RTT is now enabled or disabled
1024 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1025 * on, null otherwise.
1026 */
1027 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1028
1029 /**
1030 * Invoked when the remote end of the connection has requested that an RTT communication
1031 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1032 * with the same ID that this method is invoked with.
1033 * @param call The call which the RTT request was placed on
1034 * @param id The ID of the request.
1035 */
1036 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001037
1038 /**
1039 * Invoked when the RTT session failed to initiate for some reason, including rejection
1040 * by the remote party.
1041 * @param call The call which the RTT initiation failure occurred on.
1042 * @param reason One of the status codes defined in
1043 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1044 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1045 */
1046 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001047
1048 /**
1049 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1050 * has completed successfully.
1051 * @param call The call which had initiated handover.
1052 */
1053 public void onHandoverComplete(Call call) {}
1054
1055 /**
1056 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1057 * has failed.
1058 * @param call The call which had initiated handover.
1059 * @param failureReason Error reason for failure
1060 */
1061 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001062 }
1063
1064 /**
1065 * A class that holds the state that describes the state of the RTT channel to the remote
1066 * party, if it is active.
1067 */
1068 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001069 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001070 @Retention(RetentionPolicy.SOURCE)
1071 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1072 public @interface RttAudioMode {}
1073
1074 /**
1075 * For metrics use. Default value in the proto.
1076 * @hide
1077 */
1078 public static final int RTT_MODE_INVALID = 0;
1079
1080 /**
1081 * Indicates that there should be a bidirectional audio stream between the two parties
1082 * on the call.
1083 */
1084 public static final int RTT_MODE_FULL = 1;
1085
1086 /**
1087 * Indicates that the local user should be able to hear the audio stream from the remote
1088 * user, but not vice versa. Equivalent to muting the microphone.
1089 */
1090 public static final int RTT_MODE_HCO = 2;
1091
1092 /**
1093 * Indicates that the remote user should be able to hear the audio stream from the local
1094 * user, but not vice versa. Equivalent to setting the volume to zero.
1095 */
1096 public static final int RTT_MODE_VCO = 3;
1097
1098 private static final int READ_BUFFER_SIZE = 1000;
1099
1100 private InputStreamReader mReceiveStream;
1101 private OutputStreamWriter mTransmitStream;
1102 private int mRttMode;
1103 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001104 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001105 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1106
1107 /**
1108 * @hide
1109 */
Hall Liu57006aa2017-02-06 10:49:48 -08001110 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1111 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1112 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001113 mReceiveStream = receiveStream;
1114 mTransmitStream = transmitStream;
1115 mRttMode = mode;
1116 mInCallAdapter = inCallAdapter;
1117 }
1118
1119 /**
1120 * Returns the current RTT audio mode.
1121 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1122 * {@link #RTT_MODE_HCO}.
1123 */
1124 public int getRttAudioMode() {
1125 return mRttMode;
1126 }
1127
1128 /**
1129 * Sets the RTT audio mode. The requested mode change will be communicated through
1130 * {@link Callback#onRttModeChanged(Call, int)}.
1131 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1132 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1133 */
1134 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001135 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001136 }
1137
1138 /**
1139 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1140 * RTT transmits text in real-time, this method should be called once for each character
1141 * the user enters into the device.
1142 *
1143 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1144 * lead to interleaved text.
1145 * @param input The message to send to the remote user.
1146 */
1147 public void write(String input) throws IOException {
1148 mTransmitStream.write(input);
1149 mTransmitStream.flush();
1150 }
1151
1152 /**
1153 * Reads a string from the remote user, blocking if there is no data available. Returns
1154 * {@code null} if the RTT conversation has been terminated and there is no further data
1155 * to read.
1156 *
1157 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1158 * lead to interleaved text.
1159 * @return A string containing text sent by the remote user, or {@code null} if the
1160 * conversation has been terminated or if there was an error while reading.
1161 */
Hall Liub1c8a772017-07-17 17:04:41 -07001162 public String read() {
1163 try {
1164 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1165 if (numRead < 0) {
1166 return null;
1167 }
1168 return new String(mReadBuffer, 0, numRead);
1169 } catch (IOException e) {
1170 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001171 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001172 }
Hall Liuffa4a812017-03-02 16:11:00 -08001173 }
1174
1175 /**
1176 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1177 * be read.
1178 * @return A string containing text entered by the user, or {@code null} if the user has
1179 * not entered any new text yet.
1180 */
1181 public String readImmediately() throws IOException {
1182 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001183 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1184 if (numRead < 0) {
1185 return null;
1186 }
1187 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001188 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001189 return null;
1190 }
1191 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001192 }
1193
Andrew Leeda80c872015-04-15 14:09:50 -07001194 /**
1195 * @deprecated Use {@code Call.Callback} instead.
1196 * @hide
1197 */
1198 @Deprecated
1199 @SystemApi
1200 public static abstract class Listener extends Callback { }
1201
Ihab Awade63fadb2014-07-09 21:52:04 -07001202 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001203 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001204 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001205 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001206 private final List<Call> mChildren = new ArrayList<>();
1207 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001208 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001209 private final List<Call> mConferenceableCalls = new ArrayList<>();
1210 private final List<Call> mUnmodifiableConferenceableCalls =
1211 Collections.unmodifiableList(mConferenceableCalls);
1212
Santos Cordon823fd3c2014-08-07 18:35:18 -07001213 private boolean mChildrenCached;
1214 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001215 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001216 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001217 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001218 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001219 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001220 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001221 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001222 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001223 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001224
1225 /**
1226 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1227 *
1228 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1229 * remaining or this {@code Call} is not in a post-dial state.
1230 */
1231 public String getRemainingPostDialSequence() {
1232 return mRemainingPostDialSequence;
1233 }
1234
1235 /**
1236 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001237 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001238 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001239 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001240 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001241 }
1242
1243 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301244 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1245 *
1246 * @param address The address to which the call will be deflected.
1247 */
1248 public void deflect(Uri address) {
1249 mInCallAdapter.deflectCall(mTelecomCallId, address);
1250 }
1251
1252 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001253 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1254 *
1255 * @param rejectWithMessage Whether to reject with a text message.
1256 * @param textMessage An optional text message with which to respond.
1257 */
1258 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001259 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001260 }
1261
1262 /**
1263 * Instructs this {@code Call} to disconnect.
1264 */
1265 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001266 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001267 }
1268
1269 /**
1270 * Instructs this {@code Call} to go on hold.
1271 */
1272 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001273 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001274 }
1275
1276 /**
1277 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1278 */
1279 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001280 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001281 }
1282
1283 /**
1284 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1285 *
1286 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1287 *
1288 * @param digit A character representing the DTMF digit for which to play the tone. This
1289 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1290 */
1291 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001292 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001293 }
1294
1295 /**
1296 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1297 * currently playing.
1298 *
1299 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1300 * currently playing, this method will do nothing.
1301 */
1302 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001303 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001304 }
1305
1306 /**
1307 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1308 *
1309 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1310 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001311 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001312 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001313 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1314 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001315 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001316 * {@code Call} will pause playing the tones and notify callbacks via
1317 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001318 * should display to the user an indication of this state and an affordance to continue
1319 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1320 * app should invoke the {@link #postDialContinue(boolean)} method.
1321 *
1322 * @param proceed Whether or not to continue with the post-dial sequence.
1323 */
1324 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001325 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001326 }
1327
1328 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001329 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001330 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001331 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001332 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1333 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001334
1335 }
1336
1337 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001338 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001339 *
1340 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001341 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001342 public void conference(Call callToConferenceWith) {
1343 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001344 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001345 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001346 }
1347
1348 /**
1349 * Instructs this {@code Call} to split from any conference call with which it may be
1350 * connected.
1351 */
1352 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001353 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001354 }
1355
1356 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001357 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001358 */
1359 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001360 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001361 }
1362
1363 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001364 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001365 */
1366 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001367 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001368 }
1369
1370 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001371 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1372 * device.
1373 * <p>
1374 * Calls to this method are ignored if the call does not have the
1375 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1376 * <p>
1377 * An {@link InCallService} will only see calls which support this method if it has the
1378 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1379 * in its manifest.
1380 */
1381 public void pullExternalCall() {
1382 // If this isn't an external call, ignore the request.
1383 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1384 return;
1385 }
1386
1387 mInCallAdapter.pullExternalCall(mTelecomCallId);
1388 }
1389
1390 /**
1391 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1392 * the {@link ConnectionService}.
1393 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001394 * Call events are used to communicate point in time information from an {@link InCallService}
1395 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1396 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1397 * {@link ConnectionService}.
1398 * <p>
1399 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1400 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1401 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001402 * Events are exposed to {@link ConnectionService} implementations via
1403 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1404 * <p>
1405 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001406 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1407 * ignore some events altogether.
1408 * <p>
1409 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1410 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1411 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1412 * they define their own event types in this namespace. When defining a custom event type,
1413 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1414 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1415 * <p>
1416 * When defining events and the associated extras, it is important to keep their behavior
1417 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1418 * events/extras should me maintained to ensure backwards compatibility with older
1419 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001420 *
1421 * @param event The connection event.
1422 * @param extras Bundle containing extra information associated with the event.
1423 */
1424 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001425 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001426 }
1427
1428 /**
Hall Liu95d55872017-01-25 17:12:49 -08001429 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1430 * guaranteed, and notification of success will be via the
1431 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1432 */
1433 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001434 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001435 }
1436
1437 /**
1438 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1439 * callback.
1440 * The ID used here should be the same as the ID that was received via the callback.
1441 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1442 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1443 */
1444 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001445 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001446 }
1447
1448 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001449 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1450 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1451 * handover.
1452 * <p>
1453 * A handover request is initiated by the user from one app to indicate a desire
1454 * to handover a call to another.
1455 *
1456 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1457 * this call to.
1458 * @param videoState Indicates the video state desired after the handover.
1459 * @param extras Bundle containing extra information to be passed to the
1460 * {@link ConnectionService}
1461 */
1462 public void handoverTo(PhoneAccountHandle toHandle, int videoState, Bundle extras) {
1463 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1464 }
1465
1466 /**
Hall Liu95d55872017-01-25 17:12:49 -08001467 * Terminate the RTT session on this call. The resulting state change will be notified via
1468 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1469 */
1470 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001471 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001472 }
1473
1474 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001475 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1476 * added.
1477 * <p>
1478 * No assumptions should be made as to how an In-Call UI or service will handle these
1479 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1480 *
1481 * @param extras The extras to add.
1482 */
1483 public final void putExtras(Bundle extras) {
1484 if (extras == null) {
1485 return;
1486 }
1487
1488 if (mExtras == null) {
1489 mExtras = new Bundle();
1490 }
1491 mExtras.putAll(extras);
1492 mInCallAdapter.putExtras(mTelecomCallId, extras);
1493 }
1494
1495 /**
1496 * Adds a boolean extra to this {@link Call}.
1497 *
1498 * @param key The extra key.
1499 * @param value The value.
1500 * @hide
1501 */
1502 public final void putExtra(String key, boolean value) {
1503 if (mExtras == null) {
1504 mExtras = new Bundle();
1505 }
1506 mExtras.putBoolean(key, value);
1507 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1508 }
1509
1510 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001511 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001512 *
1513 * @param key The extra key.
1514 * @param value The value.
1515 * @hide
1516 */
1517 public final void putExtra(String key, int value) {
1518 if (mExtras == null) {
1519 mExtras = new Bundle();
1520 }
1521 mExtras.putInt(key, value);
1522 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1523 }
1524
1525 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001526 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001527 *
1528 * @param key The extra key.
1529 * @param value The value.
1530 * @hide
1531 */
1532 public final void putExtra(String key, String value) {
1533 if (mExtras == null) {
1534 mExtras = new Bundle();
1535 }
1536 mExtras.putString(key, value);
1537 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1538 }
1539
1540 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001541 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001542 *
1543 * @param keys The keys of the extras to remove.
1544 */
1545 public final void removeExtras(List<String> keys) {
1546 if (mExtras != null) {
1547 for (String key : keys) {
1548 mExtras.remove(key);
1549 }
1550 if (mExtras.size() == 0) {
1551 mExtras = null;
1552 }
1553 }
1554 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1555 }
1556
1557 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001558 * Removes extras from this {@link Call}.
1559 *
1560 * @param keys The keys of the extras to remove.
1561 */
1562 public final void removeExtras(String ... keys) {
1563 removeExtras(Arrays.asList(keys));
1564 }
1565
1566 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001567 * Obtains the parent of this {@code Call} in a conference, if any.
1568 *
1569 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1570 * child of any conference {@code Call}s.
1571 */
1572 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001573 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001574 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001575 }
1576 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001577 }
1578
1579 /**
1580 * Obtains the children of this conference {@code Call}, if any.
1581 *
1582 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1583 * {@code List} otherwise.
1584 */
1585 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001586 if (!mChildrenCached) {
1587 mChildrenCached = true;
1588 mChildren.clear();
1589
1590 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001591 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001592 if (call == null) {
1593 // At least one child was still not found, so do not save true for "cached"
1594 mChildrenCached = false;
1595 } else {
1596 mChildren.add(call);
1597 }
1598 }
1599 }
1600
Ihab Awade63fadb2014-07-09 21:52:04 -07001601 return mUnmodifiableChildren;
1602 }
1603
1604 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001605 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1606 *
1607 * @return The list of conferenceable {@code Call}s.
1608 */
1609 public List<Call> getConferenceableCalls() {
1610 return mUnmodifiableConferenceableCalls;
1611 }
1612
1613 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001614 * Obtains the state of this {@code Call}.
1615 *
1616 * @return A state value, chosen from the {@code STATE_*} constants.
1617 */
1618 public int getState() {
1619 return mState;
1620 }
1621
1622 /**
1623 * Obtains a list of canned, pre-configured message responses to present to the user as
1624 * ways of rejecting this {@code Call} using via a text message.
1625 *
1626 * @see #reject(boolean, String)
1627 *
1628 * @return A list of canned text message responses.
1629 */
1630 public List<String> getCannedTextResponses() {
1631 return mCannedTextResponses;
1632 }
1633
1634 /**
1635 * Obtains an object that can be used to display video from this {@code Call}.
1636 *
Andrew Lee50aca232014-07-22 16:41:54 -07001637 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001638 */
Andrew Lee50aca232014-07-22 16:41:54 -07001639 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001640 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001641 }
1642
1643 /**
1644 * Obtains an object containing call details.
1645 *
1646 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1647 * result may be {@code null}.
1648 */
1649 public Details getDetails() {
1650 return mDetails;
1651 }
1652
1653 /**
Hall Liu95d55872017-01-25 17:12:49 -08001654 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1655 * receive RTT text data, as well as to change the RTT mode.
1656 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1657 */
1658 public @Nullable RttCall getRttCall() {
1659 return mRttCall;
1660 }
1661
1662 /**
1663 * Returns whether this call has an active RTT connection.
1664 * @return true if there is a connection, false otherwise.
1665 */
1666 public boolean isRttActive() {
1667 return mRttCall != null;
1668 }
1669
1670 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001671 * Registers a callback to this {@code Call}.
1672 *
1673 * @param callback A {@code Callback}.
1674 */
1675 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001676 registerCallback(callback, new Handler());
1677 }
1678
1679 /**
1680 * Registers a callback to this {@code Call}.
1681 *
1682 * @param callback A {@code Callback}.
1683 * @param handler A handler which command and status changes will be delivered to.
1684 */
1685 public void registerCallback(Callback callback, Handler handler) {
1686 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001687 // Don't allow new callback registration if the call is already being destroyed.
1688 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001689 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1690 }
Andrew Leeda80c872015-04-15 14:09:50 -07001691 }
1692
1693 /**
1694 * Unregisters a callback from this {@code Call}.
1695 *
1696 * @param callback A {@code Callback}.
1697 */
1698 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001699 // Don't allow callback deregistration if the call is already being destroyed.
1700 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001701 for (CallbackRecord<Callback> record : mCallbackRecords) {
1702 if (record.getCallback() == callback) {
1703 mCallbackRecords.remove(record);
1704 break;
1705 }
1706 }
Andrew Leeda80c872015-04-15 14:09:50 -07001707 }
1708 }
1709
Santos Cordon3c20d632016-02-25 16:12:35 -08001710 @Override
1711 public String toString() {
1712 return new StringBuilder().
1713 append("Call [id: ").
1714 append(mTelecomCallId).
1715 append(", state: ").
1716 append(stateToString(mState)).
1717 append(", details: ").
1718 append(mDetails).
1719 append("]").toString();
1720 }
1721
1722 /**
1723 * @param state An integer value of a {@code STATE_*} constant.
1724 * @return A string representation of the value.
1725 */
1726 private static String stateToString(int state) {
1727 switch (state) {
1728 case STATE_NEW:
1729 return "NEW";
1730 case STATE_RINGING:
1731 return "RINGING";
1732 case STATE_DIALING:
1733 return "DIALING";
1734 case STATE_ACTIVE:
1735 return "ACTIVE";
1736 case STATE_HOLDING:
1737 return "HOLDING";
1738 case STATE_DISCONNECTED:
1739 return "DISCONNECTED";
1740 case STATE_CONNECTING:
1741 return "CONNECTING";
1742 case STATE_DISCONNECTING:
1743 return "DISCONNECTING";
1744 case STATE_SELECT_PHONE_ACCOUNT:
1745 return "SELECT_PHONE_ACCOUNT";
1746 default:
1747 Log.w(Call.class, "Unknown state %d", state);
1748 return "UNKNOWN";
1749 }
1750 }
1751
Andrew Leeda80c872015-04-15 14:09:50 -07001752 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001753 * Adds a listener to this {@code Call}.
1754 *
1755 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001756 * @deprecated Use {@link #registerCallback} instead.
1757 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001758 */
Andrew Leeda80c872015-04-15 14:09:50 -07001759 @Deprecated
1760 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001761 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001762 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001763 }
1764
1765 /**
1766 * Removes a listener from this {@code Call}.
1767 *
1768 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001769 * @deprecated Use {@link #unregisterCallback} instead.
1770 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001771 */
Andrew Leeda80c872015-04-15 14:09:50 -07001772 @Deprecated
1773 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001774 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001775 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001776 }
1777
1778 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001779 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1780 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001781 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001782 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001783 mInCallAdapter = inCallAdapter;
1784 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001785 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001786 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001787 }
1788
1789 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001790 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001791 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001792 mPhone = phone;
1793 mTelecomCallId = telecomCallId;
1794 mInCallAdapter = inCallAdapter;
1795 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001796 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001797 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001798 }
1799
1800 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001801 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001802 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001803 }
1804
1805 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001806 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001807
Ihab Awade63fadb2014-07-09 21:52:04 -07001808 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001809 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001810 boolean detailsChanged = !Objects.equals(mDetails, details);
1811 if (detailsChanged) {
1812 mDetails = details;
1813 }
1814
1815 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001816 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1817 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1818 mCannedTextResponses =
1819 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001820 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001821 }
1822
Tyler Gunn159f35c2017-03-02 09:28:37 -08001823 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1824 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001825 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001826 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001827 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001828 mVideoCallImpl = newVideoCallImpl;
1829 }
1830 if (mVideoCallImpl != null) {
1831 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001832 }
1833
Santos Cordone3c507b2015-04-23 14:44:19 -07001834 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001835 boolean stateChanged = mState != state;
1836 if (stateChanged) {
1837 mState = state;
1838 }
1839
Santos Cordon823fd3c2014-08-07 18:35:18 -07001840 String parentId = parcelableCall.getParentCallId();
1841 boolean parentChanged = !Objects.equals(mParentId, parentId);
1842 if (parentChanged) {
1843 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001844 }
1845
Santos Cordon823fd3c2014-08-07 18:35:18 -07001846 List<String> childCallIds = parcelableCall.getChildCallIds();
1847 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1848 if (childrenChanged) {
1849 mChildrenIds.clear();
1850 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1851 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001852 }
1853
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001854 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1855 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1856 for (String otherId : conferenceableCallIds) {
1857 if (callIdMap.containsKey(otherId)) {
1858 conferenceableCalls.add(callIdMap.get(otherId));
1859 }
1860 }
1861
1862 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1863 mConferenceableCalls.clear();
1864 mConferenceableCalls.addAll(conferenceableCalls);
1865 fireConferenceableCallsChanged();
1866 }
1867
Hall Liu95d55872017-01-25 17:12:49 -08001868 boolean isRttChanged = false;
1869 boolean rttModeChanged = false;
1870 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1871 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1872 InputStreamReader receiveStream = new InputStreamReader(
1873 new ParcelFileDescriptor.AutoCloseInputStream(
1874 parcelableRttCall.getReceiveStream()),
1875 StandardCharsets.UTF_8);
1876 OutputStreamWriter transmitStream = new OutputStreamWriter(
1877 new ParcelFileDescriptor.AutoCloseOutputStream(
1878 parcelableRttCall.getTransmitStream()),
1879 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08001880 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08001881 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1882 if (mRttCall == null) {
1883 isRttChanged = true;
1884 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1885 rttModeChanged = true;
1886 }
1887 mRttCall = newRttCall;
1888 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1889 && parcelableCall.getIsRttCallChanged()) {
1890 isRttChanged = true;
1891 mRttCall = null;
1892 }
1893
Ihab Awade63fadb2014-07-09 21:52:04 -07001894 // Now we fire updates, ensuring that any client who listens to any of these notifications
1895 // gets the most up-to-date state.
1896
1897 if (stateChanged) {
1898 fireStateChanged(mState);
1899 }
1900 if (detailsChanged) {
1901 fireDetailsChanged(mDetails);
1902 }
1903 if (cannedTextResponsesChanged) {
1904 fireCannedTextResponsesLoaded(mCannedTextResponses);
1905 }
Andrew Lee50aca232014-07-22 16:41:54 -07001906 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001907 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001908 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001909 if (parentChanged) {
1910 fireParentChanged(getParent());
1911 }
1912 if (childrenChanged) {
1913 fireChildrenChanged(getChildren());
1914 }
Hall Liu95d55872017-01-25 17:12:49 -08001915 if (isRttChanged) {
1916 fireOnIsRttChanged(mRttCall != null, mRttCall);
1917 }
1918 if (rttModeChanged) {
1919 fireOnRttModeChanged(mRttCall.getRttAudioMode());
1920 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001921
1922 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1923 // remove ourselves from the Phone. Note that we do this after completing all state updates
1924 // so a client can cleanly transition all their UI to the state appropriate for a
1925 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1926 if (mState == STATE_DISCONNECTED) {
1927 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001928 }
1929 }
1930
1931 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001932 final void internalSetPostDialWait(String remaining) {
1933 mRemainingPostDialSequence = remaining;
1934 firePostDialWait(mRemainingPostDialSequence);
1935 }
1936
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001937 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001938 final void internalSetDisconnected() {
1939 if (mState != Call.STATE_DISCONNECTED) {
1940 mState = Call.STATE_DISCONNECTED;
1941 fireStateChanged(mState);
1942 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001943 }
1944 }
1945
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001946 /** {@hide} */
1947 final void internalOnConnectionEvent(String event, Bundle extras) {
1948 fireOnConnectionEvent(event, extras);
1949 }
1950
Hall Liu95d55872017-01-25 17:12:49 -08001951 /** {@hide} */
1952 final void internalOnRttUpgradeRequest(final int requestId) {
1953 for (CallbackRecord<Callback> record : mCallbackRecords) {
1954 final Call call = this;
1955 final Callback callback = record.getCallback();
1956 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
1957 }
1958 }
1959
Hall Liu57006aa2017-02-06 10:49:48 -08001960 /** @hide */
1961 final void internalOnRttInitiationFailure(int reason) {
1962 for (CallbackRecord<Callback> record : mCallbackRecords) {
1963 final Call call = this;
1964 final Callback callback = record.getCallback();
1965 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
1966 }
1967 }
1968
Sanket Padawe85291f62017-12-01 13:59:27 -08001969 /** {@hide} */
1970 final void internalOnHandoverFailed(int error) {
1971 for (CallbackRecord<Callback> record : mCallbackRecords) {
1972 final Call call = this;
1973 final Callback callback = record.getCallback();
1974 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
1975 }
1976 }
1977
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001978 /** {@hide} */
1979 final void internalOnHandoverComplete() {
1980 for (CallbackRecord<Callback> record : mCallbackRecords) {
1981 final Call call = this;
1982 final Callback callback = record.getCallback();
1983 record.getHandler().post(() -> callback.onHandoverComplete(call));
1984 }
1985 }
1986
Andrew Lee011728f2015-04-23 15:47:06 -07001987 private void fireStateChanged(final int newState) {
1988 for (CallbackRecord<Callback> record : mCallbackRecords) {
1989 final Call call = this;
1990 final Callback callback = record.getCallback();
1991 record.getHandler().post(new Runnable() {
1992 @Override
1993 public void run() {
1994 callback.onStateChanged(call, newState);
1995 }
1996 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001997 }
1998 }
1999
Andrew Lee011728f2015-04-23 15:47:06 -07002000 private void fireParentChanged(final Call newParent) {
2001 for (CallbackRecord<Callback> record : mCallbackRecords) {
2002 final Call call = this;
2003 final Callback callback = record.getCallback();
2004 record.getHandler().post(new Runnable() {
2005 @Override
2006 public void run() {
2007 callback.onParentChanged(call, newParent);
2008 }
2009 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002010 }
2011 }
2012
Andrew Lee011728f2015-04-23 15:47:06 -07002013 private void fireChildrenChanged(final List<Call> children) {
2014 for (CallbackRecord<Callback> record : mCallbackRecords) {
2015 final Call call = this;
2016 final Callback callback = record.getCallback();
2017 record.getHandler().post(new Runnable() {
2018 @Override
2019 public void run() {
2020 callback.onChildrenChanged(call, children);
2021 }
2022 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002023 }
2024 }
2025
Andrew Lee011728f2015-04-23 15:47:06 -07002026 private void fireDetailsChanged(final Details details) {
2027 for (CallbackRecord<Callback> record : mCallbackRecords) {
2028 final Call call = this;
2029 final Callback callback = record.getCallback();
2030 record.getHandler().post(new Runnable() {
2031 @Override
2032 public void run() {
2033 callback.onDetailsChanged(call, details);
2034 }
2035 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002036 }
2037 }
2038
Andrew Lee011728f2015-04-23 15:47:06 -07002039 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2040 for (CallbackRecord<Callback> record : mCallbackRecords) {
2041 final Call call = this;
2042 final Callback callback = record.getCallback();
2043 record.getHandler().post(new Runnable() {
2044 @Override
2045 public void run() {
2046 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2047 }
2048 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002049 }
2050 }
2051
Andrew Lee011728f2015-04-23 15:47:06 -07002052 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2053 for (CallbackRecord<Callback> record : mCallbackRecords) {
2054 final Call call = this;
2055 final Callback callback = record.getCallback();
2056 record.getHandler().post(new Runnable() {
2057 @Override
2058 public void run() {
2059 callback.onVideoCallChanged(call, videoCall);
2060 }
2061 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002062 }
2063 }
2064
Andrew Lee011728f2015-04-23 15:47:06 -07002065 private void firePostDialWait(final String remainingPostDialSequence) {
2066 for (CallbackRecord<Callback> record : mCallbackRecords) {
2067 final Call call = this;
2068 final Callback callback = record.getCallback();
2069 record.getHandler().post(new Runnable() {
2070 @Override
2071 public void run() {
2072 callback.onPostDialWait(call, remainingPostDialSequence);
2073 }
2074 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002075 }
2076 }
2077
2078 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002079 /**
2080 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2081 * onCallRemoved callback, we remove this call from the Phone's record
2082 * only once all of the registered onCallDestroyed callbacks are executed.
2083 * All the callbacks get removed from our records as a part of this operation
2084 * since onCallDestroyed is the final callback.
2085 */
2086 final Call call = this;
2087 if (mCallbackRecords.isEmpty()) {
2088 // No callbacks registered, remove the call from Phone's record.
2089 mPhone.internalRemoveCall(call);
2090 }
2091 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002092 final Callback callback = record.getCallback();
2093 record.getHandler().post(new Runnable() {
2094 @Override
2095 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002096 boolean isFinalRemoval = false;
2097 RuntimeException toThrow = null;
2098 try {
2099 callback.onCallDestroyed(call);
2100 } catch (RuntimeException e) {
2101 toThrow = e;
2102 }
2103 synchronized(Call.this) {
2104 mCallbackRecords.remove(record);
2105 if (mCallbackRecords.isEmpty()) {
2106 isFinalRemoval = true;
2107 }
2108 }
2109 if (isFinalRemoval) {
2110 mPhone.internalRemoveCall(call);
2111 }
2112 if (toThrow != null) {
2113 throw toThrow;
2114 }
Andrew Lee011728f2015-04-23 15:47:06 -07002115 }
2116 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002117 }
2118 }
2119
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002120 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002121 for (CallbackRecord<Callback> record : mCallbackRecords) {
2122 final Call call = this;
2123 final Callback callback = record.getCallback();
2124 record.getHandler().post(new Runnable() {
2125 @Override
2126 public void run() {
2127 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2128 }
2129 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002130 }
2131 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002132
2133 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002134 * Notifies listeners of an incoming connection event.
2135 * <p>
2136 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2137 *
2138 * @param event
2139 * @param extras
2140 */
2141 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2142 for (CallbackRecord<Callback> record : mCallbackRecords) {
2143 final Call call = this;
2144 final Callback callback = record.getCallback();
2145 record.getHandler().post(new Runnable() {
2146 @Override
2147 public void run() {
2148 callback.onConnectionEvent(call, event, extras);
2149 }
2150 });
2151 }
2152 }
2153
2154 /**
Hall Liu95d55872017-01-25 17:12:49 -08002155 * Notifies listeners of an RTT on/off change
2156 *
2157 * @param enabled True if RTT is now enabled, false otherwise
2158 */
2159 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2160 for (CallbackRecord<Callback> record : mCallbackRecords) {
2161 final Call call = this;
2162 final Callback callback = record.getCallback();
2163 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2164 }
2165 }
2166
2167 /**
2168 * Notifies listeners of a RTT mode change
2169 *
2170 * @param mode The new RTT mode
2171 */
2172 private void fireOnRttModeChanged(final int mode) {
2173 for (CallbackRecord<Callback> record : mCallbackRecords) {
2174 final Call call = this;
2175 final Callback callback = record.getCallback();
2176 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2177 }
2178 }
2179
2180 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002181 * Determines if two bundles are equal.
2182 *
2183 * @param bundle The original bundle.
2184 * @param newBundle The bundle to compare with.
2185 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2186 */
2187 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2188 if (bundle == null || newBundle == null) {
2189 return bundle == newBundle;
2190 }
2191
2192 if (bundle.size() != newBundle.size()) {
2193 return false;
2194 }
2195
2196 for(String key : bundle.keySet()) {
2197 if (key != null) {
2198 final Object value = bundle.get(key);
2199 final Object newValue = newBundle.get(key);
2200 if (!Objects.equals(value, newValue)) {
2201 return false;
2202 }
2203 }
2204 }
2205 return true;
2206 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002207}