blob: e13bd619371994e0dda381cb11e3ea04f1973fdb [file] [log] [blame]
Ihab Awade63fadb2014-07-09 21:52:04 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awade63fadb2014-07-09 21:52:04 -070018
Hall Liu95d55872017-01-25 17:12:49 -080019import android.annotation.IntDef;
20import android.annotation.Nullable;
Andrew Leeda80c872015-04-15 14:09:50 -070021import android.annotation.SystemApi;
Ihab Awade63fadb2014-07-09 21:52:04 -070022import android.net.Uri;
Nancy Chen10798dc2014-08-08 14:00:25 -070023import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070024import android.os.Handler;
Hall Liu95d55872017-01-25 17:12:49 -080025import android.os.ParcelFileDescriptor;
Ihab Awade63fadb2014-07-09 21:52:04 -070026
Hall Liu95d55872017-01-25 17:12:49 -080027import java.io.IOException;
28import java.io.InputStreamReader;
29import java.io.OutputStreamWriter;
Andrew Lee50aca232014-07-22 16:41:54 -070030import java.lang.String;
Hall Liu95d55872017-01-25 17:12:49 -080031import java.lang.annotation.Retention;
32import java.lang.annotation.RetentionPolicy;
33import java.nio.charset.StandardCharsets;
Ihab Awade63fadb2014-07-09 21:52:04 -070034import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070035import java.util.Arrays;
Ihab Awade63fadb2014-07-09 21:52:04 -070036import java.util.Collections;
37import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070038import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070039import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070040import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070041
42/**
43 * Represents an ongoing phone call that the in-call app should present to the user.
44 */
45public final class Call {
46 /**
47 * The state of a {@code Call} when newly created.
48 */
49 public static final int STATE_NEW = 0;
50
51 /**
52 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
53 */
54 public static final int STATE_DIALING = 1;
55
56 /**
57 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
58 */
59 public static final int STATE_RINGING = 2;
60
61 /**
62 * The state of a {@code Call} when in a holding state.
63 */
64 public static final int STATE_HOLDING = 3;
65
66 /**
67 * The state of a {@code Call} when actively supporting conversation.
68 */
69 public static final int STATE_ACTIVE = 4;
70
71 /**
72 * The state of a {@code Call} when no further voice or other communication is being
73 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
74 * is no longer active, and the local data transport has or inevitably will release resources
75 * associated with this {@code Call}.
76 */
77 public static final int STATE_DISCONNECTED = 7;
78
Nancy Chen5da0fd52014-07-08 14:16:17 -070079 /**
Santos Cordone3c507b2015-04-23 14:44:19 -070080 * The state of an outgoing {@code Call} when waiting on user to select a
81 * {@link PhoneAccount} through which to place the call.
Nancy Chen5da0fd52014-07-08 14:16:17 -070082 */
Santos Cordone3c507b2015-04-23 14:44:19 -070083 public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
84
85 /**
86 * @hide
87 * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
88 */
89 @Deprecated
90 @SystemApi
91 public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
Nancy Chen5da0fd52014-07-08 14:16:17 -070092
Nancy Chene20930f2014-08-07 16:17:21 -070093 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070094 * The initial state of an outgoing {@code Call}.
95 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
96 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070097 */
98 public static final int STATE_CONNECTING = 9;
99
Nancy Chen513c8922014-09-17 14:47:20 -0700100 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -0700101 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
102 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
103 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
104 */
105 public static final int STATE_DISCONNECTING = 10;
106
107 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700108 * The state of an external call which is in the process of being pulled from a remote device to
109 * the local device.
110 * <p>
111 * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
112 * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
113 * <p>
114 * An {@link InCallService} will only see this state if it has the
115 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
116 * manifest.
117 */
118 public static final int STATE_PULLING_CALL = 11;
119
120 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700121 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
122 * extras. Used to pass the phone accounts to display on the front end to the user in order to
123 * select phone accounts to (for example) place a call.
Nancy Chen513c8922014-09-17 14:47:20 -0700124 */
125 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
126
mike dooley4af561f2016-12-20 08:55:17 -0800127 /**
mike dooley91217422017-03-09 12:58:42 -0800128 * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
129 * when the last outgoing emergency call was made. This is used to identify potential emergency
130 * callbacks.
mike dooley4af561f2016-12-20 08:55:17 -0800131 */
132 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
133 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
134
Tyler Gunn8bf76572017-04-06 15:30:08 -0700135 /**
136 * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform
137 * Telecom that the user has requested that the current {@link Call} should be handed over
138 * to another {@link ConnectionService}.
139 * <p>
140 * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to
141 * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to.
142 * @hide
143 */
144 public static final String EVENT_REQUEST_HANDOVER =
145 "android.telecom.event.REQUEST_HANDOVER";
146
147 /**
148 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
149 * {@link PhoneAccountHandle} to which a call should be handed over to.
150 * @hide
151 */
152 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE =
153 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE";
154
155 /**
156 * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the
157 * video state of the call when it is handed over to the new {@link PhoneAccount}.
158 * <p>
159 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
160 * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and
161 * {@link VideoProfile#STATE_TX_ENABLED}.
162 * @hide
163 */
164 public static final String EXTRA_HANDOVER_VIDEO_STATE =
165 "android.telecom.extra.HANDOVER_VIDEO_STATE";
166
167 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700168 * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the
169 * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra
170 * information to the handover {@link ConnectionService} specified by
171 * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}.
172 * <p>
173 * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the
174 * {@link ConnectionService} via the request extras when
175 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
176 * is called to initate the handover.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700177 * @hide
178 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700179 public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700180
181 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700182 * Call event sent from Telecom to the handover {@link ConnectionService} via
183 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
184 * to the {@link ConnectionService} has completed successfully.
185 * <p>
186 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700187 * @hide
188 */
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700189 public static final String EVENT_HANDOVER_COMPLETE =
190 "android.telecom.event.HANDOVER_COMPLETE";
Tyler Gunn34a2b312017-06-23 08:32:00 -0700191
192 /**
193 * Call event sent from Telecom to the handover destination {@link ConnectionService} via
194 * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the
195 * source connection has disconnected. The {@link Bundle} parameter for the call event will be
196 * {@code null}.
197 * <p>
198 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
199 * @hide
200 */
201 public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED =
202 "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED";
203
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700204 /**
205 * Call event sent from Telecom to the handover {@link ConnectionService} via
206 * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover
207 * to the {@link ConnectionService} has failed.
208 * <p>
209 * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event.
210 * @hide
211 */
212 public static final String EVENT_HANDOVER_FAILED =
213 "android.telecom.event.HANDOVER_FAILED";
Tyler Gunn8bf76572017-04-06 15:30:08 -0700214
Ihab Awade63fadb2014-07-09 21:52:04 -0700215 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800216
217 /** Call can currently be put on hold or unheld. */
218 public static final int CAPABILITY_HOLD = 0x00000001;
219
220 /** Call supports the hold feature. */
221 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
222
223 /**
224 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
225 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
226 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
227 * capability allows a merge button to be shown while the conference call is in the foreground
228 * of the in-call UI.
229 * <p>
230 * This is only intended for use by a {@link Conference}.
231 */
232 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
233
234 /**
235 * Calls within a conference can be swapped between foreground and background.
236 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
237 * <p>
238 * This is only intended for use by a {@link Conference}.
239 */
240 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
241
242 /**
243 * @hide
244 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700245 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800246
247 /** Call supports responding via text option. */
248 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
249
250 /** Call can be muted. */
251 public static final int CAPABILITY_MUTE = 0x00000040;
252
253 /**
254 * Call supports conference call management. This capability only applies to {@link Conference}
255 * calls which can have {@link Connection}s as children.
256 */
257 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
258
259 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700260 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800261 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700262 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800263
264 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700265 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800266 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700267 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800268
269 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700270 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800271 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700272 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700273 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800274
275 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700276 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800277 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700278 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
279
280 /**
281 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700282 */
283 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
284
285 /**
286 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700287 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700288 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700289 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800290
291 /**
292 * Call is able to be separated from its parent {@code Conference}, if any.
293 */
294 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
295
296 /**
297 * Call is able to be individually disconnected when in a {@code Conference}.
298 */
299 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
300
301 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500302 * Speed up audio setup for MT call.
303 * @hide
304 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700305 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
306
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700307 /**
308 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700309 * @hide
310 */
311 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
312
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700313 /**
314 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700315 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700316 */
317 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
318
Bryce Lee81901682015-08-28 16:38:02 -0700319 /**
320 * Call sends responses through connection.
321 * @hide
322 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800323 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
324
325 /**
326 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
327 * <p>
328 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
329 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
330 * downgraded from a video call back to a VideoState of
331 * {@link VideoProfile#STATE_AUDIO_ONLY}.
332 * <p>
333 * Intuitively, a call which can be downgraded to audio should also have local and remote
334 * video
335 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
336 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
337 */
338 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700339
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700340 /**
341 * When set for an external call, indicates that this {@code Call} can be pulled from a
342 * remote device to the current device.
343 * <p>
344 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
345 * <p>
346 * An {@link InCallService} will only see calls with this capability if it has the
347 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
348 * in its manifest.
349 * <p>
350 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700351 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700352 */
353 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
354
Tyler Gunnd11a3152015-03-18 13:09:14 -0700355 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700356 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700357 //******************************************************************************************
358
359 /**
360 * Whether the call is currently a conference.
361 */
362 public static final int PROPERTY_CONFERENCE = 0x00000001;
363
364 /**
365 * Whether the call is a generic conference, where we do not know the precise state of
366 * participants in the conference (eg. on CDMA).
367 */
368 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
369
370 /**
371 * Whether the call is made while the device is in emergency callback mode.
372 */
373 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
374
375 /**
376 * Connection is using WIFI.
377 */
378 public static final int PROPERTY_WIFI = 0x00000008;
379
380 /**
381 * Call is using high definition audio.
382 */
383 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
384
Tony Maka68dcce2015-12-17 09:31:18 +0000385 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100386 * Whether the call is associated with the work profile.
387 */
388 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
389
390 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700391 * When set, indicates that this {@code Call} does not actually exist locally for the
392 * {@link ConnectionService}.
393 * <p>
394 * Consider, for example, a scenario where a user has two phones with the same phone number.
395 * When a user places a call on one device, the telephony stack can represent that call on
396 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700397 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700398 * <p>
399 * An {@link InCallService} will only see calls with this property if it has the
400 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
401 * in its manifest.
402 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700403 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700404 */
405 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
406
Brad Ebinger15847072016-05-18 11:08:36 -0700407 /**
408 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
409 */
410 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
411
Tyler Gunn24e18332017-02-10 09:42:49 -0800412 /**
413 * Indicates that the call is from a self-managed {@link ConnectionService}.
414 * <p>
415 * See also {@link Connection#PROPERTY_SELF_MANAGED}
416 */
417 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
418
Andrew Lee2378ea72015-04-29 14:38:11 -0700419 //******************************************************************************************
Tyler Gunn24e18332017-02-10 09:42:49 -0800420 // Next PROPERTY value: 0x00000200
Tyler Gunnd11a3152015-03-18 13:09:14 -0700421 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800422
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800423 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700424 private final Uri mHandle;
425 private final int mHandlePresentation;
426 private final String mCallerDisplayName;
427 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700428 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700429 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700430 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800431 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700432 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700433 private final long mConnectTimeMillis;
434 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700435 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700436 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700437 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700438 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700439 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700440
441 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800442 * Whether the supplied capabilities supports the specified capability.
443 *
444 * @param capabilities A bit field of capabilities.
445 * @param capability The capability to check capabilities for.
446 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800447 */
448 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800449 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800450 }
451
452 /**
453 * Whether the capabilities of this {@code Details} supports the specified capability.
454 *
455 * @param capability The capability to check capabilities for.
456 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800457 */
458 public boolean can(int capability) {
459 return can(mCallCapabilities, capability);
460 }
461
462 /**
463 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
464 *
465 * @param capabilities A capability bit field.
466 * @return A human readable string representation.
467 */
468 public static String capabilitiesToString(int capabilities) {
469 StringBuilder builder = new StringBuilder();
470 builder.append("[Capabilities:");
471 if (can(capabilities, CAPABILITY_HOLD)) {
472 builder.append(" CAPABILITY_HOLD");
473 }
474 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
475 builder.append(" CAPABILITY_SUPPORT_HOLD");
476 }
477 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
478 builder.append(" CAPABILITY_MERGE_CONFERENCE");
479 }
480 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
481 builder.append(" CAPABILITY_SWAP_CONFERENCE");
482 }
483 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
484 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
485 }
486 if (can(capabilities, CAPABILITY_MUTE)) {
487 builder.append(" CAPABILITY_MUTE");
488 }
489 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
490 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
491 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700492 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
493 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
494 }
495 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
496 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
497 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700498 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
499 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800500 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700501 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
502 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
503 }
504 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
505 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
506 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800507 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
508 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
509 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700510 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
511 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800512 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500513 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700514 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500515 }
Rekha Kumar07366812015-03-24 16:42:31 -0700516 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
517 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
518 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700519 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
520 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
521 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700522 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
523 builder.append(" CAPABILITY_CAN_PULL_CALL");
524 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800525 builder.append("]");
526 return builder.toString();
527 }
528
529 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700530 * Whether the supplied properties includes the specified property.
531 *
532 * @param properties A bit field of properties.
533 * @param property The property to check properties for.
534 * @return Whether the specified property is supported.
535 */
536 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800537 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700538 }
539
540 /**
541 * Whether the properties of this {@code Details} includes the specified property.
542 *
543 * @param property The property to check properties for.
544 * @return Whether the specified property is supported.
545 */
546 public boolean hasProperty(int property) {
547 return hasProperty(mCallProperties, property);
548 }
549
550 /**
551 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
552 *
553 * @param properties A property bit field.
554 * @return A human readable string representation.
555 */
556 public static String propertiesToString(int properties) {
557 StringBuilder builder = new StringBuilder();
558 builder.append("[Properties:");
559 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
560 builder.append(" PROPERTY_CONFERENCE");
561 }
562 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
563 builder.append(" PROPERTY_GENERIC_CONFERENCE");
564 }
565 if (hasProperty(properties, PROPERTY_WIFI)) {
566 builder.append(" PROPERTY_WIFI");
567 }
568 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
569 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
570 }
571 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700572 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700573 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700574 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
575 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
576 }
Brad Ebinger15847072016-05-18 11:08:36 -0700577 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
578 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
579 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700580 builder.append("]");
581 return builder.toString();
582 }
583
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800584 /** {@hide} */
585 public String getTelecomCallId() {
586 return mTelecomCallId;
587 }
588
Andrew Lee2378ea72015-04-29 14:38:11 -0700589 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700590 * @return The handle (e.g., phone number) to which the {@code Call} is currently
591 * connected.
592 */
593 public Uri getHandle() {
594 return mHandle;
595 }
596
597 /**
598 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700599 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700600 */
601 public int getHandlePresentation() {
602 return mHandlePresentation;
603 }
604
605 /**
606 * @return The display name for the caller.
607 */
608 public String getCallerDisplayName() {
609 return mCallerDisplayName;
610 }
611
612 /**
613 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700614 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700615 */
616 public int getCallerDisplayNamePresentation() {
617 return mCallerDisplayNamePresentation;
618 }
619
620 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700621 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
622 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700623 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700624 public PhoneAccountHandle getAccountHandle() {
625 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700626 }
627
628 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800629 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
630 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700631 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700632 public int getCallCapabilities() {
633 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700634 }
635
636 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700637 * @return A bitmask of the properties of the {@code Call}, as defined by the various
638 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700639 */
640 public int getCallProperties() {
641 return mCallProperties;
642 }
643
644 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800645 * @return a bitmask of the audio routes available for the call.
646 *
647 * @hide
648 */
649 public int getSupportedAudioRoutes() {
650 return mSupportedAudioRoutes;
651 }
652
653 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700654 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700655 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700656 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700657 public DisconnectCause getDisconnectCause() {
658 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700659 }
660
661 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700662 * Returns the time the {@link Call} connected (i.e. became active). This information is
663 * updated periodically, but user interfaces should not rely on this to display the "call
664 * time clock". For the time when the call was first added to Telecom, see
665 * {@link #getCreationTimeMillis()}.
666 *
667 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700668 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700669 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700670 return mConnectTimeMillis;
671 }
672
673 /**
674 * @return Information about any calling gateway the {@code Call} may be using.
675 */
676 public GatewayInfo getGatewayInfo() {
677 return mGatewayInfo;
678 }
679
Andrew Lee7a341382014-07-15 17:05:08 -0700680 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700681 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700682 */
683 public int getVideoState() {
684 return mVideoState;
685 }
686
Ihab Awad5d0410f2014-07-30 10:07:40 -0700687 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700688 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700689 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700690 */
691 public StatusHints getStatusHints() {
692 return mStatusHints;
693 }
694
Nancy Chen10798dc2014-08-08 14:00:25 -0700695 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700696 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700697 */
698 public Bundle getExtras() {
699 return mExtras;
700 }
701
Santos Cordon6b7f9552015-05-27 17:21:45 -0700702 /**
703 * @return The extras used with the original intent to place this call.
704 */
705 public Bundle getIntentExtras() {
706 return mIntentExtras;
707 }
708
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700709 /**
710 * Returns the time when the call was first created and added to Telecom. This is the same
711 * time that is logged as the start time in the Call Log (see
712 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
713 * (became active), see {@link #getConnectTimeMillis()}.
714 *
715 * @return The creation time of the call, in millis since the epoch.
716 */
717 public long getCreationTimeMillis() {
718 return mCreationTimeMillis;
719 }
720
Ihab Awade63fadb2014-07-09 21:52:04 -0700721 @Override
722 public boolean equals(Object o) {
723 if (o instanceof Details) {
724 Details d = (Details) o;
725 return
726 Objects.equals(mHandle, d.mHandle) &&
727 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
728 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
729 Objects.equals(mCallerDisplayNamePresentation,
730 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700731 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700732 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700733 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700734 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700735 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700736 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700737 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700738 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700739 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700740 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
741 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700742 }
743 return false;
744 }
745
746 @Override
747 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700748 return Objects.hash(mHandle,
749 mHandlePresentation,
750 mCallerDisplayName,
751 mCallerDisplayNamePresentation,
752 mAccountHandle,
753 mCallCapabilities,
754 mCallProperties,
755 mDisconnectCause,
756 mConnectTimeMillis,
757 mGatewayInfo,
758 mVideoState,
759 mStatusHints,
760 mExtras,
761 mIntentExtras,
762 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700763 }
764
765 /** {@hide} */
766 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800767 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700768 Uri handle,
769 int handlePresentation,
770 String callerDisplayName,
771 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700772 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700773 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700774 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700775 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700776 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700777 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700778 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700779 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700780 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700781 Bundle intentExtras,
782 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800783 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700784 mHandle = handle;
785 mHandlePresentation = handlePresentation;
786 mCallerDisplayName = callerDisplayName;
787 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700788 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700789 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700790 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700791 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700792 mConnectTimeMillis = connectTimeMillis;
793 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700794 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700795 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700796 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700797 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700798 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700799 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800800
801 /** {@hide} */
802 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
803 return new Details(
804 parcelableCall.getId(),
805 parcelableCall.getHandle(),
806 parcelableCall.getHandlePresentation(),
807 parcelableCall.getCallerDisplayName(),
808 parcelableCall.getCallerDisplayNamePresentation(),
809 parcelableCall.getAccountHandle(),
810 parcelableCall.getCapabilities(),
811 parcelableCall.getProperties(),
812 parcelableCall.getDisconnectCause(),
813 parcelableCall.getConnectTimeMillis(),
814 parcelableCall.getGatewayInfo(),
815 parcelableCall.getVideoState(),
816 parcelableCall.getStatusHints(),
817 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700818 parcelableCall.getIntentExtras(),
819 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800820 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800821
822 @Override
823 public String toString() {
824 StringBuilder sb = new StringBuilder();
825 sb.append("[pa: ");
826 sb.append(mAccountHandle);
827 sb.append(", hdl: ");
828 sb.append(Log.pii(mHandle));
829 sb.append(", caps: ");
830 sb.append(capabilitiesToString(mCallCapabilities));
831 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700832 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800833 sb.append("]");
834 return sb.toString();
835 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700836 }
837
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700838 /**
839 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
840 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
841 * implementation.
842 * <p>
843 * You can handle these callbacks by extending the {@link Callback} class and overriding the
844 * callbacks that your {@link InCallService} is interested in. The callback methods include the
845 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
846 * {@link Callback} implementation, if desired.
847 * <p>
848 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
849 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
850 * (typically in {@link InCallService#onCallRemoved(Call)}).
851 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
852 * reach your implementation of {@link Callback}, so it is important to register your callback
853 * as soon as your {@link InCallService} is notified of a new call via
854 * {@link InCallService#onCallAdded(Call)}.
855 */
Andrew Leeda80c872015-04-15 14:09:50 -0700856 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700857 /**
858 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
859 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700860 * @param call The {@code Call} invoking this method.
861 * @param state The new state of the {@code Call}.
862 */
863 public void onStateChanged(Call call, int state) {}
864
865 /**
866 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
867 *
868 * @param call The {@code Call} invoking this method.
869 * @param parent The new parent of the {@code Call}.
870 */
871 public void onParentChanged(Call call, Call parent) {}
872
873 /**
874 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
875 *
876 * @param call The {@code Call} invoking this method.
877 * @param children The new children of the {@code Call}.
878 */
879 public void onChildrenChanged(Call call, List<Call> children) {}
880
881 /**
882 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
883 *
884 * @param call The {@code Call} invoking this method.
885 * @param details A {@code Details} object describing the {@code Call}.
886 */
887 public void onDetailsChanged(Call call, Details details) {}
888
889 /**
890 * Invoked when the text messages that can be used as responses to the incoming
891 * {@code Call} are loaded from the relevant database.
892 * See {@link #getCannedTextResponses()}.
893 *
894 * @param call The {@code Call} invoking this method.
895 * @param cannedTextResponses The text messages useable as responses.
896 */
897 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
898
899 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700900 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
901 * character. This causes the post-dial signals to stop pending user confirmation. An
902 * implementation should present this choice to the user and invoke
903 * {@link #postDialContinue(boolean)} when the user makes the choice.
904 *
905 * @param call The {@code Call} invoking this method.
906 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
907 */
908 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
909
910 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700911 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700912 *
913 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700914 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700915 */
Andrew Lee50aca232014-07-22 16:41:54 -0700916 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700917
918 /**
919 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
920 * up their UI for the {@code Call} in response to state transitions. Specifically,
921 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
922 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
923 * clients should wait for this method to be invoked.
924 *
925 * @param call The {@code Call} being destroyed.
926 */
927 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700928
929 /**
930 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
931 * conferenced.
932 *
933 * @param call The {@code Call} being updated.
934 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
935 * conferenced.
936 */
937 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700938
939 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700940 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
941 * <p>
942 * Where possible, the Call should make an attempt to handle {@link Connection} events which
943 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
944 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
945 * possible that a {@link ConnectionService} has defined its own Connection events which a
946 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700947 * <p>
948 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
949 *
950 * @param call The {@code Call} receiving the event.
951 * @param event The event.
952 * @param extras Extras associated with the connection event.
953 */
954 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -0800955
956 /**
957 * Invoked when the RTT mode changes for this call.
958 * @param call The call whose RTT mode has changed.
959 * @param mode the new RTT mode, one of
960 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
961 * or {@link RttCall#RTT_MODE_VCO}
962 */
963 public void onRttModeChanged(Call call, int mode) {}
964
965 /**
966 * Invoked when the call's RTT status changes, either from off to on or from on to off.
967 * @param call The call whose RTT status has changed.
968 * @param enabled whether RTT is now enabled or disabled
969 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
970 * on, null otherwise.
971 */
972 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
973
974 /**
975 * Invoked when the remote end of the connection has requested that an RTT communication
976 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
977 * with the same ID that this method is invoked with.
978 * @param call The call which the RTT request was placed on
979 * @param id The ID of the request.
980 */
981 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -0800982
983 /**
984 * Invoked when the RTT session failed to initiate for some reason, including rejection
985 * by the remote party.
986 * @param call The call which the RTT initiation failure occurred on.
987 * @param reason One of the status codes defined in
988 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
989 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
990 */
991 public void onRttInitiationFailure(Call call, int reason) {}
Hall Liu95d55872017-01-25 17:12:49 -0800992 }
993
994 /**
995 * A class that holds the state that describes the state of the RTT channel to the remote
996 * party, if it is active.
997 */
998 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -0800999 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -08001000 @Retention(RetentionPolicy.SOURCE)
1001 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1002 public @interface RttAudioMode {}
1003
1004 /**
1005 * For metrics use. Default value in the proto.
1006 * @hide
1007 */
1008 public static final int RTT_MODE_INVALID = 0;
1009
1010 /**
1011 * Indicates that there should be a bidirectional audio stream between the two parties
1012 * on the call.
1013 */
1014 public static final int RTT_MODE_FULL = 1;
1015
1016 /**
1017 * Indicates that the local user should be able to hear the audio stream from the remote
1018 * user, but not vice versa. Equivalent to muting the microphone.
1019 */
1020 public static final int RTT_MODE_HCO = 2;
1021
1022 /**
1023 * Indicates that the remote user should be able to hear the audio stream from the local
1024 * user, but not vice versa. Equivalent to setting the volume to zero.
1025 */
1026 public static final int RTT_MODE_VCO = 3;
1027
1028 private static final int READ_BUFFER_SIZE = 1000;
1029
1030 private InputStreamReader mReceiveStream;
1031 private OutputStreamWriter mTransmitStream;
1032 private int mRttMode;
1033 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -08001034 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001035 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1036
1037 /**
1038 * @hide
1039 */
Hall Liu57006aa2017-02-06 10:49:48 -08001040 public RttCall(String telecomCallId, InputStreamReader receiveStream,
1041 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1042 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -08001043 mReceiveStream = receiveStream;
1044 mTransmitStream = transmitStream;
1045 mRttMode = mode;
1046 mInCallAdapter = inCallAdapter;
1047 }
1048
1049 /**
1050 * Returns the current RTT audio mode.
1051 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1052 * {@link #RTT_MODE_HCO}.
1053 */
1054 public int getRttAudioMode() {
1055 return mRttMode;
1056 }
1057
1058 /**
1059 * Sets the RTT audio mode. The requested mode change will be communicated through
1060 * {@link Callback#onRttModeChanged(Call, int)}.
1061 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1062 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1063 */
1064 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -08001065 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -08001066 }
1067
1068 /**
1069 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1070 * RTT transmits text in real-time, this method should be called once for each character
1071 * the user enters into the device.
1072 *
1073 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1074 * lead to interleaved text.
1075 * @param input The message to send to the remote user.
1076 */
1077 public void write(String input) throws IOException {
1078 mTransmitStream.write(input);
1079 mTransmitStream.flush();
1080 }
1081
1082 /**
1083 * Reads a string from the remote user, blocking if there is no data available. Returns
1084 * {@code null} if the RTT conversation has been terminated and there is no further data
1085 * to read.
1086 *
1087 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1088 * lead to interleaved text.
1089 * @return A string containing text sent by the remote user, or {@code null} if the
1090 * conversation has been terminated or if there was an error while reading.
1091 */
Hall Liub1c8a772017-07-17 17:04:41 -07001092 public String read() {
1093 try {
1094 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1095 if (numRead < 0) {
1096 return null;
1097 }
1098 return new String(mReadBuffer, 0, numRead);
1099 } catch (IOException e) {
1100 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
Jeff Sharkey90396362017-06-12 16:26:53 -06001101 return null;
Hall Liuffa4a812017-03-02 16:11:00 -08001102 }
Hall Liuffa4a812017-03-02 16:11:00 -08001103 }
1104
1105 /**
1106 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1107 * be read.
1108 * @return A string containing text entered by the user, or {@code null} if the user has
1109 * not entered any new text yet.
1110 */
1111 public String readImmediately() throws IOException {
1112 if (mReceiveStream.ready()) {
Hall Liub1c8a772017-07-17 17:04:41 -07001113 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1114 if (numRead < 0) {
1115 return null;
1116 }
1117 return new String(mReadBuffer, 0, numRead);
Hall Liuffa4a812017-03-02 16:11:00 -08001118 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001119 return null;
1120 }
1121 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001122 }
1123
Andrew Leeda80c872015-04-15 14:09:50 -07001124 /**
1125 * @deprecated Use {@code Call.Callback} instead.
1126 * @hide
1127 */
1128 @Deprecated
1129 @SystemApi
1130 public static abstract class Listener extends Callback { }
1131
Ihab Awade63fadb2014-07-09 21:52:04 -07001132 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001133 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001134 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001135 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001136 private final List<Call> mChildren = new ArrayList<>();
1137 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001138 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001139 private final List<Call> mConferenceableCalls = new ArrayList<>();
1140 private final List<Call> mUnmodifiableConferenceableCalls =
1141 Collections.unmodifiableList(mConferenceableCalls);
1142
Santos Cordon823fd3c2014-08-07 18:35:18 -07001143 private boolean mChildrenCached;
1144 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001145 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001146 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001147 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001148 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001149 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001150 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001151 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001152 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001153 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001154
1155 /**
1156 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1157 *
1158 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1159 * remaining or this {@code Call} is not in a post-dial state.
1160 */
1161 public String getRemainingPostDialSequence() {
1162 return mRemainingPostDialSequence;
1163 }
1164
1165 /**
1166 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001167 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001168 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001169 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001170 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001171 }
1172
1173 /**
1174 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1175 *
1176 * @param rejectWithMessage Whether to reject with a text message.
1177 * @param textMessage An optional text message with which to respond.
1178 */
1179 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001180 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001181 }
1182
1183 /**
1184 * Instructs this {@code Call} to disconnect.
1185 */
1186 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001187 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001188 }
1189
1190 /**
1191 * Instructs this {@code Call} to go on hold.
1192 */
1193 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001194 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001195 }
1196
1197 /**
1198 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1199 */
1200 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001201 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001202 }
1203
1204 /**
1205 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1206 *
1207 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1208 *
1209 * @param digit A character representing the DTMF digit for which to play the tone. This
1210 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1211 */
1212 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001213 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001214 }
1215
1216 /**
1217 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1218 * currently playing.
1219 *
1220 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1221 * currently playing, this method will do nothing.
1222 */
1223 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001224 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001225 }
1226
1227 /**
1228 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1229 *
1230 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1231 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001232 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001233 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001234 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1235 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001236 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001237 * {@code Call} will pause playing the tones and notify callbacks via
1238 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001239 * should display to the user an indication of this state and an affordance to continue
1240 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1241 * app should invoke the {@link #postDialContinue(boolean)} method.
1242 *
1243 * @param proceed Whether or not to continue with the post-dial sequence.
1244 */
1245 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001246 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001247 }
1248
1249 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001250 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001251 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001252 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001253 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1254 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001255
1256 }
1257
1258 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001259 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001260 *
1261 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001262 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001263 public void conference(Call callToConferenceWith) {
1264 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001265 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001266 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001267 }
1268
1269 /**
1270 * Instructs this {@code Call} to split from any conference call with which it may be
1271 * connected.
1272 */
1273 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001274 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001275 }
1276
1277 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001278 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001279 */
1280 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001281 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001282 }
1283
1284 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001285 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001286 */
1287 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001288 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001289 }
1290
1291 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001292 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1293 * device.
1294 * <p>
1295 * Calls to this method are ignored if the call does not have the
1296 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1297 * <p>
1298 * An {@link InCallService} will only see calls which support this method if it has the
1299 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1300 * in its manifest.
1301 */
1302 public void pullExternalCall() {
1303 // If this isn't an external call, ignore the request.
1304 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1305 return;
1306 }
1307
1308 mInCallAdapter.pullExternalCall(mTelecomCallId);
1309 }
1310
1311 /**
1312 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1313 * the {@link ConnectionService}.
1314 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001315 * Call events are used to communicate point in time information from an {@link InCallService}
1316 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1317 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1318 * {@link ConnectionService}.
1319 * <p>
1320 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1321 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1322 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001323 * Events are exposed to {@link ConnectionService} implementations via
1324 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1325 * <p>
1326 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001327 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1328 * ignore some events altogether.
1329 * <p>
1330 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1331 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1332 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1333 * they define their own event types in this namespace. When defining a custom event type,
1334 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1335 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1336 * <p>
1337 * When defining events and the associated extras, it is important to keep their behavior
1338 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1339 * events/extras should me maintained to ensure backwards compatibility with older
1340 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001341 *
1342 * @param event The connection event.
1343 * @param extras Bundle containing extra information associated with the event.
1344 */
1345 public void sendCallEvent(String event, Bundle extras) {
1346 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1347 }
1348
1349 /**
Hall Liu95d55872017-01-25 17:12:49 -08001350 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1351 * guaranteed, and notification of success will be via the
1352 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1353 */
1354 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001355 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001356 }
1357
1358 /**
1359 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1360 * callback.
1361 * The ID used here should be the same as the ID that was received via the callback.
1362 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1363 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1364 */
1365 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001366 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001367 }
1368
1369 /**
1370 * Terminate the RTT session on this call. The resulting state change will be notified via
1371 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1372 */
1373 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001374 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001375 }
1376
1377 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001378 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1379 * added.
1380 * <p>
1381 * No assumptions should be made as to how an In-Call UI or service will handle these
1382 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1383 *
1384 * @param extras The extras to add.
1385 */
1386 public final void putExtras(Bundle extras) {
1387 if (extras == null) {
1388 return;
1389 }
1390
1391 if (mExtras == null) {
1392 mExtras = new Bundle();
1393 }
1394 mExtras.putAll(extras);
1395 mInCallAdapter.putExtras(mTelecomCallId, extras);
1396 }
1397
1398 /**
1399 * Adds a boolean extra to this {@link Call}.
1400 *
1401 * @param key The extra key.
1402 * @param value The value.
1403 * @hide
1404 */
1405 public final void putExtra(String key, boolean value) {
1406 if (mExtras == null) {
1407 mExtras = new Bundle();
1408 }
1409 mExtras.putBoolean(key, value);
1410 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1411 }
1412
1413 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001414 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001415 *
1416 * @param key The extra key.
1417 * @param value The value.
1418 * @hide
1419 */
1420 public final void putExtra(String key, int value) {
1421 if (mExtras == null) {
1422 mExtras = new Bundle();
1423 }
1424 mExtras.putInt(key, value);
1425 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1426 }
1427
1428 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001429 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001430 *
1431 * @param key The extra key.
1432 * @param value The value.
1433 * @hide
1434 */
1435 public final void putExtra(String key, String value) {
1436 if (mExtras == null) {
1437 mExtras = new Bundle();
1438 }
1439 mExtras.putString(key, value);
1440 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1441 }
1442
1443 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001444 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001445 *
1446 * @param keys The keys of the extras to remove.
1447 */
1448 public final void removeExtras(List<String> keys) {
1449 if (mExtras != null) {
1450 for (String key : keys) {
1451 mExtras.remove(key);
1452 }
1453 if (mExtras.size() == 0) {
1454 mExtras = null;
1455 }
1456 }
1457 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1458 }
1459
1460 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001461 * Removes extras from this {@link Call}.
1462 *
1463 * @param keys The keys of the extras to remove.
1464 */
1465 public final void removeExtras(String ... keys) {
1466 removeExtras(Arrays.asList(keys));
1467 }
1468
1469 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001470 * Obtains the parent of this {@code Call} in a conference, if any.
1471 *
1472 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1473 * child of any conference {@code Call}s.
1474 */
1475 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001476 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001477 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001478 }
1479 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001480 }
1481
1482 /**
1483 * Obtains the children of this conference {@code Call}, if any.
1484 *
1485 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1486 * {@code List} otherwise.
1487 */
1488 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001489 if (!mChildrenCached) {
1490 mChildrenCached = true;
1491 mChildren.clear();
1492
1493 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001494 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001495 if (call == null) {
1496 // At least one child was still not found, so do not save true for "cached"
1497 mChildrenCached = false;
1498 } else {
1499 mChildren.add(call);
1500 }
1501 }
1502 }
1503
Ihab Awade63fadb2014-07-09 21:52:04 -07001504 return mUnmodifiableChildren;
1505 }
1506
1507 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001508 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1509 *
1510 * @return The list of conferenceable {@code Call}s.
1511 */
1512 public List<Call> getConferenceableCalls() {
1513 return mUnmodifiableConferenceableCalls;
1514 }
1515
1516 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001517 * Obtains the state of this {@code Call}.
1518 *
1519 * @return A state value, chosen from the {@code STATE_*} constants.
1520 */
1521 public int getState() {
1522 return mState;
1523 }
1524
1525 /**
1526 * Obtains a list of canned, pre-configured message responses to present to the user as
1527 * ways of rejecting this {@code Call} using via a text message.
1528 *
1529 * @see #reject(boolean, String)
1530 *
1531 * @return A list of canned text message responses.
1532 */
1533 public List<String> getCannedTextResponses() {
1534 return mCannedTextResponses;
1535 }
1536
1537 /**
1538 * Obtains an object that can be used to display video from this {@code Call}.
1539 *
Andrew Lee50aca232014-07-22 16:41:54 -07001540 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001541 */
Andrew Lee50aca232014-07-22 16:41:54 -07001542 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001543 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001544 }
1545
1546 /**
1547 * Obtains an object containing call details.
1548 *
1549 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1550 * result may be {@code null}.
1551 */
1552 public Details getDetails() {
1553 return mDetails;
1554 }
1555
1556 /**
Hall Liu95d55872017-01-25 17:12:49 -08001557 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1558 * receive RTT text data, as well as to change the RTT mode.
1559 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1560 */
1561 public @Nullable RttCall getRttCall() {
1562 return mRttCall;
1563 }
1564
1565 /**
1566 * Returns whether this call has an active RTT connection.
1567 * @return true if there is a connection, false otherwise.
1568 */
1569 public boolean isRttActive() {
1570 return mRttCall != null;
1571 }
1572
1573 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001574 * Registers a callback to this {@code Call}.
1575 *
1576 * @param callback A {@code Callback}.
1577 */
1578 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001579 registerCallback(callback, new Handler());
1580 }
1581
1582 /**
1583 * Registers a callback to this {@code Call}.
1584 *
1585 * @param callback A {@code Callback}.
1586 * @param handler A handler which command and status changes will be delivered to.
1587 */
1588 public void registerCallback(Callback callback, Handler handler) {
1589 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001590 // Don't allow new callback registration if the call is already being destroyed.
1591 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001592 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1593 }
Andrew Leeda80c872015-04-15 14:09:50 -07001594 }
1595
1596 /**
1597 * Unregisters a callback from this {@code Call}.
1598 *
1599 * @param callback A {@code Callback}.
1600 */
1601 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001602 // Don't allow callback deregistration if the call is already being destroyed.
1603 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001604 for (CallbackRecord<Callback> record : mCallbackRecords) {
1605 if (record.getCallback() == callback) {
1606 mCallbackRecords.remove(record);
1607 break;
1608 }
1609 }
Andrew Leeda80c872015-04-15 14:09:50 -07001610 }
1611 }
1612
Santos Cordon3c20d632016-02-25 16:12:35 -08001613 @Override
1614 public String toString() {
1615 return new StringBuilder().
1616 append("Call [id: ").
1617 append(mTelecomCallId).
1618 append(", state: ").
1619 append(stateToString(mState)).
1620 append(", details: ").
1621 append(mDetails).
1622 append("]").toString();
1623 }
1624
1625 /**
1626 * @param state An integer value of a {@code STATE_*} constant.
1627 * @return A string representation of the value.
1628 */
1629 private static String stateToString(int state) {
1630 switch (state) {
1631 case STATE_NEW:
1632 return "NEW";
1633 case STATE_RINGING:
1634 return "RINGING";
1635 case STATE_DIALING:
1636 return "DIALING";
1637 case STATE_ACTIVE:
1638 return "ACTIVE";
1639 case STATE_HOLDING:
1640 return "HOLDING";
1641 case STATE_DISCONNECTED:
1642 return "DISCONNECTED";
1643 case STATE_CONNECTING:
1644 return "CONNECTING";
1645 case STATE_DISCONNECTING:
1646 return "DISCONNECTING";
1647 case STATE_SELECT_PHONE_ACCOUNT:
1648 return "SELECT_PHONE_ACCOUNT";
1649 default:
1650 Log.w(Call.class, "Unknown state %d", state);
1651 return "UNKNOWN";
1652 }
1653 }
1654
Andrew Leeda80c872015-04-15 14:09:50 -07001655 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001656 * Adds a listener to this {@code Call}.
1657 *
1658 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001659 * @deprecated Use {@link #registerCallback} instead.
1660 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001661 */
Andrew Leeda80c872015-04-15 14:09:50 -07001662 @Deprecated
1663 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001664 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001665 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001666 }
1667
1668 /**
1669 * Removes a listener from this {@code Call}.
1670 *
1671 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001672 * @deprecated Use {@link #unregisterCallback} instead.
1673 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001674 */
Andrew Leeda80c872015-04-15 14:09:50 -07001675 @Deprecated
1676 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001677 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001678 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001679 }
1680
1681 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001682 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1683 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001684 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001685 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001686 mInCallAdapter = inCallAdapter;
1687 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001688 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001689 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001690 }
1691
1692 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001693 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001694 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001695 mPhone = phone;
1696 mTelecomCallId = telecomCallId;
1697 mInCallAdapter = inCallAdapter;
1698 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001699 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001700 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001701 }
1702
1703 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001704 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001705 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001706 }
1707
1708 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001709 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001710
Ihab Awade63fadb2014-07-09 21:52:04 -07001711 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001712 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001713 boolean detailsChanged = !Objects.equals(mDetails, details);
1714 if (detailsChanged) {
1715 mDetails = details;
1716 }
1717
1718 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001719 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1720 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1721 mCannedTextResponses =
1722 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001723 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001724 }
1725
Tyler Gunn159f35c2017-03-02 09:28:37 -08001726 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1727 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001728 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001729 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001730 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001731 mVideoCallImpl = newVideoCallImpl;
1732 }
1733 if (mVideoCallImpl != null) {
1734 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001735 }
1736
Santos Cordone3c507b2015-04-23 14:44:19 -07001737 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001738 boolean stateChanged = mState != state;
1739 if (stateChanged) {
1740 mState = state;
1741 }
1742
Santos Cordon823fd3c2014-08-07 18:35:18 -07001743 String parentId = parcelableCall.getParentCallId();
1744 boolean parentChanged = !Objects.equals(mParentId, parentId);
1745 if (parentChanged) {
1746 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001747 }
1748
Santos Cordon823fd3c2014-08-07 18:35:18 -07001749 List<String> childCallIds = parcelableCall.getChildCallIds();
1750 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1751 if (childrenChanged) {
1752 mChildrenIds.clear();
1753 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1754 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001755 }
1756
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001757 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1758 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1759 for (String otherId : conferenceableCallIds) {
1760 if (callIdMap.containsKey(otherId)) {
1761 conferenceableCalls.add(callIdMap.get(otherId));
1762 }
1763 }
1764
1765 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1766 mConferenceableCalls.clear();
1767 mConferenceableCalls.addAll(conferenceableCalls);
1768 fireConferenceableCallsChanged();
1769 }
1770
Hall Liu95d55872017-01-25 17:12:49 -08001771 boolean isRttChanged = false;
1772 boolean rttModeChanged = false;
1773 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1774 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1775 InputStreamReader receiveStream = new InputStreamReader(
1776 new ParcelFileDescriptor.AutoCloseInputStream(
1777 parcelableRttCall.getReceiveStream()),
1778 StandardCharsets.UTF_8);
1779 OutputStreamWriter transmitStream = new OutputStreamWriter(
1780 new ParcelFileDescriptor.AutoCloseOutputStream(
1781 parcelableRttCall.getTransmitStream()),
1782 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08001783 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08001784 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1785 if (mRttCall == null) {
1786 isRttChanged = true;
1787 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1788 rttModeChanged = true;
1789 }
1790 mRttCall = newRttCall;
1791 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1792 && parcelableCall.getIsRttCallChanged()) {
1793 isRttChanged = true;
1794 mRttCall = null;
1795 }
1796
Ihab Awade63fadb2014-07-09 21:52:04 -07001797 // Now we fire updates, ensuring that any client who listens to any of these notifications
1798 // gets the most up-to-date state.
1799
1800 if (stateChanged) {
1801 fireStateChanged(mState);
1802 }
1803 if (detailsChanged) {
1804 fireDetailsChanged(mDetails);
1805 }
1806 if (cannedTextResponsesChanged) {
1807 fireCannedTextResponsesLoaded(mCannedTextResponses);
1808 }
Andrew Lee50aca232014-07-22 16:41:54 -07001809 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001810 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001811 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001812 if (parentChanged) {
1813 fireParentChanged(getParent());
1814 }
1815 if (childrenChanged) {
1816 fireChildrenChanged(getChildren());
1817 }
Hall Liu95d55872017-01-25 17:12:49 -08001818 if (isRttChanged) {
1819 fireOnIsRttChanged(mRttCall != null, mRttCall);
1820 }
1821 if (rttModeChanged) {
1822 fireOnRttModeChanged(mRttCall.getRttAudioMode());
1823 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001824
1825 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1826 // remove ourselves from the Phone. Note that we do this after completing all state updates
1827 // so a client can cleanly transition all their UI to the state appropriate for a
1828 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1829 if (mState == STATE_DISCONNECTED) {
1830 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001831 }
1832 }
1833
1834 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001835 final void internalSetPostDialWait(String remaining) {
1836 mRemainingPostDialSequence = remaining;
1837 firePostDialWait(mRemainingPostDialSequence);
1838 }
1839
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001840 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001841 final void internalSetDisconnected() {
1842 if (mState != Call.STATE_DISCONNECTED) {
1843 mState = Call.STATE_DISCONNECTED;
1844 fireStateChanged(mState);
1845 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001846 }
1847 }
1848
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001849 /** {@hide} */
1850 final void internalOnConnectionEvent(String event, Bundle extras) {
1851 fireOnConnectionEvent(event, extras);
1852 }
1853
Hall Liu95d55872017-01-25 17:12:49 -08001854 /** {@hide} */
1855 final void internalOnRttUpgradeRequest(final int requestId) {
1856 for (CallbackRecord<Callback> record : mCallbackRecords) {
1857 final Call call = this;
1858 final Callback callback = record.getCallback();
1859 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
1860 }
1861 }
1862
Hall Liu57006aa2017-02-06 10:49:48 -08001863 /** @hide */
1864 final void internalOnRttInitiationFailure(int reason) {
1865 for (CallbackRecord<Callback> record : mCallbackRecords) {
1866 final Call call = this;
1867 final Callback callback = record.getCallback();
1868 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
1869 }
1870 }
1871
Andrew Lee011728f2015-04-23 15:47:06 -07001872 private void fireStateChanged(final int newState) {
1873 for (CallbackRecord<Callback> record : mCallbackRecords) {
1874 final Call call = this;
1875 final Callback callback = record.getCallback();
1876 record.getHandler().post(new Runnable() {
1877 @Override
1878 public void run() {
1879 callback.onStateChanged(call, newState);
1880 }
1881 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001882 }
1883 }
1884
Andrew Lee011728f2015-04-23 15:47:06 -07001885 private void fireParentChanged(final Call newParent) {
1886 for (CallbackRecord<Callback> record : mCallbackRecords) {
1887 final Call call = this;
1888 final Callback callback = record.getCallback();
1889 record.getHandler().post(new Runnable() {
1890 @Override
1891 public void run() {
1892 callback.onParentChanged(call, newParent);
1893 }
1894 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001895 }
1896 }
1897
Andrew Lee011728f2015-04-23 15:47:06 -07001898 private void fireChildrenChanged(final List<Call> children) {
1899 for (CallbackRecord<Callback> record : mCallbackRecords) {
1900 final Call call = this;
1901 final Callback callback = record.getCallback();
1902 record.getHandler().post(new Runnable() {
1903 @Override
1904 public void run() {
1905 callback.onChildrenChanged(call, children);
1906 }
1907 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001908 }
1909 }
1910
Andrew Lee011728f2015-04-23 15:47:06 -07001911 private void fireDetailsChanged(final Details details) {
1912 for (CallbackRecord<Callback> record : mCallbackRecords) {
1913 final Call call = this;
1914 final Callback callback = record.getCallback();
1915 record.getHandler().post(new Runnable() {
1916 @Override
1917 public void run() {
1918 callback.onDetailsChanged(call, details);
1919 }
1920 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001921 }
1922 }
1923
Andrew Lee011728f2015-04-23 15:47:06 -07001924 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1925 for (CallbackRecord<Callback> record : mCallbackRecords) {
1926 final Call call = this;
1927 final Callback callback = record.getCallback();
1928 record.getHandler().post(new Runnable() {
1929 @Override
1930 public void run() {
1931 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1932 }
1933 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001934 }
1935 }
1936
Andrew Lee011728f2015-04-23 15:47:06 -07001937 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1938 for (CallbackRecord<Callback> record : mCallbackRecords) {
1939 final Call call = this;
1940 final Callback callback = record.getCallback();
1941 record.getHandler().post(new Runnable() {
1942 @Override
1943 public void run() {
1944 callback.onVideoCallChanged(call, videoCall);
1945 }
1946 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001947 }
1948 }
1949
Andrew Lee011728f2015-04-23 15:47:06 -07001950 private void firePostDialWait(final String remainingPostDialSequence) {
1951 for (CallbackRecord<Callback> record : mCallbackRecords) {
1952 final Call call = this;
1953 final Callback callback = record.getCallback();
1954 record.getHandler().post(new Runnable() {
1955 @Override
1956 public void run() {
1957 callback.onPostDialWait(call, remainingPostDialSequence);
1958 }
1959 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001960 }
1961 }
1962
1963 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001964 /**
1965 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1966 * onCallRemoved callback, we remove this call from the Phone's record
1967 * only once all of the registered onCallDestroyed callbacks are executed.
1968 * All the callbacks get removed from our records as a part of this operation
1969 * since onCallDestroyed is the final callback.
1970 */
1971 final Call call = this;
1972 if (mCallbackRecords.isEmpty()) {
1973 // No callbacks registered, remove the call from Phone's record.
1974 mPhone.internalRemoveCall(call);
1975 }
1976 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001977 final Callback callback = record.getCallback();
1978 record.getHandler().post(new Runnable() {
1979 @Override
1980 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001981 boolean isFinalRemoval = false;
1982 RuntimeException toThrow = null;
1983 try {
1984 callback.onCallDestroyed(call);
1985 } catch (RuntimeException e) {
1986 toThrow = e;
1987 }
1988 synchronized(Call.this) {
1989 mCallbackRecords.remove(record);
1990 if (mCallbackRecords.isEmpty()) {
1991 isFinalRemoval = true;
1992 }
1993 }
1994 if (isFinalRemoval) {
1995 mPhone.internalRemoveCall(call);
1996 }
1997 if (toThrow != null) {
1998 throw toThrow;
1999 }
Andrew Lee011728f2015-04-23 15:47:06 -07002000 }
2001 });
Ihab Awade63fadb2014-07-09 21:52:04 -07002002 }
2003 }
2004
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002005 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07002006 for (CallbackRecord<Callback> record : mCallbackRecords) {
2007 final Call call = this;
2008 final Callback callback = record.getCallback();
2009 record.getHandler().post(new Runnable() {
2010 @Override
2011 public void run() {
2012 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2013 }
2014 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002015 }
2016 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002017
2018 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002019 * Notifies listeners of an incoming connection event.
2020 * <p>
2021 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2022 *
2023 * @param event
2024 * @param extras
2025 */
2026 private void fireOnConnectionEvent(final String event, final Bundle extras) {
2027 for (CallbackRecord<Callback> record : mCallbackRecords) {
2028 final Call call = this;
2029 final Callback callback = record.getCallback();
2030 record.getHandler().post(new Runnable() {
2031 @Override
2032 public void run() {
2033 callback.onConnectionEvent(call, event, extras);
2034 }
2035 });
2036 }
2037 }
2038
2039 /**
Hall Liu95d55872017-01-25 17:12:49 -08002040 * Notifies listeners of an RTT on/off change
2041 *
2042 * @param enabled True if RTT is now enabled, false otherwise
2043 */
2044 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2045 for (CallbackRecord<Callback> record : mCallbackRecords) {
2046 final Call call = this;
2047 final Callback callback = record.getCallback();
2048 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2049 }
2050 }
2051
2052 /**
2053 * Notifies listeners of a RTT mode change
2054 *
2055 * @param mode The new RTT mode
2056 */
2057 private void fireOnRttModeChanged(final int mode) {
2058 for (CallbackRecord<Callback> record : mCallbackRecords) {
2059 final Call call = this;
2060 final Callback callback = record.getCallback();
2061 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2062 }
2063 }
2064
2065 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07002066 * Determines if two bundles are equal.
2067 *
2068 * @param bundle The original bundle.
2069 * @param newBundle The bundle to compare with.
2070 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2071 */
2072 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2073 if (bundle == null || newBundle == null) {
2074 return bundle == newBundle;
2075 }
2076
2077 if (bundle.size() != newBundle.size()) {
2078 return false;
2079 }
2080
2081 for(String key : bundle.keySet()) {
2082 if (key != null) {
2083 final Object value = bundle.get(key);
2084 final Object newValue = newBundle.get(key);
2085 if (!Objects.equals(value, newValue)) {
2086 return false;
2087 }
2088 }
2089 }
2090 return true;
2091 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002092}