blob: f80ee7386f9991f58b0afb34a1be9cf74cb259f8 [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 Gunn3251a552017-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 Gunn3251a552017-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 Gunn3251a552017-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 Gunn3251a552017-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 Gunn3251a552017-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 Gunn3251a552017-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 Gunn3251a552017-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 Gunn3251a552017-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 */
1012 public String read() {
1013 try {
1014 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1015 if (numRead < 0) {
1016 return null;
1017 }
1018 return new String(mReadBuffer, 0, numRead);
1019 } catch (IOException e) {
1020 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
1021 return null;
1022 }
1023 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001024 }
1025
Andrew Leeda80c872015-04-15 14:09:50 -07001026 /**
1027 * @deprecated Use {@code Call.Callback} instead.
1028 * @hide
1029 */
1030 @Deprecated
1031 @SystemApi
1032 public static abstract class Listener extends Callback { }
1033
Ihab Awade63fadb2014-07-09 21:52:04 -07001034 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001035 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001036 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001037 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001038 private final List<Call> mChildren = new ArrayList<>();
1039 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001040 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001041 private final List<Call> mConferenceableCalls = new ArrayList<>();
1042 private final List<Call> mUnmodifiableConferenceableCalls =
1043 Collections.unmodifiableList(mConferenceableCalls);
1044
Santos Cordon823fd3c2014-08-07 18:35:18 -07001045 private boolean mChildrenCached;
1046 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001047 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001048 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001049 private String mCallingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001050 private int mTargetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001051 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001052 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001053 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001054 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001055 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001056
1057 /**
1058 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1059 *
1060 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1061 * remaining or this {@code Call} is not in a post-dial state.
1062 */
1063 public String getRemainingPostDialSequence() {
1064 return mRemainingPostDialSequence;
1065 }
1066
1067 /**
1068 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001069 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001070 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001071 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001072 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001073 }
1074
1075 /**
1076 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1077 *
1078 * @param rejectWithMessage Whether to reject with a text message.
1079 * @param textMessage An optional text message with which to respond.
1080 */
1081 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001082 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001083 }
1084
1085 /**
1086 * Instructs this {@code Call} to disconnect.
1087 */
1088 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001089 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001090 }
1091
1092 /**
1093 * Instructs this {@code Call} to go on hold.
1094 */
1095 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001096 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001097 }
1098
1099 /**
1100 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1101 */
1102 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001103 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001104 }
1105
1106 /**
1107 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1108 *
1109 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1110 *
1111 * @param digit A character representing the DTMF digit for which to play the tone. This
1112 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1113 */
1114 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001115 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001116 }
1117
1118 /**
1119 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1120 * currently playing.
1121 *
1122 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1123 * currently playing, this method will do nothing.
1124 */
1125 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001126 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001127 }
1128
1129 /**
1130 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1131 *
1132 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1133 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001134 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001135 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001136 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1137 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001138 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001139 * {@code Call} will pause playing the tones and notify callbacks via
1140 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001141 * should display to the user an indication of this state and an affordance to continue
1142 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1143 * app should invoke the {@link #postDialContinue(boolean)} method.
1144 *
1145 * @param proceed Whether or not to continue with the post-dial sequence.
1146 */
1147 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001148 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001149 }
1150
1151 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001152 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001153 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001154 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001155 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1156 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001157
1158 }
1159
1160 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001161 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001162 *
1163 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001164 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001165 public void conference(Call callToConferenceWith) {
1166 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001167 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001168 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001169 }
1170
1171 /**
1172 * Instructs this {@code Call} to split from any conference call with which it may be
1173 * connected.
1174 */
1175 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001176 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001177 }
1178
1179 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001180 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001181 */
1182 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001183 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001184 }
1185
1186 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001187 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001188 */
1189 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001190 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001191 }
1192
1193 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001194 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1195 * device.
1196 * <p>
1197 * Calls to this method are ignored if the call does not have the
1198 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1199 * <p>
1200 * An {@link InCallService} will only see calls which support this method if it has the
1201 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1202 * in its manifest.
1203 */
1204 public void pullExternalCall() {
1205 // If this isn't an external call, ignore the request.
1206 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1207 return;
1208 }
1209
1210 mInCallAdapter.pullExternalCall(mTelecomCallId);
1211 }
1212
1213 /**
1214 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1215 * the {@link ConnectionService}.
1216 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001217 * Call events are used to communicate point in time information from an {@link InCallService}
1218 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1219 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1220 * {@link ConnectionService}.
1221 * <p>
1222 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1223 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1224 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001225 * Events are exposed to {@link ConnectionService} implementations via
1226 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1227 * <p>
1228 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001229 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1230 * ignore some events altogether.
1231 * <p>
1232 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1233 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1234 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1235 * they define their own event types in this namespace. When defining a custom event type,
1236 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1237 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1238 * <p>
1239 * When defining events and the associated extras, it is important to keep their behavior
1240 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1241 * events/extras should me maintained to ensure backwards compatibility with older
1242 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001243 *
1244 * @param event The connection event.
1245 * @param extras Bundle containing extra information associated with the event.
1246 */
1247 public void sendCallEvent(String event, Bundle extras) {
1248 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1249 }
1250
1251 /**
Hall Liu95d55872017-01-25 17:12:49 -08001252 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1253 * guaranteed, and notification of success will be via the
1254 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1255 */
1256 public void sendRttRequest() {
Hall Liu57006aa2017-02-06 10:49:48 -08001257 mInCallAdapter.sendRttRequest(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001258 }
1259
1260 /**
1261 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1262 * callback.
1263 * The ID used here should be the same as the ID that was received via the callback.
1264 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1265 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1266 */
1267 public void respondToRttRequest(int id, boolean accept) {
Hall Liu57006aa2017-02-06 10:49:48 -08001268 mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
Hall Liu95d55872017-01-25 17:12:49 -08001269 }
1270
1271 /**
1272 * Terminate the RTT session on this call. The resulting state change will be notified via
1273 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1274 */
1275 public void stopRtt() {
Hall Liu57006aa2017-02-06 10:49:48 -08001276 mInCallAdapter.stopRtt(mTelecomCallId);
Hall Liu95d55872017-01-25 17:12:49 -08001277 }
1278
1279 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001280 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1281 * added.
1282 * <p>
1283 * No assumptions should be made as to how an In-Call UI or service will handle these
1284 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1285 *
1286 * @param extras The extras to add.
1287 */
1288 public final void putExtras(Bundle extras) {
1289 if (extras == null) {
1290 return;
1291 }
1292
1293 if (mExtras == null) {
1294 mExtras = new Bundle();
1295 }
1296 mExtras.putAll(extras);
1297 mInCallAdapter.putExtras(mTelecomCallId, extras);
1298 }
1299
1300 /**
1301 * Adds a boolean extra to this {@link Call}.
1302 *
1303 * @param key The extra key.
1304 * @param value The value.
1305 * @hide
1306 */
1307 public final void putExtra(String key, boolean value) {
1308 if (mExtras == null) {
1309 mExtras = new Bundle();
1310 }
1311 mExtras.putBoolean(key, value);
1312 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1313 }
1314
1315 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001316 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001317 *
1318 * @param key The extra key.
1319 * @param value The value.
1320 * @hide
1321 */
1322 public final void putExtra(String key, int value) {
1323 if (mExtras == null) {
1324 mExtras = new Bundle();
1325 }
1326 mExtras.putInt(key, value);
1327 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1328 }
1329
1330 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001331 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001332 *
1333 * @param key The extra key.
1334 * @param value The value.
1335 * @hide
1336 */
1337 public final void putExtra(String key, String value) {
1338 if (mExtras == null) {
1339 mExtras = new Bundle();
1340 }
1341 mExtras.putString(key, value);
1342 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1343 }
1344
1345 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001346 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001347 *
1348 * @param keys The keys of the extras to remove.
1349 */
1350 public final void removeExtras(List<String> keys) {
1351 if (mExtras != null) {
1352 for (String key : keys) {
1353 mExtras.remove(key);
1354 }
1355 if (mExtras.size() == 0) {
1356 mExtras = null;
1357 }
1358 }
1359 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1360 }
1361
1362 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001363 * Removes extras from this {@link Call}.
1364 *
1365 * @param keys The keys of the extras to remove.
1366 */
1367 public final void removeExtras(String ... keys) {
1368 removeExtras(Arrays.asList(keys));
1369 }
1370
1371 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001372 * Obtains the parent of this {@code Call} in a conference, if any.
1373 *
1374 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1375 * child of any conference {@code Call}s.
1376 */
1377 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001378 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001379 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001380 }
1381 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001382 }
1383
1384 /**
1385 * Obtains the children of this conference {@code Call}, if any.
1386 *
1387 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1388 * {@code List} otherwise.
1389 */
1390 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001391 if (!mChildrenCached) {
1392 mChildrenCached = true;
1393 mChildren.clear();
1394
1395 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001396 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001397 if (call == null) {
1398 // At least one child was still not found, so do not save true for "cached"
1399 mChildrenCached = false;
1400 } else {
1401 mChildren.add(call);
1402 }
1403 }
1404 }
1405
Ihab Awade63fadb2014-07-09 21:52:04 -07001406 return mUnmodifiableChildren;
1407 }
1408
1409 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001410 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1411 *
1412 * @return The list of conferenceable {@code Call}s.
1413 */
1414 public List<Call> getConferenceableCalls() {
1415 return mUnmodifiableConferenceableCalls;
1416 }
1417
1418 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001419 * Obtains the state of this {@code Call}.
1420 *
1421 * @return A state value, chosen from the {@code STATE_*} constants.
1422 */
1423 public int getState() {
1424 return mState;
1425 }
1426
1427 /**
1428 * Obtains a list of canned, pre-configured message responses to present to the user as
1429 * ways of rejecting this {@code Call} using via a text message.
1430 *
1431 * @see #reject(boolean, String)
1432 *
1433 * @return A list of canned text message responses.
1434 */
1435 public List<String> getCannedTextResponses() {
1436 return mCannedTextResponses;
1437 }
1438
1439 /**
1440 * Obtains an object that can be used to display video from this {@code Call}.
1441 *
Andrew Lee50aca232014-07-22 16:41:54 -07001442 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001443 */
Andrew Lee50aca232014-07-22 16:41:54 -07001444 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001445 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001446 }
1447
1448 /**
1449 * Obtains an object containing call details.
1450 *
1451 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1452 * result may be {@code null}.
1453 */
1454 public Details getDetails() {
1455 return mDetails;
1456 }
1457
1458 /**
Hall Liu95d55872017-01-25 17:12:49 -08001459 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1460 * receive RTT text data, as well as to change the RTT mode.
1461 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1462 */
1463 public @Nullable RttCall getRttCall() {
1464 return mRttCall;
1465 }
1466
1467 /**
1468 * Returns whether this call has an active RTT connection.
1469 * @return true if there is a connection, false otherwise.
1470 */
1471 public boolean isRttActive() {
1472 return mRttCall != null;
1473 }
1474
1475 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001476 * Registers a callback to this {@code Call}.
1477 *
1478 * @param callback A {@code Callback}.
1479 */
1480 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001481 registerCallback(callback, new Handler());
1482 }
1483
1484 /**
1485 * Registers a callback to this {@code Call}.
1486 *
1487 * @param callback A {@code Callback}.
1488 * @param handler A handler which command and status changes will be delivered to.
1489 */
1490 public void registerCallback(Callback callback, Handler handler) {
1491 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001492 // Don't allow new callback registration if the call is already being destroyed.
1493 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001494 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1495 }
Andrew Leeda80c872015-04-15 14:09:50 -07001496 }
1497
1498 /**
1499 * Unregisters a callback from this {@code Call}.
1500 *
1501 * @param callback A {@code Callback}.
1502 */
1503 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001504 // Don't allow callback deregistration if the call is already being destroyed.
1505 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001506 for (CallbackRecord<Callback> record : mCallbackRecords) {
1507 if (record.getCallback() == callback) {
1508 mCallbackRecords.remove(record);
1509 break;
1510 }
1511 }
Andrew Leeda80c872015-04-15 14:09:50 -07001512 }
1513 }
1514
Santos Cordon3c20d632016-02-25 16:12:35 -08001515 @Override
1516 public String toString() {
1517 return new StringBuilder().
1518 append("Call [id: ").
1519 append(mTelecomCallId).
1520 append(", state: ").
1521 append(stateToString(mState)).
1522 append(", details: ").
1523 append(mDetails).
1524 append("]").toString();
1525 }
1526
1527 /**
1528 * @param state An integer value of a {@code STATE_*} constant.
1529 * @return A string representation of the value.
1530 */
1531 private static String stateToString(int state) {
1532 switch (state) {
1533 case STATE_NEW:
1534 return "NEW";
1535 case STATE_RINGING:
1536 return "RINGING";
1537 case STATE_DIALING:
1538 return "DIALING";
1539 case STATE_ACTIVE:
1540 return "ACTIVE";
1541 case STATE_HOLDING:
1542 return "HOLDING";
1543 case STATE_DISCONNECTED:
1544 return "DISCONNECTED";
1545 case STATE_CONNECTING:
1546 return "CONNECTING";
1547 case STATE_DISCONNECTING:
1548 return "DISCONNECTING";
1549 case STATE_SELECT_PHONE_ACCOUNT:
1550 return "SELECT_PHONE_ACCOUNT";
1551 default:
1552 Log.w(Call.class, "Unknown state %d", state);
1553 return "UNKNOWN";
1554 }
1555 }
1556
Andrew Leeda80c872015-04-15 14:09:50 -07001557 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001558 * Adds a listener to this {@code Call}.
1559 *
1560 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001561 * @deprecated Use {@link #registerCallback} instead.
1562 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001563 */
Andrew Leeda80c872015-04-15 14:09:50 -07001564 @Deprecated
1565 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001566 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001567 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001568 }
1569
1570 /**
1571 * Removes a listener from this {@code Call}.
1572 *
1573 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001574 * @deprecated Use {@link #unregisterCallback} instead.
1575 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001576 */
Andrew Leeda80c872015-04-15 14:09:50 -07001577 @Deprecated
1578 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001579 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001580 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001581 }
1582
1583 /** {@hide} */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001584 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
1585 int targetSdkVersion) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001586 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001587 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001588 mInCallAdapter = inCallAdapter;
1589 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001590 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001591 mTargetSdkVersion = targetSdkVersion;
Ihab Awade63fadb2014-07-09 21:52:04 -07001592 }
1593
1594 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001595 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001596 String callingPackage, int targetSdkVersion) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001597 mPhone = phone;
1598 mTelecomCallId = telecomCallId;
1599 mInCallAdapter = inCallAdapter;
1600 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001601 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001602 mTargetSdkVersion = targetSdkVersion;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001603 }
1604
1605 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001606 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001607 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001608 }
1609
1610 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001611 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001612
Ihab Awade63fadb2014-07-09 21:52:04 -07001613 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001614 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001615 boolean detailsChanged = !Objects.equals(mDetails, details);
1616 if (detailsChanged) {
1617 mDetails = details;
1618 }
1619
1620 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001621 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1622 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1623 mCannedTextResponses =
1624 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001625 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001626 }
1627
Tyler Gunn159f35c2017-03-02 09:28:37 -08001628 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage,
1629 mTargetSdkVersion);
Tyler Gunn75958422015-04-15 14:23:42 -07001630 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001631 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001632 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001633 mVideoCallImpl = newVideoCallImpl;
1634 }
1635 if (mVideoCallImpl != null) {
1636 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001637 }
1638
Santos Cordone3c507b2015-04-23 14:44:19 -07001639 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001640 boolean stateChanged = mState != state;
1641 if (stateChanged) {
1642 mState = state;
1643 }
1644
Santos Cordon823fd3c2014-08-07 18:35:18 -07001645 String parentId = parcelableCall.getParentCallId();
1646 boolean parentChanged = !Objects.equals(mParentId, parentId);
1647 if (parentChanged) {
1648 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001649 }
1650
Santos Cordon823fd3c2014-08-07 18:35:18 -07001651 List<String> childCallIds = parcelableCall.getChildCallIds();
1652 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1653 if (childrenChanged) {
1654 mChildrenIds.clear();
1655 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1656 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001657 }
1658
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001659 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1660 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1661 for (String otherId : conferenceableCallIds) {
1662 if (callIdMap.containsKey(otherId)) {
1663 conferenceableCalls.add(callIdMap.get(otherId));
1664 }
1665 }
1666
1667 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1668 mConferenceableCalls.clear();
1669 mConferenceableCalls.addAll(conferenceableCalls);
1670 fireConferenceableCallsChanged();
1671 }
1672
Hall Liu95d55872017-01-25 17:12:49 -08001673 boolean isRttChanged = false;
1674 boolean rttModeChanged = false;
1675 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1676 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1677 InputStreamReader receiveStream = new InputStreamReader(
1678 new ParcelFileDescriptor.AutoCloseInputStream(
1679 parcelableRttCall.getReceiveStream()),
1680 StandardCharsets.UTF_8);
1681 OutputStreamWriter transmitStream = new OutputStreamWriter(
1682 new ParcelFileDescriptor.AutoCloseOutputStream(
1683 parcelableRttCall.getTransmitStream()),
1684 StandardCharsets.UTF_8);
Hall Liu57006aa2017-02-06 10:49:48 -08001685 RttCall newRttCall = new Call.RttCall(mTelecomCallId,
Hall Liu95d55872017-01-25 17:12:49 -08001686 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1687 if (mRttCall == null) {
1688 isRttChanged = true;
1689 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1690 rttModeChanged = true;
1691 }
1692 mRttCall = newRttCall;
1693 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1694 && parcelableCall.getIsRttCallChanged()) {
1695 isRttChanged = true;
1696 mRttCall = null;
1697 }
1698
Ihab Awade63fadb2014-07-09 21:52:04 -07001699 // Now we fire updates, ensuring that any client who listens to any of these notifications
1700 // gets the most up-to-date state.
1701
1702 if (stateChanged) {
1703 fireStateChanged(mState);
1704 }
1705 if (detailsChanged) {
1706 fireDetailsChanged(mDetails);
1707 }
1708 if (cannedTextResponsesChanged) {
1709 fireCannedTextResponsesLoaded(mCannedTextResponses);
1710 }
Andrew Lee50aca232014-07-22 16:41:54 -07001711 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001712 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001713 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001714 if (parentChanged) {
1715 fireParentChanged(getParent());
1716 }
1717 if (childrenChanged) {
1718 fireChildrenChanged(getChildren());
1719 }
Hall Liu95d55872017-01-25 17:12:49 -08001720 if (isRttChanged) {
1721 fireOnIsRttChanged(mRttCall != null, mRttCall);
1722 }
1723 if (rttModeChanged) {
1724 fireOnRttModeChanged(mRttCall.getRttAudioMode());
1725 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001726
1727 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1728 // remove ourselves from the Phone. Note that we do this after completing all state updates
1729 // so a client can cleanly transition all their UI to the state appropriate for a
1730 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1731 if (mState == STATE_DISCONNECTED) {
1732 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001733 }
1734 }
1735
1736 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001737 final void internalSetPostDialWait(String remaining) {
1738 mRemainingPostDialSequence = remaining;
1739 firePostDialWait(mRemainingPostDialSequence);
1740 }
1741
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001742 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001743 final void internalSetDisconnected() {
1744 if (mState != Call.STATE_DISCONNECTED) {
1745 mState = Call.STATE_DISCONNECTED;
1746 fireStateChanged(mState);
1747 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001748 }
1749 }
1750
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001751 /** {@hide} */
1752 final void internalOnConnectionEvent(String event, Bundle extras) {
1753 fireOnConnectionEvent(event, extras);
1754 }
1755
Hall Liu95d55872017-01-25 17:12:49 -08001756 /** {@hide} */
1757 final void internalOnRttUpgradeRequest(final int requestId) {
1758 for (CallbackRecord<Callback> record : mCallbackRecords) {
1759 final Call call = this;
1760 final Callback callback = record.getCallback();
1761 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
1762 }
1763 }
1764
Hall Liu57006aa2017-02-06 10:49:48 -08001765 /** @hide */
1766 final void internalOnRttInitiationFailure(int reason) {
1767 for (CallbackRecord<Callback> record : mCallbackRecords) {
1768 final Call call = this;
1769 final Callback callback = record.getCallback();
1770 record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
1771 }
1772 }
1773
Andrew Lee011728f2015-04-23 15:47:06 -07001774 private void fireStateChanged(final int newState) {
1775 for (CallbackRecord<Callback> record : mCallbackRecords) {
1776 final Call call = this;
1777 final Callback callback = record.getCallback();
1778 record.getHandler().post(new Runnable() {
1779 @Override
1780 public void run() {
1781 callback.onStateChanged(call, newState);
1782 }
1783 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001784 }
1785 }
1786
Andrew Lee011728f2015-04-23 15:47:06 -07001787 private void fireParentChanged(final Call newParent) {
1788 for (CallbackRecord<Callback> record : mCallbackRecords) {
1789 final Call call = this;
1790 final Callback callback = record.getCallback();
1791 record.getHandler().post(new Runnable() {
1792 @Override
1793 public void run() {
1794 callback.onParentChanged(call, newParent);
1795 }
1796 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001797 }
1798 }
1799
Andrew Lee011728f2015-04-23 15:47:06 -07001800 private void fireChildrenChanged(final List<Call> children) {
1801 for (CallbackRecord<Callback> record : mCallbackRecords) {
1802 final Call call = this;
1803 final Callback callback = record.getCallback();
1804 record.getHandler().post(new Runnable() {
1805 @Override
1806 public void run() {
1807 callback.onChildrenChanged(call, children);
1808 }
1809 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001810 }
1811 }
1812
Andrew Lee011728f2015-04-23 15:47:06 -07001813 private void fireDetailsChanged(final Details details) {
1814 for (CallbackRecord<Callback> record : mCallbackRecords) {
1815 final Call call = this;
1816 final Callback callback = record.getCallback();
1817 record.getHandler().post(new Runnable() {
1818 @Override
1819 public void run() {
1820 callback.onDetailsChanged(call, details);
1821 }
1822 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001823 }
1824 }
1825
Andrew Lee011728f2015-04-23 15:47:06 -07001826 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1827 for (CallbackRecord<Callback> record : mCallbackRecords) {
1828 final Call call = this;
1829 final Callback callback = record.getCallback();
1830 record.getHandler().post(new Runnable() {
1831 @Override
1832 public void run() {
1833 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1834 }
1835 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001836 }
1837 }
1838
Andrew Lee011728f2015-04-23 15:47:06 -07001839 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1840 for (CallbackRecord<Callback> record : mCallbackRecords) {
1841 final Call call = this;
1842 final Callback callback = record.getCallback();
1843 record.getHandler().post(new Runnable() {
1844 @Override
1845 public void run() {
1846 callback.onVideoCallChanged(call, videoCall);
1847 }
1848 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001849 }
1850 }
1851
Andrew Lee011728f2015-04-23 15:47:06 -07001852 private void firePostDialWait(final String remainingPostDialSequence) {
1853 for (CallbackRecord<Callback> record : mCallbackRecords) {
1854 final Call call = this;
1855 final Callback callback = record.getCallback();
1856 record.getHandler().post(new Runnable() {
1857 @Override
1858 public void run() {
1859 callback.onPostDialWait(call, remainingPostDialSequence);
1860 }
1861 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001862 }
1863 }
1864
1865 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001866 /**
1867 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1868 * onCallRemoved callback, we remove this call from the Phone's record
1869 * only once all of the registered onCallDestroyed callbacks are executed.
1870 * All the callbacks get removed from our records as a part of this operation
1871 * since onCallDestroyed is the final callback.
1872 */
1873 final Call call = this;
1874 if (mCallbackRecords.isEmpty()) {
1875 // No callbacks registered, remove the call from Phone's record.
1876 mPhone.internalRemoveCall(call);
1877 }
1878 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001879 final Callback callback = record.getCallback();
1880 record.getHandler().post(new Runnable() {
1881 @Override
1882 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001883 boolean isFinalRemoval = false;
1884 RuntimeException toThrow = null;
1885 try {
1886 callback.onCallDestroyed(call);
1887 } catch (RuntimeException e) {
1888 toThrow = e;
1889 }
1890 synchronized(Call.this) {
1891 mCallbackRecords.remove(record);
1892 if (mCallbackRecords.isEmpty()) {
1893 isFinalRemoval = true;
1894 }
1895 }
1896 if (isFinalRemoval) {
1897 mPhone.internalRemoveCall(call);
1898 }
1899 if (toThrow != null) {
1900 throw toThrow;
1901 }
Andrew Lee011728f2015-04-23 15:47:06 -07001902 }
1903 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001904 }
1905 }
1906
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001907 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001908 for (CallbackRecord<Callback> record : mCallbackRecords) {
1909 final Call call = this;
1910 final Callback callback = record.getCallback();
1911 record.getHandler().post(new Runnable() {
1912 @Override
1913 public void run() {
1914 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1915 }
1916 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001917 }
1918 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001919
1920 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001921 * Notifies listeners of an incoming connection event.
1922 * <p>
1923 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1924 *
1925 * @param event
1926 * @param extras
1927 */
1928 private void fireOnConnectionEvent(final String event, final Bundle extras) {
1929 for (CallbackRecord<Callback> record : mCallbackRecords) {
1930 final Call call = this;
1931 final Callback callback = record.getCallback();
1932 record.getHandler().post(new Runnable() {
1933 @Override
1934 public void run() {
1935 callback.onConnectionEvent(call, event, extras);
1936 }
1937 });
1938 }
1939 }
1940
1941 /**
Hall Liu95d55872017-01-25 17:12:49 -08001942 * Notifies listeners of an RTT on/off change
1943 *
1944 * @param enabled True if RTT is now enabled, false otherwise
1945 */
1946 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
1947 for (CallbackRecord<Callback> record : mCallbackRecords) {
1948 final Call call = this;
1949 final Callback callback = record.getCallback();
1950 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
1951 }
1952 }
1953
1954 /**
1955 * Notifies listeners of a RTT mode change
1956 *
1957 * @param mode The new RTT mode
1958 */
1959 private void fireOnRttModeChanged(final int mode) {
1960 for (CallbackRecord<Callback> record : mCallbackRecords) {
1961 final Call call = this;
1962 final Callback callback = record.getCallback();
1963 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
1964 }
1965 }
1966
1967 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001968 * Determines if two bundles are equal.
1969 *
1970 * @param bundle The original bundle.
1971 * @param newBundle The bundle to compare with.
1972 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1973 */
1974 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1975 if (bundle == null || newBundle == null) {
1976 return bundle == newBundle;
1977 }
1978
1979 if (bundle.size() != newBundle.size()) {
1980 return false;
1981 }
1982
1983 for(String key : bundle.keySet()) {
1984 if (key != null) {
1985 final Object value = bundle.get(key);
1986 final Object newValue = newBundle.get(key);
1987 if (!Objects.equals(value, newValue)) {
1988 return false;
1989 }
1990 }
1991 }
1992 return true;
1993 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001994}