blob: 5cd2044f8318c4bc8cb346bb1dbb6ba688671b7a [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
Tyler Gunnd11a3152015-03-18 13:09:14 -0700355 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700356 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700357 //******************************************************************************************
358
359 /**
360 * Whether the call is currently a conference.
361 */
362 public static final int PROPERTY_CONFERENCE = 0x00000001;
363
364 /**
365 * Whether the call is a generic conference, where we do not know the precise state of
366 * participants in the conference (eg. on CDMA).
367 */
368 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
369
370 /**
371 * Whether the call is made while the device is in emergency callback mode.
372 */
373 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
374
375 /**
376 * Connection is using WIFI.
377 */
378 public static final int PROPERTY_WIFI = 0x00000008;
379
380 /**
381 * Call is using high definition audio.
382 */
383 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
384
Tony Maka68dcce2015-12-17 09:31:18 +0000385 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100386 * Whether the call is associated with the work profile.
387 */
388 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
389
390 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700391 * When set, indicates that this {@code Call} does not actually exist locally for the
392 * {@link ConnectionService}.
393 * <p>
394 * Consider, for example, a scenario where a user has two phones with the same phone number.
395 * When a user places a call on one device, the telephony stack can represent that call on
396 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700397 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700398 * <p>
399 * An {@link InCallService} will only see calls with this property if it has the
400 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
401 * in its manifest.
402 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700403 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700404 */
405 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
406
Brad Ebinger15847072016-05-18 11:08:36 -0700407 /**
408 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
409 */
410 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
411
Tyler Gunn24e18332017-02-10 09:42:49 -0800412 /**
413 * Indicates that the call is from a self-managed {@link ConnectionService}.
414 * <p>
415 * See also {@link Connection#PROPERTY_SELF_MANAGED}
416 */
417 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
418
Eric Erfanianec881872017-12-06 16:27:53 -0800419 /**
420 * Indicates the call used Assisted Dialing.
421 * See also {@link Connection#PROPERTY_ASSISTED_DIALING_USED}
422 * @hide
423 */
424 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
425
Andrew Lee2378ea72015-04-29 14:38:11 -0700426 //******************************************************************************************
Eric Erfanianec881872017-12-06 16:27:53 -0800427 // Next PROPERTY value: 0x00000400
Tyler Gunnd11a3152015-03-18 13:09:14 -0700428 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800429
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800430 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700431 private final Uri mHandle;
432 private final int mHandlePresentation;
433 private final String mCallerDisplayName;
434 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700435 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700436 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700437 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800438 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700439 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700440 private final long mConnectTimeMillis;
441 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700442 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700443 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700444 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700445 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700446 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700447
448 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800449 * Whether the supplied capabilities supports the specified capability.
450 *
451 * @param capabilities A bit field of capabilities.
452 * @param capability The capability to check capabilities for.
453 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800454 */
455 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800456 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800457 }
458
459 /**
460 * Whether the capabilities of this {@code Details} supports the specified capability.
461 *
462 * @param capability The capability to check capabilities for.
463 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800464 */
465 public boolean can(int capability) {
466 return can(mCallCapabilities, capability);
467 }
468
469 /**
470 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
471 *
472 * @param capabilities A capability bit field.
473 * @return A human readable string representation.
474 */
475 public static String capabilitiesToString(int capabilities) {
476 StringBuilder builder = new StringBuilder();
477 builder.append("[Capabilities:");
478 if (can(capabilities, CAPABILITY_HOLD)) {
479 builder.append(" CAPABILITY_HOLD");
480 }
481 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
482 builder.append(" CAPABILITY_SUPPORT_HOLD");
483 }
484 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
485 builder.append(" CAPABILITY_MERGE_CONFERENCE");
486 }
487 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
488 builder.append(" CAPABILITY_SWAP_CONFERENCE");
489 }
490 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
491 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
492 }
493 if (can(capabilities, CAPABILITY_MUTE)) {
494 builder.append(" CAPABILITY_MUTE");
495 }
496 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
497 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
498 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700499 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
500 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
501 }
502 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
503 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
504 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700505 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
506 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800507 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700508 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
509 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
510 }
511 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
512 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
513 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800514 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
515 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
516 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700517 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
518 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800519 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500520 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700521 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500522 }
Rekha Kumar07366812015-03-24 16:42:31 -0700523 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
524 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
525 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700526 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
527 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
528 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700529 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
530 builder.append(" CAPABILITY_CAN_PULL_CALL");
531 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800532 builder.append("]");
533 return builder.toString();
534 }
535
536 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700537 * Whether the supplied properties includes the specified property.
538 *
539 * @param properties A bit field of properties.
540 * @param property The property to check properties for.
541 * @return Whether the specified property is supported.
542 */
543 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800544 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700545 }
546
547 /**
548 * Whether the properties of this {@code Details} includes the specified property.
549 *
550 * @param property The property to check properties for.
551 * @return Whether the specified property is supported.
552 */
553 public boolean hasProperty(int property) {
554 return hasProperty(mCallProperties, property);
555 }
556
557 /**
558 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
559 *
560 * @param properties A property bit field.
561 * @return A human readable string representation.
562 */
563 public static String propertiesToString(int properties) {
564 StringBuilder builder = new StringBuilder();
565 builder.append("[Properties:");
566 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
567 builder.append(" PROPERTY_CONFERENCE");
568 }
569 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
570 builder.append(" PROPERTY_GENERIC_CONFERENCE");
571 }
572 if (hasProperty(properties, PROPERTY_WIFI)) {
573 builder.append(" PROPERTY_WIFI");
574 }
575 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
576 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
577 }
578 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700579 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700580 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700581 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
582 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
583 }
Brad Ebinger15847072016-05-18 11:08:36 -0700584 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
585 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
586 }
Eric Erfanianec881872017-12-06 16:27:53 -0800587 if(hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
588 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
589 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700590 builder.append("]");
591 return builder.toString();
592 }
593
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800594 /** {@hide} */
595 public String getTelecomCallId() {
596 return mTelecomCallId;
597 }
598
Andrew Lee2378ea72015-04-29 14:38:11 -0700599 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700600 * @return The handle (e.g., phone number) to which the {@code Call} is currently
601 * connected.
602 */
603 public Uri getHandle() {
604 return mHandle;
605 }
606
607 /**
608 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700609 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700610 */
611 public int getHandlePresentation() {
612 return mHandlePresentation;
613 }
614
615 /**
616 * @return The display name for the caller.
617 */
618 public String getCallerDisplayName() {
619 return mCallerDisplayName;
620 }
621
622 /**
623 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700624 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700625 */
626 public int getCallerDisplayNamePresentation() {
627 return mCallerDisplayNamePresentation;
628 }
629
630 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700631 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
632 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700633 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700634 public PhoneAccountHandle getAccountHandle() {
635 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700636 }
637
638 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800639 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
640 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700641 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700642 public int getCallCapabilities() {
643 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700644 }
645
646 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700647 * @return A bitmask of the properties of the {@code Call}, as defined by the various
648 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700649 */
650 public int getCallProperties() {
651 return mCallProperties;
652 }
653
654 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800655 * @return a bitmask of the audio routes available for the call.
656 *
657 * @hide
658 */
659 public int getSupportedAudioRoutes() {
660 return mSupportedAudioRoutes;
661 }
662
663 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700664 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700665 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700666 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700667 public DisconnectCause getDisconnectCause() {
668 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700669 }
670
671 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700672 * Returns the time the {@link Call} connected (i.e. became active). This information is
673 * updated periodically, but user interfaces should not rely on this to display the "call
674 * time clock". For the time when the call was first added to Telecom, see
675 * {@link #getCreationTimeMillis()}.
676 *
677 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700678 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700679 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700680 return mConnectTimeMillis;
681 }
682
683 /**
684 * @return Information about any calling gateway the {@code Call} may be using.
685 */
686 public GatewayInfo getGatewayInfo() {
687 return mGatewayInfo;
688 }
689
Andrew Lee7a341382014-07-15 17:05:08 -0700690 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700691 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700692 */
693 public int getVideoState() {
694 return mVideoState;
695 }
696
Ihab Awad5d0410f2014-07-30 10:07:40 -0700697 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700698 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700699 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700700 */
701 public StatusHints getStatusHints() {
702 return mStatusHints;
703 }
704
Nancy Chen10798dc2014-08-08 14:00:25 -0700705 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700706 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700707 */
708 public Bundle getExtras() {
709 return mExtras;
710 }
711
Santos Cordon6b7f9552015-05-27 17:21:45 -0700712 /**
713 * @return The extras used with the original intent to place this call.
714 */
715 public Bundle getIntentExtras() {
716 return mIntentExtras;
717 }
718
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700719 /**
720 * Returns the time when the call was first created and added to Telecom. This is the same
721 * time that is logged as the start time in the Call Log (see
722 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
723 * (became active), see {@link #getConnectTimeMillis()}.
724 *
725 * @return The creation time of the call, in millis since the epoch.
726 */
727 public long getCreationTimeMillis() {
728 return mCreationTimeMillis;
729 }
730
Ihab Awade63fadb2014-07-09 21:52:04 -0700731 @Override
732 public boolean equals(Object o) {
733 if (o instanceof Details) {
734 Details d = (Details) o;
735 return
736 Objects.equals(mHandle, d.mHandle) &&
737 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
738 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
739 Objects.equals(mCallerDisplayNamePresentation,
740 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700741 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700742 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700743 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700744 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700745 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700746 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700747 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700748 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700749 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700750 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
751 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700752 }
753 return false;
754 }
755
756 @Override
757 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700758 return Objects.hash(mHandle,
759 mHandlePresentation,
760 mCallerDisplayName,
761 mCallerDisplayNamePresentation,
762 mAccountHandle,
763 mCallCapabilities,
764 mCallProperties,
765 mDisconnectCause,
766 mConnectTimeMillis,
767 mGatewayInfo,
768 mVideoState,
769 mStatusHints,
770 mExtras,
771 mIntentExtras,
772 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700773 }
774
775 /** {@hide} */
776 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800777 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700778 Uri handle,
779 int handlePresentation,
780 String callerDisplayName,
781 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700782 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700783 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700784 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700785 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700786 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700787 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700788 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700789 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700790 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700791 Bundle intentExtras,
792 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800793 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700794 mHandle = handle;
795 mHandlePresentation = handlePresentation;
796 mCallerDisplayName = callerDisplayName;
797 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700798 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700799 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700800 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700801 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700802 mConnectTimeMillis = connectTimeMillis;
803 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700804 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700805 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700806 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700807 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700808 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700809 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800810
811 /** {@hide} */
812 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
813 return new Details(
814 parcelableCall.getId(),
815 parcelableCall.getHandle(),
816 parcelableCall.getHandlePresentation(),
817 parcelableCall.getCallerDisplayName(),
818 parcelableCall.getCallerDisplayNamePresentation(),
819 parcelableCall.getAccountHandle(),
820 parcelableCall.getCapabilities(),
821 parcelableCall.getProperties(),
822 parcelableCall.getDisconnectCause(),
823 parcelableCall.getConnectTimeMillis(),
824 parcelableCall.getGatewayInfo(),
825 parcelableCall.getVideoState(),
826 parcelableCall.getStatusHints(),
827 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700828 parcelableCall.getIntentExtras(),
829 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800830 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800831
832 @Override
833 public String toString() {
834 StringBuilder sb = new StringBuilder();
835 sb.append("[pa: ");
836 sb.append(mAccountHandle);
837 sb.append(", hdl: ");
838 sb.append(Log.pii(mHandle));
839 sb.append(", caps: ");
840 sb.append(capabilitiesToString(mCallCapabilities));
841 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700842 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800843 sb.append("]");
844 return sb.toString();
845 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700846 }
847
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700848 /**
849 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
850 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
851 * implementation.
852 * <p>
853 * You can handle these callbacks by extending the {@link Callback} class and overriding the
854 * callbacks that your {@link InCallService} is interested in. The callback methods include the
855 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
856 * {@link Callback} implementation, if desired.
857 * <p>
858 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
859 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
860 * (typically in {@link InCallService#onCallRemoved(Call)}).
861 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
862 * reach your implementation of {@link Callback}, so it is important to register your callback
863 * as soon as your {@link InCallService} is notified of a new call via
864 * {@link InCallService#onCallAdded(Call)}.
865 */
Andrew Leeda80c872015-04-15 14:09:50 -0700866 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700867 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -0700868 * @hide
869 */
870 @IntDef({HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_DEST_NOT_SUPPORTED,
871 HANDOVER_FAILURE_DEST_INVALID_PERM, HANDOVER_FAILURE_DEST_USER_REJECTED})
872 @Retention(RetentionPolicy.SOURCE)
873 public @interface HandoverFailureErrors {}
874
875 /**
876 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
877 * to handover the call rejects handover.
878 */
879 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
880
881 /**
882 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there is
883 * an error associated with unsupported handover.
884 */
885 public static final int HANDOVER_FAILURE_DEST_NOT_SUPPORTED = 2;
886
887 /**
888 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
889 * are some permission errors associated with APIs doing handover.
890 */
891 public static final int HANDOVER_FAILURE_DEST_INVALID_PERM = 3;
892
893 /**
894 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when user
895 * rejects handover.
896 */
897 public static final int HANDOVER_FAILURE_DEST_USER_REJECTED = 4;
898
899
900 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700901 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
902 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700903 * @param call The {@code Call} invoking this method.
904 * @param state The new state of the {@code Call}.
905 */
906 public void onStateChanged(Call call, int state) {}
907
908 /**
909 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
910 *
911 * @param call The {@code Call} invoking this method.
912 * @param parent The new parent of the {@code Call}.
913 */
914 public void onParentChanged(Call call, Call parent) {}
915
916 /**
917 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
918 *
919 * @param call The {@code Call} invoking this method.
920 * @param children The new children of the {@code Call}.
921 */
922 public void onChildrenChanged(Call call, List<Call> children) {}
923
924 /**
925 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
926 *
927 * @param call The {@code Call} invoking this method.
928 * @param details A {@code Details} object describing the {@code Call}.
929 */
930 public void onDetailsChanged(Call call, Details details) {}
931
932 /**
933 * Invoked when the text messages that can be used as responses to the incoming
934 * {@code Call} are loaded from the relevant database.
935 * See {@link #getCannedTextResponses()}.
936 *
937 * @param call The {@code Call} invoking this method.
938 * @param cannedTextResponses The text messages useable as responses.
939 */
940 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
941
942 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700943 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
944 * character. This causes the post-dial signals to stop pending user confirmation. An
945 * implementation should present this choice to the user and invoke
946 * {@link #postDialContinue(boolean)} when the user makes the choice.
947 *
948 * @param call The {@code Call} invoking this method.
949 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
950 */
951 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
952
953 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700954 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700955 *
956 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700957 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700958 */
Andrew Lee50aca232014-07-22 16:41:54 -0700959 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700960
961 /**
962 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
963 * up their UI for the {@code Call} in response to state transitions. Specifically,
964 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
965 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
966 * clients should wait for this method to be invoked.
967 *
968 * @param call The {@code Call} being destroyed.
969 */
970 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700971
972 /**
973 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
974 * conferenced.
975 *
976 * @param call The {@code Call} being updated.
977 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
978 * conferenced.
979 */
980 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700981
982 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700983 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
984 * <p>
985 * Where possible, the Call should make an attempt to handle {@link Connection} events which
986 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
987 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
988 * possible that a {@link ConnectionService} has defined its own Connection events which a
989 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700990 * <p>
991 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
992 *
993 * @param call The {@code Call} receiving the event.
994 * @param event The event.
995 * @param extras Extras associated with the connection event.
996 */
997 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -0800998
999 /**
1000 * Invoked when the RTT mode changes for this call.
1001 * @param call The call whose RTT mode has changed.
1002 * @param mode the new RTT mode, one of
1003 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1004 * or {@link RttCall#RTT_MODE_VCO}
1005 */
1006 public void onRttModeChanged(Call call, int mode) {}
1007
1008 /**
1009 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1010 * @param call The call whose RTT status has changed.
1011 * @param enabled whether RTT is now enabled or disabled
1012 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1013 * on, null otherwise.
1014 */
1015 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1016
1017 /**
1018 * Invoked when the remote end of the connection has requested that an RTT communication
1019 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1020 * with the same ID that this method is invoked with.
1021 * @param call The call which the RTT request was placed on
1022 * @param id The ID of the request.
1023 */
1024 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001025
1026 /**
1027 * Invoked when the RTT session failed to initiate for some reason, including rejection
1028 * by the remote party.
1029 * @param call The call which the RTT initiation failure occurred on.
1030 * @param reason One of the status codes defined in
1031 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1032 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1033 */
1034 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001035
1036 /**
1037 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1038 * has completed successfully.
1039 * @param call The call which had initiated handover.
1040 */
1041 public void onHandoverComplete(Call call) {}
1042
1043 /**
1044 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1045 * has failed.
1046 * @param call The call which had initiated handover.
1047 * @param failureReason Error reason for failure
1048 */
1049 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001050 }
1051
1052 /**
1053 * A class that holds the state that describes the state of the RTT channel to the remote
1054 * party, if it is active.
1055 */
1056 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001057 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001058 @Retention(RetentionPolicy.SOURCE)
1059 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1060 public @interface RttAudioMode {}
1061
1062 /**
1063 * For metrics use. Default value in the proto.
1064 * @hide
1065 */
1066 public static final int RTT_MODE_INVALID = 0;
1067
1068 /**
1069 * Indicates that there should be a bidirectional audio stream between the two parties
1070 * on the call.
1071 */
1072 public static final int RTT_MODE_FULL = 1;
1073
1074 /**
1075 * Indicates that the local user should be able to hear the audio stream from the remote
1076 * user, but not vice versa. Equivalent to muting the microphone.
1077 */
1078 public static final int RTT_MODE_HCO = 2;
1079
1080 /**
1081 * Indicates that the remote user should be able to hear the audio stream from the local
1082 * user, but not vice versa. Equivalent to setting the volume to zero.
1083 */
1084 public static final int RTT_MODE_VCO = 3;
1085
1086 private static final int READ_BUFFER_SIZE = 1000;
1087
1088 private InputStreamReader mReceiveStream;
1089 private OutputStreamWriter mTransmitStream;
1090 private int mRttMode;
1091 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001092 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001093 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1094
1095 /**
1096 * @hide
1097 */
Hall Liu57006aa2017-02-06 10:49:48 -08001098 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1099 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1100 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001101 mReceiveStream = receiveStream;
1102 mTransmitStream = transmitStream;
1103 mRttMode = mode;
1104 mInCallAdapter = inCallAdapter;
1105 }
1106
1107 /**
1108 * Returns the current RTT audio mode.
1109 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1110 * {@link #RTT_MODE_HCO}.
1111 */
1112 public int getRttAudioMode() {
1113 return mRttMode;
1114 }
1115
1116 /**
1117 * Sets the RTT audio mode. The requested mode change will be communicated through
1118 * {@link Callback#onRttModeChanged(Call, int)}.
1119 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1120 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1121 */
1122 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001123 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001124 }
1125
1126 /**
1127 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1128 * RTT transmits text in real-time, this method should be called once for each character
1129 * the user enters into the device.
1130 *
1131 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1132 * lead to interleaved text.
1133 * @param input The message to send to the remote user.
1134 */
1135 public void write(String input) throws IOException {
1136 mTransmitStream.write(input);
1137 mTransmitStream.flush();
1138 }
1139
1140 /**
1141 * Reads a string from the remote user, blocking if there is no data available. Returns
1142 * {@code null} if the RTT conversation has been terminated and there is no further data
1143 * to read.
1144 *
1145 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1146 * lead to interleaved text.
1147 * @return A string containing text sent by the remote user, or {@code null} if the
1148 * conversation has been terminated or if there was an error while reading.
1149 */
Hall Liub1c8a772017-07-17 17:04:41 -07001150 public String read() {
1151 try {
1152 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1153 if (numRead < 0) {
1154 return null;
1155 }
1156 return new String(mReadBuffer, 0, numRead);
1157 } catch (IOException e) {
1158 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001159 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001160 }
Hall Liuffa4a812017-03-02 16:11:00 -08001161 }
1162
1163 /**
1164 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1165 * be read.
1166 * @return A string containing text entered by the user, or {@code null} if the user has
1167 * not entered any new text yet.
1168 */
1169 public String readImmediately() throws IOException {
1170 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001171 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1172 if (numRead < 0) {
1173 return null;
1174 }
1175 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001176 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001177 return null;
1178 }
1179 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001180 }
1181
Andrew Leeda80c872015-04-15 14:09:50 -07001182 /**
1183 * @deprecated Use {@code Call.Callback} instead.
1184 * @hide
1185 */
1186 @Deprecated
1187 @SystemApi
1188 public static abstract class Listener extends Callback { }
1189
Ihab Awade63fadb2014-07-09 21:52:04 -07001190 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001191 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001192 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001193 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001194 private final List<Call> mChildren = new ArrayList<>();
1195 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001196 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001197 private final List<Call> mConferenceableCalls = new ArrayList<>();
1198 private final List<Call> mUnmodifiableConferenceableCalls =
1199 Collections.unmodifiableList(mConferenceableCalls);
1200
Santos Cordon823fd3c2014-08-07 18:35:18 -07001201 private boolean mChildrenCached;
1202 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001203 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001204 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001205 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001206 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001207 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001208 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001209 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001210 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001211 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001212
1213 /**
1214 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1215 *
1216 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1217 * remaining or this {@code Call} is not in a post-dial state.
1218 */
1219 public String getRemainingPostDialSequence() {
1220 return mRemainingPostDialSequence;
1221 }
1222
1223 /**
1224 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001225 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001226 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001227 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001228 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001229 }
1230
1231 /**
1232 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1233 *
1234 * @param rejectWithMessage Whether to reject with a text message.
1235 * @param textMessage An optional text message with which to respond.
1236 */
1237 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001238 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001239 }
1240
1241 /**
1242 * Instructs this {@code Call} to disconnect.
1243 */
1244 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001245 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001246 }
1247
1248 /**
1249 * Instructs this {@code Call} to go on hold.
1250 */
1251 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001252 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001253 }
1254
1255 /**
1256 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1257 */
1258 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001259 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001260 }
1261
1262 /**
1263 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1264 *
1265 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1266 *
1267 * @param digit A character representing the DTMF digit for which to play the tone. This
1268 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1269 */
1270 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001271 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001272 }
1273
1274 /**
1275 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1276 * currently playing.
1277 *
1278 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1279 * currently playing, this method will do nothing.
1280 */
1281 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001282 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001283 }
1284
1285 /**
1286 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1287 *
1288 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1289 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001290 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001291 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001292 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1293 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001294 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001295 * {@code Call} will pause playing the tones and notify callbacks via
1296 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001297 * should display to the user an indication of this state and an affordance to continue
1298 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1299 * app should invoke the {@link #postDialContinue(boolean)} method.
1300 *
1301 * @param proceed Whether or not to continue with the post-dial sequence.
1302 */
1303 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001304 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001305 }
1306
1307 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001308 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001309 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001310 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001311 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1312 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001313
1314 }
1315
1316 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001317 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001318 *
1319 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001320 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001321 public void conference(Call callToConferenceWith) {
1322 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001323 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001324 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001325 }
1326
1327 /**
1328 * Instructs this {@code Call} to split from any conference call with which it may be
1329 * connected.
1330 */
1331 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001332 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001333 }
1334
1335 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001336 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001337 */
1338 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001339 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001340 }
1341
1342 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001343 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001344 */
1345 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001346 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001347 }
1348
1349 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001350 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1351 * device.
1352 * <p>
1353 * Calls to this method are ignored if the call does not have the
1354 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1355 * <p>
1356 * An {@link InCallService} will only see calls which support this method if it has the
1357 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1358 * in its manifest.
1359 */
1360 public void pullExternalCall() {
1361 // If this isn't an external call, ignore the request.
1362 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1363 return;
1364 }
1365
1366 mInCallAdapter.pullExternalCall(mTelecomCallId);
1367 }
1368
1369 /**
1370 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1371 * the {@link ConnectionService}.
1372 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001373 * Call events are used to communicate point in time information from an {@link InCallService}
1374 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1375 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1376 * {@link ConnectionService}.
1377 * <p>
1378 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1379 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1380 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001381 * Events are exposed to {@link ConnectionService} implementations via
1382 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1383 * <p>
1384 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001385 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1386 * ignore some events altogether.
1387 * <p>
1388 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1389 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1390 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1391 * they define their own event types in this namespace. When defining a custom event type,
1392 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1393 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1394 * <p>
1395 * When defining events and the associated extras, it is important to keep their behavior
1396 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1397 * events/extras should me maintained to ensure backwards compatibility with older
1398 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001399 *
1400 * @param event The connection event.
1401 * @param extras Bundle containing extra information associated with the event.
1402 */
1403 public void sendCallEvent(String event, Bundle extras) {
1404 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1405 }
1406
1407 /**
Hall Liu95d55872017-01-25 17:12:49 -08001408 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1409 * guaranteed, and notification of success will be via the
1410 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1411 */
1412 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001413 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001414 }
1415
1416 /**
1417 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1418 * callback.
1419 * The ID used here should be the same as the ID that was received via the callback.
1420 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1421 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1422 */
1423 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001424 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001425 }
1426
1427 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001428 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1429 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1430 * handover.
1431 * <p>
1432 * A handover request is initiated by the user from one app to indicate a desire
1433 * to handover a call to another.
1434 *
1435 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1436 * this call to.
1437 * @param videoState Indicates the video state desired after the handover.
1438 * @param extras Bundle containing extra information to be passed to the
1439 * {@link ConnectionService}
1440 */
1441 public void handoverTo(PhoneAccountHandle toHandle, int videoState, Bundle extras) {
1442 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1443 }
1444
1445 /**
Hall Liu95d55872017-01-25 17:12:49 -08001446 * Terminate the RTT session on this call. The resulting state change will be notified via
1447 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1448 */
1449 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001450 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001451 }
1452
1453 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001454 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1455 * added.
1456 * <p>
1457 * No assumptions should be made as to how an In-Call UI or service will handle these
1458 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1459 *
1460 * @param extras The extras to add.
1461 */
1462 public final void putExtras(Bundle extras) {
1463 if (extras == null) {
1464 return;
1465 }
1466
1467 if (mExtras == null) {
1468 mExtras = new Bundle();
1469 }
1470 mExtras.putAll(extras);
1471 mInCallAdapter.putExtras(mTelecomCallId, extras);
1472 }
1473
1474 /**
1475 * Adds a boolean extra to this {@link Call}.
1476 *
1477 * @param key The extra key.
1478 * @param value The value.
1479 * @hide
1480 */
1481 public final void putExtra(String key, boolean value) {
1482 if (mExtras == null) {
1483 mExtras = new Bundle();
1484 }
1485 mExtras.putBoolean(key, value);
1486 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1487 }
1488
1489 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001490 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001491 *
1492 * @param key The extra key.
1493 * @param value The value.
1494 * @hide
1495 */
1496 public final void putExtra(String key, int value) {
1497 if (mExtras == null) {
1498 mExtras = new Bundle();
1499 }
1500 mExtras.putInt(key, value);
1501 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1502 }
1503
1504 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001505 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001506 *
1507 * @param key The extra key.
1508 * @param value The value.
1509 * @hide
1510 */
1511 public final void putExtra(String key, String value) {
1512 if (mExtras == null) {
1513 mExtras = new Bundle();
1514 }
1515 mExtras.putString(key, value);
1516 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1517 }
1518
1519 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001520 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001521 *
1522 * @param keys The keys of the extras to remove.
1523 */
1524 public final void removeExtras(List<String> keys) {
1525 if (mExtras != null) {
1526 for (String key : keys) {
1527 mExtras.remove(key);
1528 }
1529 if (mExtras.size() == 0) {
1530 mExtras = null;
1531 }
1532 }
1533 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1534 }
1535
1536 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001537 * Removes extras from this {@link Call}.
1538 *
1539 * @param keys The keys of the extras to remove.
1540 */
1541 public final void removeExtras(String ... keys) {
1542 removeExtras(Arrays.asList(keys));
1543 }
1544
1545 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001546 * Obtains the parent of this {@code Call} in a conference, if any.
1547 *
1548 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1549 * child of any conference {@code Call}s.
1550 */
1551 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001552 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001553 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001554 }
1555 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001556 }
1557
1558 /**
1559 * Obtains the children of this conference {@code Call}, if any.
1560 *
1561 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1562 * {@code List} otherwise.
1563 */
1564 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001565 if (!mChildrenCached) {
1566 mChildrenCached = true;
1567 mChildren.clear();
1568
1569 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001570 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001571 if (call == null) {
1572 // At least one child was still not found, so do not save true for "cached"
1573 mChildrenCached = false;
1574 } else {
1575 mChildren.add(call);
1576 }
1577 }
1578 }
1579
Ihab Awade63fadb2014-07-09 21:52:04 -07001580 return mUnmodifiableChildren;
1581 }
1582
1583 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001584 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1585 *
1586 * @return The list of conferenceable {@code Call}s.
1587 */
1588 public List<Call> getConferenceableCalls() {
1589 return mUnmodifiableConferenceableCalls;
1590 }
1591
1592 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001593 * Obtains the state of this {@code Call}.
1594 *
1595 * @return A state value, chosen from the {@code STATE_*} constants.
1596 */
1597 public int getState() {
1598 return mState;
1599 }
1600
1601 /**
1602 * Obtains a list of canned, pre-configured message responses to present to the user as
1603 * ways of rejecting this {@code Call} using via a text message.
1604 *
1605 * @see #reject(boolean, String)
1606 *
1607 * @return A list of canned text message responses.
1608 */
1609 public List<String> getCannedTextResponses() {
1610 return mCannedTextResponses;
1611 }
1612
1613 /**
1614 * Obtains an object that can be used to display video from this {@code Call}.
1615 *
Andrew Lee50aca232014-07-22 16:41:54 -07001616 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001617 */
Andrew Lee50aca232014-07-22 16:41:54 -07001618 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001619 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001620 }
1621
1622 /**
1623 * Obtains an object containing call details.
1624 *
1625 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1626 * result may be {@code null}.
1627 */
1628 public Details getDetails() {
1629 return mDetails;
1630 }
1631
1632 /**
Hall Liu95d55872017-01-25 17:12:49 -08001633 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1634 * receive RTT text data, as well as to change the RTT mode.
1635 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1636 */
1637 public @Nullable RttCall getRttCall() {
1638 return mRttCall;
1639 }
1640
1641 /**
1642 * Returns whether this call has an active RTT connection.
1643 * @return true if there is a connection, false otherwise.
1644 */
1645 public boolean isRttActive() {
1646 return mRttCall != null;
1647 }
1648
1649 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001650 * Registers a callback to this {@code Call}.
1651 *
1652 * @param callback A {@code Callback}.
1653 */
1654 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001655 registerCallback(callback, new Handler());
1656 }
1657
1658 /**
1659 * Registers a callback to this {@code Call}.
1660 *
1661 * @param callback A {@code Callback}.
1662 * @param handler A handler which command and status changes will be delivered to.
1663 */
1664 public void registerCallback(Callback callback, Handler handler) {
1665 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001666 // Don't allow new callback registration if the call is already being destroyed.
1667 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001668 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1669 }
Andrew Leeda80c872015-04-15 14:09:50 -07001670 }
1671
1672 /**
1673 * Unregisters a callback from this {@code Call}.
1674 *
1675 * @param callback A {@code Callback}.
1676 */
1677 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001678 // Don't allow callback deregistration if the call is already being destroyed.
1679 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001680 for (CallbackRecord<Callback> record : mCallbackRecords) {
1681 if (record.getCallback() == callback) {
1682 mCallbackRecords.remove(record);
1683 break;
1684 }
1685 }
Andrew Leeda80c872015-04-15 14:09:50 -07001686 }
1687 }
1688
Santos Cordon3c20d632016-02-25 16:12:35 -08001689 @Override
1690 public String toString() {
1691 return new StringBuilder().
1692 append("Call [id: ").
1693 append(mTelecomCallId).
1694 append(", state: ").
1695 append(stateToString(mState)).
1696 append(", details: ").
1697 append(mDetails).
1698 append("]").toString();
1699 }
1700
1701 /**
1702 * @param state An integer value of a {@code STATE_*} constant.
1703 * @return A string representation of the value.
1704 */
1705 private static String stateToString(int state) {
1706 switch (state) {
1707 case STATE_NEW:
1708 return "NEW";
1709 case STATE_RINGING:
1710 return "RINGING";
1711 case STATE_DIALING:
1712 return "DIALING";
1713 case STATE_ACTIVE:
1714 return "ACTIVE";
1715 case STATE_HOLDING:
1716 return "HOLDING";
1717 case STATE_DISCONNECTED:
1718 return "DISCONNECTED";
1719 case STATE_CONNECTING:
1720 return "CONNECTING";
1721 case STATE_DISCONNECTING:
1722 return "DISCONNECTING";
1723 case STATE_SELECT_PHONE_ACCOUNT:
1724 return "SELECT_PHONE_ACCOUNT";
1725 default:
1726 Log.w(Call.class, "Unknown state %d", state);
1727 return "UNKNOWN";
1728 }
1729 }
1730
Andrew Leeda80c872015-04-15 14:09:50 -07001731 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001732 * Adds a listener to this {@code Call}.
1733 *
1734 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001735 * @deprecated Use {@link #registerCallback} instead.
1736 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001737 */
Andrew Leeda80c872015-04-15 14:09:50 -07001738 @Deprecated
1739 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001740 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001741 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001742 }
1743
1744 /**
1745 * Removes a listener from this {@code Call}.
1746 *
1747 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001748 * @deprecated Use {@link #unregisterCallback} instead.
1749 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001750 */
Andrew Leeda80c872015-04-15 14:09:50 -07001751 @Deprecated
1752 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001753 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001754 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001755 }
1756
1757 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001758 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1759 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001760 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001761 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001762 mInCallAdapter = inCallAdapter;
1763 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001764 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001765 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001766 }
1767
1768 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001769 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001770 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001771 mPhone = phone;
1772 mTelecomCallId = telecomCallId;
1773 mInCallAdapter = inCallAdapter;
1774 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001775 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001776 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001777 }
1778
1779 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001780 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001781 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001782 }
1783
1784 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001785 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001786
Ihab Awade63fadb2014-07-09 21:52:04 -07001787 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001788 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001789 boolean detailsChanged = !Objects.equals(mDetails, details);
1790 if (detailsChanged) {
1791 mDetails = details;
1792 }
1793
1794 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001795 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1796 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1797 mCannedTextResponses =
1798 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001799 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001800 }
1801
Tyler Gunn159f35c2017-03-02 09:28:37 -08001802 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1803 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001804 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001805 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001806 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001807 mVideoCallImpl = newVideoCallImpl;
1808 }
1809 if (mVideoCallImpl != null) {
1810 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001811 }
1812
Santos Cordone3c507b2015-04-23 14:44:19 -07001813 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001814 boolean stateChanged = mState != state;
1815 if (stateChanged) {
1816 mState = state;
1817 }
1818
Santos Cordon823fd3c2014-08-07 18:35:18 -07001819 String parentId = parcelableCall.getParentCallId();
1820 boolean parentChanged = !Objects.equals(mParentId, parentId);
1821 if (parentChanged) {
1822 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001823 }
1824
Santos Cordon823fd3c2014-08-07 18:35:18 -07001825 List<String> childCallIds = parcelableCall.getChildCallIds();
1826 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1827 if (childrenChanged) {
1828 mChildrenIds.clear();
1829 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1830 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001831 }
1832
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001833 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1834 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1835 for (String otherId : conferenceableCallIds) {
1836 if (callIdMap.containsKey(otherId)) {
1837 conferenceableCalls.add(callIdMap.get(otherId));
1838 }
1839 }
1840
1841 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1842 mConferenceableCalls.clear();
1843 mConferenceableCalls.addAll(conferenceableCalls);
1844 fireConferenceableCallsChanged();
1845 }
1846
Hall Liu95d55872017-01-25 17:12:49 -08001847 boolean isRttChanged = false;
1848 boolean rttModeChanged = false;
1849 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1850 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1851 InputStreamReader receiveStream = new InputStreamReader(
1852 new ParcelFileDescriptor.AutoCloseInputStream(
1853 parcelableRttCall.getReceiveStream()),
1854 StandardCharsets.UTF_8);
1855 OutputStreamWriter transmitStream = new OutputStreamWriter(
1856 new ParcelFileDescriptor.AutoCloseOutputStream(
1857 parcelableRttCall.getTransmitStream()),
1858 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08001859 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08001860 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1861 if (mRttCall == null) {
1862 isRttChanged = true;
1863 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1864 rttModeChanged = true;
1865 }
1866 mRttCall = newRttCall;
1867 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1868 && parcelableCall.getIsRttCallChanged()) {
1869 isRttChanged = true;
1870 mRttCall = null;
1871 }
1872
Ihab Awade63fadb2014-07-09 21:52:04 -07001873 // Now we fire updates, ensuring that any client who listens to any of these notifications
1874 // gets the most up-to-date state.
1875
1876 if (stateChanged) {
1877 fireStateChanged(mState);
1878 }
1879 if (detailsChanged) {
1880 fireDetailsChanged(mDetails);
1881 }
1882 if (cannedTextResponsesChanged) {
1883 fireCannedTextResponsesLoaded(mCannedTextResponses);
1884 }
Andrew Lee50aca232014-07-22 16:41:54 -07001885 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001886 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001887 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001888 if (parentChanged) {
1889 fireParentChanged(getParent());
1890 }
1891 if (childrenChanged) {
1892 fireChildrenChanged(getChildren());
1893 }
Hall Liu95d55872017-01-25 17:12:49 -08001894 if (isRttChanged) {
1895 fireOnIsRttChanged(mRttCall != null, mRttCall);
1896 }
1897 if (rttModeChanged) {
1898 fireOnRttModeChanged(mRttCall.getRttAudioMode());
1899 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001900
1901 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1902 // remove ourselves from the Phone. Note that we do this after completing all state updates
1903 // so a client can cleanly transition all their UI to the state appropriate for a
1904 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1905 if (mState == STATE_DISCONNECTED) {
1906 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001907 }
1908 }
1909
1910 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001911 final void internalSetPostDialWait(String remaining) {
1912 mRemainingPostDialSequence = remaining;
1913 firePostDialWait(mRemainingPostDialSequence);
1914 }
1915
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001916 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001917 final void internalSetDisconnected() {
1918 if (mState != Call.STATE_DISCONNECTED) {
1919 mState = Call.STATE_DISCONNECTED;
1920 fireStateChanged(mState);
1921 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001922 }
1923 }
1924
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001925 /** {@hide} */
1926 final void internalOnConnectionEvent(String event, Bundle extras) {
1927 fireOnConnectionEvent(event, extras);
1928 }
1929
Hall Liu95d55872017-01-25 17:12:49 -08001930 /** {@hide} */
1931 final void internalOnRttUpgradeRequest(final int requestId) {
1932 for (CallbackRecord<Callback> record : mCallbackRecords) {
1933 final Call call = this;
1934 final Callback callback = record.getCallback();
1935 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
1936 }
1937 }
1938
Hall Liu57006aa2017-02-06 10:49:48 -08001939 /** @hide */
1940 final void internalOnRttInitiationFailure(int reason) {
1941 for (CallbackRecord<Callback> record : mCallbackRecords) {
1942 final Call call = this;
1943 final Callback callback = record.getCallback();
1944 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
1945 }
1946 }
1947
Andrew Lee011728f2015-04-23 15:47:06 -07001948 private void fireStateChanged(final int newState) {
1949 for (CallbackRecord<Callback> record : mCallbackRecords) {
1950 final Call call = this;
1951 final Callback callback = record.getCallback();
1952 record.getHandler().post(new Runnable() {
1953 @Override
1954 public void run() {
1955 callback.onStateChanged(call, newState);
1956 }
1957 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001958 }
1959 }
1960
Andrew Lee011728f2015-04-23 15:47:06 -07001961 private void fireParentChanged(final Call newParent) {
1962 for (CallbackRecord<Callback> record : mCallbackRecords) {
1963 final Call call = this;
1964 final Callback callback = record.getCallback();
1965 record.getHandler().post(new Runnable() {
1966 @Override
1967 public void run() {
1968 callback.onParentChanged(call, newParent);
1969 }
1970 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001971 }
1972 }
1973
Andrew Lee011728f2015-04-23 15:47:06 -07001974 private void fireChildrenChanged(final List<Call> children) {
1975 for (CallbackRecord<Callback> record : mCallbackRecords) {
1976 final Call call = this;
1977 final Callback callback = record.getCallback();
1978 record.getHandler().post(new Runnable() {
1979 @Override
1980 public void run() {
1981 callback.onChildrenChanged(call, children);
1982 }
1983 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001984 }
1985 }
1986
Andrew Lee011728f2015-04-23 15:47:06 -07001987 private void fireDetailsChanged(final Details details) {
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.onDetailsChanged(call, details);
1995 }
1996 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001997 }
1998 }
1999
Andrew Lee011728f2015-04-23 15:47:06 -07002000 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
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.onCannedTextResponsesLoaded(call, cannedTextResponses);
2008 }
2009 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002010 }
2011 }
2012
Andrew Lee011728f2015-04-23 15:47:06 -07002013 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
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.onVideoCallChanged(call, videoCall);
2021 }
2022 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002023 }
2024 }
2025
Andrew Lee011728f2015-04-23 15:47:06 -07002026 private void firePostDialWait(final String remainingPostDialSequence) {
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.onPostDialWait(call, remainingPostDialSequence);
2034 }
2035 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002036 }
2037 }
2038
2039 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002040 /**
2041 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2042 * onCallRemoved callback, we remove this call from the Phone's record
2043 * only once all of the registered onCallDestroyed callbacks are executed.
2044 * All the callbacks get removed from our records as a part of this operation
2045 * since onCallDestroyed is the final callback.
2046 */
2047 final Call call = this;
2048 if (mCallbackRecords.isEmpty()) {
2049 // No callbacks registered, remove the call from Phone's record.
2050 mPhone.internalRemoveCall(call);
2051 }
2052 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002053 final Callback callback = record.getCallback();
2054 record.getHandler().post(new Runnable() {
2055 @Override
2056 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002057 boolean isFinalRemoval = false;
2058 RuntimeException toThrow = null;
2059 try {
2060 callback.onCallDestroyed(call);
2061 } catch (RuntimeException e) {
2062 toThrow = e;
2063 }
2064 synchronized(Call.this) {
2065 mCallbackRecords.remove(record);
2066 if (mCallbackRecords.isEmpty()) {
2067 isFinalRemoval = true;
2068 }
2069 }
2070 if (isFinalRemoval) {
2071 mPhone.internalRemoveCall(call);
2072 }
2073 if (toThrow != null) {
2074 throw toThrow;
2075 }
Andrew Lee011728f2015-04-23 15:47:06 -07002076 }
2077 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002078 }
2079 }
2080
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002081 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002082 for (CallbackRecord<Callback> record : mCallbackRecords) {
2083 final Call call = this;
2084 final Callback callback = record.getCallback();
2085 record.getHandler().post(new Runnable() {
2086 @Override
2087 public void run() {
2088 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2089 }
2090 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002091 }
2092 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002093
2094 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002095 * Notifies listeners of an incoming connection event.
2096 * <p>
2097 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2098 *
2099 * @param event
2100 * @param extras
2101 */
2102 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2103 for (CallbackRecord<Callback> record : mCallbackRecords) {
2104 final Call call = this;
2105 final Callback callback = record.getCallback();
2106 record.getHandler().post(new Runnable() {
2107 @Override
2108 public void run() {
2109 callback.onConnectionEvent(call, event, extras);
2110 }
2111 });
2112 }
2113 }
2114
2115 /**
Hall Liu95d55872017-01-25 17:12:49 -08002116 * Notifies listeners of an RTT on/off change
2117 *
2118 * @param enabled True if RTT is now enabled, false otherwise
2119 */
2120 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2121 for (CallbackRecord<Callback> record : mCallbackRecords) {
2122 final Call call = this;
2123 final Callback callback = record.getCallback();
2124 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2125 }
2126 }
2127
2128 /**
2129 * Notifies listeners of a RTT mode change
2130 *
2131 * @param mode The new RTT mode
2132 */
2133 private void fireOnRttModeChanged(final int mode) {
2134 for (CallbackRecord<Callback> record : mCallbackRecords) {
2135 final Call call = this;
2136 final Callback callback = record.getCallback();
2137 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2138 }
2139 }
2140
2141 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002142 * Determines if two bundles are equal.
2143 *
2144 * @param bundle The original bundle.
2145 * @param newBundle The bundle to compare with.
2146 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2147 */
2148 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2149 if (bundle == null || newBundle == null) {
2150 return bundle == newBundle;
2151 }
2152
2153 if (bundle.size() != newBundle.size()) {
2154 return false;
2155 }
2156
2157 for(String key : bundle.keySet()) {
2158 if (key != null) {
2159 final Object value = bundle.get(key);
2160 final Object newValue = newBundle.get(key);
2161 if (!Objects.equals(value, newValue)) {
2162 return false;
2163 }
2164 }
2165 }
2166 return true;
2167 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002168}