blob: e82bd9902268761dacf983e1680dab744500867a [file] [log] [blame]
Ihab Awade63fadb2014-07-09 21:52:04 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awade63fadb2014-07-09 21:52:04 -070018
Hall Liu95d55872017-01-25 17:12:49 -080019import android.annotation.IntDef;
20import android.annotation.Nullable;
Andrew Leeda80c872015-04-15 14:09:50 -070021import android.annotation.SystemApi;
Ihab Awade63fadb2014-07-09 21:52:04 -070022import android.net.Uri;
Nancy Chen10798dc2014-08-08 14:00:25 -070023import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070024import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080025import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070026
Hall Liu95d55872017-01-25 17:12:49 -080027import java.io.IOException;
28import java.io.InputStreamReader;
29import java.io.OutputStreamWriter;
Andrew Lee50aca232014-07-22 16:41:54 -070030import java.lang.String;
Hall Liu95d55872017-01-25 17:12:49 -080031import java.lang.annotation.Retention;
32import java.lang.annotation.RetentionPolicy;
33import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070034import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070035import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070036import java.util.Collections;
37import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070038import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070039import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070040import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070041
42/**
43 * Represents an ongoing phone call that the in-call app should present to the user.
44 */
45public final class Call {
46 /**
47 * The state of a {@code Call} when newly created.
48 */
49 public static final int STATE_NEW = 0;
50
51 /**
52 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
53 */
54 public static final int STATE_DIALING = 1;
55
56 /**
57 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
58 */
59 public static final int STATE_RINGING = 2;
60
61 /**
62 * The state of a {@code Call} when in a holding state.
63 */
64 public static final int STATE_HOLDING = 3;
65
66 /**
67 * The state of a {@code Call} when actively supporting conversation.
68 */
69 public static final int STATE_ACTIVE = 4;
70
71 /**
72 * The state of a {@code Call} when no further voice or other communication is being
73 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
74 * is no longer active, and the local data transport has or inevitably will release resources
75 * associated with this {@code Call}.
76 */
77 public static final int STATE_DISCONNECTED = 7;
78
Nancy Chen5da0fd52014-07-08 14:16:17 -070079 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070080 * The state of an outgoing {@code Call} when waiting on user to select a
81 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070082 */
Santos Cordone3c507b2015-04-23 14:44:19 -070083 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
84
85 /**
86 * @hide
87 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
88 */
89 @Deprecated
90 @SystemApi
91 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070092
Nancy Chene20930f2014-08-07 16:17:21 -070093 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070094 * The initial state of an outgoing {@code Call}.
95 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
96 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070097 */
98 public static final int STATE_CONNECTING = 9;
99
Nancy Chen513c8922014-09-17 14:47:20 -0700100 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700101 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
102 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
103 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
104 */
105 public static final int STATE_DISCONNECTING = 10;
106
107 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700108 * The state of an external call which is in the process of being pulled from a remote device to
109 * the local device.
110 * <p>
111 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
112 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
113 * <p>
114 * An {@link InCallService} will only see this state if it has the
115 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
116 * manifest.
117 */
118 public static final int STATE_PULLING_CALL = 11;
119
120 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700121 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
122 * extras. Used to pass the phone accounts to display on the front end to the user in order to
123 * select phone accounts to (for example) place a call.
Nancy Chen513c8922014-09-17 14:47:20 -0700124 */
125 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
126
mike dooley4af561f2016-12-20 08:55:17 -0800127 /**
mike dooley91217422017-03-09 12:58:42 -0800128 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
129 * when the last outgoing emergency call was made. This is used to identify potential emergency
130 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800131 */
132 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
133 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
134
Tyler Gunn8bf76572017-04-06 15:30:08 -0700135 /**
136 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
137 * Telecom that the user has requested that the current {@link Call} should be handed over
138 * to another {@link ConnectionService}.
139 * <p>
140 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
141 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
142 * @hide
143 */
144 public static final String EVENT_REQUEST_HANDOVER =
145 "android.telecom.event.REQUEST_HANDOVER";
146
147 /**
148 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
149 * {@link PhoneAccountHandle} to which a call should be handed over to.
150 * @hide
151 */
152 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
153 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
154
155 /**
156 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
157 * video state of the call when it is handed over to the new {@link PhoneAccount}.
158 * <p>
159 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
160 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
161 * {@link VideoProfile#STATE_TX_ENABLED}.
162 * @hide
163 */
164 public static final String EXTRA_HANDOVER_VIDEO_STATE =
165 "android.telecom.extra.HANDOVER_VIDEO_STATE";
166
167 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700168 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
169 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
170 * information to the handover {@link ConnectionService} specified by
171 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
172 * <p>
173 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
174 * {@link ConnectionService} via the request extras when
175 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
176 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700177 * @hide
178 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700179 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700180
181 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700182 * Call event sent from Telecom to the handover {@link ConnectionService} via
183 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
184 * to the {@link ConnectionService} has completed successfully.
185 * <p>
186 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700187 * @hide
188 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700189 public static final String EVENT_HANDOVER_COMPLETE =
190 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700191
192 /**
193 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
194 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
195 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
196 * {@code null}.
197 * <p>
198 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
199 * @hide
200 */
201 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
202 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
203
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700204 /**
205 * Call event sent from Telecom to the handover {@link ConnectionService} via
206 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
207 * to the {@link ConnectionService} has failed.
208 * <p>
209 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
210 * @hide
211 */
212 public static final String EVENT_HANDOVER_FAILED =
213 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700214
Ihab Awade63fadb2014-07-09 21:52:04 -0700215 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800216
217 /** Call can currently be put on hold or unheld. */
218 public static final int CAPABILITY_HOLD = 0x00000001;
219
220 /** Call supports the hold feature. */
221 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
222
223 /**
224 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
225 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
226 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
227 * capability allows a merge button to be shown while the conference call is in the foreground
228 * of the in-call UI.
229 * <p>
230 * This is only intended for use by a {@link Conference}.
231 */
232 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
233
234 /**
235 * Calls within a conference can be swapped between foreground and background.
236 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
237 * <p>
238 * This is only intended for use by a {@link Conference}.
239 */
240 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
241
242 /**
243 * @hide
244 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700245 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800246
247 /** Call supports responding via text option. */
248 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
249
250 /** Call can be muted. */
251 public static final int CAPABILITY_MUTE = 0x00000040;
252
253 /**
254 * Call supports conference call management. This capability only applies to {@link Conference}
255 * calls which can have {@link Connection}s as children.
256 */
257 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
258
259 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700260 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800261 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700262 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800263
264 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700265 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800266 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700267 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800268
269 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700270 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800271 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700272 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700273 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800274
275 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700276 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800277 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700278 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
279
280 /**
281 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700282 */
283 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
284
285 /**
286 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700287 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700288 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700289 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800290
291 /**
292 * Call is able to be separated from its parent {@code Conference}, if any.
293 */
294 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
295
296 /**
297 * Call is able to be individually disconnected when in a {@code Conference}.
298 */
299 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
300
301 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500302 * Speed up audio setup for MT call.
303 * @hide
304 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700305 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
306
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700307 /**
308 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700309 * @hide
310 */
311 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
312
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700313 /**
314 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700315 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700316 */
317 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
318
Bryce Lee81901682015-08-28 16:38:02 -0700319 /**
320 * Call sends responses through connection.
321 * @hide
322 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800323 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
324
325 /**
326 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
327 * <p>
328 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
329 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
330 * downgraded from a video call back to a VideoState of
331 * {@link VideoProfile#STATE_AUDIO_ONLY}.
332 * <p>
333 * Intuitively, a call which can be downgraded to audio should also have local and remote
334 * video
335 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
336 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
337 */
338 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700339
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700340 /**
341 * When set for an external call, indicates that this {@code Call} can be pulled from a
342 * remote device to the current device.
343 * <p>
344 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
345 * <p>
346 * An {@link InCallService} will only see calls with this capability if it has the
347 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
348 * in its manifest.
349 * <p>
350 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700351 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700352 */
353 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
354
Pooja Jaind34698d2017-12-28 14:15:31 +0530355 /** Call supports the deflect feature. */
356 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
357
Tyler Gunnd11a3152015-03-18 13:09:14 -0700358 //******************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530359 // Next CAPABILITY value: 0x02000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700360 //******************************************************************************************
361
362 /**
363 * Whether the call is currently a conference.
364 */
365 public static final int PROPERTY_CONFERENCE = 0x00000001;
366
367 /**
368 * Whether the call is a generic conference, where we do not know the precise state of
369 * participants in the conference (eg. on CDMA).
370 */
371 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
372
373 /**
374 * Whether the call is made while the device is in emergency callback mode.
375 */
376 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
377
378 /**
379 * Connection is using WIFI.
380 */
381 public static final int PROPERTY_WIFI = 0x00000008;
382
383 /**
384 * Call is using high definition audio.
385 */
386 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
387
Tony Maka68dcce2015-12-17 09:31:18 +0000388 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100389 * Whether the call is associated with the work profile.
390 */
391 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
392
393 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700394 * When set, indicates that this {@code Call} does not actually exist locally for the
395 * {@link ConnectionService}.
396 * <p>
397 * Consider, for example, a scenario where a user has two phones with the same phone number.
398 * When a user places a call on one device, the telephony stack can represent that call on
399 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700400 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700401 * <p>
402 * An {@link InCallService} will only see calls with this property if it has the
403 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
404 * in its manifest.
405 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700406 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700407 */
408 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
409
Brad Ebinger15847072016-05-18 11:08:36 -0700410 /**
411 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
412 */
413 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
414
Tyler Gunn24e18332017-02-10 09:42:49 -0800415 /**
416 * Indicates that the call is from a self-managed {@link ConnectionService}.
417 * <p>
418 * See also {@link Connection#PROPERTY_SELF_MANAGED}
419 */
420 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
421
Eric Erfanianec881872017-12-06 16:27:53 -0800422 /**
423 * Indicates the call used Assisted Dialing.
424 * See also {@link Connection#PROPERTY_ASSISTED_DIALING_USED}
425 * @hide
426 */
427 public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200;
428
Andrew Lee2378ea72015-04-29 14:38:11 -0700429 //******************************************************************************************
Eric Erfanianec881872017-12-06 16:27:53 -0800430 // Next PROPERTY value: 0x00000400
Tyler Gunnd11a3152015-03-18 13:09:14 -0700431 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800432
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800433 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700434 private final Uri mHandle;
435 private final int mHandlePresentation;
436 private final String mCallerDisplayName;
437 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700438 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700439 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700440 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800441 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700442 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700443 private final long mConnectTimeMillis;
444 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700445 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700446 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700447 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700448 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700449 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700450
451 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800452 * Whether the supplied capabilities supports the specified capability.
453 *
454 * @param capabilities A bit field of capabilities.
455 * @param capability The capability to check capabilities for.
456 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800457 */
458 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800459 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800460 }
461
462 /**
463 * Whether the capabilities of this {@code Details} supports the specified capability.
464 *
465 * @param capability The capability to check capabilities for.
466 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800467 */
468 public boolean can(int capability) {
469 return can(mCallCapabilities, capability);
470 }
471
472 /**
473 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
474 *
475 * @param capabilities A capability bit field.
476 * @return A human readable string representation.
477 */
478 public static String capabilitiesToString(int capabilities) {
479 StringBuilder builder = new StringBuilder();
480 builder.append("[Capabilities:");
481 if (can(capabilities, CAPABILITY_HOLD)) {
482 builder.append(" CAPABILITY_HOLD");
483 }
484 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
485 builder.append(" CAPABILITY_SUPPORT_HOLD");
486 }
487 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
488 builder.append(" CAPABILITY_MERGE_CONFERENCE");
489 }
490 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
491 builder.append(" CAPABILITY_SWAP_CONFERENCE");
492 }
493 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
494 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
495 }
496 if (can(capabilities, CAPABILITY_MUTE)) {
497 builder.append(" CAPABILITY_MUTE");
498 }
499 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
500 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
501 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700502 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
503 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
504 }
505 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
506 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
507 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700508 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
509 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800510 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700511 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
512 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
513 }
514 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
515 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
516 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800517 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
518 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
519 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700520 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
521 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800522 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500523 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700524 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500525 }
Rekha Kumar07366812015-03-24 16:42:31 -0700526 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
527 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
528 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700529 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
530 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
531 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700532 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
533 builder.append(" CAPABILITY_CAN_PULL_CALL");
534 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530535 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
536 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
537 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800538 builder.append("]");
539 return builder.toString();
540 }
541
542 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700543 * Whether the supplied properties includes the specified property.
544 *
545 * @param properties A bit field of properties.
546 * @param property The property to check properties for.
547 * @return Whether the specified property is supported.
548 */
549 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800550 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700551 }
552
553 /**
554 * Whether the properties of this {@code Details} includes the specified property.
555 *
556 * @param property The property to check properties for.
557 * @return Whether the specified property is supported.
558 */
559 public boolean hasProperty(int property) {
560 return hasProperty(mCallProperties, property);
561 }
562
563 /**
564 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
565 *
566 * @param properties A property bit field.
567 * @return A human readable string representation.
568 */
569 public static String propertiesToString(int properties) {
570 StringBuilder builder = new StringBuilder();
571 builder.append("[Properties:");
572 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
573 builder.append(" PROPERTY_CONFERENCE");
574 }
575 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
576 builder.append(" PROPERTY_GENERIC_CONFERENCE");
577 }
578 if (hasProperty(properties, PROPERTY_WIFI)) {
579 builder.append(" PROPERTY_WIFI");
580 }
581 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
582 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
583 }
584 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700585 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700586 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700587 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
588 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
589 }
Brad Ebinger15847072016-05-18 11:08:36 -0700590 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
591 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
592 }
Eric Erfanianec881872017-12-06 16:27:53 -0800593 if(hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) {
594 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
595 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700596 builder.append("]");
597 return builder.toString();
598 }
599
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800600 /** {@hide} */
601 public String getTelecomCallId() {
602 return mTelecomCallId;
603 }
604
Andrew Lee2378ea72015-04-29 14:38:11 -0700605 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700606 * @return The handle (e.g., phone number) to which the {@code Call} is currently
607 * connected.
608 */
609 public Uri getHandle() {
610 return mHandle;
611 }
612
613 /**
614 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700615 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700616 */
617 public int getHandlePresentation() {
618 return mHandlePresentation;
619 }
620
621 /**
622 * @return The display name for the caller.
623 */
624 public String getCallerDisplayName() {
625 return mCallerDisplayName;
626 }
627
628 /**
629 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700630 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700631 */
632 public int getCallerDisplayNamePresentation() {
633 return mCallerDisplayNamePresentation;
634 }
635
636 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700637 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
638 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700639 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700640 public PhoneAccountHandle getAccountHandle() {
641 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700642 }
643
644 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800645 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
646 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700647 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700648 public int getCallCapabilities() {
649 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700650 }
651
652 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700653 * @return A bitmask of the properties of the {@code Call}, as defined by the various
654 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700655 */
656 public int getCallProperties() {
657 return mCallProperties;
658 }
659
660 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800661 * @return a bitmask of the audio routes available for the call.
662 *
663 * @hide
664 */
665 public int getSupportedAudioRoutes() {
666 return mSupportedAudioRoutes;
667 }
668
669 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700670 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700671 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700672 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700673 public DisconnectCause getDisconnectCause() {
674 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700675 }
676
677 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700678 * Returns the time the {@link Call} connected (i.e. became active). This information is
679 * updated periodically, but user interfaces should not rely on this to display the "call
680 * time clock". For the time when the call was first added to Telecom, see
681 * {@link #getCreationTimeMillis()}.
682 *
683 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700684 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700685 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700686 return mConnectTimeMillis;
687 }
688
689 /**
690 * @return Information about any calling gateway the {@code Call} may be using.
691 */
692 public GatewayInfo getGatewayInfo() {
693 return mGatewayInfo;
694 }
695
Andrew Lee7a341382014-07-15 17:05:08 -0700696 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700697 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700698 */
699 public int getVideoState() {
700 return mVideoState;
701 }
702
Ihab Awad5d0410f2014-07-30 10:07:40 -0700703 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700704 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700705 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700706 */
707 public StatusHints getStatusHints() {
708 return mStatusHints;
709 }
710
Nancy Chen10798dc2014-08-08 14:00:25 -0700711 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700712 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700713 */
714 public Bundle getExtras() {
715 return mExtras;
716 }
717
Santos Cordon6b7f9552015-05-27 17:21:45 -0700718 /**
719 * @return The extras used with the original intent to place this call.
720 */
721 public Bundle getIntentExtras() {
722 return mIntentExtras;
723 }
724
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700725 /**
726 * Returns the time when the call was first created and added to Telecom. This is the same
727 * time that is logged as the start time in the Call Log (see
728 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
729 * (became active), see {@link #getConnectTimeMillis()}.
730 *
731 * @return The creation time of the call, in millis since the epoch.
732 */
733 public long getCreationTimeMillis() {
734 return mCreationTimeMillis;
735 }
736
Ihab Awade63fadb2014-07-09 21:52:04 -0700737 @Override
738 public boolean equals(Object o) {
739 if (o instanceof Details) {
740 Details d = (Details) o;
741 return
742 Objects.equals(mHandle, d.mHandle) &&
743 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
744 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
745 Objects.equals(mCallerDisplayNamePresentation,
746 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700747 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700748 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700749 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700750 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700751 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700752 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700753 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700754 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700755 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700756 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
757 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700758 }
759 return false;
760 }
761
762 @Override
763 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700764 return Objects.hash(mHandle,
765 mHandlePresentation,
766 mCallerDisplayName,
767 mCallerDisplayNamePresentation,
768 mAccountHandle,
769 mCallCapabilities,
770 mCallProperties,
771 mDisconnectCause,
772 mConnectTimeMillis,
773 mGatewayInfo,
774 mVideoState,
775 mStatusHints,
776 mExtras,
777 mIntentExtras,
778 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700779 }
780
781 /** {@hide} */
782 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800783 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700784 Uri handle,
785 int handlePresentation,
786 String callerDisplayName,
787 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700788 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700789 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700790 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700791 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700792 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700793 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700794 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700795 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700796 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700797 Bundle intentExtras,
798 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800799 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700800 mHandle = handle;
801 mHandlePresentation = handlePresentation;
802 mCallerDisplayName = callerDisplayName;
803 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700804 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700805 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700806 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700807 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700808 mConnectTimeMillis = connectTimeMillis;
809 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700810 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700811 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700812 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700813 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700814 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700815 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800816
817 /** {@hide} */
818 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
819 return new Details(
820 parcelableCall.getId(),
821 parcelableCall.getHandle(),
822 parcelableCall.getHandlePresentation(),
823 parcelableCall.getCallerDisplayName(),
824 parcelableCall.getCallerDisplayNamePresentation(),
825 parcelableCall.getAccountHandle(),
826 parcelableCall.getCapabilities(),
827 parcelableCall.getProperties(),
828 parcelableCall.getDisconnectCause(),
829 parcelableCall.getConnectTimeMillis(),
830 parcelableCall.getGatewayInfo(),
831 parcelableCall.getVideoState(),
832 parcelableCall.getStatusHints(),
833 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700834 parcelableCall.getIntentExtras(),
835 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800836 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800837
838 @Override
839 public String toString() {
840 StringBuilder sb = new StringBuilder();
841 sb.append("[pa: ");
842 sb.append(mAccountHandle);
843 sb.append(", hdl: ");
844 sb.append(Log.pii(mHandle));
845 sb.append(", caps: ");
846 sb.append(capabilitiesToString(mCallCapabilities));
847 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700848 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800849 sb.append("]");
850 return sb.toString();
851 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700852 }
853
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700854 /**
855 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
856 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
857 * implementation.
858 * <p>
859 * You can handle these callbacks by extending the {@link Callback} class and overriding the
860 * callbacks that your {@link InCallService} is interested in. The callback methods include the
861 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
862 * {@link Callback} implementation, if desired.
863 * <p>
864 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
865 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
866 * (typically in {@link InCallService#onCallRemoved(Call)}).
867 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
868 * reach your implementation of {@link Callback}, so it is important to register your callback
869 * as soon as your {@link InCallService} is notified of a new call via
870 * {@link InCallService#onCallAdded(Call)}.
871 */
Andrew Leeda80c872015-04-15 14:09:50 -0700872 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700873 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -0700874 * @hide
875 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800876 @IntDef(prefix = { "HANDOVER_" },
877 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
878 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERG_CALL,
879 HANDOVER_FAILURE_UNKNOWN})
Sanket Padawea8eddd42017-11-03 11:07:35 -0700880 @Retention(RetentionPolicy.SOURCE)
881 public @interface HandoverFailureErrors {}
882
883 /**
884 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
Tyler Gunn9d127732018-03-02 15:45:51 -0800885 * to handover the call to rejects the handover request.
886 * <p>
887 * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
888 * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
889 * {@code null} {@link Connection} from
890 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
891 * ConnectionRequest)}.
892 * <p>
893 * For more information on call handovers, see
894 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700895 */
896 public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
897
898 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800899 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
900 * is initiated but the source or destination app does not support handover.
901 * <p>
902 * Will be returned when a handover is requested via
903 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
904 * {@link PhoneAccountHandle} does not declare
905 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is
906 * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
907 * {@link Details#getAccountHandle()}) does not declare
908 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
909 * <p>
910 * For more information on call handovers, see
911 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700912 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800913 public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700914
915 /**
Tyler Gunn9d127732018-03-02 15:45:51 -0800916 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
917 * user rejects the handover request.
918 * <p>
919 * For more information on call handovers, see
920 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700921 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800922 public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700923
Sanket Padawe85291f62017-12-01 13:59:27 -0800924 /**
925 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
926 * is ongoing emergency call.
Tyler Gunn9d127732018-03-02 15:45:51 -0800927 * <p>
928 * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
929 * called on an emergency call, or if any other call is an emergency call.
930 * <p>
931 * Handovers are not permitted while there are ongoing emergency calls.
932 * <p>
933 * For more information on call handovers, see
934 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
Sanket Padawe85291f62017-12-01 13:59:27 -0800935 */
Tyler Gunn9d127732018-03-02 15:45:51 -0800936 public static final int HANDOVER_FAILURE_ONGOING_EMERG_CALL = 4;
Sanket Padawe85291f62017-12-01 13:59:27 -0800937
Tyler Gunn9d127732018-03-02 15:45:51 -0800938 /**
939 * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
940 * fails for an unknown reason.
941 * <p>
942 * For more information on call handovers, see
943 * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
944 */
945 public static final int HANDOVER_FAILURE_UNKNOWN = 5;
Sanket Padawea8eddd42017-11-03 11:07:35 -0700946
947 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700948 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
949 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700950 * @param call The {@code Call} invoking this method.
951 * @param state The new state of the {@code Call}.
952 */
953 public void onStateChanged(Call call, int state) {}
954
955 /**
956 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
957 *
958 * @param call The {@code Call} invoking this method.
959 * @param parent The new parent of the {@code Call}.
960 */
961 public void onParentChanged(Call call, Call parent) {}
962
963 /**
964 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
965 *
966 * @param call The {@code Call} invoking this method.
967 * @param children The new children of the {@code Call}.
968 */
969 public void onChildrenChanged(Call call, List<Call> children) {}
970
971 /**
972 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
973 *
974 * @param call The {@code Call} invoking this method.
975 * @param details A {@code Details} object describing the {@code Call}.
976 */
977 public void onDetailsChanged(Call call, Details details) {}
978
979 /**
980 * Invoked when the text messages that can be used as responses to the incoming
981 * {@code Call} are loaded from the relevant database.
982 * See {@link #getCannedTextResponses()}.
983 *
984 * @param call The {@code Call} invoking this method.
985 * @param cannedTextResponses The text messages useable as responses.
986 */
987 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
988
989 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700990 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
991 * character. This causes the post-dial signals to stop pending user confirmation. An
992 * implementation should present this choice to the user and invoke
993 * {@link #postDialContinue(boolean)} when the user makes the choice.
994 *
995 * @param call The {@code Call} invoking this method.
996 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
997 */
998 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
999
1000 /**
Andrew Lee50aca232014-07-22 16:41:54 -07001001 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -07001002 *
1003 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -07001004 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001005 */
Andrew Lee50aca232014-07-22 16:41:54 -07001006 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -07001007
1008 /**
1009 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1010 * up their UI for the {@code Call} in response to state transitions. Specifically,
1011 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1012 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1013 * clients should wait for this method to be invoked.
1014 *
1015 * @param call The {@code Call} being destroyed.
1016 */
1017 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001018
1019 /**
1020 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1021 * conferenced.
1022 *
1023 * @param call The {@code Call} being updated.
1024 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1025 * conferenced.
1026 */
1027 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001028
1029 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001030 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
1031 * <p>
1032 * Where possible, the Call should make an attempt to handle {@link Connection} events which
1033 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
1034 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
1035 * possible that a {@link ConnectionService} has defined its own Connection events which a
1036 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001037 * <p>
1038 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
1039 *
1040 * @param call The {@code Call} receiving the event.
1041 * @param event The event.
1042 * @param extras Extras associated with the connection event.
1043 */
1044 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -08001045
1046 /**
1047 * Invoked when the RTT mode changes for this call.
1048 * @param call The call whose RTT mode has changed.
1049 * @param mode the new RTT mode, one of
1050 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1051 * or {@link RttCall#RTT_MODE_VCO}
1052 */
1053 public void onRttModeChanged(Call call, int mode) {}
1054
1055 /**
1056 * Invoked when the call's RTT status changes, either from off to on or from on to off.
1057 * @param call The call whose RTT status has changed.
1058 * @param enabled whether RTT is now enabled or disabled
1059 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1060 * on, null otherwise.
1061 */
1062 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1063
1064 /**
1065 * Invoked when the remote end of the connection has requested that an RTT communication
1066 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1067 * with the same ID that this method is invoked with.
1068 * @param call The call which the RTT request was placed on
1069 * @param id The ID of the request.
1070 */
1071 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -08001072
1073 /**
1074 * Invoked when the RTT session failed to initiate for some reason, including rejection
1075 * by the remote party.
1076 * @param call The call which the RTT initiation failure occurred on.
1077 * @param reason One of the status codes defined in
1078 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1079 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1080 */
1081 public void onRttInitiationFailure(Call call, int reason) {}
Sanket Padawea8eddd42017-11-03 11:07:35 -07001082
1083 /**
1084 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1085 * has completed successfully.
Tyler Gunn9d127732018-03-02 15:45:51 -08001086 * <p>
1087 * For a full discussion of the handover process and the APIs involved, see
1088 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1089 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001090 * @param call The call which had initiated handover.
1091 */
1092 public void onHandoverComplete(Call call) {}
1093
1094 /**
1095 * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1096 * has failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08001097 * <p>
1098 * For a full discussion of the handover process and the APIs involved, see
1099 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1100 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07001101 * @param call The call which had initiated handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08001102 * @param failureReason Error reason for failure.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001103 */
1104 public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
Hall Liu95d55872017-01-25 17:12:49 -08001105 }
1106
1107 /**
1108 * A class that holds the state that describes the state of the RTT channel to the remote
1109 * party, if it is active.
1110 */
1111 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001112 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001113 @Retention(RetentionPolicy.SOURCE)
1114 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1115 public @interface RttAudioMode {}
1116
1117 /**
1118 * For metrics use. Default value in the proto.
1119 * @hide
1120 */
1121 public static final int RTT_MODE_INVALID = 0;
1122
1123 /**
1124 * Indicates that there should be a bidirectional audio stream between the two parties
1125 * on the call.
1126 */
1127 public static final int RTT_MODE_FULL = 1;
1128
1129 /**
1130 * Indicates that the local user should be able to hear the audio stream from the remote
1131 * user, but not vice versa. Equivalent to muting the microphone.
1132 */
1133 public static final int RTT_MODE_HCO = 2;
1134
1135 /**
1136 * Indicates that the remote user should be able to hear the audio stream from the local
1137 * user, but not vice versa. Equivalent to setting the volume to zero.
1138 */
1139 public static final int RTT_MODE_VCO = 3;
1140
1141 private static final int READ_BUFFER_SIZE = 1000;
1142
1143 private InputStreamReader mReceiveStream;
1144 private OutputStreamWriter mTransmitStream;
1145 private int mRttMode;
1146 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001147 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001148 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1149
1150 /**
1151 * @hide
1152 */
Hall Liu57006aa2017-02-06 10:49:48 -08001153 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1154 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1155 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001156 mReceiveStream = receiveStream;
1157 mTransmitStream = transmitStream;
1158 mRttMode = mode;
1159 mInCallAdapter = inCallAdapter;
1160 }
1161
1162 /**
1163 * Returns the current RTT audio mode.
1164 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1165 * {@link #RTT_MODE_HCO}.
1166 */
1167 public int getRttAudioMode() {
1168 return mRttMode;
1169 }
1170
1171 /**
1172 * Sets the RTT audio mode. The requested mode change will be communicated through
1173 * {@link Callback#onRttModeChanged(Call, int)}.
1174 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1175 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1176 */
1177 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001178 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001179 }
1180
1181 /**
1182 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1183 * RTT transmits text in real-time, this method should be called once for each character
1184 * the user enters into the device.
1185 *
1186 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1187 * lead to interleaved text.
1188 * @param input The message to send to the remote user.
1189 */
1190 public void write(String input) throws IOException {
1191 mTransmitStream.write(input);
1192 mTransmitStream.flush();
1193 }
1194
1195 /**
1196 * Reads a string from the remote user, blocking if there is no data available. Returns
1197 * {@code null} if the RTT conversation has been terminated and there is no further data
1198 * to read.
1199 *
1200 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1201 * lead to interleaved text.
1202 * @return A string containing text sent by the remote user, or {@code null} if the
1203 * conversation has been terminated or if there was an error while reading.
1204 */
Hall Liub1c8a772017-07-17 17:04:41 -07001205 public String read() {
1206 try {
1207 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1208 if (numRead < 0) {
1209 return null;
1210 }
1211 return new String(mReadBuffer, 0, numRead);
1212 } catch (IOException e) {
1213 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001214 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001215 }
Hall Liuffa4a812017-03-02 16:11:00 -08001216 }
1217
1218 /**
1219 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1220 * be read.
1221 * @return A string containing text entered by the user, or {@code null} if the user has
1222 * not entered any new text yet.
1223 */
1224 public String readImmediately() throws IOException {
1225 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001226 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1227 if (numRead < 0) {
1228 return null;
1229 }
1230 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001231 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001232 return null;
1233 }
1234 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001235 }
1236
Andrew Leeda80c872015-04-15 14:09:50 -07001237 /**
1238 * @deprecated Use {@code Call.Callback} instead.
1239 * @hide
1240 */
1241 @Deprecated
1242 @SystemApi
1243 public static abstract class Listener extends Callback { }
1244
Ihab Awade63fadb2014-07-09 21:52:04 -07001245 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001246 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001247 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001248 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001249 private final List<Call> mChildren = new ArrayList<>();
1250 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001251 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001252 private final List<Call> mConferenceableCalls = new ArrayList<>();
1253 private final List<Call> mUnmodifiableConferenceableCalls =
1254 Collections.unmodifiableList(mConferenceableCalls);
1255
Santos Cordon823fd3c2014-08-07 18:35:18 -07001256 private boolean mChildrenCached;
1257 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001258 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001259 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001260 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001261 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001262 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001263 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001264 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001265 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001266 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001267
1268 /**
1269 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1270 *
1271 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1272 * remaining or this {@code Call} is not in a post-dial state.
1273 */
1274 public String getRemainingPostDialSequence() {
1275 return mRemainingPostDialSequence;
1276 }
1277
1278 /**
1279 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001280 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001281 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001282 public void answer(@VideoProfile.VideoState int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001283 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001284 }
1285
1286 /**
Pooja Jaind34698d2017-12-28 14:15:31 +05301287 * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1288 *
1289 * @param address The address to which the call will be deflected.
1290 */
1291 public void deflect(Uri address) {
1292 mInCallAdapter.deflectCall(mTelecomCallId, address);
1293 }
1294
1295 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001296 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1297 *
1298 * @param rejectWithMessage Whether to reject with a text message.
1299 * @param textMessage An optional text message with which to respond.
1300 */
1301 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001302 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001303 }
1304
1305 /**
1306 * Instructs this {@code Call} to disconnect.
1307 */
1308 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001309 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001310 }
1311
1312 /**
1313 * Instructs this {@code Call} to go on hold.
1314 */
1315 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001316 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001317 }
1318
1319 /**
1320 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1321 */
1322 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001323 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001324 }
1325
1326 /**
1327 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1328 *
1329 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1330 *
1331 * @param digit A character representing the DTMF digit for which to play the tone. This
1332 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1333 */
1334 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001335 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001336 }
1337
1338 /**
1339 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1340 * currently playing.
1341 *
1342 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1343 * currently playing, this method will do nothing.
1344 */
1345 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001346 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001347 }
1348
1349 /**
1350 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1351 *
1352 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1353 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001354 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001355 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001356 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1357 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001358 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001359 * {@code Call} will pause playing the tones and notify callbacks via
1360 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001361 * should display to the user an indication of this state and an affordance to continue
1362 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1363 * app should invoke the {@link #postDialContinue(boolean)} method.
1364 *
1365 * @param proceed Whether or not to continue with the post-dial sequence.
1366 */
1367 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001368 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001369 }
1370
1371 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001372 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001373 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001374 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001375 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1376 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001377
1378 }
1379
1380 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001381 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001382 *
1383 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001384 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001385 public void conference(Call callToConferenceWith) {
1386 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001387 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001388 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001389 }
1390
1391 /**
1392 * Instructs this {@code Call} to split from any conference call with which it may be
1393 * connected.
1394 */
1395 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001396 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001397 }
1398
1399 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001400 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001401 */
1402 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001403 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001404 }
1405
1406 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001407 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001408 */
1409 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001410 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001411 }
1412
1413 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001414 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1415 * device.
1416 * <p>
1417 * Calls to this method are ignored if the call does not have the
1418 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1419 * <p>
1420 * An {@link InCallService} will only see calls which support this method if it has the
1421 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1422 * in its manifest.
1423 */
1424 public void pullExternalCall() {
1425 // If this isn't an external call, ignore the request.
1426 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1427 return;
1428 }
1429
1430 mInCallAdapter.pullExternalCall(mTelecomCallId);
1431 }
1432
1433 /**
1434 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1435 * the {@link ConnectionService}.
1436 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001437 * Call events are used to communicate point in time information from an {@link InCallService}
1438 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1439 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1440 * {@link ConnectionService}.
1441 * <p>
1442 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1443 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1444 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001445 * Events are exposed to {@link ConnectionService} implementations via
1446 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1447 * <p>
1448 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001449 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1450 * ignore some events altogether.
1451 * <p>
1452 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1453 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1454 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1455 * they define their own event types in this namespace. When defining a custom event type,
1456 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1457 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1458 * <p>
1459 * When defining events and the associated extras, it is important to keep their behavior
1460 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1461 * events/extras should me maintained to ensure backwards compatibility with older
1462 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001463 *
1464 * @param event The connection event.
1465 * @param extras Bundle containing extra information associated with the event.
1466 */
1467 public void sendCallEvent(String event, Bundle extras) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001468 mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001469 }
1470
1471 /**
Hall Liu95d55872017-01-25 17:12:49 -08001472 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1473 * guaranteed, and notification of success will be via the
1474 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1475 */
1476 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001477 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001478 }
1479
1480 /**
1481 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1482 * callback.
1483 * The ID used here should be the same as the ID that was received via the callback.
1484 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1485 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1486 */
1487 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001488 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001489 }
1490
1491 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07001492 * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
1493 * by {@code toHandle}. The videoState specified indicates the desired video state after the
1494 * handover.
1495 * <p>
Tyler Gunn9d127732018-03-02 15:45:51 -08001496 * A call handover is the process where an ongoing call is transferred from one app (i.e.
1497 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
1498 * mobile network call in a video calling app. The mobile network call via the Telephony stack
1499 * is referred to as the source of the handover, and the video calling app is referred to as the
1500 * destination.
1501 * <p>
1502 * When considering a handover scenario the device this method is called on is considered the
1503 * <em>initiating</em> device (since the user initiates the handover from this device), and the
1504 * other device is considered the <em>receiving</em> device.
1505 * <p>
1506 * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
1507 * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
1508 * and invoke
1509 * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1510 * ConnectionRequest)} to inform the destination app that a request has been made to handover a
1511 * call to it. The app returns an instance of {@link Connection} to represent the handover call
1512 * At this point the app should display UI to indicate to the user that a call
1513 * handover is in process.
1514 * <p>
1515 * The destination app is responsible for communicating the handover request from the
1516 * <em>initiating</em> device to the <em>receiving</em> device.
1517 * <p>
1518 * When the app on the <em>receiving</em> device receives the handover request, it calls
1519 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
1520 * process from the <em>initiating</em> device to the <em>receiving</em> device. At this point
1521 * the destination app on the <em>receiving</em> device should show UI to allow the user to
1522 * choose whether they want to continue their call in the destination app.
1523 * <p>
1524 * When the destination app on the <em>receiving</em> device calls
1525 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
1526 * {@link ConnectionService} and call
1527 * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
1528 * ConnectionRequest)} to inform it of the handover request. The app returns an instance of
1529 * {@link Connection} to represent the handover call.
1530 * <p>
1531 * If the user of the <em>receiving</em> device accepts the handover, the app calls
1532 * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
1533 * original call. If the user rejects the handover, the app calls
1534 * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
1535 * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
1536 * <p>
1537 * Telecom will only allow handovers from {@link PhoneAccount}s which declare
1538 * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount}
1539 * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
1540 * <p>
1541 * Errors in the handover process are reported to the {@link InCallService} via
1542 * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to
1543 * the involved {@link ConnectionService}s via
1544 * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
Sanket Padawea8eddd42017-11-03 11:07:35 -07001545 *
1546 * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
1547 * this call to.
Tyler Gunn9d127732018-03-02 15:45:51 -08001548 * @param videoState Indicates the video state desired after the handover (see the
1549 * {@code STATE_*} constants defined in {@link VideoProfile}).
Sanket Padawea8eddd42017-11-03 11:07:35 -07001550 * @param extras Bundle containing extra information to be passed to the
1551 * {@link ConnectionService}
1552 */
Tyler Gunn9d127732018-03-02 15:45:51 -08001553 public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
1554 Bundle extras) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07001555 mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
1556 }
1557
1558 /**
Hall Liu95d55872017-01-25 17:12:49 -08001559 * Terminate the RTT session on this call. The resulting state change will be notified via
1560 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1561 */
1562 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001563 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001564 }
1565
1566 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001567 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1568 * added.
1569 * <p>
1570 * No assumptions should be made as to how an In-Call UI or service will handle these
1571 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1572 *
1573 * @param extras The extras to add.
1574 */
1575 public final void putExtras(Bundle extras) {
1576 if (extras == null) {
1577 return;
1578 }
1579
1580 if (mExtras == null) {
1581 mExtras = new Bundle();
1582 }
1583 mExtras.putAll(extras);
1584 mInCallAdapter.putExtras(mTelecomCallId, extras);
1585 }
1586
1587 /**
1588 * Adds a boolean extra to this {@link Call}.
1589 *
1590 * @param key The extra key.
1591 * @param value The value.
1592 * @hide
1593 */
1594 public final void putExtra(String key, boolean value) {
1595 if (mExtras == null) {
1596 mExtras = new Bundle();
1597 }
1598 mExtras.putBoolean(key, value);
1599 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1600 }
1601
1602 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001603 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001604 *
1605 * @param key The extra key.
1606 * @param value The value.
1607 * @hide
1608 */
1609 public final void putExtra(String key, int value) {
1610 if (mExtras == null) {
1611 mExtras = new Bundle();
1612 }
1613 mExtras.putInt(key, value);
1614 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1615 }
1616
1617 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001618 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001619 *
1620 * @param key The extra key.
1621 * @param value The value.
1622 * @hide
1623 */
1624 public final void putExtra(String key, String value) {
1625 if (mExtras == null) {
1626 mExtras = new Bundle();
1627 }
1628 mExtras.putString(key, value);
1629 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1630 }
1631
1632 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001633 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001634 *
1635 * @param keys The keys of the extras to remove.
1636 */
1637 public final void removeExtras(List<String> keys) {
1638 if (mExtras != null) {
1639 for (String key : keys) {
1640 mExtras.remove(key);
1641 }
1642 if (mExtras.size() == 0) {
1643 mExtras = null;
1644 }
1645 }
1646 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1647 }
1648
1649 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001650 * Removes extras from this {@link Call}.
1651 *
1652 * @param keys The keys of the extras to remove.
1653 */
1654 public final void removeExtras(String ... keys) {
1655 removeExtras(Arrays.asList(keys));
1656 }
1657
1658 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001659 * Obtains the parent of this {@code Call} in a conference, if any.
1660 *
1661 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1662 * child of any conference {@code Call}s.
1663 */
1664 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001665 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001666 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001667 }
1668 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001669 }
1670
1671 /**
1672 * Obtains the children of this conference {@code Call}, if any.
1673 *
1674 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1675 * {@code List} otherwise.
1676 */
1677 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001678 if (!mChildrenCached) {
1679 mChildrenCached = true;
1680 mChildren.clear();
1681
1682 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001683 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001684 if (call == null) {
1685 // At least one child was still not found, so do not save true for "cached"
1686 mChildrenCached = false;
1687 } else {
1688 mChildren.add(call);
1689 }
1690 }
1691 }
1692
Ihab Awade63fadb2014-07-09 21:52:04 -07001693 return mUnmodifiableChildren;
1694 }
1695
1696 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001697 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1698 *
1699 * @return The list of conferenceable {@code Call}s.
1700 */
1701 public List<Call> getConferenceableCalls() {
1702 return mUnmodifiableConferenceableCalls;
1703 }
1704
1705 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001706 * Obtains the state of this {@code Call}.
1707 *
1708 * @return A state value, chosen from the {@code STATE_*} constants.
1709 */
1710 public int getState() {
1711 return mState;
1712 }
1713
1714 /**
1715 * Obtains a list of canned, pre-configured message responses to present to the user as
1716 * ways of rejecting this {@code Call} using via a text message.
1717 *
1718 * @see #reject(boolean, String)
1719 *
1720 * @return A list of canned text message responses.
1721 */
1722 public List<String> getCannedTextResponses() {
1723 return mCannedTextResponses;
1724 }
1725
1726 /**
1727 * Obtains an object that can be used to display video from this {@code Call}.
1728 *
Andrew Lee50aca232014-07-22 16:41:54 -07001729 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001730 */
Andrew Lee50aca232014-07-22 16:41:54 -07001731 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001732 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001733 }
1734
1735 /**
1736 * Obtains an object containing call details.
1737 *
1738 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1739 * result may be {@code null}.
1740 */
1741 public Details getDetails() {
1742 return mDetails;
1743 }
1744
1745 /**
Hall Liu95d55872017-01-25 17:12:49 -08001746 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1747 * receive RTT text data, as well as to change the RTT mode.
1748 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1749 */
1750 public @Nullable RttCall getRttCall() {
1751 return mRttCall;
1752 }
1753
1754 /**
1755 * Returns whether this call has an active RTT connection.
1756 * @return true if there is a connection, false otherwise.
1757 */
1758 public boolean isRttActive() {
1759 return mRttCall != null;
1760 }
1761
1762 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001763 * Registers a callback to this {@code Call}.
1764 *
1765 * @param callback A {@code Callback}.
1766 */
1767 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001768 registerCallback(callback, new Handler());
1769 }
1770
1771 /**
1772 * Registers a callback to this {@code Call}.
1773 *
1774 * @param callback A {@code Callback}.
1775 * @param handler A handler which command and status changes will be delivered to.
1776 */
1777 public void registerCallback(Callback callback, Handler handler) {
1778 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001779 // Don't allow new callback registration if the call is already being destroyed.
1780 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001781 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1782 }
Andrew Leeda80c872015-04-15 14:09:50 -07001783 }
1784
1785 /**
1786 * Unregisters a callback from this {@code Call}.
1787 *
1788 * @param callback A {@code Callback}.
1789 */
1790 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001791 // Don't allow callback deregistration if the call is already being destroyed.
1792 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001793 for (CallbackRecord<Callback> record : mCallbackRecords) {
1794 if (record.getCallback() == callback) {
1795 mCallbackRecords.remove(record);
1796 break;
1797 }
1798 }
Andrew Leeda80c872015-04-15 14:09:50 -07001799 }
1800 }
1801
Santos Cordon3c20d632016-02-25 16:12:35 -08001802 @Override
1803 public String toString() {
1804 return new StringBuilder().
1805 append("Call [id: ").
1806 append(mTelecomCallId).
1807 append(", state: ").
1808 append(stateToString(mState)).
1809 append(", details: ").
1810 append(mDetails).
1811 append("]").toString();
1812 }
1813
1814 /**
1815 * @param state An integer value of a {@code STATE_*} constant.
1816 * @return A string representation of the value.
1817 */
1818 private static String stateToString(int state) {
1819 switch (state) {
1820 case STATE_NEW:
1821 return "NEW";
1822 case STATE_RINGING:
1823 return "RINGING";
1824 case STATE_DIALING:
1825 return "DIALING";
1826 case STATE_ACTIVE:
1827 return "ACTIVE";
1828 case STATE_HOLDING:
1829 return "HOLDING";
1830 case STATE_DISCONNECTED:
1831 return "DISCONNECTED";
1832 case STATE_CONNECTING:
1833 return "CONNECTING";
1834 case STATE_DISCONNECTING:
1835 return "DISCONNECTING";
1836 case STATE_SELECT_PHONE_ACCOUNT:
1837 return "SELECT_PHONE_ACCOUNT";
1838 default:
1839 Log.w(Call.class, "Unknown state %d", state);
1840 return "UNKNOWN";
1841 }
1842 }
1843
Andrew Leeda80c872015-04-15 14:09:50 -07001844 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001845 * Adds a listener to this {@code Call}.
1846 *
1847 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001848 * @deprecated Use {@link #registerCallback} instead.
1849 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001850 */
Andrew Leeda80c872015-04-15 14:09:50 -07001851 @Deprecated
1852 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001853 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001854 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001855 }
1856
1857 /**
1858 * Removes a listener from this {@code Call}.
1859 *
1860 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001861 * @deprecated Use {@link #unregisterCallback} instead.
1862 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001863 */
Andrew Leeda80c872015-04-15 14:09:50 -07001864 @Deprecated
1865 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001866 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001867 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001868 }
1869
1870 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001871 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1872 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001873 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001874 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001875 mInCallAdapter = inCallAdapter;
1876 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001877 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001878 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001879 }
1880
1881 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001882 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001883 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001884 mPhone = phone;
1885 mTelecomCallId = telecomCallId;
1886 mInCallAdapter = inCallAdapter;
1887 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001888 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001889 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001890 }
1891
1892 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001893 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001894 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001895 }
1896
1897 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001898 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001899
Ihab Awade63fadb2014-07-09 21:52:04 -07001900 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001901 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001902 boolean detailsChanged = !Objects.equals(mDetails, details);
1903 if (detailsChanged) {
1904 mDetails = details;
1905 }
1906
1907 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001908 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1909 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1910 mCannedTextResponses =
1911 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001912 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001913 }
1914
Tyler Gunn159f35c2017-03-02 09:28:37 -08001915 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1916 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001917 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001918 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001919 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001920 mVideoCallImpl = newVideoCallImpl;
1921 }
1922 if (mVideoCallImpl != null) {
1923 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001924 }
1925
Santos Cordone3c507b2015-04-23 14:44:19 -07001926 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001927 boolean stateChanged = mState != state;
1928 if (stateChanged) {
1929 mState = state;
1930 }
1931
Santos Cordon823fd3c2014-08-07 18:35:18 -07001932 String parentId = parcelableCall.getParentCallId();
1933 boolean parentChanged = !Objects.equals(mParentId, parentId);
1934 if (parentChanged) {
1935 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001936 }
1937
Santos Cordon823fd3c2014-08-07 18:35:18 -07001938 List<String> childCallIds = parcelableCall.getChildCallIds();
1939 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1940 if (childrenChanged) {
1941 mChildrenIds.clear();
1942 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1943 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001944 }
1945
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001946 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1947 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1948 for (String otherId : conferenceableCallIds) {
1949 if (callIdMap.containsKey(otherId)) {
1950 conferenceableCalls.add(callIdMap.get(otherId));
1951 }
1952 }
1953
1954 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1955 mConferenceableCalls.clear();
1956 mConferenceableCalls.addAll(conferenceableCalls);
1957 fireConferenceableCallsChanged();
1958 }
1959
Hall Liu95d55872017-01-25 17:12:49 -08001960 boolean isRttChanged = false;
1961 boolean rttModeChanged = false;
1962 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1963 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1964 InputStreamReader receiveStream = new InputStreamReader(
1965 new ParcelFileDescriptor.AutoCloseInputStream(
1966 parcelableRttCall.getReceiveStream()),
1967 StandardCharsets.UTF_8);
1968 OutputStreamWriter transmitStream = new OutputStreamWriter(
1969 new ParcelFileDescriptor.AutoCloseOutputStream(
1970 parcelableRttCall.getTransmitStream()),
1971 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08001972 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08001973 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1974 if (mRttCall == null) {
1975 isRttChanged = true;
1976 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1977 rttModeChanged = true;
1978 }
1979 mRttCall = newRttCall;
1980 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1981 && parcelableCall.getIsRttCallChanged()) {
1982 isRttChanged = true;
1983 mRttCall = null;
1984 }
1985
Ihab Awade63fadb2014-07-09 21:52:04 -07001986 // Now we fire updates, ensuring that any client who listens to any of these notifications
1987 // gets the most up-to-date state.
1988
1989 if (stateChanged) {
1990 fireStateChanged(mState);
1991 }
1992 if (detailsChanged) {
1993 fireDetailsChanged(mDetails);
1994 }
1995 if (cannedTextResponsesChanged) {
1996 fireCannedTextResponsesLoaded(mCannedTextResponses);
1997 }
Andrew Lee50aca232014-07-22 16:41:54 -07001998 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001999 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07002000 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002001 if (parentChanged) {
2002 fireParentChanged(getParent());
2003 }
2004 if (childrenChanged) {
2005 fireChildrenChanged(getChildren());
2006 }
Hall Liu95d55872017-01-25 17:12:49 -08002007 if (isRttChanged) {
2008 fireOnIsRttChanged(mRttCall != null, mRttCall);
2009 }
2010 if (rttModeChanged) {
2011 fireOnRttModeChanged(mRttCall.getRttAudioMode());
2012 }
Ihab Awade63fadb2014-07-09 21:52:04 -07002013
2014 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2015 // remove ourselves from the Phone. Note that we do this after completing all state updates
2016 // so a client can cleanly transition all their UI to the state appropriate for a
2017 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2018 if (mState == STATE_DISCONNECTED) {
2019 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07002020 }
2021 }
2022
2023 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07002024 final void internalSetPostDialWait(String remaining) {
2025 mRemainingPostDialSequence = remaining;
2026 firePostDialWait(mRemainingPostDialSequence);
2027 }
2028
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07002029 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07002030 final void internalSetDisconnected() {
2031 if (mState != Call.STATE_DISCONNECTED) {
2032 mState = Call.STATE_DISCONNECTED;
2033 fireStateChanged(mState);
2034 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07002035 }
2036 }
2037
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002038 /** {@hide} */
2039 final void internalOnConnectionEvent(String event, Bundle extras) {
2040 fireOnConnectionEvent(event, extras);
2041 }
2042
Hall Liu95d55872017-01-25 17:12:49 -08002043 /** {@hide} */
2044 final void internalOnRttUpgradeRequest(final int requestId) {
2045 for (CallbackRecord<Callback> record : mCallbackRecords) {
2046 final Call call = this;
2047 final Callback callback = record.getCallback();
2048 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2049 }
2050 }
2051
Hall Liu57006aa2017-02-06 10:49:48 -08002052 /** @hide */
2053 final void internalOnRttInitiationFailure(int reason) {
2054 for (CallbackRecord<Callback> record : mCallbackRecords) {
2055 final Call call = this;
2056 final Callback callback = record.getCallback();
2057 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2058 }
2059 }
2060
Sanket Padawe85291f62017-12-01 13:59:27 -08002061 /** {@hide} */
2062 final void internalOnHandoverFailed(int error) {
2063 for (CallbackRecord<Callback> record : mCallbackRecords) {
2064 final Call call = this;
2065 final Callback callback = record.getCallback();
2066 record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2067 }
2068 }
2069
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002070 /** {@hide} */
2071 final void internalOnHandoverComplete() {
2072 for (CallbackRecord<Callback> record : mCallbackRecords) {
2073 final Call call = this;
2074 final Callback callback = record.getCallback();
2075 record.getHandler().post(() -> callback.onHandoverComplete(call));
2076 }
2077 }
2078
Andrew Lee011728f2015-04-23 15:47:06 -07002079 private void fireStateChanged(final int newState) {
2080 for (CallbackRecord<Callback> record : mCallbackRecords) {
2081 final Call call = this;
2082 final Callback callback = record.getCallback();
2083 record.getHandler().post(new Runnable() {
2084 @Override
2085 public void run() {
2086 callback.onStateChanged(call, newState);
2087 }
2088 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002089 }
2090 }
2091
Andrew Lee011728f2015-04-23 15:47:06 -07002092 private void fireParentChanged(final Call newParent) {
2093 for (CallbackRecord<Callback> record : mCallbackRecords) {
2094 final Call call = this;
2095 final Callback callback = record.getCallback();
2096 record.getHandler().post(new Runnable() {
2097 @Override
2098 public void run() {
2099 callback.onParentChanged(call, newParent);
2100 }
2101 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002102 }
2103 }
2104
Andrew Lee011728f2015-04-23 15:47:06 -07002105 private void fireChildrenChanged(final List<Call> children) {
2106 for (CallbackRecord<Callback> record : mCallbackRecords) {
2107 final Call call = this;
2108 final Callback callback = record.getCallback();
2109 record.getHandler().post(new Runnable() {
2110 @Override
2111 public void run() {
2112 callback.onChildrenChanged(call, children);
2113 }
2114 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002115 }
2116 }
2117
Andrew Lee011728f2015-04-23 15:47:06 -07002118 private void fireDetailsChanged(final Details details) {
2119 for (CallbackRecord<Callback> record : mCallbackRecords) {
2120 final Call call = this;
2121 final Callback callback = record.getCallback();
2122 record.getHandler().post(new Runnable() {
2123 @Override
2124 public void run() {
2125 callback.onDetailsChanged(call, details);
2126 }
2127 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002128 }
2129 }
2130
Andrew Lee011728f2015-04-23 15:47:06 -07002131 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2132 for (CallbackRecord<Callback> record : mCallbackRecords) {
2133 final Call call = this;
2134 final Callback callback = record.getCallback();
2135 record.getHandler().post(new Runnable() {
2136 @Override
2137 public void run() {
2138 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2139 }
2140 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002141 }
2142 }
2143
Andrew Lee011728f2015-04-23 15:47:06 -07002144 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2145 for (CallbackRecord<Callback> record : mCallbackRecords) {
2146 final Call call = this;
2147 final Callback callback = record.getCallback();
2148 record.getHandler().post(new Runnable() {
2149 @Override
2150 public void run() {
2151 callback.onVideoCallChanged(call, videoCall);
2152 }
2153 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002154 }
2155 }
2156
Andrew Lee011728f2015-04-23 15:47:06 -07002157 private void firePostDialWait(final String remainingPostDialSequence) {
2158 for (CallbackRecord<Callback> record : mCallbackRecords) {
2159 final Call call = this;
2160 final Callback callback = record.getCallback();
2161 record.getHandler().post(new Runnable() {
2162 @Override
2163 public void run() {
2164 callback.onPostDialWait(call, remainingPostDialSequence);
2165 }
2166 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002167 }
2168 }
2169
2170 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002171 /**
2172 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2173 * onCallRemoved callback, we remove this call from the Phone's record
2174 * only once all of the registered onCallDestroyed callbacks are executed.
2175 * All the callbacks get removed from our records as a part of this operation
2176 * since onCallDestroyed is the final callback.
2177 */
2178 final Call call = this;
2179 if (mCallbackRecords.isEmpty()) {
2180 // No callbacks registered, remove the call from Phone's record.
2181 mPhone.internalRemoveCall(call);
2182 }
2183 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07002184 final Callback callback = record.getCallback();
2185 record.getHandler().post(new Runnable() {
2186 @Override
2187 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07002188 boolean isFinalRemoval = false;
2189 RuntimeException toThrow = null;
2190 try {
2191 callback.onCallDestroyed(call);
2192 } catch (RuntimeException e) {
2193 toThrow = e;
2194 }
2195 synchronized(Call.this) {
2196 mCallbackRecords.remove(record);
2197 if (mCallbackRecords.isEmpty()) {
2198 isFinalRemoval = true;
2199 }
2200 }
2201 if (isFinalRemoval) {
2202 mPhone.internalRemoveCall(call);
2203 }
2204 if (toThrow != null) {
2205 throw toThrow;
2206 }
Andrew Lee011728f2015-04-23 15:47:06 -07002207 }
2208 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002209 }
2210 }
2211
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002212 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002213 for (CallbackRecord<Callback> record : mCallbackRecords) {
2214 final Call call = this;
2215 final Callback callback = record.getCallback();
2216 record.getHandler().post(new Runnable() {
2217 @Override
2218 public void run() {
2219 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2220 }
2221 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002222 }
2223 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002224
2225 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002226 * Notifies listeners of an incoming connection event.
2227 * <p>
2228 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2229 *
2230 * @param event
2231 * @param extras
2232 */
2233 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2234 for (CallbackRecord<Callback> record : mCallbackRecords) {
2235 final Call call = this;
2236 final Callback callback = record.getCallback();
2237 record.getHandler().post(new Runnable() {
2238 @Override
2239 public void run() {
2240 callback.onConnectionEvent(call, event, extras);
2241 }
2242 });
2243 }
2244 }
2245
2246 /**
Hall Liu95d55872017-01-25 17:12:49 -08002247 * Notifies listeners of an RTT on/off change
2248 *
2249 * @param enabled True if RTT is now enabled, false otherwise
2250 */
2251 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2252 for (CallbackRecord<Callback> record : mCallbackRecords) {
2253 final Call call = this;
2254 final Callback callback = record.getCallback();
2255 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2256 }
2257 }
2258
2259 /**
2260 * Notifies listeners of a RTT mode change
2261 *
2262 * @param mode The new RTT mode
2263 */
2264 private void fireOnRttModeChanged(final int mode) {
2265 for (CallbackRecord<Callback> record : mCallbackRecords) {
2266 final Call call = this;
2267 final Callback callback = record.getCallback();
2268 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2269 }
2270 }
2271
2272 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002273 * Determines if two bundles are equal.
2274 *
2275 * @param bundle The original bundle.
2276 * @param newBundle The bundle to compare with.
2277 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2278 */
2279 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2280 if (bundle == null || newBundle == null) {
2281 return bundle == newBundle;
2282 }
2283
2284 if (bundle.size() != newBundle.size()) {
2285 return false;
2286 }
2287
2288 for(String key : bundle.keySet()) {
2289 if (key != null) {
2290 final Object value = bundle.get(key);
2291 final Object newValue = newBundle.get(key);
2292 if (!Objects.equals(value, newValue)) {
2293 return false;
2294 }
2295 }
2296 }
2297 return true;
2298 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002299}