blob: b4414d5b6168062f24b9cbedc5e17948736f1d7b [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
Ihab Awade63fadb2014-07-09 21:52:04 -0700135 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800136
137 /** Call can currently be put on hold or unheld. */
138 public static final int CAPABILITY_HOLD = 0x00000001;
139
140 /** Call supports the hold feature. */
141 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
142
143 /**
144 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
145 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
146 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
147 * capability allows a merge button to be shown while the conference call is in the foreground
148 * of the in-call UI.
149 * <p>
150 * This is only intended for use by a {@link Conference}.
151 */
152 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
153
154 /**
155 * Calls within a conference can be swapped between foreground and background.
156 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
157 * <p>
158 * This is only intended for use by a {@link Conference}.
159 */
160 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
161
162 /**
163 * @hide
164 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700165 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800166
167 /** Call supports responding via text option. */
168 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
169
170 /** Call can be muted. */
171 public static final int CAPABILITY_MUTE = 0x00000040;
172
173 /**
174 * Call supports conference call management. This capability only applies to {@link Conference}
175 * calls which can have {@link Connection}s as children.
176 */
177 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
178
179 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700180 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800181 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700182 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800183
184 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700185 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800186 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700187 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800188
189 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700190 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800191 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700192 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700193 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800194
195 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700196 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800197 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700198 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
199
200 /**
201 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700202 */
203 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
204
205 /**
206 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700207 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700208 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700209 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800210
211 /**
212 * Call is able to be separated from its parent {@code Conference}, if any.
213 */
214 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
215
216 /**
217 * Call is able to be individually disconnected when in a {@code Conference}.
218 */
219 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
220
221 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500222 * Speed up audio setup for MT call.
223 * @hide
224 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700225 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
226
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700227 /**
228 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700229 * @hide
230 */
231 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
232
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700233 /**
234 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700235 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700236 */
237 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
238
Bryce Lee81901682015-08-28 16:38:02 -0700239 /**
240 * Call sends responses through connection.
241 * @hide
242 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800243 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
244
245 /**
246 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
247 * <p>
248 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
249 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
250 * downgraded from a video call back to a VideoState of
251 * {@link VideoProfile#STATE_AUDIO_ONLY}.
252 * <p>
253 * Intuitively, a call which can be downgraded to audio should also have local and remote
254 * video
255 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
256 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
257 */
258 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700259
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700260 /**
261 * When set for an external call, indicates that this {@code Call} can be pulled from a
262 * remote device to the current device.
263 * <p>
264 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
265 * <p>
266 * An {@link InCallService} will only see calls with this capability if it has the
267 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
268 * in its manifest.
269 * <p>
270 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700271 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700272 */
273 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
274
Tyler Gunnd11a3152015-03-18 13:09:14 -0700275 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700276 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700277 //******************************************************************************************
278
279 /**
280 * Whether the call is currently a conference.
281 */
282 public static final int PROPERTY_CONFERENCE = 0x00000001;
283
284 /**
285 * Whether the call is a generic conference, where we do not know the precise state of
286 * participants in the conference (eg. on CDMA).
287 */
288 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
289
290 /**
291 * Whether the call is made while the device is in emergency callback mode.
292 */
293 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
294
295 /**
296 * Connection is using WIFI.
297 */
298 public static final int PROPERTY_WIFI = 0x00000008;
299
300 /**
301 * Call is using high definition audio.
302 */
303 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
304
Tony Maka68dcce2015-12-17 09:31:18 +0000305 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100306 * Whether the call is associated with the work profile.
307 */
308 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
309
310 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700311 * When set, indicates that this {@code Call} does not actually exist locally for the
312 * {@link ConnectionService}.
313 * <p>
314 * Consider, for example, a scenario where a user has two phones with the same phone number.
315 * When a user places a call on one device, the telephony stack can represent that call on
316 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700317 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700318 * <p>
319 * An {@link InCallService} will only see calls with this property if it has the
320 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
321 * in its manifest.
322 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700323 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700324 */
325 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
326
Brad Ebinger15847072016-05-18 11:08:36 -0700327 /**
328 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
329 */
330 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
331
Tyler Gunn24e18332017-02-10 09:42:49 -0800332 /**
333 * Indicates that the call is from a self-managed {@link ConnectionService}.
334 * <p>
335 * See also {@link Connection#PROPERTY_SELF_MANAGED}
336 */
337 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
338
Andrew Lee2378ea72015-04-29 14:38:11 -0700339 //******************************************************************************************
Tyler Gunn24e18332017-02-10 09:42:49 -0800340 // Next PROPERTY value: 0x00000200
Tyler Gunnd11a3152015-03-18 13:09:14 -0700341 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800342
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800343 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700344 private final Uri mHandle;
345 private final int mHandlePresentation;
346 private final String mCallerDisplayName;
347 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700348 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700349 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700350 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800351 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700352 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700353 private final long mConnectTimeMillis;
354 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700355 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700356 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700357 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700358 private final Bundle mIntentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700359 private final long mCreationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700360
361 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800362 * Whether the supplied capabilities supports the specified capability.
363 *
364 * @param capabilities A bit field of capabilities.
365 * @param capability The capability to check capabilities for.
366 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800367 */
368 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800369 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800370 }
371
372 /**
373 * Whether the capabilities of this {@code Details} supports the specified capability.
374 *
375 * @param capability The capability to check capabilities for.
376 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800377 */
378 public boolean can(int capability) {
379 return can(mCallCapabilities, capability);
380 }
381
382 /**
383 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
384 *
385 * @param capabilities A capability bit field.
386 * @return A human readable string representation.
387 */
388 public static String capabilitiesToString(int capabilities) {
389 StringBuilder builder = new StringBuilder();
390 builder.append("[Capabilities:");
391 if (can(capabilities, CAPABILITY_HOLD)) {
392 builder.append(" CAPABILITY_HOLD");
393 }
394 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
395 builder.append(" CAPABILITY_SUPPORT_HOLD");
396 }
397 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
398 builder.append(" CAPABILITY_MERGE_CONFERENCE");
399 }
400 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
401 builder.append(" CAPABILITY_SWAP_CONFERENCE");
402 }
403 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
404 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
405 }
406 if (can(capabilities, CAPABILITY_MUTE)) {
407 builder.append(" CAPABILITY_MUTE");
408 }
409 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
410 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
411 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700412 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
413 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
414 }
415 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
416 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
417 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700418 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
419 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800420 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700421 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
422 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
423 }
424 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
425 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
426 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800427 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
428 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
429 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700430 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
431 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800432 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500433 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700434 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500435 }
Rekha Kumar07366812015-03-24 16:42:31 -0700436 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
437 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
438 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700439 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
440 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
441 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700442 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
443 builder.append(" CAPABILITY_CAN_PULL_CALL");
444 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800445 builder.append("]");
446 return builder.toString();
447 }
448
449 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700450 * Whether the supplied properties includes the specified property.
451 *
452 * @param properties A bit field of properties.
453 * @param property The property to check properties for.
454 * @return Whether the specified property is supported.
455 */
456 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800457 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700458 }
459
460 /**
461 * Whether the properties of this {@code Details} includes the specified property.
462 *
463 * @param property The property to check properties for.
464 * @return Whether the specified property is supported.
465 */
466 public boolean hasProperty(int property) {
467 return hasProperty(mCallProperties, property);
468 }
469
470 /**
471 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
472 *
473 * @param properties A property bit field.
474 * @return A human readable string representation.
475 */
476 public static String propertiesToString(int properties) {
477 StringBuilder builder = new StringBuilder();
478 builder.append("[Properties:");
479 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
480 builder.append(" PROPERTY_CONFERENCE");
481 }
482 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
483 builder.append(" PROPERTY_GENERIC_CONFERENCE");
484 }
485 if (hasProperty(properties, PROPERTY_WIFI)) {
486 builder.append(" PROPERTY_WIFI");
487 }
488 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
489 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
490 }
491 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700492 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700493 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700494 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
495 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
496 }
Brad Ebinger15847072016-05-18 11:08:36 -0700497 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
498 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
499 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700500 builder.append("]");
501 return builder.toString();
502 }
503
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800504 /** {@hide} */
505 public String getTelecomCallId() {
506 return mTelecomCallId;
507 }
508
Andrew Lee2378ea72015-04-29 14:38:11 -0700509 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700510 * @return The handle (e.g., phone number) to which the {@code Call} is currently
511 * connected.
512 */
513 public Uri getHandle() {
514 return mHandle;
515 }
516
517 /**
518 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700519 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700520 */
521 public int getHandlePresentation() {
522 return mHandlePresentation;
523 }
524
525 /**
526 * @return The display name for the caller.
527 */
528 public String getCallerDisplayName() {
529 return mCallerDisplayName;
530 }
531
532 /**
533 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700534 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700535 */
536 public int getCallerDisplayNamePresentation() {
537 return mCallerDisplayNamePresentation;
538 }
539
540 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700541 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
542 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700543 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700544 public PhoneAccountHandle getAccountHandle() {
545 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700546 }
547
548 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800549 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
550 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700551 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700552 public int getCallCapabilities() {
553 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700554 }
555
556 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700557 * @return A bitmask of the properties of the {@code Call}, as defined by the various
558 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700559 */
560 public int getCallProperties() {
561 return mCallProperties;
562 }
563
564 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800565 * @return a bitmask of the audio routes available for the call.
566 *
567 * @hide
568 */
569 public int getSupportedAudioRoutes() {
570 return mSupportedAudioRoutes;
571 }
572
573 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700574 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700575 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700576 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700577 public DisconnectCause getDisconnectCause() {
578 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700579 }
580
581 /**
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700582 * Returns the time the {@link Call} connected (i.e. became active). This information is
583 * updated periodically, but user interfaces should not rely on this to display the "call
584 * time clock". For the time when the call was first added to Telecom, see
585 * {@link #getCreationTimeMillis()}.
586 *
587 * @return The time the {@link Call} connected in milliseconds since the epoch.
Ihab Awade63fadb2014-07-09 21:52:04 -0700588 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700589 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700590 return mConnectTimeMillis;
591 }
592
593 /**
594 * @return Information about any calling gateway the {@code Call} may be using.
595 */
596 public GatewayInfo getGatewayInfo() {
597 return mGatewayInfo;
598 }
599
Andrew Lee7a341382014-07-15 17:05:08 -0700600 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700601 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700602 */
603 public int getVideoState() {
604 return mVideoState;
605 }
606
Ihab Awad5d0410f2014-07-30 10:07:40 -0700607 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700608 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700609 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700610 */
611 public StatusHints getStatusHints() {
612 return mStatusHints;
613 }
614
Nancy Chen10798dc2014-08-08 14:00:25 -0700615 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700616 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700617 */
618 public Bundle getExtras() {
619 return mExtras;
620 }
621
Santos Cordon6b7f9552015-05-27 17:21:45 -0700622 /**
623 * @return The extras used with the original intent to place this call.
624 */
625 public Bundle getIntentExtras() {
626 return mIntentExtras;
627 }
628
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700629 /**
630 * Returns the time when the call was first created and added to Telecom. This is the same
631 * time that is logged as the start time in the Call Log (see
632 * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected
633 * (became active), see {@link #getConnectTimeMillis()}.
634 *
635 * @return The creation time of the call, in millis since the epoch.
636 */
637 public long getCreationTimeMillis() {
638 return mCreationTimeMillis;
639 }
640
Ihab Awade63fadb2014-07-09 21:52:04 -0700641 @Override
642 public boolean equals(Object o) {
643 if (o instanceof Details) {
644 Details d = (Details) o;
645 return
646 Objects.equals(mHandle, d.mHandle) &&
647 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
648 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
649 Objects.equals(mCallerDisplayNamePresentation,
650 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700651 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700652 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700653 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700654 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700655 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700656 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700657 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700658 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700659 areBundlesEqual(mExtras, d.mExtras) &&
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700660 areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
661 Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700662 }
663 return false;
664 }
665
666 @Override
667 public int hashCode() {
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700668 return Objects.hash(mHandle,
669 mHandlePresentation,
670 mCallerDisplayName,
671 mCallerDisplayNamePresentation,
672 mAccountHandle,
673 mCallCapabilities,
674 mCallProperties,
675 mDisconnectCause,
676 mConnectTimeMillis,
677 mGatewayInfo,
678 mVideoState,
679 mStatusHints,
680 mExtras,
681 mIntentExtras,
682 mCreationTimeMillis);
Ihab Awade63fadb2014-07-09 21:52:04 -0700683 }
684
685 /** {@hide} */
686 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800687 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700688 Uri handle,
689 int handlePresentation,
690 String callerDisplayName,
691 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700692 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700693 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700694 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700695 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700696 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700697 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700698 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700699 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700700 Bundle extras,
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700701 Bundle intentExtras,
702 long creationTimeMillis) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800703 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700704 mHandle = handle;
705 mHandlePresentation = handlePresentation;
706 mCallerDisplayName = callerDisplayName;
707 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700708 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700709 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700710 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700711 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700712 mConnectTimeMillis = connectTimeMillis;
713 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700714 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700715 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700716 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700717 mIntentExtras = intentExtras;
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700718 mCreationTimeMillis = creationTimeMillis;
Ihab Awade63fadb2014-07-09 21:52:04 -0700719 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800720
721 /** {@hide} */
722 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
723 return new Details(
724 parcelableCall.getId(),
725 parcelableCall.getHandle(),
726 parcelableCall.getHandlePresentation(),
727 parcelableCall.getCallerDisplayName(),
728 parcelableCall.getCallerDisplayNamePresentation(),
729 parcelableCall.getAccountHandle(),
730 parcelableCall.getCapabilities(),
731 parcelableCall.getProperties(),
732 parcelableCall.getDisconnectCause(),
733 parcelableCall.getConnectTimeMillis(),
734 parcelableCall.getGatewayInfo(),
735 parcelableCall.getVideoState(),
736 parcelableCall.getStatusHints(),
737 parcelableCall.getExtras(),
Tyler Gunnc0bf6de2017-03-17 11:27:09 -0700738 parcelableCall.getIntentExtras(),
739 parcelableCall.getCreationTimeMillis());
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800740 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800741
742 @Override
743 public String toString() {
744 StringBuilder sb = new StringBuilder();
745 sb.append("[pa: ");
746 sb.append(mAccountHandle);
747 sb.append(", hdl: ");
748 sb.append(Log.pii(mHandle));
749 sb.append(", caps: ");
750 sb.append(capabilitiesToString(mCallCapabilities));
751 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700752 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800753 sb.append("]");
754 return sb.toString();
755 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700756 }
757
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700758 /**
759 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
760 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
761 * implementation.
762 * <p>
763 * You can handle these callbacks by extending the {@link Callback} class and overriding the
764 * callbacks that your {@link InCallService} is interested in. The callback methods include the
765 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
766 * {@link Callback} implementation, if desired.
767 * <p>
768 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
769 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
770 * (typically in {@link InCallService#onCallRemoved(Call)}).
771 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
772 * reach your implementation of {@link Callback}, so it is important to register your callback
773 * as soon as your {@link InCallService} is notified of a new call via
774 * {@link InCallService#onCallAdded(Call)}.
775 */
Andrew Leeda80c872015-04-15 14:09:50 -0700776 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700777 /**
778 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
779 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700780 * @param call The {@code Call} invoking this method.
781 * @param state The new state of the {@code Call}.
782 */
783 public void onStateChanged(Call call, int state) {}
784
785 /**
786 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
787 *
788 * @param call The {@code Call} invoking this method.
789 * @param parent The new parent of the {@code Call}.
790 */
791 public void onParentChanged(Call call, Call parent) {}
792
793 /**
794 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
795 *
796 * @param call The {@code Call} invoking this method.
797 * @param children The new children of the {@code Call}.
798 */
799 public void onChildrenChanged(Call call, List<Call> children) {}
800
801 /**
802 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
803 *
804 * @param call The {@code Call} invoking this method.
805 * @param details A {@code Details} object describing the {@code Call}.
806 */
807 public void onDetailsChanged(Call call, Details details) {}
808
809 /**
810 * Invoked when the text messages that can be used as responses to the incoming
811 * {@code Call} are loaded from the relevant database.
812 * See {@link #getCannedTextResponses()}.
813 *
814 * @param call The {@code Call} invoking this method.
815 * @param cannedTextResponses The text messages useable as responses.
816 */
817 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
818
819 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700820 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
821 * character. This causes the post-dial signals to stop pending user confirmation. An
822 * implementation should present this choice to the user and invoke
823 * {@link #postDialContinue(boolean)} when the user makes the choice.
824 *
825 * @param call The {@code Call} invoking this method.
826 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
827 */
828 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
829
830 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700831 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700832 *
833 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700834 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700835 */
Andrew Lee50aca232014-07-22 16:41:54 -0700836 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700837
838 /**
839 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
840 * up their UI for the {@code Call} in response to state transitions. Specifically,
841 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
842 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
843 * clients should wait for this method to be invoked.
844 *
845 * @param call The {@code Call} being destroyed.
846 */
847 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700848
849 /**
850 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
851 * conferenced.
852 *
853 * @param call The {@code Call} being updated.
854 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
855 * conferenced.
856 */
857 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700858
859 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700860 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
861 * <p>
862 * Where possible, the Call should make an attempt to handle {@link Connection} events which
863 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
864 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
865 * possible that a {@link ConnectionService} has defined its own Connection events which a
866 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700867 * <p>
868 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
869 *
870 * @param call The {@code Call} receiving the event.
871 * @param event The event.
872 * @param extras Extras associated with the connection event.
873 */
874 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -0800875
876 /**
877 * Invoked when the RTT mode changes for this call.
878 * @param call The call whose RTT mode has changed.
879 * @param mode the new RTT mode, one of
880 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
881 * or {@link RttCall#RTT_MODE_VCO}
882 */
883 public void onRttModeChanged(Call call, int mode) {}
884
885 /**
886 * Invoked when the call's RTT status changes, either from off to on or from on to off.
887 * @param call The call whose RTT status has changed.
888 * @param enabled whether RTT is now enabled or disabled
889 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
890 * on, null otherwise.
891 */
892 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
893
894 /**
895 * Invoked when the remote end of the connection has requested that an RTT communication
896 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
897 * with the same ID that this method is invoked with.
898 * @param call The call which the RTT request was placed on
899 * @param id The ID of the request.
900 */
901 public void onRttRequest(Call call, int id) {}
Hall Liu57006aa2017-02-06 10:49:48 -0800902
903 /**
904 * Invoked when the RTT session failed to initiate for some reason, including rejection
905 * by the remote party.
906 * @param call The call which the RTT initiation failure occurred on.
907 * @param reason One of the status codes defined in
908 * {@link android.telecom.Connection.RttModifyStatus}, with the exception of
909 * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
910 */
911 public void onRttInitiationFailure(Call call, int reason) {}
Hall Liu95d55872017-01-25 17:12:49 -0800912 }
913
914 /**
915 * A class that holds the state that describes the state of the RTT channel to the remote
916 * party, if it is active.
917 */
918 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -0800919 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -0800920 @Retention(RetentionPolicy.SOURCE)
921 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
922 public @interface RttAudioMode {}
923
924 /**
925 * For metrics use. Default value in the proto.
926 * @hide
927 */
928 public static final int RTT_MODE_INVALID = 0;
929
930 /**
931 * Indicates that there should be a bidirectional audio stream between the two parties
932 * on the call.
933 */
934 public static final int RTT_MODE_FULL = 1;
935
936 /**
937 * Indicates that the local user should be able to hear the audio stream from the remote
938 * user, but not vice versa. Equivalent to muting the microphone.
939 */
940 public static final int RTT_MODE_HCO = 2;
941
942 /**
943 * Indicates that the remote user should be able to hear the audio stream from the local
944 * user, but not vice versa. Equivalent to setting the volume to zero.
945 */
946 public static final int RTT_MODE_VCO = 3;
947
948 private static final int READ_BUFFER_SIZE = 1000;
949
950 private InputStreamReader mReceiveStream;
951 private OutputStreamWriter mTransmitStream;
952 private int mRttMode;
953 private final InCallAdapter mInCallAdapter;
Hall Liu57006aa2017-02-06 10:49:48 -0800954 private final String mTelecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -0800955 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
956
957 /**
958 * @hide
959 */
Hall Liu57006aa2017-02-06 10:49:48 -0800960 public RttCall(String telecomCallId, InputStreamReader receiveStream,
961 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
962 mTelecomCallId = telecomCallId;
Hall Liu95d55872017-01-25 17:12:49 -0800963 mReceiveStream = receiveStream;
964 mTransmitStream = transmitStream;
965 mRttMode = mode;
966 mInCallAdapter = inCallAdapter;
967 }
968
969 /**
970 * Returns the current RTT audio mode.
971 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
972 * {@link #RTT_MODE_HCO}.
973 */
974 public int getRttAudioMode() {
975 return mRttMode;
976 }
977
978 /**
979 * Sets the RTT audio mode. The requested mode change will be communicated through
980 * {@link Callback#onRttModeChanged(Call, int)}.
981 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
982 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
983 */
984 public void setRttMode(@RttAudioMode int mode) {
Hall Liu57006aa2017-02-06 10:49:48 -0800985 mInCallAdapter.setRttMode(mTelecomCallId, mode);
Hall Liu95d55872017-01-25 17:12:49 -0800986 }
987
988 /**
989 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
990 * RTT transmits text in real-time, this method should be called once for each character
991 * the user enters into the device.
992 *
993 * This method is not thread-safe -- calling it from multiple threads simultaneously may
994 * lead to interleaved text.
995 * @param input The message to send to the remote user.
996 */
997 public void write(String input) throws IOException {
998 mTransmitStream.write(input);
999 mTransmitStream.flush();
1000 }
1001
1002 /**
1003 * Reads a string from the remote user, blocking if there is no data available. Returns
1004 * {@code null} if the RTT conversation has been terminated and there is no further data
1005 * to read.
1006 *
1007 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1008 * lead to interleaved text.
1009 * @return A string containing text sent by the remote user, or {@code null} if the
1010 * conversation has been terminated or if there was an error while reading.
1011 */
Hall Liuffa4a812017-03-02 16:11:00 -08001012 public String read() throws IOException {
1013 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1014 if (numRead < 0) {
1015 return null;
1016 }
1017 return new String(mReadBuffer, 0, numRead);
1018 }
1019
1020 /**
1021 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1022 * be read.
1023 * @return A string containing text entered by the user, or {@code null} if the user has
1024 * not entered any new text yet.
1025 */
1026 public String readImmediately() throws IOException {
1027 if (mReceiveStream.ready()) {
1028 return read();
1029 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001030 return null;
1031 }
1032 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001033 }
1034
Andrew Leeda80c872015-04-15 14:09:50 -07001035 /**
1036 * @deprecated Use {@code Call.Callback} instead.
1037 * @hide
1038 */
1039 @Deprecated
1040 @SystemApi
1041 public static abstract class Listener extends Callback { }
1042
Ihab Awade63fadb2014-07-09 21:52:04 -07001043 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001044 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001045 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001046 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001047 private final List<Call> mChildren = new ArrayList<>();
1048 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001049 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001050 private final List<Call> mConferenceableCalls = new ArrayList<>();
1051 private final List<Call> mUnmodifiableConferenceableCalls =
1052 Collections.unmodifiableList(mConferenceableCalls);
1053
Santos Cordon823fd3c2014-08-07 18:35:18 -07001054 private boolean mChildrenCached;
1055 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001056 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001057 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001058 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001059 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001060 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001061 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001062 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001063 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001064 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001065
1066 /**
1067 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1068 *
1069 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1070 * remaining or this {@code Call} is not in a post-dial state.
1071 */
1072 public String getRemainingPostDialSequence() {
1073 return mRemainingPostDialSequence;
1074 }
1075
1076 /**
1077 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001078 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001079 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001080 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001081 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001082 }
1083
1084 /**
1085 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1086 *
1087 * @param rejectWithMessage Whether to reject with a text message.
1088 * @param textMessage An optional text message with which to respond.
1089 */
1090 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001091 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001092 }
1093
1094 /**
1095 * Instructs this {@code Call} to disconnect.
1096 */
1097 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001098 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001099 }
1100
1101 /**
1102 * Instructs this {@code Call} to go on hold.
1103 */
1104 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001105 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001106 }
1107
1108 /**
1109 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1110 */
1111 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001112 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001113 }
1114
1115 /**
1116 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1117 *
1118 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1119 *
1120 * @param digit A character representing the DTMF digit for which to play the tone. This
1121 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1122 */
1123 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001124 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001125 }
1126
1127 /**
1128 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1129 * currently playing.
1130 *
1131 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1132 * currently playing, this method will do nothing.
1133 */
1134 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001135 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001136 }
1137
1138 /**
1139 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1140 *
1141 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1142 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001143 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001144 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001145 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1146 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001147 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001148 * {@code Call} will pause playing the tones and notify callbacks via
1149 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001150 * should display to the user an indication of this state and an affordance to continue
1151 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1152 * app should invoke the {@link #postDialContinue(boolean)} method.
1153 *
1154 * @param proceed Whether or not to continue with the post-dial sequence.
1155 */
1156 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001157 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001158 }
1159
1160 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001161 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001162 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001163 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001164 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1165 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001166
1167 }
1168
1169 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001170 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001171 *
1172 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001173 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001174 public void conference(Call callToConferenceWith) {
1175 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001176 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001177 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001178 }
1179
1180 /**
1181 * Instructs this {@code Call} to split from any conference call with which it may be
1182 * connected.
1183 */
1184 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001185 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001186 }
1187
1188 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001189 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001190 */
1191 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001192 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001193 }
1194
1195 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001196 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001197 */
1198 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001199 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001200 }
1201
1202 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001203 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1204 * device.
1205 * <p>
1206 * Calls to this method are ignored if the call does not have the
1207 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1208 * <p>
1209 * An {@link InCallService} will only see calls which support this method if it has the
1210 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1211 * in its manifest.
1212 */
1213 public void pullExternalCall() {
1214 // If this isn't an external call, ignore the request.
1215 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1216 return;
1217 }
1218
1219 mInCallAdapter.pullExternalCall(mTelecomCallId);
1220 }
1221
1222 /**
1223 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1224 * the {@link ConnectionService}.
1225 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001226 * Call events are used to communicate point in time information from an {@link InCallService}
1227 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1228 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1229 * {@link ConnectionService}.
1230 * <p>
1231 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1232 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1233 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001234 * Events are exposed to {@link ConnectionService} implementations via
1235 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1236 * <p>
1237 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001238 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1239 * ignore some events altogether.
1240 * <p>
1241 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1242 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1243 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1244 * they define their own event types in this namespace. When defining a custom event type,
1245 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1246 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1247 * <p>
1248 * When defining events and the associated extras, it is important to keep their behavior
1249 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1250 * events/extras should me maintained to ensure backwards compatibility with older
1251 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001252 *
1253 * @param event The connection event.
1254 * @param extras Bundle containing extra information associated with the event.
1255 */
1256 public void sendCallEvent(String event, Bundle extras) {
1257 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1258 }
1259
1260 /**
Hall Liu95d55872017-01-25 17:12:49 -08001261 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1262 * guaranteed, and notification of success will be via the
1263 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1264 */
1265 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001266 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001267 }
1268
1269 /**
1270 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1271 * callback.
1272 * The ID used here should be the same as the ID that was received via the callback.
1273 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1274 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1275 */
1276 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001277 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001278 }
1279
1280 /**
1281 * Terminate the RTT session on this call. The resulting state change will be notified via
1282 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1283 */
1284 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001285 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001286 }
1287
1288 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001289 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1290 * added.
1291 * <p>
1292 * No assumptions should be made as to how an In-Call UI or service will handle these
1293 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1294 *
1295 * @param extras The extras to add.
1296 */
1297 public final void putExtras(Bundle extras) {
1298 if (extras == null) {
1299 return;
1300 }
1301
1302 if (mExtras == null) {
1303 mExtras = new Bundle();
1304 }
1305 mExtras.putAll(extras);
1306 mInCallAdapter.putExtras(mTelecomCallId, extras);
1307 }
1308
1309 /**
1310 * Adds a boolean extra to this {@link Call}.
1311 *
1312 * @param key The extra key.
1313 * @param value The value.
1314 * @hide
1315 */
1316 public final void putExtra(String key, boolean value) {
1317 if (mExtras == null) {
1318 mExtras = new Bundle();
1319 }
1320 mExtras.putBoolean(key, value);
1321 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1322 }
1323
1324 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001325 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001326 *
1327 * @param key The extra key.
1328 * @param value The value.
1329 * @hide
1330 */
1331 public final void putExtra(String key, int value) {
1332 if (mExtras == null) {
1333 mExtras = new Bundle();
1334 }
1335 mExtras.putInt(key, value);
1336 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1337 }
1338
1339 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001340 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001341 *
1342 * @param key The extra key.
1343 * @param value The value.
1344 * @hide
1345 */
1346 public final void putExtra(String key, String value) {
1347 if (mExtras == null) {
1348 mExtras = new Bundle();
1349 }
1350 mExtras.putString(key, value);
1351 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1352 }
1353
1354 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001355 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001356 *
1357 * @param keys The keys of the extras to remove.
1358 */
1359 public final void removeExtras(List<String> keys) {
1360 if (mExtras != null) {
1361 for (String key : keys) {
1362 mExtras.remove(key);
1363 }
1364 if (mExtras.size() == 0) {
1365 mExtras = null;
1366 }
1367 }
1368 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1369 }
1370
1371 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001372 * Removes extras from this {@link Call}.
1373 *
1374 * @param keys The keys of the extras to remove.
1375 */
1376 public final void removeExtras(String ... keys) {
1377 removeExtras(Arrays.asList(keys));
1378 }
1379
1380 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001381 * Obtains the parent of this {@code Call} in a conference, if any.
1382 *
1383 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1384 * child of any conference {@code Call}s.
1385 */
1386 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001387 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001388 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001389 }
1390 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001391 }
1392
1393 /**
1394 * Obtains the children of this conference {@code Call}, if any.
1395 *
1396 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1397 * {@code List} otherwise.
1398 */
1399 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001400 if (!mChildrenCached) {
1401 mChildrenCached = true;
1402 mChildren.clear();
1403
1404 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001405 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001406 if (call == null) {
1407 // At least one child was still not found, so do not save true for "cached"
1408 mChildrenCached = false;
1409 } else {
1410 mChildren.add(call);
1411 }
1412 }
1413 }
1414
Ihab Awade63fadb2014-07-09 21:52:04 -07001415 return mUnmodifiableChildren;
1416 }
1417
1418 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001419 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1420 *
1421 * @return The list of conferenceable {@code Call}s.
1422 */
1423 public List<Call> getConferenceableCalls() {
1424 return mUnmodifiableConferenceableCalls;
1425 }
1426
1427 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001428 * Obtains the state of this {@code Call}.
1429 *
1430 * @return A state value, chosen from the {@code STATE_*} constants.
1431 */
1432 public int getState() {
1433 return mState;
1434 }
1435
1436 /**
1437 * Obtains a list of canned, pre-configured message responses to present to the user as
1438 * ways of rejecting this {@code Call} using via a text message.
1439 *
1440 * @see #reject(boolean, String)
1441 *
1442 * @return A list of canned text message responses.
1443 */
1444 public List<String> getCannedTextResponses() {
1445 return mCannedTextResponses;
1446 }
1447
1448 /**
1449 * Obtains an object that can be used to display video from this {@code Call}.
1450 *
Andrew Lee50aca232014-07-22 16:41:54 -07001451 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001452 */
Andrew Lee50aca232014-07-22 16:41:54 -07001453 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001454 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001455 }
1456
1457 /**
1458 * Obtains an object containing call details.
1459 *
1460 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1461 * result may be {@code null}.
1462 */
1463 public Details getDetails() {
1464 return mDetails;
1465 }
1466
1467 /**
Hall Liu95d55872017-01-25 17:12:49 -08001468 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1469 * receive RTT text data, as well as to change the RTT mode.
1470 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1471 */
1472 public @Nullable RttCall getRttCall() {
1473 return mRttCall;
1474 }
1475
1476 /**
1477 * Returns whether this call has an active RTT connection.
1478 * @return true if there is a connection, false otherwise.
1479 */
1480 public boolean isRttActive() {
1481 return mRttCall != null;
1482 }
1483
1484 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001485 * Registers a callback to this {@code Call}.
1486 *
1487 * @param callback A {@code Callback}.
1488 */
1489 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001490 registerCallback(callback, new Handler());
1491 }
1492
1493 /**
1494 * Registers a callback to this {@code Call}.
1495 *
1496 * @param callback A {@code Callback}.
1497 * @param handler A handler which command and status changes will be delivered to.
1498 */
1499 public void registerCallback(Callback callback, Handler handler) {
1500 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001501 // Don't allow new callback registration if the call is already being destroyed.
1502 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001503 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1504 }
Andrew Leeda80c872015-04-15 14:09:50 -07001505 }
1506
1507 /**
1508 * Unregisters a callback from this {@code Call}.
1509 *
1510 * @param callback A {@code Callback}.
1511 */
1512 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001513 // Don't allow callback deregistration if the call is already being destroyed.
1514 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001515 for (CallbackRecord<Callback> record : mCallbackRecords) {
1516 if (record.getCallback() == callback) {
1517 mCallbackRecords.remove(record);
1518 break;
1519 }
1520 }
Andrew Leeda80c872015-04-15 14:09:50 -07001521 }
1522 }
1523
Santos Cordon3c20d632016-02-25 16:12:35 -08001524 @Override
1525 public String toString() {
1526 return new StringBuilder().
1527 append("Call [id: ").
1528 append(mTelecomCallId).
1529 append(", state: ").
1530 append(stateToString(mState)).
1531 append(", details: ").
1532 append(mDetails).
1533 append("]").toString();
1534 }
1535
1536 /**
1537 * @param state An integer value of a {@code STATE_*} constant.
1538 * @return A string representation of the value.
1539 */
1540 private static String stateToString(int state) {
1541 switch (state) {
1542 case STATE_NEW:
1543 return "NEW";
1544 case STATE_RINGING:
1545 return "RINGING";
1546 case STATE_DIALING:
1547 return "DIALING";
1548 case STATE_ACTIVE:
1549 return "ACTIVE";
1550 case STATE_HOLDING:
1551 return "HOLDING";
1552 case STATE_DISCONNECTED:
1553 return "DISCONNECTED";
1554 case STATE_CONNECTING:
1555 return "CONNECTING";
1556 case STATE_DISCONNECTING:
1557 return "DISCONNECTING";
1558 case STATE_SELECT_PHONE_ACCOUNT:
1559 return "SELECT_PHONE_ACCOUNT";
1560 default:
1561 Log.w(Call.class, "Unknown state %d", state);
1562 return "UNKNOWN";
1563 }
1564 }
1565
Andrew Leeda80c872015-04-15 14:09:50 -07001566 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001567 * Adds a listener to this {@code Call}.
1568 *
1569 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001570 * @deprecated Use {@link #registerCallback} instead.
1571 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001572 */
Andrew Leeda80c872015-04-15 14:09:50 -07001573 @Deprecated
1574 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001575 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001576 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001577 }
1578
1579 /**
1580 * Removes a listener from this {@code Call}.
1581 *
1582 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001583 * @deprecated Use {@link #unregisterCallback} instead.
1584 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001585 */
Andrew Leeda80c872015-04-15 14:09:50 -07001586 @Deprecated
1587 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001588 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001589 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001590 }
1591
1592 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001593 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1594 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001595 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001596 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001597 mInCallAdapter = inCallAdapter;
1598 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001599 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001600 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001601 }
1602
1603 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001604 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001605 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001606 mPhone = phone;
1607 mTelecomCallId = telecomCallId;
1608 mInCallAdapter = inCallAdapter;
1609 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001610 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001611 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001612 }
1613
1614 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001615 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001616 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001617 }
1618
1619 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001620 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001621
Ihab Awade63fadb2014-07-09 21:52:04 -07001622 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001623 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001624 boolean detailsChanged = !Objects.equals(mDetails, details);
1625 if (detailsChanged) {
1626 mDetails = details;
1627 }
1628
1629 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001630 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1631 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1632 mCannedTextResponses =
1633 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001634 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001635 }
1636
Tyler Gunn159f35c2017-03-02 09:28:37 -08001637 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1638 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001639 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001640 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001641 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001642 mVideoCallImpl = newVideoCallImpl;
1643 }
1644 if (mVideoCallImpl != null) {
1645 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001646 }
1647
Santos Cordone3c507b2015-04-23 14:44:19 -07001648 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001649 boolean stateChanged = mState != state;
1650 if (stateChanged) {
1651 mState = state;
1652 }
1653
Santos Cordon823fd3c2014-08-07 18:35:18 -07001654 String parentId = parcelableCall.getParentCallId();
1655 boolean parentChanged = !Objects.equals(mParentId, parentId);
1656 if (parentChanged) {
1657 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001658 }
1659
Santos Cordon823fd3c2014-08-07 18:35:18 -07001660 List<String> childCallIds = parcelableCall.getChildCallIds();
1661 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1662 if (childrenChanged) {
1663 mChildrenIds.clear();
1664 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1665 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001666 }
1667
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001668 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1669 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1670 for (String otherId : conferenceableCallIds) {
1671 if (callIdMap.containsKey(otherId)) {
1672 conferenceableCalls.add(callIdMap.get(otherId));
1673 }
1674 }
1675
1676 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1677 mConferenceableCalls.clear();
1678 mConferenceableCalls.addAll(conferenceableCalls);
1679 fireConferenceableCallsChanged();
1680 }
1681
Hall Liu95d55872017-01-25 17:12:49 -08001682 boolean isRttChanged = false;
1683 boolean rttModeChanged = false;
1684 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1685 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1686 InputStreamReader receiveStream = new InputStreamReader(
1687 new ParcelFileDescriptor.AutoCloseInputStream(
1688 parcelableRttCall.getReceiveStream()),
1689 StandardCharsets.UTF_8);
1690 OutputStreamWriter transmitStream = new OutputStreamWriter(
1691 new ParcelFileDescriptor.AutoCloseOutputStream(
1692 parcelableRttCall.getTransmitStream()),
1693 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08001694 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08001695 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1696 if (mRttCall == null) {
1697 isRttChanged = true;
1698 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1699 rttModeChanged = true;
1700 }
1701 mRttCall = newRttCall;
1702 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1703 && parcelableCall.getIsRttCallChanged()) {
1704 isRttChanged = true;
1705 mRttCall = null;
1706 }
1707
Ihab Awade63fadb2014-07-09 21:52:04 -07001708 // Now we fire updates, ensuring that any client who listens to any of these notifications
1709 // gets the most up-to-date state.
1710
1711 if (stateChanged) {
1712 fireStateChanged(mState);
1713 }
1714 if (detailsChanged) {
1715 fireDetailsChanged(mDetails);
1716 }
1717 if (cannedTextResponsesChanged) {
1718 fireCannedTextResponsesLoaded(mCannedTextResponses);
1719 }
Andrew Lee50aca232014-07-22 16:41:54 -07001720 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001721 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001722 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001723 if (parentChanged) {
1724 fireParentChanged(getParent());
1725 }
1726 if (childrenChanged) {
1727 fireChildrenChanged(getChildren());
1728 }
Hall Liu95d55872017-01-25 17:12:49 -08001729 if (isRttChanged) {
1730 fireOnIsRttChanged(mRttCall != null, mRttCall);
1731 }
1732 if (rttModeChanged) {
1733 fireOnRttModeChanged(mRttCall.getRttAudioMode());
1734 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001735
1736 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1737 // remove ourselves from the Phone. Note that we do this after completing all state updates
1738 // so a client can cleanly transition all their UI to the state appropriate for a
1739 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1740 if (mState == STATE_DISCONNECTED) {
1741 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001742 }
1743 }
1744
1745 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001746 final void internalSetPostDialWait(String remaining) {
1747 mRemainingPostDialSequence = remaining;
1748 firePostDialWait(mRemainingPostDialSequence);
1749 }
1750
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001751 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001752 final void internalSetDisconnected() {
1753 if (mState != Call.STATE_DISCONNECTED) {
1754 mState = Call.STATE_DISCONNECTED;
1755 fireStateChanged(mState);
1756 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001757 }
1758 }
1759
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001760 /** {@hide} */
1761 final void internalOnConnectionEvent(String event, Bundle extras) {
1762 fireOnConnectionEvent(event, extras);
1763 }
1764
Hall Liu95d55872017-01-25 17:12:49 -08001765 /** {@hide} */
1766 final void internalOnRttUpgradeRequest(final int requestId) {
1767 for (CallbackRecord<Callback> record : mCallbackRecords) {
1768 final Call call = this;
1769 final Callback callback = record.getCallback();
1770 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
1771 }
1772 }
1773
Hall Liu57006aa2017-02-06 10:49:48 -08001774 /** @hide */
1775 final void internalOnRttInitiationFailure(int reason) {
1776 for (CallbackRecord<Callback> record : mCallbackRecords) {
1777 final Call call = this;
1778 final Callback callback = record.getCallback();
1779 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
1780 }
1781 }
1782
Andrew Lee011728f2015-04-23 15:47:06 -07001783 private void fireStateChanged(final int newState) {
1784 for (CallbackRecord<Callback> record : mCallbackRecords) {
1785 final Call call = this;
1786 final Callback callback = record.getCallback();
1787 record.getHandler().post(new Runnable() {
1788 @Override
1789 public void run() {
1790 callback.onStateChanged(call, newState);
1791 }
1792 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001793 }
1794 }
1795
Andrew Lee011728f2015-04-23 15:47:06 -07001796 private void fireParentChanged(final Call newParent) {
1797 for (CallbackRecord<Callback> record : mCallbackRecords) {
1798 final Call call = this;
1799 final Callback callback = record.getCallback();
1800 record.getHandler().post(new Runnable() {
1801 @Override
1802 public void run() {
1803 callback.onParentChanged(call, newParent);
1804 }
1805 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001806 }
1807 }
1808
Andrew Lee011728f2015-04-23 15:47:06 -07001809 private void fireChildrenChanged(final List<Call> children) {
1810 for (CallbackRecord<Callback> record : mCallbackRecords) {
1811 final Call call = this;
1812 final Callback callback = record.getCallback();
1813 record.getHandler().post(new Runnable() {
1814 @Override
1815 public void run() {
1816 callback.onChildrenChanged(call, children);
1817 }
1818 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001819 }
1820 }
1821
Andrew Lee011728f2015-04-23 15:47:06 -07001822 private void fireDetailsChanged(final Details details) {
1823 for (CallbackRecord<Callback> record : mCallbackRecords) {
1824 final Call call = this;
1825 final Callback callback = record.getCallback();
1826 record.getHandler().post(new Runnable() {
1827 @Override
1828 public void run() {
1829 callback.onDetailsChanged(call, details);
1830 }
1831 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001832 }
1833 }
1834
Andrew Lee011728f2015-04-23 15:47:06 -07001835 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1836 for (CallbackRecord<Callback> record : mCallbackRecords) {
1837 final Call call = this;
1838 final Callback callback = record.getCallback();
1839 record.getHandler().post(new Runnable() {
1840 @Override
1841 public void run() {
1842 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1843 }
1844 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001845 }
1846 }
1847
Andrew Lee011728f2015-04-23 15:47:06 -07001848 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1849 for (CallbackRecord<Callback> record : mCallbackRecords) {
1850 final Call call = this;
1851 final Callback callback = record.getCallback();
1852 record.getHandler().post(new Runnable() {
1853 @Override
1854 public void run() {
1855 callback.onVideoCallChanged(call, videoCall);
1856 }
1857 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001858 }
1859 }
1860
Andrew Lee011728f2015-04-23 15:47:06 -07001861 private void firePostDialWait(final String remainingPostDialSequence) {
1862 for (CallbackRecord<Callback> record : mCallbackRecords) {
1863 final Call call = this;
1864 final Callback callback = record.getCallback();
1865 record.getHandler().post(new Runnable() {
1866 @Override
1867 public void run() {
1868 callback.onPostDialWait(call, remainingPostDialSequence);
1869 }
1870 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001871 }
1872 }
1873
1874 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001875 /**
1876 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1877 * onCallRemoved callback, we remove this call from the Phone's record
1878 * only once all of the registered onCallDestroyed callbacks are executed.
1879 * All the callbacks get removed from our records as a part of this operation
1880 * since onCallDestroyed is the final callback.
1881 */
1882 final Call call = this;
1883 if (mCallbackRecords.isEmpty()) {
1884 // No callbacks registered, remove the call from Phone's record.
1885 mPhone.internalRemoveCall(call);
1886 }
1887 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001888 final Callback callback = record.getCallback();
1889 record.getHandler().post(new Runnable() {
1890 @Override
1891 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001892 boolean isFinalRemoval = false;
1893 RuntimeException toThrow = null;
1894 try {
1895 callback.onCallDestroyed(call);
1896 } catch (RuntimeException e) {
1897 toThrow = e;
1898 }
1899 synchronized(Call.this) {
1900 mCallbackRecords.remove(record);
1901 if (mCallbackRecords.isEmpty()) {
1902 isFinalRemoval = true;
1903 }
1904 }
1905 if (isFinalRemoval) {
1906 mPhone.internalRemoveCall(call);
1907 }
1908 if (toThrow != null) {
1909 throw toThrow;
1910 }
Andrew Lee011728f2015-04-23 15:47:06 -07001911 }
1912 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001913 }
1914 }
1915
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001916 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001917 for (CallbackRecord<Callback> record : mCallbackRecords) {
1918 final Call call = this;
1919 final Callback callback = record.getCallback();
1920 record.getHandler().post(new Runnable() {
1921 @Override
1922 public void run() {
1923 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1924 }
1925 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001926 }
1927 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001928
1929 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001930 * Notifies listeners of an incoming connection event.
1931 * <p>
1932 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1933 *
1934 * @param event
1935 * @param extras
1936 */
1937 private void fireOnConnectionEvent(final String event, final Bundle extras) {
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.onConnectionEvent(call, event, extras);
1945 }
1946 });
1947 }
1948 }
1949
1950 /**
Hall Liu95d55872017-01-25 17:12:49 -08001951 * Notifies listeners of an RTT on/off change
1952 *
1953 * @param enabled True if RTT is now enabled, false otherwise
1954 */
1955 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
1956 for (CallbackRecord<Callback> record : mCallbackRecords) {
1957 final Call call = this;
1958 final Callback callback = record.getCallback();
1959 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
1960 }
1961 }
1962
1963 /**
1964 * Notifies listeners of a RTT mode change
1965 *
1966 * @param mode The new RTT mode
1967 */
1968 private void fireOnRttModeChanged(final int mode) {
1969 for (CallbackRecord<Callback> record : mCallbackRecords) {
1970 final Call call = this;
1971 final Callback callback = record.getCallback();
1972 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
1973 }
1974 }
1975
1976 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001977 * Determines if two bundles are equal.
1978 *
1979 * @param bundle The original bundle.
1980 * @param newBundle The bundle to compare with.
1981 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1982 */
1983 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1984 if (bundle == null || newBundle == null) {
1985 return bundle == newBundle;
1986 }
1987
1988 if (bundle.size() != newBundle.size()) {
1989 return false;
1990 }
1991
1992 for(String key : bundle.keySet()) {
1993 if (key != null) {
1994 final Object value = bundle.get(key);
1995 final Object newValue = newBundle.get(key);
1996 if (!Objects.equals(value, newValue)) {
1997 return false;
1998 }
1999 }
2000 }
2001 return true;
2002 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002003}