blob: e8e06808e1896b5ef05d40631a3ce5b438e3aaab [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";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700192
193 /**
194 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
195 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
196 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
197 * {@code null}.
198 * <p>
199 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
200 * @hide
201 */
202 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
203 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
204
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700205 /**
206 * Call event sent from Telecom to the handover {@link ConnectionService} via
207 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
208 * to the {@link ConnectionService} has failed.
209 * <p>
210 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
211 * @hide
212 */
213 public static final String EVENT_HANDOVER_FAILED =
214 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700215
Ihab Awade63fadb2014-07-09 21:52:04 -0700216 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800217
218 /** Call can currently be put on hold or unheld. */
219 public static final int CAPABILITY_HOLD = 0x00000001;
220
221 /** Call supports the hold feature. */
222 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
223
224 /**
225 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
226 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
227 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
228 * capability allows a merge button to be shown while the conference call is in the foreground
229 * of the in-call UI.
230 * <p>
231 * This is only intended for use by a {@link Conference}.
232 */
233 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
234
235 /**
236 * Calls within a conference can be swapped between foreground and background.
237 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
238 * <p>
239 * This is only intended for use by a {@link Conference}.
240 */
241 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
242
243 /**
244 * @hide
245 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700246 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800247
248 /** Call supports responding via text option. */
249 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
250
251 /** Call can be muted. */
252 public static final int CAPABILITY_MUTE = 0x00000040;
253
254 /**
255 * Call supports conference call management. This capability only applies to {@link Conference}
256 * calls which can have {@link Connection}s as children.
257 */
258 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
259
260 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700261 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800262 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700263 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800264
265 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700266 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800267 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700268 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800269
270 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700271 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800272 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700273 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700274 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800275
276 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700277 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800278 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700279 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
280
281 /**
282 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700283 */
284 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
285
286 /**
287 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700288 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700289 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700290 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800291
292 /**
293 * Call is able to be separated from its parent {@code Conference}, if any.
294 */
295 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
296
297 /**
298 * Call is able to be individually disconnected when in a {@code Conference}.
299 */
300 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
301
302 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500303 * Speed up audio setup for MT call.
304 * @hide
305 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700306 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
307
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700308 /**
309 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700310 * @hide
311 */
312 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
313
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700314 /**
315 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700316 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700317 */
318 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
319
Bryce Lee81901682015-08-28 16:38:02 -0700320 /**
321 * Call sends responses through connection.
322 * @hide
323 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800324 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
325
326 /**
327 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
328 * <p>
329 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
330 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
331 * downgraded from a video call back to a VideoState of
332 * {@link VideoProfile#STATE_AUDIO_ONLY}.
333 * <p>
334 * Intuitively, a call which can be downgraded to audio should also have local and remote
335 * video
336 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
337 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
338 */
339 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700340
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700341 /**
342 * When set for an external call, indicates that this {@code Call} can be pulled from a
343 * remote device to the current device.
344 * <p>
345 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
346 * <p>
347 * An {@link InCallService} will only see calls with this capability if it has the
348 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
349 * in its manifest.
350 * <p>
351 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700352 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700353 */
354 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
355
Tyler Gunnd11a3152015-03-18 13:09:14 -0700356 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700357 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700358 //******************************************************************************************
359
360 /**
361 * Whether the call is currently a conference.
362 */
363 public static final int PROPERTY_CONFERENCE = 0x00000001;
364
365 /**
366 * Whether the call is a generic conference, where we do not know the precise state of
367 * participants in the conference (eg. on CDMA).
368 */
369 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
370
371 /**
372 * Whether the call is made while the device is in emergency callback mode.
373 */
374 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
375
376 /**
377 * Connection is using WIFI.
378 */
379 public static final int PROPERTY_WIFI = 0x00000008;
380
381 /**
382 * Call is using high definition audio.
383 */
384 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
385
Tony Maka68dcce2015-12-17 09:31:18 +0000386 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100387 * Whether the call is associated with the work profile.
388 */
389 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
390
391 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700392 * When set, indicates that this {@code Call} does not actually exist locally for the
393 * {@link ConnectionService}.
394 * <p>
395 * Consider, for example, a scenario where a user has two phones with the same phone number.
396 * When a user places a call on one device, the telephony stack can represent that call on
397 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700398 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700399 * <p>
400 * An {@link InCallService} will only see calls with this property if it has the
401 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
402 * in its manifest.
403 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700404 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700405 */
406 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
407
Brad Ebinger15847072016-05-18 11:08:36 -0700408 /**
409 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
410 */
411 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
412
Tyler Gunn24e18332017-02-10 09:42:49 -0800413 /**
414 * Indicates that the call is from a self-managed {@link ConnectionService}.
415 * <p>
416 * See also {@link Connection#PROPERTY_SELF_MANAGED}
417 */
418 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
419
Andrew Lee2378ea72015-04-29 14:38:11 -0700420 //******************************************************************************************
Tyler Gunn24e18332017-02-10 09:42:49 -0800421 // Next PROPERTY value: 0x00000200
Tyler Gunnd11a3152015-03-18 13:09:14 -0700422 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800423
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800424 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700425 private final Uri mHandle;
426 private final int mHandlePresentation;
427 private final String mCallerDisplayName;
428 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700429 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700430 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700431 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800432 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700433 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700434 private final long mConnectTimeMillis;
435 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700436 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700437 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700438 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700439 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700440 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700441
442 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800443 * Whether the supplied capabilities supports the specified capability.
444 *
445 * @param capabilities A bit field of capabilities.
446 * @param capability The capability to check capabilities for.
447 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800448 */
449 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800450 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800451 }
452
453 /**
454 * Whether the capabilities of this {@code Details} supports the specified capability.
455 *
456 * @param capability The capability to check capabilities for.
457 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800458 */
459 public boolean can(int capability) {
460 return can(mCallCapabilities, capability);
461 }
462
463 /**
464 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
465 *
466 * @param capabilities A capability bit field.
467 * @return A human readable string representation.
468 */
469 public static String capabilitiesToString(int capabilities) {
470 StringBuilder builder = new StringBuilder();
471 builder.append("[Capabilities:");
472 if (can(capabilities, CAPABILITY_HOLD)) {
473 builder.append(" CAPABILITY_HOLD");
474 }
475 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
476 builder.append(" CAPABILITY_SUPPORT_HOLD");
477 }
478 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
479 builder.append(" CAPABILITY_MERGE_CONFERENCE");
480 }
481 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
482 builder.append(" CAPABILITY_SWAP_CONFERENCE");
483 }
484 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
485 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
486 }
487 if (can(capabilities, CAPABILITY_MUTE)) {
488 builder.append(" CAPABILITY_MUTE");
489 }
490 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
491 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
492 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700493 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
494 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
495 }
496 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
497 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
498 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700499 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
500 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800501 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700502 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
503 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
504 }
505 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
506 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
507 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800508 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
509 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
510 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700511 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
512 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800513 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500514 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700515 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500516 }
Rekha Kumar07366812015-03-24 16:42:31 -0700517 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
518 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
519 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700520 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
521 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
522 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700523 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
524 builder.append(" CAPABILITY_CAN_PULL_CALL");
525 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800526 builder.append("]");
527 return builder.toString();
528 }
529
530 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700531 * Whether the supplied properties includes the specified property.
532 *
533 * @param properties A bit field of properties.
534 * @param property The property to check properties for.
535 * @return Whether the specified property is supported.
536 */
537 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800538 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700539 }
540
541 /**
542 * Whether the properties of this {@code Details} includes the specified property.
543 *
544 * @param property The property to check properties for.
545 * @return Whether the specified property is supported.
546 */
547 public boolean hasProperty(int property) {
548 return hasProperty(mCallProperties, property);
549 }
550
551 /**
552 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
553 *
554 * @param properties A property bit field.
555 * @return A human readable string representation.
556 */
557 public static String propertiesToString(int properties) {
558 StringBuilder builder = new StringBuilder();
559 builder.append("[Properties:");
560 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
561 builder.append(" PROPERTY_CONFERENCE");
562 }
563 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
564 builder.append(" PROPERTY_GENERIC_CONFERENCE");
565 }
566 if (hasProperty(properties, PROPERTY_WIFI)) {
567 builder.append(" PROPERTY_WIFI");
568 }
569 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
570 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
571 }
572 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700573 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700574 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700575 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
576 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
577 }
Brad Ebinger15847072016-05-18 11:08:36 -0700578 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
579 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
580 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700581 builder.append("]");
582 return builder.toString();
583 }
584
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800585 /** {@hide} */
586 public String getTelecomCallId() {
587 return mTelecomCallId;
588 }
589
Andrew Lee2378ea72015-04-29 14:38:11 -0700590 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700591 * @return The handle (e.g., phone number) to which the {@code Call} is currently
592 * connected.
593 */
594 public Uri getHandle() {
595 return mHandle;
596 }
597
598 /**
599 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700600 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700601 */
602 public int getHandlePresentation() {
603 return mHandlePresentation;
604 }
605
606 /**
607 * @return The display name for the caller.
608 */
609 public String getCallerDisplayName() {
610 return mCallerDisplayName;
611 }
612
613 /**
614 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700615 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700616 */
617 public int getCallerDisplayNamePresentation() {
618 return mCallerDisplayNamePresentation;
619 }
620
621 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700622 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
623 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700624 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700625 public PhoneAccountHandle getAccountHandle() {
626 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700627 }
628
629 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800630 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
631 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700632 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700633 public int getCallCapabilities() {
634 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700635 }
636
637 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700638 * @return A bitmask of the properties of the {@code Call}, as defined by the various
639 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700640 */
641 public int getCallProperties() {
642 return mCallProperties;
643 }
644
645 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800646 * @return a bitmask of the audio routes available for the call.
647 *
648 * @hide
649 */
650 public int getSupportedAudioRoutes() {
651 return mSupportedAudioRoutes;
652 }
653
654 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700655 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700656 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700657 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700658 public DisconnectCause getDisconnectCause() {
659 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700660 }
661
662 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700663 * Returns the time the {@link Call} connected (i.e. became active). This information is
664 * updated periodically, but user interfaces should not rely on this to display the "call
665 * time clock". For the time when the call was first added to Telecom, see
666 * {@link #getCreationTimeMillis()}.
667 *
668 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700669 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700670 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700671 return mConnectTimeMillis;
672 }
673
674 /**
675 * @return Information about any calling gateway the {@code Call} may be using.
676 */
677 public GatewayInfo getGatewayInfo() {
678 return mGatewayInfo;
679 }
680
Andrew Lee7a341382014-07-15 17:05:08 -0700681 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700682 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700683 */
684 public int getVideoState() {
685 return mVideoState;
686 }
687
Ihab Awad5d0410f2014-07-30 10:07:40 -0700688 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700689 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700690 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700691 */
692 public StatusHints getStatusHints() {
693 return mStatusHints;
694 }
695
Nancy Chen10798dc2014-08-08 14:00:25 -0700696 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700697 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700698 */
699 public Bundle getExtras() {
700 return mExtras;
701 }
702
Santos Cordon6b7f9552015-05-27 17:21:45 -0700703 /**
704 * @return The extras used with the original intent to place this call.
705 */
706 public Bundle getIntentExtras() {
707 return mIntentExtras;
708 }
709
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700710 /**
711 * Returns the time when the call was first created and added to Telecom. This is the same
712 * time that is logged as the start time in the Call Log (see
713 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
714 * (became active), see {@link #getConnectTimeMillis()}.
715 *
716 * @return The creation time of the call, in millis since the epoch.
717 */
718 public long getCreationTimeMillis() {
719 return mCreationTimeMillis;
720 }
721
Ihab Awade63fadb2014-07-09 21:52:04 -0700722 @Override
723 public boolean equals(Object o) {
724 if (o instanceof Details) {
725 Details d = (Details) o;
726 return
727 Objects.equals(mHandle, d.mHandle) &&
728 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
729 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
730 Objects.equals(mCallerDisplayNamePresentation,
731 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700732 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700733 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700734 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700735 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700736 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700737 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700738 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700739 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700740 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700741 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
742 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700743 }
744 return false;
745 }
746
747 @Override
748 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700749 return Objects.hash(mHandle,
750 mHandlePresentation,
751 mCallerDisplayName,
752 mCallerDisplayNamePresentation,
753 mAccountHandle,
754 mCallCapabilities,
755 mCallProperties,
756 mDisconnectCause,
757 mConnectTimeMillis,
758 mGatewayInfo,
759 mVideoState,
760 mStatusHints,
761 mExtras,
762 mIntentExtras,
763 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700764 }
765
766 /** {@hide} */
767 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800768 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700769 Uri handle,
770 int handlePresentation,
771 String callerDisplayName,
772 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700773 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700774 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700775 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700776 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700777 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700778 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700779 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700780 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700781 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700782 Bundle intentExtras,
783 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800784 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700785 mHandle = handle;
786 mHandlePresentation = handlePresentation;
787 mCallerDisplayName = callerDisplayName;
788 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700789 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700790 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700791 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700792 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700793 mConnectTimeMillis = connectTimeMillis;
794 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700795 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700796 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700797 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700798 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700799 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700800 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800801
802 /** {@hide} */
803 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
804 return new Details(
805 parcelableCall.getId(),
806 parcelableCall.getHandle(),
807 parcelableCall.getHandlePresentation(),
808 parcelableCall.getCallerDisplayName(),
809 parcelableCall.getCallerDisplayNamePresentation(),
810 parcelableCall.getAccountHandle(),
811 parcelableCall.getCapabilities(),
812 parcelableCall.getProperties(),
813 parcelableCall.getDisconnectCause(),
814 parcelableCall.getConnectTimeMillis(),
815 parcelableCall.getGatewayInfo(),
816 parcelableCall.getVideoState(),
817 parcelableCall.getStatusHints(),
818 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700819 parcelableCall.getIntentExtras(),
820 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800821 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800822
823 @Override
824 public String toString() {
825 StringBuilder sb = new StringBuilder();
826 sb.append("[pa: ");
827 sb.append(mAccountHandle);
828 sb.append(", hdl: ");
829 sb.append(Log.pii(mHandle));
830 sb.append(", caps: ");
831 sb.append(capabilitiesToString(mCallCapabilities));
832 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700833 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800834 sb.append("]");
835 return sb.toString();
836 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700837 }
838
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700839 /**
840 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
841 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
842 * implementation.
843 * <p>
844 * You can handle these callbacks by extending the {@link Callback} class and overriding the
845 * callbacks that your {@link InCallService} is interested in. The callback methods include the
846 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
847 * {@link Callback} implementation, if desired.
848 * <p>
849 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
850 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
851 * (typically in {@link InCallService#onCallRemoved(Call)}).
852 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
853 * reach your implementation of {@link Callback}, so it is important to register your callback
854 * as soon as your {@link InCallService} is notified of a new call via
855 * {@link InCallService#onCallAdded(Call)}.
856 */
Andrew Leeda80c872015-04-15 14:09:50 -0700857 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700858 /**
859 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
860 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700861 * @param call The {@code Call} invoking this method.
862 * @param state The new state of the {@code Call}.
863 */
864 public void onStateChanged(Call call, int state) {}
865
866 /**
867 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
868 *
869 * @param call The {@code Call} invoking this method.
870 * @param parent The new parent of the {@code Call}.
871 */
872 public void onParentChanged(Call call, Call parent) {}
873
874 /**
875 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
876 *
877 * @param call The {@code Call} invoking this method.
878 * @param children The new children of the {@code Call}.
879 */
880 public void onChildrenChanged(Call call, List<Call> children) {}
881
882 /**
883 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
884 *
885 * @param call The {@code Call} invoking this method.
886 * @param details A {@code Details} object describing the {@code Call}.
887 */
888 public void onDetailsChanged(Call call, Details details) {}
889
890 /**
891 * Invoked when the text messages that can be used as responses to the incoming
892 * {@code Call} are loaded from the relevant database.
893 * See {@link #getCannedTextResponses()}.
894 *
895 * @param call The {@code Call} invoking this method.
896 * @param cannedTextResponses The text messages useable as responses.
897 */
898 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
899
900 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700901 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
902 * character. This causes the post-dial signals to stop pending user confirmation. An
903 * implementation should present this choice to the user and invoke
904 * {@link #postDialContinue(boolean)} when the user makes the choice.
905 *
906 * @param call The {@code Call} invoking this method.
907 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
908 */
909 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
910
911 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700912 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700913 *
914 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700915 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700916 */
Andrew Lee50aca232014-07-22 16:41:54 -0700917 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700918
919 /**
920 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
921 * up their UI for the {@code Call} in response to state transitions. Specifically,
922 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
923 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
924 * clients should wait for this method to be invoked.
925 *
926 * @param call The {@code Call} being destroyed.
927 */
928 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700929
930 /**
931 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
932 * conferenced.
933 *
934 * @param call The {@code Call} being updated.
935 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
936 * conferenced.
937 */
938 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700939
940 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700941 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
942 * <p>
943 * Where possible, the Call should make an attempt to handle {@link Connection} events which
944 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
945 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
946 * possible that a {@link ConnectionService} has defined its own Connection events which a
947 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700948 * <p>
949 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
950 *
951 * @param call The {@code Call} receiving the event.
952 * @param event The event.
953 * @param extras Extras associated with the connection event.
954 */
955 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -0800956
957 /**
958 * Invoked when the RTT mode changes for this call.
959 * @param call The call whose RTT mode has changed.
960 * @param mode the new RTT mode, one of
961 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
962 * or {@link RttCall#RTT_MODE_VCO}
963 */
964 public void onRttModeChanged(Call call, int mode) {}
965
966 /**
967 * Invoked when the call's RTT status changes, either from off to on or from on to off.
968 * @param call The call whose RTT status has changed.
969 * @param enabled whether RTT is now enabled or disabled
970 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
971 * on, null otherwise.
972 */
973 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
974
975 /**
976 * Invoked when the remote end of the connection has requested that an RTT communication
977 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
978 * with the same ID that this method is invoked with.
979 * @param call The call which the RTT request was placed on
980 * @param id The ID of the request.
981 */
982 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -0800983
984 /**
985 * Invoked when the RTT session failed to initiate for some reason, including rejection
986 * by the remote party.
987 * @param call The call which the RTT initiation failure occurred on.
988 * @param reason One of the status codes defined in
989 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
990 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
991 */
992 public void onRttInitiationFailure(Call call, int reason) {}
Hall Liu95d55872017-01-25 17:12:49 -0800993 }
994
995 /**
996 * A class that holds the state that describes the state of the RTT channel to the remote
997 * party, if it is active.
998 */
999 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -08001000 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001001 @Retention(RetentionPolicy.SOURCE)
1002 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1003 public @interface RttAudioMode {}
1004
1005 /**
1006 * For metrics use. Default value in the proto.
1007 * @hide
1008 */
1009 public static final int RTT_MODE_INVALID = 0;
1010
1011 /**
1012 * Indicates that there should be a bidirectional audio stream between the two parties
1013 * on the call.
1014 */
1015 public static final int RTT_MODE_FULL = 1;
1016
1017 /**
1018 * Indicates that the local user should be able to hear the audio stream from the remote
1019 * user, but not vice versa. Equivalent to muting the microphone.
1020 */
1021 public static final int RTT_MODE_HCO = 2;
1022
1023 /**
1024 * Indicates that the remote user should be able to hear the audio stream from the local
1025 * user, but not vice versa. Equivalent to setting the volume to zero.
1026 */
1027 public static final int RTT_MODE_VCO = 3;
1028
1029 private static final int READ_BUFFER_SIZE = 1000;
1030
1031 private InputStreamReader mReceiveStream;
1032 private OutputStreamWriter mTransmitStream;
1033 private int mRttMode;
1034 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001035 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001036 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1037
1038 /**
1039 * @hide
1040 */
Hall Liu57006aa2017-02-06 10:49:48 -08001041 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1042 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1043 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001044 mReceiveStream = receiveStream;
1045 mTransmitStream = transmitStream;
1046 mRttMode = mode;
1047 mInCallAdapter = inCallAdapter;
1048 }
1049
1050 /**
1051 * Returns the current RTT audio mode.
1052 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1053 * {@link #RTT_MODE_HCO}.
1054 */
1055 public int getRttAudioMode() {
1056 return mRttMode;
1057 }
1058
1059 /**
1060 * Sets the RTT audio mode. The requested mode change will be communicated through
1061 * {@link Callback#onRttModeChanged(Call, int)}.
1062 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1063 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1064 */
1065 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001066 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001067 }
1068
1069 /**
1070 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1071 * RTT transmits text in real-time, this method should be called once for each character
1072 * the user enters into the device.
1073 *
1074 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1075 * lead to interleaved text.
1076 * @param input The message to send to the remote user.
1077 */
1078 public void write(String input) throws IOException {
1079 mTransmitStream.write(input);
1080 mTransmitStream.flush();
1081 }
1082
1083 /**
1084 * Reads a string from the remote user, blocking if there is no data available. Returns
1085 * {@code null} if the RTT conversation has been terminated and there is no further data
1086 * to read.
1087 *
1088 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1089 * lead to interleaved text.
1090 * @return A string containing text sent by the remote user, or {@code null} if the
1091 * conversation has been terminated or if there was an error while reading.
1092 */
Jeff Sharkey0c28d432017-06-09 11:37:02 -06001093 public String read() {
1094 try {
1095 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1096 if (numRead < 0) {
1097 return null;
1098 }
1099 return new String(mReadBuffer, 0, numRead);
1100 } catch (IOException e) {
1101 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Hall Liuffa4a812017-03-02 16:11:00 -08001102 }
Jeff Sharkey0c28d432017-06-09 11:37:02 -06001103 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001104 }
1105
1106 /**
1107 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1108 * be read.
1109 * @return A string containing text entered by the user, or {@code null} if the user has
1110 * not entered any new text yet.
Jeff Sharkey0c28d432017-06-09 11:37:02 -06001111 * @hide
Hall Liuffa4a812017-03-02 16:11:00 -08001112 */
Jeff Sharkey0c28d432017-06-09 11:37:02 -06001113 @TestApi
Hall Liuffa4a812017-03-02 16:11:00 -08001114 public String readImmediately() throws IOException {
1115 if (mReceiveStream.ready()) {
1116 return read();
1117 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001118 return null;
1119 }
1120 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001121 }
1122
Andrew Leeda80c872015-04-15 14:09:50 -07001123 /**
1124 * @deprecated Use {@code Call.Callback} instead.
1125 * @hide
1126 */
1127 @Deprecated
1128 @SystemApi
1129 public static abstract class Listener extends Callback { }
1130
Ihab Awade63fadb2014-07-09 21:52:04 -07001131 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001132 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001133 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001134 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001135 private final List<Call> mChildren = new ArrayList<>();
1136 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001137 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001138 private final List<Call> mConferenceableCalls = new ArrayList<>();
1139 private final List<Call> mUnmodifiableConferenceableCalls =
1140 Collections.unmodifiableList(mConferenceableCalls);
1141
Santos Cordon823fd3c2014-08-07 18:35:18 -07001142 private boolean mChildrenCached;
1143 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001144 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001145 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001146 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001147 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001148 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001149 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001150 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001151 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001152 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001153
1154 /**
1155 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1156 *
1157 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1158 * remaining or this {@code Call} is not in a post-dial state.
1159 */
1160 public String getRemainingPostDialSequence() {
1161 return mRemainingPostDialSequence;
1162 }
1163
1164 /**
1165 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001166 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001167 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001168 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001169 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001170 }
1171
1172 /**
1173 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1174 *
1175 * @param rejectWithMessage Whether to reject with a text message.
1176 * @param textMessage An optional text message with which to respond.
1177 */
1178 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001179 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001180 }
1181
1182 /**
1183 * Instructs this {@code Call} to disconnect.
1184 */
1185 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001186 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001187 }
1188
1189 /**
1190 * Instructs this {@code Call} to go on hold.
1191 */
1192 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001193 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001194 }
1195
1196 /**
1197 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1198 */
1199 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001200 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001201 }
1202
1203 /**
1204 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1205 *
1206 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1207 *
1208 * @param digit A character representing the DTMF digit for which to play the tone. This
1209 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1210 */
1211 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001212 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001213 }
1214
1215 /**
1216 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1217 * currently playing.
1218 *
1219 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1220 * currently playing, this method will do nothing.
1221 */
1222 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001223 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001224 }
1225
1226 /**
1227 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1228 *
1229 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1230 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001231 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001232 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001233 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1234 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001235 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001236 * {@code Call} will pause playing the tones and notify callbacks via
1237 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001238 * should display to the user an indication of this state and an affordance to continue
1239 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1240 * app should invoke the {@link #postDialContinue(boolean)} method.
1241 *
1242 * @param proceed Whether or not to continue with the post-dial sequence.
1243 */
1244 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001245 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001246 }
1247
1248 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001249 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001250 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001251 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001252 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1253 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001254
1255 }
1256
1257 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001258 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001259 *
1260 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001261 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001262 public void conference(Call callToConferenceWith) {
1263 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001264 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001265 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001266 }
1267
1268 /**
1269 * Instructs this {@code Call} to split from any conference call with which it may be
1270 * connected.
1271 */
1272 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001273 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001274 }
1275
1276 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001277 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001278 */
1279 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001280 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001281 }
1282
1283 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001284 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001285 */
1286 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001287 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001288 }
1289
1290 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001291 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1292 * device.
1293 * <p>
1294 * Calls to this method are ignored if the call does not have the
1295 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1296 * <p>
1297 * An {@link InCallService} will only see calls which support this method if it has the
1298 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1299 * in its manifest.
1300 */
1301 public void pullExternalCall() {
1302 // If this isn't an external call, ignore the request.
1303 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1304 return;
1305 }
1306
1307 mInCallAdapter.pullExternalCall(mTelecomCallId);
1308 }
1309
1310 /**
1311 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1312 * the {@link ConnectionService}.
1313 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001314 * Call events are used to communicate point in time information from an {@link InCallService}
1315 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1316 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1317 * {@link ConnectionService}.
1318 * <p>
1319 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1320 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1321 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001322 * Events are exposed to {@link ConnectionService} implementations via
1323 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1324 * <p>
1325 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001326 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1327 * ignore some events altogether.
1328 * <p>
1329 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1330 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1331 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1332 * they define their own event types in this namespace. When defining a custom event type,
1333 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1334 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1335 * <p>
1336 * When defining events and the associated extras, it is important to keep their behavior
1337 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1338 * events/extras should me maintained to ensure backwards compatibility with older
1339 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001340 *
1341 * @param event The connection event.
1342 * @param extras Bundle containing extra information associated with the event.
1343 */
1344 public void sendCallEvent(String event, Bundle extras) {
1345 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1346 }
1347
1348 /**
Hall Liu95d55872017-01-25 17:12:49 -08001349 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1350 * guaranteed, and notification of success will be via the
1351 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1352 */
1353 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001354 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001355 }
1356
1357 /**
1358 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1359 * callback.
1360 * The ID used here should be the same as the ID that was received via the callback.
1361 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1362 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1363 */
1364 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001365 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001366 }
1367
1368 /**
1369 * Terminate the RTT session on this call. The resulting state change will be notified via
1370 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1371 */
1372 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001373 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001374 }
1375
1376 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001377 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1378 * added.
1379 * <p>
1380 * No assumptions should be made as to how an In-Call UI or service will handle these
1381 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1382 *
1383 * @param extras The extras to add.
1384 */
1385 public final void putExtras(Bundle extras) {
1386 if (extras == null) {
1387 return;
1388 }
1389
1390 if (mExtras == null) {
1391 mExtras = new Bundle();
1392 }
1393 mExtras.putAll(extras);
1394 mInCallAdapter.putExtras(mTelecomCallId, extras);
1395 }
1396
1397 /**
1398 * Adds a boolean extra to this {@link Call}.
1399 *
1400 * @param key The extra key.
1401 * @param value The value.
1402 * @hide
1403 */
1404 public final void putExtra(String key, boolean value) {
1405 if (mExtras == null) {
1406 mExtras = new Bundle();
1407 }
1408 mExtras.putBoolean(key, value);
1409 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1410 }
1411
1412 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001413 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001414 *
1415 * @param key The extra key.
1416 * @param value The value.
1417 * @hide
1418 */
1419 public final void putExtra(String key, int value) {
1420 if (mExtras == null) {
1421 mExtras = new Bundle();
1422 }
1423 mExtras.putInt(key, value);
1424 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1425 }
1426
1427 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001428 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001429 *
1430 * @param key The extra key.
1431 * @param value The value.
1432 * @hide
1433 */
1434 public final void putExtra(String key, String value) {
1435 if (mExtras == null) {
1436 mExtras = new Bundle();
1437 }
1438 mExtras.putString(key, value);
1439 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1440 }
1441
1442 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001443 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001444 *
1445 * @param keys The keys of the extras to remove.
1446 */
1447 public final void removeExtras(List<String> keys) {
1448 if (mExtras != null) {
1449 for (String key : keys) {
1450 mExtras.remove(key);
1451 }
1452 if (mExtras.size() == 0) {
1453 mExtras = null;
1454 }
1455 }
1456 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1457 }
1458
1459 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001460 * Removes extras from this {@link Call}.
1461 *
1462 * @param keys The keys of the extras to remove.
1463 */
1464 public final void removeExtras(String ... keys) {
1465 removeExtras(Arrays.asList(keys));
1466 }
1467
1468 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001469 * Obtains the parent of this {@code Call} in a conference, if any.
1470 *
1471 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1472 * child of any conference {@code Call}s.
1473 */
1474 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001475 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001476 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001477 }
1478 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001479 }
1480
1481 /**
1482 * Obtains the children of this conference {@code Call}, if any.
1483 *
1484 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1485 * {@code List} otherwise.
1486 */
1487 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001488 if (!mChildrenCached) {
1489 mChildrenCached = true;
1490 mChildren.clear();
1491
1492 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001493 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001494 if (call == null) {
1495 // At least one child was still not found, so do not save true for "cached"
1496 mChildrenCached = false;
1497 } else {
1498 mChildren.add(call);
1499 }
1500 }
1501 }
1502
Ihab Awade63fadb2014-07-09 21:52:04 -07001503 return mUnmodifiableChildren;
1504 }
1505
1506 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001507 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1508 *
1509 * @return The list of conferenceable {@code Call}s.
1510 */
1511 public List<Call> getConferenceableCalls() {
1512 return mUnmodifiableConferenceableCalls;
1513 }
1514
1515 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001516 * Obtains the state of this {@code Call}.
1517 *
1518 * @return A state value, chosen from the {@code STATE_*} constants.
1519 */
1520 public int getState() {
1521 return mState;
1522 }
1523
1524 /**
1525 * Obtains a list of canned, pre-configured message responses to present to the user as
1526 * ways of rejecting this {@code Call} using via a text message.
1527 *
1528 * @see #reject(boolean, String)
1529 *
1530 * @return A list of canned text message responses.
1531 */
1532 public List<String> getCannedTextResponses() {
1533 return mCannedTextResponses;
1534 }
1535
1536 /**
1537 * Obtains an object that can be used to display video from this {@code Call}.
1538 *
Andrew Lee50aca232014-07-22 16:41:54 -07001539 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001540 */
Andrew Lee50aca232014-07-22 16:41:54 -07001541 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001542 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001543 }
1544
1545 /**
1546 * Obtains an object containing call details.
1547 *
1548 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1549 * result may be {@code null}.
1550 */
1551 public Details getDetails() {
1552 return mDetails;
1553 }
1554
1555 /**
Hall Liu95d55872017-01-25 17:12:49 -08001556 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1557 * receive RTT text data, as well as to change the RTT mode.
1558 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1559 */
1560 public @Nullable RttCall getRttCall() {
1561 return mRttCall;
1562 }
1563
1564 /**
1565 * Returns whether this call has an active RTT connection.
1566 * @return true if there is a connection, false otherwise.
1567 */
1568 public boolean isRttActive() {
1569 return mRttCall != null;
1570 }
1571
1572 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001573 * Registers a callback to this {@code Call}.
1574 *
1575 * @param callback A {@code Callback}.
1576 */
1577 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001578 registerCallback(callback, new Handler());
1579 }
1580
1581 /**
1582 * Registers a callback to this {@code Call}.
1583 *
1584 * @param callback A {@code Callback}.
1585 * @param handler A handler which command and status changes will be delivered to.
1586 */
1587 public void registerCallback(Callback callback, Handler handler) {
1588 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001589 // Don't allow new callback registration if the call is already being destroyed.
1590 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001591 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1592 }
Andrew Leeda80c872015-04-15 14:09:50 -07001593 }
1594
1595 /**
1596 * Unregisters a callback from this {@code Call}.
1597 *
1598 * @param callback A {@code Callback}.
1599 */
1600 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001601 // Don't allow callback deregistration if the call is already being destroyed.
1602 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001603 for (CallbackRecord<Callback> record : mCallbackRecords) {
1604 if (record.getCallback() == callback) {
1605 mCallbackRecords.remove(record);
1606 break;
1607 }
1608 }
Andrew Leeda80c872015-04-15 14:09:50 -07001609 }
1610 }
1611
Santos Cordon3c20d632016-02-25 16:12:35 -08001612 @Override
1613 public String toString() {
1614 return new StringBuilder().
1615 append("Call [id: ").
1616 append(mTelecomCallId).
1617 append(", state: ").
1618 append(stateToString(mState)).
1619 append(", details: ").
1620 append(mDetails).
1621 append("]").toString();
1622 }
1623
1624 /**
1625 * @param state An integer value of a {@code STATE_*} constant.
1626 * @return A string representation of the value.
1627 */
1628 private static String stateToString(int state) {
1629 switch (state) {
1630 case STATE_NEW:
1631 return "NEW";
1632 case STATE_RINGING:
1633 return "RINGING";
1634 case STATE_DIALING:
1635 return "DIALING";
1636 case STATE_ACTIVE:
1637 return "ACTIVE";
1638 case STATE_HOLDING:
1639 return "HOLDING";
1640 case STATE_DISCONNECTED:
1641 return "DISCONNECTED";
1642 case STATE_CONNECTING:
1643 return "CONNECTING";
1644 case STATE_DISCONNECTING:
1645 return "DISCONNECTING";
1646 case STATE_SELECT_PHONE_ACCOUNT:
1647 return "SELECT_PHONE_ACCOUNT";
1648 default:
1649 Log.w(Call.class, "Unknown state %d", state);
1650 return "UNKNOWN";
1651 }
1652 }
1653
Andrew Leeda80c872015-04-15 14:09:50 -07001654 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001655 * Adds a listener to this {@code Call}.
1656 *
1657 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001658 * @deprecated Use {@link #registerCallback} 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 addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001664 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001665 }
1666
1667 /**
1668 * Removes a listener from this {@code Call}.
1669 *
1670 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001671 * @deprecated Use {@link #unregisterCallback} instead.
1672 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001673 */
Andrew Leeda80c872015-04-15 14:09:50 -07001674 @Deprecated
1675 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001676 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001677 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001678 }
1679
1680 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001681 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1682 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001683 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001684 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001685 mInCallAdapter = inCallAdapter;
1686 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001687 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001688 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001689 }
1690
1691 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001692 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001693 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001694 mPhone = phone;
1695 mTelecomCallId = telecomCallId;
1696 mInCallAdapter = inCallAdapter;
1697 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001698 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001699 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001700 }
1701
1702 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001703 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001704 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001705 }
1706
1707 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001708 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001709
Ihab Awade63fadb2014-07-09 21:52:04 -07001710 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001711 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001712 boolean detailsChanged = !Objects.equals(mDetails, details);
1713 if (detailsChanged) {
1714 mDetails = details;
1715 }
1716
1717 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001718 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1719 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1720 mCannedTextResponses =
1721 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001722 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001723 }
1724
Tyler Gunn159f35c2017-03-02 09:28:37 -08001725 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1726 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001727 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001728 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001729 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001730 mVideoCallImpl = newVideoCallImpl;
1731 }
1732 if (mVideoCallImpl != null) {
1733 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001734 }
1735
Santos Cordone3c507b2015-04-23 14:44:19 -07001736 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001737 boolean stateChanged = mState != state;
1738 if (stateChanged) {
1739 mState = state;
1740 }
1741
Santos Cordon823fd3c2014-08-07 18:35:18 -07001742 String parentId = parcelableCall.getParentCallId();
1743 boolean parentChanged = !Objects.equals(mParentId, parentId);
1744 if (parentChanged) {
1745 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001746 }
1747
Santos Cordon823fd3c2014-08-07 18:35:18 -07001748 List<String> childCallIds = parcelableCall.getChildCallIds();
1749 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1750 if (childrenChanged) {
1751 mChildrenIds.clear();
1752 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1753 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001754 }
1755
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001756 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1757 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1758 for (String otherId : conferenceableCallIds) {
1759 if (callIdMap.containsKey(otherId)) {
1760 conferenceableCalls.add(callIdMap.get(otherId));
1761 }
1762 }
1763
1764 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1765 mConferenceableCalls.clear();
1766 mConferenceableCalls.addAll(conferenceableCalls);
1767 fireConferenceableCallsChanged();
1768 }
1769
Hall Liu95d55872017-01-25 17:12:49 -08001770 boolean isRttChanged = false;
1771 boolean rttModeChanged = false;
1772 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1773 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1774 InputStreamReader receiveStream = new InputStreamReader(
1775 new ParcelFileDescriptor.AutoCloseInputStream(
1776 parcelableRttCall.getReceiveStream()),
1777 StandardCharsets.UTF_8);
1778 OutputStreamWriter transmitStream = new OutputStreamWriter(
1779 new ParcelFileDescriptor.AutoCloseOutputStream(
1780 parcelableRttCall.getTransmitStream()),
1781 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08001782 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08001783 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1784 if (mRttCall == null) {
1785 isRttChanged = true;
1786 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1787 rttModeChanged = true;
1788 }
1789 mRttCall = newRttCall;
1790 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1791 && parcelableCall.getIsRttCallChanged()) {
1792 isRttChanged = true;
1793 mRttCall = null;
1794 }
1795
Ihab Awade63fadb2014-07-09 21:52:04 -07001796 // Now we fire updates, ensuring that any client who listens to any of these notifications
1797 // gets the most up-to-date state.
1798
1799 if (stateChanged) {
1800 fireStateChanged(mState);
1801 }
1802 if (detailsChanged) {
1803 fireDetailsChanged(mDetails);
1804 }
1805 if (cannedTextResponsesChanged) {
1806 fireCannedTextResponsesLoaded(mCannedTextResponses);
1807 }
Andrew Lee50aca232014-07-22 16:41:54 -07001808 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001809 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001810 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001811 if (parentChanged) {
1812 fireParentChanged(getParent());
1813 }
1814 if (childrenChanged) {
1815 fireChildrenChanged(getChildren());
1816 }
Hall Liu95d55872017-01-25 17:12:49 -08001817 if (isRttChanged) {
1818 fireOnIsRttChanged(mRttCall != null, mRttCall);
1819 }
1820 if (rttModeChanged) {
1821 fireOnRttModeChanged(mRttCall.getRttAudioMode());
1822 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001823
1824 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1825 // remove ourselves from the Phone. Note that we do this after completing all state updates
1826 // so a client can cleanly transition all their UI to the state appropriate for a
1827 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1828 if (mState == STATE_DISCONNECTED) {
1829 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001830 }
1831 }
1832
1833 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001834 final void internalSetPostDialWait(String remaining) {
1835 mRemainingPostDialSequence = remaining;
1836 firePostDialWait(mRemainingPostDialSequence);
1837 }
1838
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001839 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001840 final void internalSetDisconnected() {
1841 if (mState != Call.STATE_DISCONNECTED) {
1842 mState = Call.STATE_DISCONNECTED;
1843 fireStateChanged(mState);
1844 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001845 }
1846 }
1847
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001848 /** {@hide} */
1849 final void internalOnConnectionEvent(String event, Bundle extras) {
1850 fireOnConnectionEvent(event, extras);
1851 }
1852
Hall Liu95d55872017-01-25 17:12:49 -08001853 /** {@hide} */
1854 final void internalOnRttUpgradeRequest(final int requestId) {
1855 for (CallbackRecord<Callback> record : mCallbackRecords) {
1856 final Call call = this;
1857 final Callback callback = record.getCallback();
1858 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
1859 }
1860 }
1861
Hall Liu57006aa2017-02-06 10:49:48 -08001862 /** @hide */
1863 final void internalOnRttInitiationFailure(int reason) {
1864 for (CallbackRecord<Callback> record : mCallbackRecords) {
1865 final Call call = this;
1866 final Callback callback = record.getCallback();
1867 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
1868 }
1869 }
1870
Andrew Lee011728f2015-04-23 15:47:06 -07001871 private void fireStateChanged(final int newState) {
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.onStateChanged(call, newState);
1879 }
1880 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001881 }
1882 }
1883
Andrew Lee011728f2015-04-23 15:47:06 -07001884 private void fireParentChanged(final Call newParent) {
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.onParentChanged(call, newParent);
1892 }
1893 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001894 }
1895 }
1896
Andrew Lee011728f2015-04-23 15:47:06 -07001897 private void fireChildrenChanged(final List<Call> children) {
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.onChildrenChanged(call, children);
1905 }
1906 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001907 }
1908 }
1909
Andrew Lee011728f2015-04-23 15:47:06 -07001910 private void fireDetailsChanged(final Details details) {
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.onDetailsChanged(call, details);
1918 }
1919 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001920 }
1921 }
1922
Andrew Lee011728f2015-04-23 15:47:06 -07001923 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
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.onCannedTextResponsesLoaded(call, cannedTextResponses);
1931 }
1932 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001933 }
1934 }
1935
Andrew Lee011728f2015-04-23 15:47:06 -07001936 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
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.onVideoCallChanged(call, videoCall);
1944 }
1945 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001946 }
1947 }
1948
Andrew Lee011728f2015-04-23 15:47:06 -07001949 private void firePostDialWait(final String remainingPostDialSequence) {
1950 for (CallbackRecord<Callback> record : mCallbackRecords) {
1951 final Call call = this;
1952 final Callback callback = record.getCallback();
1953 record.getHandler().post(new Runnable() {
1954 @Override
1955 public void run() {
1956 callback.onPostDialWait(call, remainingPostDialSequence);
1957 }
1958 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001959 }
1960 }
1961
1962 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001963 /**
1964 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1965 * onCallRemoved callback, we remove this call from the Phone's record
1966 * only once all of the registered onCallDestroyed callbacks are executed.
1967 * All the callbacks get removed from our records as a part of this operation
1968 * since onCallDestroyed is the final callback.
1969 */
1970 final Call call = this;
1971 if (mCallbackRecords.isEmpty()) {
1972 // No callbacks registered, remove the call from Phone's record.
1973 mPhone.internalRemoveCall(call);
1974 }
1975 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001976 final Callback callback = record.getCallback();
1977 record.getHandler().post(new Runnable() {
1978 @Override
1979 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001980 boolean isFinalRemoval = false;
1981 RuntimeException toThrow = null;
1982 try {
1983 callback.onCallDestroyed(call);
1984 } catch (RuntimeException e) {
1985 toThrow = e;
1986 }
1987 synchronized(Call.this) {
1988 mCallbackRecords.remove(record);
1989 if (mCallbackRecords.isEmpty()) {
1990 isFinalRemoval = true;
1991 }
1992 }
1993 if (isFinalRemoval) {
1994 mPhone.internalRemoveCall(call);
1995 }
1996 if (toThrow != null) {
1997 throw toThrow;
1998 }
Andrew Lee011728f2015-04-23 15:47:06 -07001999 }
2000 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002001 }
2002 }
2003
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002004 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002005 for (CallbackRecord<Callback> record : mCallbackRecords) {
2006 final Call call = this;
2007 final Callback callback = record.getCallback();
2008 record.getHandler().post(new Runnable() {
2009 @Override
2010 public void run() {
2011 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2012 }
2013 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002014 }
2015 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002016
2017 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002018 * Notifies listeners of an incoming connection event.
2019 * <p>
2020 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2021 *
2022 * @param event
2023 * @param extras
2024 */
2025 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2026 for (CallbackRecord<Callback> record : mCallbackRecords) {
2027 final Call call = this;
2028 final Callback callback = record.getCallback();
2029 record.getHandler().post(new Runnable() {
2030 @Override
2031 public void run() {
2032 callback.onConnectionEvent(call, event, extras);
2033 }
2034 });
2035 }
2036 }
2037
2038 /**
Hall Liu95d55872017-01-25 17:12:49 -08002039 * Notifies listeners of an RTT on/off change
2040 *
2041 * @param enabled True if RTT is now enabled, false otherwise
2042 */
2043 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2044 for (CallbackRecord<Callback> record : mCallbackRecords) {
2045 final Call call = this;
2046 final Callback callback = record.getCallback();
2047 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2048 }
2049 }
2050
2051 /**
2052 * Notifies listeners of a RTT mode change
2053 *
2054 * @param mode The new RTT mode
2055 */
2056 private void fireOnRttModeChanged(final int mode) {
2057 for (CallbackRecord<Callback> record : mCallbackRecords) {
2058 final Call call = this;
2059 final Callback callback = record.getCallback();
2060 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2061 }
2062 }
2063
2064 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002065 * Determines if two bundles are equal.
2066 *
2067 * @param bundle The original bundle.
2068 * @param newBundle The bundle to compare with.
2069 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2070 */
2071 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2072 if (bundle == null || newBundle == null) {
2073 return bundle == newBundle;
2074 }
2075
2076 if (bundle.size() != newBundle.size()) {
2077 return false;
2078 }
2079
2080 for(String key : bundle.keySet()) {
2081 if (key != null) {
2082 final Object value = bundle.get(key);
2083 final Object newValue = newBundle.get(key);
2084 if (!Objects.equals(value, newValue)) {
2085 return false;
2086 }
2087 }
2088 }
2089 return true;
2090 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002091}