blob: a6bfbad8e0537e677512178947738ad56819befe [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;
Jeff Sharkey0c28d432017-06-09 11:37:02 -060022import android.annotation.TestApi;
Ihab Awade63fadb2014-07-09 21:52:04 -070023import android.net.Uri;
Nancy Chen10798dc2014-08-08 14:00:25 -070024import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070025import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080026import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070027
Hall Liu95d55872017-01-25 17:12:49 -080028import java.io.IOException;
29import java.io.InputStreamReader;
30import java.io.OutputStreamWriter;
Andrew Lee50aca232014-07-22 16:41:54 -070031import java.lang.String;
Hall Liu95d55872017-01-25 17:12:49 -080032import java.lang.annotation.Retention;
33import java.lang.annotation.RetentionPolicy;
34import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070035import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070036import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070037import java.util.Collections;
38import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070039import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070040import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070041import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070042
43/**
44 * Represents an ongoing phone call that the in-call app should present to the user.
45 */
46public final class Call {
47 /**
48 * The state of a {@code Call} when newly created.
49 */
50 public static final int STATE_NEW = 0;
51
52 /**
53 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
54 */
55 public static final int STATE_DIALING = 1;
56
57 /**
58 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
59 */
60 public static final int STATE_RINGING = 2;
61
62 /**
63 * The state of a {@code Call} when in a holding state.
64 */
65 public static final int STATE_HOLDING = 3;
66
67 /**
68 * The state of a {@code Call} when actively supporting conversation.
69 */
70 public static final int STATE_ACTIVE = 4;
71
72 /**
73 * The state of a {@code Call} when no further voice or other communication is being
74 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
75 * is no longer active, and the local data transport has or inevitably will release resources
76 * associated with this {@code Call}.
77 */
78 public static final int STATE_DISCONNECTED = 7;
79
Nancy Chen5da0fd52014-07-08 14:16:17 -070080 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070081 * The state of an outgoing {@code Call} when waiting on user to select a
82 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070083 */
Santos Cordone3c507b2015-04-23 14:44:19 -070084 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
85
86 /**
87 * @hide
88 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
89 */
90 @Deprecated
91 @SystemApi
92 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070093
Nancy Chene20930f2014-08-07 16:17:21 -070094 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070095 * The initial state of an outgoing {@code Call}.
96 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
97 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070098 */
99 public static final int STATE_CONNECTING = 9;
100
Nancy Chen513c8922014-09-17 14:47:20 -0700101 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700102 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
103 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
104 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
105 */
106 public static final int STATE_DISCONNECTING = 10;
107
108 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700109 * The state of an external call which is in the process of being pulled from a remote device to
110 * the local device.
111 * <p>
112 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
113 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
114 * <p>
115 * An {@link InCallService} will only see this state if it has the
116 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
117 * manifest.
118 */
119 public static final int STATE_PULLING_CALL = 11;
120
121 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700122 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
123 * extras. Used to pass the phone accounts to display on the front end to the user in order to
124 * select phone accounts to (for example) place a call.
Nancy Chen513c8922014-09-17 14:47:20 -0700125 */
126 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
127
mike dooley4af561f2016-12-20 08:55:17 -0800128 /**
mike dooley91217422017-03-09 12:58:42 -0800129 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
130 * when the last outgoing emergency call was made. This is used to identify potential emergency
131 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800132 */
133 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
134 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
135
Tyler Gunn8bf76572017-04-06 15:30:08 -0700136 /**
137 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
138 * Telecom that the user has requested that the current {@link Call} should be handed over
139 * to another {@link ConnectionService}.
140 * <p>
141 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
142 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
143 * @hide
144 */
145 public static final String EVENT_REQUEST_HANDOVER =
146 "android.telecom.event.REQUEST_HANDOVER";
147
148 /**
149 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
150 * {@link PhoneAccountHandle} to which a call should be handed over to.
151 * @hide
152 */
153 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
154 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
155
156 /**
157 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
158 * video state of the call when it is handed over to the new {@link PhoneAccount}.
159 * <p>
160 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
161 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
162 * {@link VideoProfile#STATE_TX_ENABLED}.
163 * @hide
164 */
165 public static final String EXTRA_HANDOVER_VIDEO_STATE =
166 "android.telecom.extra.HANDOVER_VIDEO_STATE";
167
168 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700169 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
170 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
171 * information to the handover {@link ConnectionService} specified by
172 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
173 * <p>
174 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
175 * {@link ConnectionService} via the request extras when
176 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
177 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700178 * @hide
179 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700180 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700181
182 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700183 * Call event sent from Telecom to the handover {@link ConnectionService} via
184 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
185 * to the {@link ConnectionService} has completed successfully.
186 * <p>
187 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700188 * @hide
189 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700190 public static final String EVENT_HANDOVER_COMPLETE =
191 "android.telecom.event.HANDOVER_COMPLETE";
192 /**
193 * Call event sent from Telecom to the handover {@link ConnectionService} via
194 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
195 * to the {@link ConnectionService} has failed.
196 * <p>
197 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
198 * @hide
199 */
200 public static final String EVENT_HANDOVER_FAILED =
201 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700202
Ihab Awade63fadb2014-07-09 21:52:04 -0700203 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800204
205 /** Call can currently be put on hold or unheld. */
206 public static final int CAPABILITY_HOLD = 0x00000001;
207
208 /** Call supports the hold feature. */
209 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
210
211 /**
212 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
213 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
214 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
215 * capability allows a merge button to be shown while the conference call is in the foreground
216 * of the in-call UI.
217 * <p>
218 * This is only intended for use by a {@link Conference}.
219 */
220 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
221
222 /**
223 * Calls within a conference can be swapped between foreground and background.
224 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
225 * <p>
226 * This is only intended for use by a {@link Conference}.
227 */
228 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
229
230 /**
231 * @hide
232 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700233 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800234
235 /** Call supports responding via text option. */
236 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
237
238 /** Call can be muted. */
239 public static final int CAPABILITY_MUTE = 0x00000040;
240
241 /**
242 * Call supports conference call management. This capability only applies to {@link Conference}
243 * calls which can have {@link Connection}s as children.
244 */
245 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
246
247 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700248 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800249 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700250 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800251
252 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700253 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800254 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700255 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800256
257 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700258 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800259 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700260 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700261 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800262
263 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700264 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800265 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700266 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
267
268 /**
269 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700270 */
271 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
272
273 /**
274 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700275 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700276 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700277 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800278
279 /**
280 * Call is able to be separated from its parent {@code Conference}, if any.
281 */
282 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
283
284 /**
285 * Call is able to be individually disconnected when in a {@code Conference}.
286 */
287 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
288
289 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500290 * Speed up audio setup for MT call.
291 * @hide
292 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700293 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
294
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700295 /**
296 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700297 * @hide
298 */
299 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
300
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700301 /**
302 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700303 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700304 */
305 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
306
Bryce Lee81901682015-08-28 16:38:02 -0700307 /**
308 * Call sends responses through connection.
309 * @hide
310 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800311 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
312
313 /**
314 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
315 * <p>
316 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
317 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
318 * downgraded from a video call back to a VideoState of
319 * {@link VideoProfile#STATE_AUDIO_ONLY}.
320 * <p>
321 * Intuitively, a call which can be downgraded to audio should also have local and remote
322 * video
323 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
324 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
325 */
326 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700327
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700328 /**
329 * When set for an external call, indicates that this {@code Call} can be pulled from a
330 * remote device to the current device.
331 * <p>
332 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
333 * <p>
334 * An {@link InCallService} will only see calls with this capability if it has the
335 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
336 * in its manifest.
337 * <p>
338 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700339 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700340 */
341 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
342
Tyler Gunnd11a3152015-03-18 13:09:14 -0700343 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700344 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700345 //******************************************************************************************
346
347 /**
348 * Whether the call is currently a conference.
349 */
350 public static final int PROPERTY_CONFERENCE = 0x00000001;
351
352 /**
353 * Whether the call is a generic conference, where we do not know the precise state of
354 * participants in the conference (eg. on CDMA).
355 */
356 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
357
358 /**
359 * Whether the call is made while the device is in emergency callback mode.
360 */
361 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
362
363 /**
364 * Connection is using WIFI.
365 */
366 public static final int PROPERTY_WIFI = 0x00000008;
367
368 /**
369 * Call is using high definition audio.
370 */
371 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
372
Tony Maka68dcce2015-12-17 09:31:18 +0000373 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100374 * Whether the call is associated with the work profile.
375 */
376 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
377
378 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700379 * When set, indicates that this {@code Call} does not actually exist locally for the
380 * {@link ConnectionService}.
381 * <p>
382 * Consider, for example, a scenario where a user has two phones with the same phone number.
383 * When a user places a call on one device, the telephony stack can represent that call on
384 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700385 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700386 * <p>
387 * An {@link InCallService} will only see calls with this property if it has the
388 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
389 * in its manifest.
390 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700391 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700392 */
393 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
394
Brad Ebinger15847072016-05-18 11:08:36 -0700395 /**
396 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
397 */
398 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
399
Tyler Gunn24e18332017-02-10 09:42:49 -0800400 /**
401 * Indicates that the call is from a self-managed {@link ConnectionService}.
402 * <p>
403 * See also {@link Connection#PROPERTY_SELF_MANAGED}
404 */
405 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
406
Andrew Lee2378ea72015-04-29 14:38:11 -0700407 //******************************************************************************************
Tyler Gunn24e18332017-02-10 09:42:49 -0800408 // Next PROPERTY value: 0x00000200
Tyler Gunnd11a3152015-03-18 13:09:14 -0700409 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800410
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800411 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700412 private final Uri mHandle;
413 private final int mHandlePresentation;
414 private final String mCallerDisplayName;
415 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700416 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700417 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700418 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800419 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700420 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700421 private final long mConnectTimeMillis;
422 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700423 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700424 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700425 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700426 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700427 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700428
429 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800430 * Whether the supplied capabilities supports the specified capability.
431 *
432 * @param capabilities A bit field of capabilities.
433 * @param capability The capability to check capabilities for.
434 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800435 */
436 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800437 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800438 }
439
440 /**
441 * Whether the capabilities of this {@code Details} supports the specified capability.
442 *
443 * @param capability The capability to check capabilities for.
444 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800445 */
446 public boolean can(int capability) {
447 return can(mCallCapabilities, capability);
448 }
449
450 /**
451 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
452 *
453 * @param capabilities A capability bit field.
454 * @return A human readable string representation.
455 */
456 public static String capabilitiesToString(int capabilities) {
457 StringBuilder builder = new StringBuilder();
458 builder.append("[Capabilities:");
459 if (can(capabilities, CAPABILITY_HOLD)) {
460 builder.append(" CAPABILITY_HOLD");
461 }
462 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
463 builder.append(" CAPABILITY_SUPPORT_HOLD");
464 }
465 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
466 builder.append(" CAPABILITY_MERGE_CONFERENCE");
467 }
468 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
469 builder.append(" CAPABILITY_SWAP_CONFERENCE");
470 }
471 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
472 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
473 }
474 if (can(capabilities, CAPABILITY_MUTE)) {
475 builder.append(" CAPABILITY_MUTE");
476 }
477 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
478 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
479 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700480 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
481 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
482 }
483 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
484 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
485 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700486 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
487 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800488 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700489 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
490 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
491 }
492 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
493 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
494 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800495 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
496 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
497 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700498 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
499 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800500 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500501 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700502 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500503 }
Rekha Kumar07366812015-03-24 16:42:31 -0700504 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
505 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
506 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700507 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
508 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
509 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700510 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
511 builder.append(" CAPABILITY_CAN_PULL_CALL");
512 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800513 builder.append("]");
514 return builder.toString();
515 }
516
517 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700518 * Whether the supplied properties includes the specified property.
519 *
520 * @param properties A bit field of properties.
521 * @param property The property to check properties for.
522 * @return Whether the specified property is supported.
523 */
524 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800525 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700526 }
527
528 /**
529 * Whether the properties of this {@code Details} includes the specified property.
530 *
531 * @param property The property to check properties for.
532 * @return Whether the specified property is supported.
533 */
534 public boolean hasProperty(int property) {
535 return hasProperty(mCallProperties, property);
536 }
537
538 /**
539 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
540 *
541 * @param properties A property bit field.
542 * @return A human readable string representation.
543 */
544 public static String propertiesToString(int properties) {
545 StringBuilder builder = new StringBuilder();
546 builder.append("[Properties:");
547 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
548 builder.append(" PROPERTY_CONFERENCE");
549 }
550 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
551 builder.append(" PROPERTY_GENERIC_CONFERENCE");
552 }
553 if (hasProperty(properties, PROPERTY_WIFI)) {
554 builder.append(" PROPERTY_WIFI");
555 }
556 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
557 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
558 }
559 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700560 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700561 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700562 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
563 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
564 }
Brad Ebinger15847072016-05-18 11:08:36 -0700565 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
566 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
567 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700568 builder.append("]");
569 return builder.toString();
570 }
571
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800572 /** {@hide} */
573 public String getTelecomCallId() {
574 return mTelecomCallId;
575 }
576
Andrew Lee2378ea72015-04-29 14:38:11 -0700577 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700578 * @return The handle (e.g., phone number) to which the {@code Call} is currently
579 * connected.
580 */
581 public Uri getHandle() {
582 return mHandle;
583 }
584
585 /**
586 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700587 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700588 */
589 public int getHandlePresentation() {
590 return mHandlePresentation;
591 }
592
593 /**
594 * @return The display name for the caller.
595 */
596 public String getCallerDisplayName() {
597 return mCallerDisplayName;
598 }
599
600 /**
601 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700602 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700603 */
604 public int getCallerDisplayNamePresentation() {
605 return mCallerDisplayNamePresentation;
606 }
607
608 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700609 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
610 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700611 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700612 public PhoneAccountHandle getAccountHandle() {
613 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700614 }
615
616 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800617 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
618 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700619 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700620 public int getCallCapabilities() {
621 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700622 }
623
624 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700625 * @return A bitmask of the properties of the {@code Call}, as defined by the various
626 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700627 */
628 public int getCallProperties() {
629 return mCallProperties;
630 }
631
632 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800633 * @return a bitmask of the audio routes available for the call.
634 *
635 * @hide
636 */
637 public int getSupportedAudioRoutes() {
638 return mSupportedAudioRoutes;
639 }
640
641 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700642 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700643 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700644 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700645 public DisconnectCause getDisconnectCause() {
646 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700647 }
648
649 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700650 * Returns the time the {@link Call} connected (i.e. became active). This information is
651 * updated periodically, but user interfaces should not rely on this to display the "call
652 * time clock". For the time when the call was first added to Telecom, see
653 * {@link #getCreationTimeMillis()}.
654 *
655 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700656 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700657 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700658 return mConnectTimeMillis;
659 }
660
661 /**
662 * @return Information about any calling gateway the {@code Call} may be using.
663 */
664 public GatewayInfo getGatewayInfo() {
665 return mGatewayInfo;
666 }
667
Andrew Lee7a341382014-07-15 17:05:08 -0700668 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700669 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700670 */
671 public int getVideoState() {
672 return mVideoState;
673 }
674
Ihab Awad5d0410f2014-07-30 10:07:40 -0700675 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700676 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700677 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700678 */
679 public StatusHints getStatusHints() {
680 return mStatusHints;
681 }
682
Nancy Chen10798dc2014-08-08 14:00:25 -0700683 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700684 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700685 */
686 public Bundle getExtras() {
687 return mExtras;
688 }
689
Santos Cordon6b7f9552015-05-27 17:21:45 -0700690 /**
691 * @return The extras used with the original intent to place this call.
692 */
693 public Bundle getIntentExtras() {
694 return mIntentExtras;
695 }
696
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700697 /**
698 * Returns the time when the call was first created and added to Telecom. This is the same
699 * time that is logged as the start time in the Call Log (see
700 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
701 * (became active), see {@link #getConnectTimeMillis()}.
702 *
703 * @return The creation time of the call, in millis since the epoch.
704 */
705 public long getCreationTimeMillis() {
706 return mCreationTimeMillis;
707 }
708
Ihab Awade63fadb2014-07-09 21:52:04 -0700709 @Override
710 public boolean equals(Object o) {
711 if (o instanceof Details) {
712 Details d = (Details) o;
713 return
714 Objects.equals(mHandle, d.mHandle) &&
715 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
716 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
717 Objects.equals(mCallerDisplayNamePresentation,
718 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700719 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700720 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700721 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700722 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700723 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700724 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700725 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700726 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700727 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700728 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
729 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700730 }
731 return false;
732 }
733
734 @Override
735 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700736 return Objects.hash(mHandle,
737 mHandlePresentation,
738 mCallerDisplayName,
739 mCallerDisplayNamePresentation,
740 mAccountHandle,
741 mCallCapabilities,
742 mCallProperties,
743 mDisconnectCause,
744 mConnectTimeMillis,
745 mGatewayInfo,
746 mVideoState,
747 mStatusHints,
748 mExtras,
749 mIntentExtras,
750 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700751 }
752
753 /** {@hide} */
754 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800755 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700756 Uri handle,
757 int handlePresentation,
758 String callerDisplayName,
759 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700760 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700761 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700762 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700763 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700764 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700765 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700766 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700767 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700768 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700769 Bundle intentExtras,
770 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800771 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700772 mHandle = handle;
773 mHandlePresentation = handlePresentation;
774 mCallerDisplayName = callerDisplayName;
775 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700776 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700777 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700778 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700779 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700780 mConnectTimeMillis = connectTimeMillis;
781 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700782 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700783 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700784 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700785 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700786 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700787 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800788
789 /** {@hide} */
790 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
791 return new Details(
792 parcelableCall.getId(),
793 parcelableCall.getHandle(),
794 parcelableCall.getHandlePresentation(),
795 parcelableCall.getCallerDisplayName(),
796 parcelableCall.getCallerDisplayNamePresentation(),
797 parcelableCall.getAccountHandle(),
798 parcelableCall.getCapabilities(),
799 parcelableCall.getProperties(),
800 parcelableCall.getDisconnectCause(),
801 parcelableCall.getConnectTimeMillis(),
802 parcelableCall.getGatewayInfo(),
803 parcelableCall.getVideoState(),
804 parcelableCall.getStatusHints(),
805 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700806 parcelableCall.getIntentExtras(),
807 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800808 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800809
810 @Override
811 public String toString() {
812 StringBuilder sb = new StringBuilder();
813 sb.append("[pa: ");
814 sb.append(mAccountHandle);
815 sb.append(", hdl: ");
816 sb.append(Log.pii(mHandle));
817 sb.append(", caps: ");
818 sb.append(capabilitiesToString(mCallCapabilities));
819 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700820 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800821 sb.append("]");
822 return sb.toString();
823 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700824 }
825
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700826 /**
827 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
828 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
829 * implementation.
830 * <p>
831 * You can handle these callbacks by extending the {@link Callback} class and overriding the
832 * callbacks that your {@link InCallService} is interested in. The callback methods include the
833 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
834 * {@link Callback} implementation, if desired.
835 * <p>
836 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
837 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
838 * (typically in {@link InCallService#onCallRemoved(Call)}).
839 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
840 * reach your implementation of {@link Callback}, so it is important to register your callback
841 * as soon as your {@link InCallService} is notified of a new call via
842 * {@link InCallService#onCallAdded(Call)}.
843 */
Andrew Leeda80c872015-04-15 14:09:50 -0700844 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700845 /**
846 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
847 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700848 * @param call The {@code Call} invoking this method.
849 * @param state The new state of the {@code Call}.
850 */
851 public void onStateChanged(Call call, int state) {}
852
853 /**
854 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
855 *
856 * @param call The {@code Call} invoking this method.
857 * @param parent The new parent of the {@code Call}.
858 */
859 public void onParentChanged(Call call, Call parent) {}
860
861 /**
862 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
863 *
864 * @param call The {@code Call} invoking this method.
865 * @param children The new children of the {@code Call}.
866 */
867 public void onChildrenChanged(Call call, List<Call> children) {}
868
869 /**
870 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
871 *
872 * @param call The {@code Call} invoking this method.
873 * @param details A {@code Details} object describing the {@code Call}.
874 */
875 public void onDetailsChanged(Call call, Details details) {}
876
877 /**
878 * Invoked when the text messages that can be used as responses to the incoming
879 * {@code Call} are loaded from the relevant database.
880 * See {@link #getCannedTextResponses()}.
881 *
882 * @param call The {@code Call} invoking this method.
883 * @param cannedTextResponses The text messages useable as responses.
884 */
885 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
886
887 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700888 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
889 * character. This causes the post-dial signals to stop pending user confirmation. An
890 * implementation should present this choice to the user and invoke
891 * {@link #postDialContinue(boolean)} when the user makes the choice.
892 *
893 * @param call The {@code Call} invoking this method.
894 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
895 */
896 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
897
898 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700899 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700900 *
901 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700902 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700903 */
Andrew Lee50aca232014-07-22 16:41:54 -0700904 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700905
906 /**
907 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
908 * up their UI for the {@code Call} in response to state transitions. Specifically,
909 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
910 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
911 * clients should wait for this method to be invoked.
912 *
913 * @param call The {@code Call} being destroyed.
914 */
915 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700916
917 /**
918 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
919 * conferenced.
920 *
921 * @param call The {@code Call} being updated.
922 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
923 * conferenced.
924 */
925 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700926
927 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700928 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
929 * <p>
930 * Where possible, the Call should make an attempt to handle {@link Connection} events which
931 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
932 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
933 * possible that a {@link ConnectionService} has defined its own Connection events which a
934 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700935 * <p>
936 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
937 *
938 * @param call The {@code Call} receiving the event.
939 * @param event The event.
940 * @param extras Extras associated with the connection event.
941 */
942 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -0800943
944 /**
945 * Invoked when the RTT mode changes for this call.
946 * @param call The call whose RTT mode has changed.
947 * @param mode the new RTT mode, one of
948 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
949 * or {@link RttCall#RTT_MODE_VCO}
950 */
951 public void onRttModeChanged(Call call, int mode) {}
952
953 /**
954 * Invoked when the call's RTT status changes, either from off to on or from on to off.
955 * @param call The call whose RTT status has changed.
956 * @param enabled whether RTT is now enabled or disabled
957 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
958 * on, null otherwise.
959 */
960 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
961
962 /**
963 * Invoked when the remote end of the connection has requested that an RTT communication
964 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
965 * with the same ID that this method is invoked with.
966 * @param call The call which the RTT request was placed on
967 * @param id The ID of the request.
968 */
969 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -0800970
971 /**
972 * Invoked when the RTT session failed to initiate for some reason, including rejection
973 * by the remote party.
974 * @param call The call which the RTT initiation failure occurred on.
975 * @param reason One of the status codes defined in
976 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
977 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
978 */
979 public void onRttInitiationFailure(Call call, int reason) {}
Hall Liu95d55872017-01-25 17:12:49 -0800980 }
981
982 /**
983 * A class that holds the state that describes the state of the RTT channel to the remote
984 * party, if it is active.
985 */
986 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -0800987 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -0800988 @Retention(RetentionPolicy.SOURCE)
989 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
990 public @interface RttAudioMode {}
991
992 /**
993 * For metrics use. Default value in the proto.
994 * @hide
995 */
996 public static final int RTT_MODE_INVALID = 0;
997
998 /**
999 * Indicates that there should be a bidirectional audio stream between the two parties
1000 * on the call.
1001 */
1002 public static final int RTT_MODE_FULL = 1;
1003
1004 /**
1005 * Indicates that the local user should be able to hear the audio stream from the remote
1006 * user, but not vice versa. Equivalent to muting the microphone.
1007 */
1008 public static final int RTT_MODE_HCO = 2;
1009
1010 /**
1011 * Indicates that the remote user should be able to hear the audio stream from the local
1012 * user, but not vice versa. Equivalent to setting the volume to zero.
1013 */
1014 public static final int RTT_MODE_VCO = 3;
1015
1016 private static final int READ_BUFFER_SIZE = 1000;
1017
1018 private InputStreamReader mReceiveStream;
1019 private OutputStreamWriter mTransmitStream;
1020 private int mRttMode;
1021 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001022 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001023 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1024
1025 /**
1026 * @hide
1027 */
Hall Liu57006aa2017-02-06 10:49:48 -08001028 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1029 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1030 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001031 mReceiveStream = receiveStream;
1032 mTransmitStream = transmitStream;
1033 mRttMode = mode;
1034 mInCallAdapter = inCallAdapter;
1035 }
1036
1037 /**
1038 * Returns the current RTT audio mode.
1039 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1040 * {@link #RTT_MODE_HCO}.
1041 */
1042 public int getRttAudioMode() {
1043 return mRttMode;
1044 }
1045
1046 /**
1047 * Sets the RTT audio mode. The requested mode change will be communicated through
1048 * {@link Callback#onRttModeChanged(Call, int)}.
1049 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1050 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1051 */
1052 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001053 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001054 }
1055
1056 /**
1057 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1058 * RTT transmits text in real-time, this method should be called once for each character
1059 * the user enters into the device.
1060 *
1061 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1062 * lead to interleaved text.
1063 * @param input The message to send to the remote user.
1064 */
1065 public void write(String input) throws IOException {
1066 mTransmitStream.write(input);
1067 mTransmitStream.flush();
1068 }
1069
1070 /**
1071 * Reads a string from the remote user, blocking if there is no data available. Returns
1072 * {@code null} if the RTT conversation has been terminated and there is no further data
1073 * to read.
1074 *
1075 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1076 * lead to interleaved text.
1077 * @return A string containing text sent by the remote user, or {@code null} if the
1078 * conversation has been terminated or if there was an error while reading.
1079 */
Jeff Sharkey0c28d432017-06-09 11:37:02 -06001080 public String read() {
1081 try {
1082 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1083 if (numRead < 0) {
1084 return null;
1085 }
1086 return new String(mReadBuffer, 0, numRead);
1087 } catch (IOException e) {
1088 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Hall Liuffa4a812017-03-02 16:11:00 -08001089 }
Jeff Sharkey0c28d432017-06-09 11:37:02 -06001090 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001091 }
1092
1093 /**
1094 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1095 * be read.
1096 * @return A string containing text entered by the user, or {@code null} if the user has
1097 * not entered any new text yet.
Jeff Sharkey0c28d432017-06-09 11:37:02 -06001098 * @hide
Hall Liuffa4a812017-03-02 16:11:00 -08001099 */
Jeff Sharkey0c28d432017-06-09 11:37:02 -06001100 @TestApi
Hall Liuffa4a812017-03-02 16:11:00 -08001101 public String readImmediately() throws IOException {
1102 if (mReceiveStream.ready()) {
1103 return read();
1104 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001105 return null;
1106 }
1107 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001108 }
1109
Andrew Leeda80c872015-04-15 14:09:50 -07001110 /**
1111 * @deprecated Use {@code Call.Callback} instead.
1112 * @hide
1113 */
1114 @Deprecated
1115 @SystemApi
1116 public static abstract class Listener extends Callback { }
1117
Ihab Awade63fadb2014-07-09 21:52:04 -07001118 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001119 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001120 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001121 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001122 private final List<Call> mChildren = new ArrayList<>();
1123 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001124 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001125 private final List<Call> mConferenceableCalls = new ArrayList<>();
1126 private final List<Call> mUnmodifiableConferenceableCalls =
1127 Collections.unmodifiableList(mConferenceableCalls);
1128
Santos Cordon823fd3c2014-08-07 18:35:18 -07001129 private boolean mChildrenCached;
1130 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001131 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001132 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001133 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001134 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001135 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001136 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001137 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001138 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001139 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001140
1141 /**
1142 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1143 *
1144 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1145 * remaining or this {@code Call} is not in a post-dial state.
1146 */
1147 public String getRemainingPostDialSequence() {
1148 return mRemainingPostDialSequence;
1149 }
1150
1151 /**
1152 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001153 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001154 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001155 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001156 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001157 }
1158
1159 /**
1160 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1161 *
1162 * @param rejectWithMessage Whether to reject with a text message.
1163 * @param textMessage An optional text message with which to respond.
1164 */
1165 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001166 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001167 }
1168
1169 /**
1170 * Instructs this {@code Call} to disconnect.
1171 */
1172 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001173 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001174 }
1175
1176 /**
1177 * Instructs this {@code Call} to go on hold.
1178 */
1179 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001180 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001181 }
1182
1183 /**
1184 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1185 */
1186 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001187 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001188 }
1189
1190 /**
1191 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1192 *
1193 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1194 *
1195 * @param digit A character representing the DTMF digit for which to play the tone. This
1196 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1197 */
1198 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001199 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001200 }
1201
1202 /**
1203 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1204 * currently playing.
1205 *
1206 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1207 * currently playing, this method will do nothing.
1208 */
1209 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001210 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001211 }
1212
1213 /**
1214 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1215 *
1216 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1217 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001218 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001219 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001220 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1221 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001222 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001223 * {@code Call} will pause playing the tones and notify callbacks via
1224 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001225 * should display to the user an indication of this state and an affordance to continue
1226 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1227 * app should invoke the {@link #postDialContinue(boolean)} method.
1228 *
1229 * @param proceed Whether or not to continue with the post-dial sequence.
1230 */
1231 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001232 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001233 }
1234
1235 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001236 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001237 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001238 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001239 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1240 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001241
1242 }
1243
1244 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001245 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001246 *
1247 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001248 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001249 public void conference(Call callToConferenceWith) {
1250 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001251 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001252 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001253 }
1254
1255 /**
1256 * Instructs this {@code Call} to split from any conference call with which it may be
1257 * connected.
1258 */
1259 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001260 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001261 }
1262
1263 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001264 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001265 */
1266 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001267 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001268 }
1269
1270 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001271 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001272 */
1273 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001274 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001275 }
1276
1277 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001278 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1279 * device.
1280 * <p>
1281 * Calls to this method are ignored if the call does not have the
1282 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1283 * <p>
1284 * An {@link InCallService} will only see calls which support this method if it has the
1285 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1286 * in its manifest.
1287 */
1288 public void pullExternalCall() {
1289 // If this isn't an external call, ignore the request.
1290 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1291 return;
1292 }
1293
1294 mInCallAdapter.pullExternalCall(mTelecomCallId);
1295 }
1296
1297 /**
1298 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1299 * the {@link ConnectionService}.
1300 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001301 * Call events are used to communicate point in time information from an {@link InCallService}
1302 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1303 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1304 * {@link ConnectionService}.
1305 * <p>
1306 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1307 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1308 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001309 * Events are exposed to {@link ConnectionService} implementations via
1310 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1311 * <p>
1312 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001313 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1314 * ignore some events altogether.
1315 * <p>
1316 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1317 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1318 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1319 * they define their own event types in this namespace. When defining a custom event type,
1320 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1321 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1322 * <p>
1323 * When defining events and the associated extras, it is important to keep their behavior
1324 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1325 * events/extras should me maintained to ensure backwards compatibility with older
1326 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001327 *
1328 * @param event The connection event.
1329 * @param extras Bundle containing extra information associated with the event.
1330 */
1331 public void sendCallEvent(String event, Bundle extras) {
1332 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1333 }
1334
1335 /**
Hall Liu95d55872017-01-25 17:12:49 -08001336 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1337 * guaranteed, and notification of success will be via the
1338 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1339 */
1340 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001341 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001342 }
1343
1344 /**
1345 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1346 * callback.
1347 * The ID used here should be the same as the ID that was received via the callback.
1348 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1349 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1350 */
1351 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001352 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001353 }
1354
1355 /**
1356 * Terminate the RTT session on this call. The resulting state change will be notified via
1357 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1358 */
1359 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001360 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001361 }
1362
1363 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001364 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1365 * added.
1366 * <p>
1367 * No assumptions should be made as to how an In-Call UI or service will handle these
1368 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1369 *
1370 * @param extras The extras to add.
1371 */
1372 public final void putExtras(Bundle extras) {
1373 if (extras == null) {
1374 return;
1375 }
1376
1377 if (mExtras == null) {
1378 mExtras = new Bundle();
1379 }
1380 mExtras.putAll(extras);
1381 mInCallAdapter.putExtras(mTelecomCallId, extras);
1382 }
1383
1384 /**
1385 * Adds a boolean extra to this {@link Call}.
1386 *
1387 * @param key The extra key.
1388 * @param value The value.
1389 * @hide
1390 */
1391 public final void putExtra(String key, boolean value) {
1392 if (mExtras == null) {
1393 mExtras = new Bundle();
1394 }
1395 mExtras.putBoolean(key, value);
1396 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1397 }
1398
1399 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001400 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001401 *
1402 * @param key The extra key.
1403 * @param value The value.
1404 * @hide
1405 */
1406 public final void putExtra(String key, int value) {
1407 if (mExtras == null) {
1408 mExtras = new Bundle();
1409 }
1410 mExtras.putInt(key, value);
1411 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1412 }
1413
1414 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001415 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001416 *
1417 * @param key The extra key.
1418 * @param value The value.
1419 * @hide
1420 */
1421 public final void putExtra(String key, String value) {
1422 if (mExtras == null) {
1423 mExtras = new Bundle();
1424 }
1425 mExtras.putString(key, value);
1426 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1427 }
1428
1429 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001430 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001431 *
1432 * @param keys The keys of the extras to remove.
1433 */
1434 public final void removeExtras(List<String> keys) {
1435 if (mExtras != null) {
1436 for (String key : keys) {
1437 mExtras.remove(key);
1438 }
1439 if (mExtras.size() == 0) {
1440 mExtras = null;
1441 }
1442 }
1443 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1444 }
1445
1446 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001447 * Removes extras from this {@link Call}.
1448 *
1449 * @param keys The keys of the extras to remove.
1450 */
1451 public final void removeExtras(String ... keys) {
1452 removeExtras(Arrays.asList(keys));
1453 }
1454
1455 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001456 * Obtains the parent of this {@code Call} in a conference, if any.
1457 *
1458 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1459 * child of any conference {@code Call}s.
1460 */
1461 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001462 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001463 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001464 }
1465 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001466 }
1467
1468 /**
1469 * Obtains the children of this conference {@code Call}, if any.
1470 *
1471 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1472 * {@code List} otherwise.
1473 */
1474 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001475 if (!mChildrenCached) {
1476 mChildrenCached = true;
1477 mChildren.clear();
1478
1479 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001480 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001481 if (call == null) {
1482 // At least one child was still not found, so do not save true for "cached"
1483 mChildrenCached = false;
1484 } else {
1485 mChildren.add(call);
1486 }
1487 }
1488 }
1489
Ihab Awade63fadb2014-07-09 21:52:04 -07001490 return mUnmodifiableChildren;
1491 }
1492
1493 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001494 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1495 *
1496 * @return The list of conferenceable {@code Call}s.
1497 */
1498 public List<Call> getConferenceableCalls() {
1499 return mUnmodifiableConferenceableCalls;
1500 }
1501
1502 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001503 * Obtains the state of this {@code Call}.
1504 *
1505 * @return A state value, chosen from the {@code STATE_*} constants.
1506 */
1507 public int getState() {
1508 return mState;
1509 }
1510
1511 /**
1512 * Obtains a list of canned, pre-configured message responses to present to the user as
1513 * ways of rejecting this {@code Call} using via a text message.
1514 *
1515 * @see #reject(boolean, String)
1516 *
1517 * @return A list of canned text message responses.
1518 */
1519 public List<String> getCannedTextResponses() {
1520 return mCannedTextResponses;
1521 }
1522
1523 /**
1524 * Obtains an object that can be used to display video from this {@code Call}.
1525 *
Andrew Lee50aca232014-07-22 16:41:54 -07001526 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001527 */
Andrew Lee50aca232014-07-22 16:41:54 -07001528 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001529 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001530 }
1531
1532 /**
1533 * Obtains an object containing call details.
1534 *
1535 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1536 * result may be {@code null}.
1537 */
1538 public Details getDetails() {
1539 return mDetails;
1540 }
1541
1542 /**
Hall Liu95d55872017-01-25 17:12:49 -08001543 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1544 * receive RTT text data, as well as to change the RTT mode.
1545 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1546 */
1547 public @Nullable RttCall getRttCall() {
1548 return mRttCall;
1549 }
1550
1551 /**
1552 * Returns whether this call has an active RTT connection.
1553 * @return true if there is a connection, false otherwise.
1554 */
1555 public boolean isRttActive() {
1556 return mRttCall != null;
1557 }
1558
1559 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001560 * Registers a callback to this {@code Call}.
1561 *
1562 * @param callback A {@code Callback}.
1563 */
1564 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001565 registerCallback(callback, new Handler());
1566 }
1567
1568 /**
1569 * Registers a callback to this {@code Call}.
1570 *
1571 * @param callback A {@code Callback}.
1572 * @param handler A handler which command and status changes will be delivered to.
1573 */
1574 public void registerCallback(Callback callback, Handler handler) {
1575 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001576 // Don't allow new callback registration if the call is already being destroyed.
1577 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001578 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1579 }
Andrew Leeda80c872015-04-15 14:09:50 -07001580 }
1581
1582 /**
1583 * Unregisters a callback from this {@code Call}.
1584 *
1585 * @param callback A {@code Callback}.
1586 */
1587 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001588 // Don't allow callback deregistration if the call is already being destroyed.
1589 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001590 for (CallbackRecord<Callback> record : mCallbackRecords) {
1591 if (record.getCallback() == callback) {
1592 mCallbackRecords.remove(record);
1593 break;
1594 }
1595 }
Andrew Leeda80c872015-04-15 14:09:50 -07001596 }
1597 }
1598
Santos Cordon3c20d632016-02-25 16:12:35 -08001599 @Override
1600 public String toString() {
1601 return new StringBuilder().
1602 append("Call [id: ").
1603 append(mTelecomCallId).
1604 append(", state: ").
1605 append(stateToString(mState)).
1606 append(", details: ").
1607 append(mDetails).
1608 append("]").toString();
1609 }
1610
1611 /**
1612 * @param state An integer value of a {@code STATE_*} constant.
1613 * @return A string representation of the value.
1614 */
1615 private static String stateToString(int state) {
1616 switch (state) {
1617 case STATE_NEW:
1618 return "NEW";
1619 case STATE_RINGING:
1620 return "RINGING";
1621 case STATE_DIALING:
1622 return "DIALING";
1623 case STATE_ACTIVE:
1624 return "ACTIVE";
1625 case STATE_HOLDING:
1626 return "HOLDING";
1627 case STATE_DISCONNECTED:
1628 return "DISCONNECTED";
1629 case STATE_CONNECTING:
1630 return "CONNECTING";
1631 case STATE_DISCONNECTING:
1632 return "DISCONNECTING";
1633 case STATE_SELECT_PHONE_ACCOUNT:
1634 return "SELECT_PHONE_ACCOUNT";
1635 default:
1636 Log.w(Call.class, "Unknown state %d", state);
1637 return "UNKNOWN";
1638 }
1639 }
1640
Andrew Leeda80c872015-04-15 14:09:50 -07001641 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001642 * Adds a listener to this {@code Call}.
1643 *
1644 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001645 * @deprecated Use {@link #registerCallback} instead.
1646 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001647 */
Andrew Leeda80c872015-04-15 14:09:50 -07001648 @Deprecated
1649 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001650 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001651 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001652 }
1653
1654 /**
1655 * Removes a listener from this {@code Call}.
1656 *
1657 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001658 * @deprecated Use {@link #unregisterCallback} instead.
1659 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001660 */
Andrew Leeda80c872015-04-15 14:09:50 -07001661 @Deprecated
1662 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001663 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001664 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001665 }
1666
1667 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001668 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1669 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001670 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001671 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001672 mInCallAdapter = inCallAdapter;
1673 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001674 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001675 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001676 }
1677
1678 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001679 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001680 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001681 mPhone = phone;
1682 mTelecomCallId = telecomCallId;
1683 mInCallAdapter = inCallAdapter;
1684 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001685 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001686 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001687 }
1688
1689 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001690 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001691 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001692 }
1693
1694 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001695 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001696
Ihab Awade63fadb2014-07-09 21:52:04 -07001697 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001698 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001699 boolean detailsChanged = !Objects.equals(mDetails, details);
1700 if (detailsChanged) {
1701 mDetails = details;
1702 }
1703
1704 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001705 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1706 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1707 mCannedTextResponses =
1708 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001709 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001710 }
1711
Tyler Gunn159f35c2017-03-02 09:28:37 -08001712 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1713 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001714 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001715 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001716 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001717 mVideoCallImpl = newVideoCallImpl;
1718 }
1719 if (mVideoCallImpl != null) {
1720 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001721 }
1722
Santos Cordone3c507b2015-04-23 14:44:19 -07001723 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001724 boolean stateChanged = mState != state;
1725 if (stateChanged) {
1726 mState = state;
1727 }
1728
Santos Cordon823fd3c2014-08-07 18:35:18 -07001729 String parentId = parcelableCall.getParentCallId();
1730 boolean parentChanged = !Objects.equals(mParentId, parentId);
1731 if (parentChanged) {
1732 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001733 }
1734
Santos Cordon823fd3c2014-08-07 18:35:18 -07001735 List<String> childCallIds = parcelableCall.getChildCallIds();
1736 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1737 if (childrenChanged) {
1738 mChildrenIds.clear();
1739 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1740 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001741 }
1742
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001743 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1744 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1745 for (String otherId : conferenceableCallIds) {
1746 if (callIdMap.containsKey(otherId)) {
1747 conferenceableCalls.add(callIdMap.get(otherId));
1748 }
1749 }
1750
1751 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1752 mConferenceableCalls.clear();
1753 mConferenceableCalls.addAll(conferenceableCalls);
1754 fireConferenceableCallsChanged();
1755 }
1756
Hall Liu95d55872017-01-25 17:12:49 -08001757 boolean isRttChanged = false;
1758 boolean rttModeChanged = false;
1759 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1760 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1761 InputStreamReader receiveStream = new InputStreamReader(
1762 new ParcelFileDescriptor.AutoCloseInputStream(
1763 parcelableRttCall.getReceiveStream()),
1764 StandardCharsets.UTF_8);
1765 OutputStreamWriter transmitStream = new OutputStreamWriter(
1766 new ParcelFileDescriptor.AutoCloseOutputStream(
1767 parcelableRttCall.getTransmitStream()),
1768 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08001769 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08001770 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1771 if (mRttCall == null) {
1772 isRttChanged = true;
1773 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1774 rttModeChanged = true;
1775 }
1776 mRttCall = newRttCall;
1777 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1778 && parcelableCall.getIsRttCallChanged()) {
1779 isRttChanged = true;
1780 mRttCall = null;
1781 }
1782
Ihab Awade63fadb2014-07-09 21:52:04 -07001783 // Now we fire updates, ensuring that any client who listens to any of these notifications
1784 // gets the most up-to-date state.
1785
1786 if (stateChanged) {
1787 fireStateChanged(mState);
1788 }
1789 if (detailsChanged) {
1790 fireDetailsChanged(mDetails);
1791 }
1792 if (cannedTextResponsesChanged) {
1793 fireCannedTextResponsesLoaded(mCannedTextResponses);
1794 }
Andrew Lee50aca232014-07-22 16:41:54 -07001795 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001796 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001797 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001798 if (parentChanged) {
1799 fireParentChanged(getParent());
1800 }
1801 if (childrenChanged) {
1802 fireChildrenChanged(getChildren());
1803 }
Hall Liu95d55872017-01-25 17:12:49 -08001804 if (isRttChanged) {
1805 fireOnIsRttChanged(mRttCall != null, mRttCall);
1806 }
1807 if (rttModeChanged) {
1808 fireOnRttModeChanged(mRttCall.getRttAudioMode());
1809 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001810
1811 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1812 // remove ourselves from the Phone. Note that we do this after completing all state updates
1813 // so a client can cleanly transition all their UI to the state appropriate for a
1814 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1815 if (mState == STATE_DISCONNECTED) {
1816 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001817 }
1818 }
1819
1820 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001821 final void internalSetPostDialWait(String remaining) {
1822 mRemainingPostDialSequence = remaining;
1823 firePostDialWait(mRemainingPostDialSequence);
1824 }
1825
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001826 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001827 final void internalSetDisconnected() {
1828 if (mState != Call.STATE_DISCONNECTED) {
1829 mState = Call.STATE_DISCONNECTED;
1830 fireStateChanged(mState);
1831 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001832 }
1833 }
1834
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001835 /** {@hide} */
1836 final void internalOnConnectionEvent(String event, Bundle extras) {
1837 fireOnConnectionEvent(event, extras);
1838 }
1839
Hall Liu95d55872017-01-25 17:12:49 -08001840 /** {@hide} */
1841 final void internalOnRttUpgradeRequest(final int requestId) {
1842 for (CallbackRecord<Callback> record : mCallbackRecords) {
1843 final Call call = this;
1844 final Callback callback = record.getCallback();
1845 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
1846 }
1847 }
1848
Hall Liu57006aa2017-02-06 10:49:48 -08001849 /** @hide */
1850 final void internalOnRttInitiationFailure(int reason) {
1851 for (CallbackRecord<Callback> record : mCallbackRecords) {
1852 final Call call = this;
1853 final Callback callback = record.getCallback();
1854 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
1855 }
1856 }
1857
Andrew Lee011728f2015-04-23 15:47:06 -07001858 private void fireStateChanged(final int newState) {
1859 for (CallbackRecord<Callback> record : mCallbackRecords) {
1860 final Call call = this;
1861 final Callback callback = record.getCallback();
1862 record.getHandler().post(new Runnable() {
1863 @Override
1864 public void run() {
1865 callback.onStateChanged(call, newState);
1866 }
1867 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001868 }
1869 }
1870
Andrew Lee011728f2015-04-23 15:47:06 -07001871 private void fireParentChanged(final Call newParent) {
1872 for (CallbackRecord<Callback> record : mCallbackRecords) {
1873 final Call call = this;
1874 final Callback callback = record.getCallback();
1875 record.getHandler().post(new Runnable() {
1876 @Override
1877 public void run() {
1878 callback.onParentChanged(call, newParent);
1879 }
1880 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001881 }
1882 }
1883
Andrew Lee011728f2015-04-23 15:47:06 -07001884 private void fireChildrenChanged(final List<Call> children) {
1885 for (CallbackRecord<Callback> record : mCallbackRecords) {
1886 final Call call = this;
1887 final Callback callback = record.getCallback();
1888 record.getHandler().post(new Runnable() {
1889 @Override
1890 public void run() {
1891 callback.onChildrenChanged(call, children);
1892 }
1893 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001894 }
1895 }
1896
Andrew Lee011728f2015-04-23 15:47:06 -07001897 private void fireDetailsChanged(final Details details) {
1898 for (CallbackRecord<Callback> record : mCallbackRecords) {
1899 final Call call = this;
1900 final Callback callback = record.getCallback();
1901 record.getHandler().post(new Runnable() {
1902 @Override
1903 public void run() {
1904 callback.onDetailsChanged(call, details);
1905 }
1906 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001907 }
1908 }
1909
Andrew Lee011728f2015-04-23 15:47:06 -07001910 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1911 for (CallbackRecord<Callback> record : mCallbackRecords) {
1912 final Call call = this;
1913 final Callback callback = record.getCallback();
1914 record.getHandler().post(new Runnable() {
1915 @Override
1916 public void run() {
1917 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1918 }
1919 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001920 }
1921 }
1922
Andrew Lee011728f2015-04-23 15:47:06 -07001923 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1924 for (CallbackRecord<Callback> record : mCallbackRecords) {
1925 final Call call = this;
1926 final Callback callback = record.getCallback();
1927 record.getHandler().post(new Runnable() {
1928 @Override
1929 public void run() {
1930 callback.onVideoCallChanged(call, videoCall);
1931 }
1932 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001933 }
1934 }
1935
Andrew Lee011728f2015-04-23 15:47:06 -07001936 private void firePostDialWait(final String remainingPostDialSequence) {
1937 for (CallbackRecord<Callback> record : mCallbackRecords) {
1938 final Call call = this;
1939 final Callback callback = record.getCallback();
1940 record.getHandler().post(new Runnable() {
1941 @Override
1942 public void run() {
1943 callback.onPostDialWait(call, remainingPostDialSequence);
1944 }
1945 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001946 }
1947 }
1948
1949 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001950 /**
1951 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1952 * onCallRemoved callback, we remove this call from the Phone's record
1953 * only once all of the registered onCallDestroyed callbacks are executed.
1954 * All the callbacks get removed from our records as a part of this operation
1955 * since onCallDestroyed is the final callback.
1956 */
1957 final Call call = this;
1958 if (mCallbackRecords.isEmpty()) {
1959 // No callbacks registered, remove the call from Phone's record.
1960 mPhone.internalRemoveCall(call);
1961 }
1962 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001963 final Callback callback = record.getCallback();
1964 record.getHandler().post(new Runnable() {
1965 @Override
1966 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001967 boolean isFinalRemoval = false;
1968 RuntimeException toThrow = null;
1969 try {
1970 callback.onCallDestroyed(call);
1971 } catch (RuntimeException e) {
1972 toThrow = e;
1973 }
1974 synchronized(Call.this) {
1975 mCallbackRecords.remove(record);
1976 if (mCallbackRecords.isEmpty()) {
1977 isFinalRemoval = true;
1978 }
1979 }
1980 if (isFinalRemoval) {
1981 mPhone.internalRemoveCall(call);
1982 }
1983 if (toThrow != null) {
1984 throw toThrow;
1985 }
Andrew Lee011728f2015-04-23 15:47:06 -07001986 }
1987 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001988 }
1989 }
1990
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001991 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001992 for (CallbackRecord<Callback> record : mCallbackRecords) {
1993 final Call call = this;
1994 final Callback callback = record.getCallback();
1995 record.getHandler().post(new Runnable() {
1996 @Override
1997 public void run() {
1998 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1999 }
2000 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002001 }
2002 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002003
2004 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002005 * Notifies listeners of an incoming connection event.
2006 * <p>
2007 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2008 *
2009 * @param event
2010 * @param extras
2011 */
2012 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2013 for (CallbackRecord<Callback> record : mCallbackRecords) {
2014 final Call call = this;
2015 final Callback callback = record.getCallback();
2016 record.getHandler().post(new Runnable() {
2017 @Override
2018 public void run() {
2019 callback.onConnectionEvent(call, event, extras);
2020 }
2021 });
2022 }
2023 }
2024
2025 /**
Hall Liu95d55872017-01-25 17:12:49 -08002026 * Notifies listeners of an RTT on/off change
2027 *
2028 * @param enabled True if RTT is now enabled, false otherwise
2029 */
2030 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2031 for (CallbackRecord<Callback> record : mCallbackRecords) {
2032 final Call call = this;
2033 final Callback callback = record.getCallback();
2034 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2035 }
2036 }
2037
2038 /**
2039 * Notifies listeners of a RTT mode change
2040 *
2041 * @param mode The new RTT mode
2042 */
2043 private void fireOnRttModeChanged(final int mode) {
2044 for (CallbackRecord<Callback> record : mCallbackRecords) {
2045 final Call call = this;
2046 final Callback callback = record.getCallback();
2047 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2048 }
2049 }
2050
2051 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002052 * Determines if two bundles are equal.
2053 *
2054 * @param bundle The original bundle.
2055 * @param newBundle The bundle to compare with.
2056 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2057 */
2058 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2059 if (bundle == null || newBundle == null) {
2060 return bundle == newBundle;
2061 }
2062
2063 if (bundle.size() != newBundle.size()) {
2064 return false;
2065 }
2066
2067 for(String key : bundle.keySet()) {
2068 if (key != null) {
2069 final Object value = bundle.get(key);
2070 final Object newValue = newBundle.get(key);
2071 if (!Objects.equals(value, newValue)) {
2072 return false;
2073 }
2074 }
2075 }
2076 return true;
2077 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002078}